Muhammad Qasim
Muhammad Qasim

Reputation: 3

Import data from DBPedia into GraphDB

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.

Upvotes: 0

Views: 1164

Answers (1)

vassil_momtchev
vassil_momtchev

Reputation: 1193

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.

Upvotes: 2

Related Questions