开发者

how we can create a query based on SPARQL to see the value of some data type property?

I create this query:

PREFIX VB: <http://VBnet#>
SELECT  ?x ?y
WHERE 
{
  ?x VB:HasName ?y
}     

HasName is one datatype property. When I run this query in Protege, system show me just the subject 开发者_JAVA技巧without any value for datatype property. mwans ?y is empty. Also when I run in jena system show me just:(String)

How can I see the value of datatype property the value of ?y?


It depends on the data contained in your RDF document. If the values are typed literals then you can parse the SPARQL result set and ask for the datatype of the values bounded to ?y variable. If the values are rendered in a non RDF compliant way (e.g. html) the datatype may not appear. Otherwise you'll see something like this:

<sparql xmlns="http://www.w3.org/2005/sparql-results#"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://www.w3.org/2001/sw/DataAccess/rf1/result2.xsd">
<head>
<variable name="y"/>
</head>
<results distinct="false" ordered="true">
 <result>
   <binding name="y"><literal xml:lang="en">John</literal></binding> //literals with language
 </result>
 <result>
   <binding name="y"><literal datatype="http://www.w3.org/2001/XMLSchema#integer">30</literal></binding> //typed literals
 </result>
...

For extracting the datatype you need to query the Jena API thou.


Assuming no language tags:

SELECT  ?x ?y (DATATYPE(?y) AS ?dt)

Note that if ?y is a plain literal then DATATYPE return xsd:string but ?y has no ^^ datatype (until RDF 1.1).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜