0

I am using rdflib, to query series of rdf files in which I know that the names have a language tag (when I query in a sparql endpoint), this is a snapshot of my data:

sample data

but when I parse the rdf file in python and extract the 'name' value I only get "Josephus" without the language tag.

I can get the tag separately with something like:

    bind(lang(?name) as ?lan) 

but that doesn't. I need to have the name and its tag when I serialize my graph.

Any suggestions what might cause this lose of information and how I can have my names with their language tags?

It's quite a simple query. Here is my full script:

    import unicodedata
    from rdflib import Namespace, URIRef, Graph , Literal , OWL, RDFS , RDF
    from SPARQLWrapper import SPARQLWrapper2, XML  , JSON , TURTLE
    import os

    sparql = SPARQLWrapper2("http://dbpedia.org/sparql")
    os.chdir('...\Desktop')

    jl = Namespace("http://data.judaicalink.org/ontology/")
    foaf = Namespace("http://xmlns.com/foaf/0.1/")

    graph = Graph()

    spar= ("""
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX owl: <http://www.w3.org/2002/07/owl#>
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX dbpedia: <http://dbpedia.org/resource/>

    SELECT ?occ ?x ?name ?same

    where {

     <http://dbpedia.org/resource/Category:Jewish_historians> rdfs:label ?occ.
      ?x dct:subject <http://dbpedia.org/resource/Category:Jewish_historians>.
      ?x rdfs:label ?name.
      ?x owl:sameAs ?same.
      }
    """)

    sparql.setQuery(spar)
    sparql.setReturnFormat(TURTLE)
    results = sparql.query().convert()

    graph.bind('jl', jl)
    graph.bind('foaf',foaf)

    if (u"x",u"name",u"occ",u"same") in results:
      bindings = results[u"x",u"name",u"occ",u"same"]
      for b in bindings:

        graph.add( (URIRef(b[u"x"].value), RDF.type , foaf.Person ) )
        graph.add( (URIRef(b[u"x"].value), jl.hasLabel, Literal(b[u"name"].value) ) )

        graph.serialize(destination= 'output.rdf' , format="turtle")
DMD
  • 103
  • 1
  • 8

0 Answers0