如何使用 sparql 查询仅获取值 "Tuýp_2" 并删除 URIRef link "http://www.semanticweb.org/ngocv/ontologies/2020/5/hotrobenhtieuduong#Tuýp_2"

How to get only value "Tuýp_2" with sparql query and remove URIRef link "http://www.semanticweb.org/ngocv/ontologies/2020/5/hotrobenhtieuduong#Tuýp_2"

我是 rdflib 新手 我试图只获取值 Tuýp_2,不包括 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)

在 protege 中尝试的查询“test”的结果很好result picture

当我使用 graph.query 它 return 值包括 iri

我也试过 SELECT (str(?b) as ?a) 但结果还是一样 我认为问题是我不太了解在 rdflib

中使用 graph.query 获取价值

请帮我查询一下值

解决了

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)}