0

I am basically looking to use a SPARQL construct query to retrieve data from DBPEdia to a local version of GraphDB. The construct query should be able to map to as many relations and data related to music. I have tried running construct queries within the GraphDB Workbench but I am not exactly sure how to go about it.

In the online tutorials for GraphDB, they always import data using a file or an online resource, and I could not find any example where they get data directly in the database by using a construct query.

Any advice regarding this would be very appreciated. Thanks for taking the time to help.

1 Answer 1

2

GraphDB supports importing data already transformed into RDF data format. The easiest way to import data from an external endpoint like DBPedia is to use SPARQL federation. Here is a sample query that takes data from a remote endpoint and imports it to the currently selected GraphDB repository:

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
INSERT {
    ?s ?p ?o2
}
WHERE {
    # Execute the query against DBPedia's endpoint
    SERVICE <http://dbpedia.org/sparql> {
        SELECT ?s ?p ?o2
        {
            # Select all triples for Madonna
            ?s ?p ?o
            FILTER (?s =  <http://dbpedia.org/resource/Madonna_(entertainer)>)


            # Hacky function to rewrite all Literals of type rdf:langStrings without a language tag
            BIND (
                IF ( 
                    (isLiteral(?o) && datatype(?o) = rdf:langString && lang(?o) = ""), 
                    (STRDT(STR(?o), xsd:string)),
                    ?o
                )
                AS ?o2
            )
        }
    }
}

Unfortunately, DBPedia and the underlying database engine are notorious for not strictly complying with SPARQL 1.1 and RDF 1.1 specifications. The service returns RDF literals of type rdf:langString without a proper language tag:

...
  <result>
   <binding name="s"><uri>http://dbpedia.org/resource/Madonna_(entertainer)</uri></binding>
   <binding name="p"><uri>http://dbpedia.org/property/d</uri></binding>
   <binding name="o"><literal datatype="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString">Q1744</literal></binding>
  </result>
...

The only way to overcome this is to add an extra filter which rewrites them on the fly.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for taking the time to answer the question. I was able to successfully get the data in my local GraphDB instance, I was wondering what the best approach would be to extend and aggregate more data within the same database. I am working on a project as part of which I need to have a local database that contains a good amount of data related to music, which I will be query using the application.
@MuhammadQasim Have a look at LinkedBrainz which is based on MusicBrainz. It has all sorts of music data in RDF format. It has a lag though and the latest dump available is from 12/2017. Available here If you're not strict on using RDF, you can always look at using MusicBrainz directly. There's an API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.