-1

I'm new to rdflib I trying to get only the value Tuýp_2, not include the IRI http://www.semanticweb.org/ngocv/ontologies/2020/5/hotrobenhtieuduong#Tuýp_2

def testontology():
    test = """PREFIX : <http://www.semanticweb.org/ngocv/ontologies/2020/5/hotrobenhtieuduong#> SELECT ?a   WHERE { <http://www.semanticweb.org/ngocv/ontologies/2020/5/hotrobenhtieuduong#Benhnhan001>:coLoaiTieuDuong ?a}"""
    r = list(graph.query(test))
    for item in r:
        result = str(item['a'])
    return render_template("testontology.html", values=result)

The result from the query "test" tried in protege is good result picture

when I use graph.query it return the value included the iri

I tried with SELECT (str(?b) as ?a) as well but the result still the same I think the problem is I dont know much about get value with graph.query in rdflib

Please help me to query the value

ngocvy
  • 11
  • 3
  • what you want is the local form of a URI. Protege does this in a post processing rendering, but this isn't part of SPARQL itself. It's just a matter of your client code. Indeed, if you know that the namespace is always the same `http://www.semanticweb.org/ngocv/ontologies/2020/5/hotrobenhtieuduong#` - you can simply use the string after it: `bind(strafter(str(?a), "http://www.semanticweb.org/ngocv/ontologies/2020/5/hotrobenhtieuduong#") as ?aTxt)` and use the new variable – UninformedUser Aug 14 '20 at 07:50
  • Thanks you so much <3 Now i'm know that i can do more things with [xpath](https://www.w3.org/2005/xpath-functions/#fo-summary) function – ngocvy Aug 14 '20 at 08:51

1 Answers1

0

Solved with

PREFIX : <http://www.semanticweb.org/ngocv/ontologies/2020/5/hotrobenhtieuduong#> 
SELECT ?aTxt ?a   WHERE { <http://www.semanticweb.org/ngocv/ontologies/2020/5/hotrobenhtieuduong#Benhnhan001>:coLoaiTieuDuong ?a}.
bind(strafter(str(?a),"http://www.semanticweb.org/ngocv/ontologies/2020/5/hotrobenhtieuduong#") as ?aTxt)}
ngocvy
  • 11
  • 3