SPARQL Construct. How to assign the value of an RDF attribute to an actual RDF variable

本秂侑毒 提交于 2019-12-11 07:36:26

问题


My query (excerpt) is roughly this.

CONSTRUCT {
?publication fb:type ?type;
fb:publicationType ?publicationType;
}
WHERE 
{
?publication a bibo:Document .
?publication vitro:mostSpecificType ?publicationType .
}

And it returns output similar to...

<rdf:Description rdf:about="https://abcd.fgh/individual/publication12345">
    <fb:publication>Example pub title</fb:publication>
    <fb:publicationType rdf:resource="http://purl.org/ontology/bibo/AcademicArticle"/>
</rdf:Description>

Perhaps a beginner-esque question, but how do I tweak the query such that the output is:

<rdf:Description rdf:about="https://abcd.fgh/individual/publication12345">
    <fb:publication>Example pub title</fb:publication>
    <fb:publicationType>Academic Article</fb:publicationType>
</rdf:Description>

Thanks


回答1:


On the assumption that the bibo ontology is in the store you're querying, you can use its rdfs:label property in a property path:

CONSTRUCT {
  ?publication fb:type ?type;
    fb:publicationType ?publicationType;
} WHERE {
  ?publication a bibo:Document ;
    vitro:mostSpecificType/rdfs:label ?publicationType .
  FILTER (LANG(?publicationType) = "en")
}

The ?a vitro:mostSpecificType/rdfs:label ?b is shorthand for ?a vitro:mostSpecificType ?something. ?something rdfs:label ?b, without binding the intermediate term.



来源:https://stackoverflow.com/questions/50510748/sparql-construct-how-to-assign-the-value-of-an-rdf-attribute-to-an-actual-rdf-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!