我在处理数字数据类型时遇到SPARQL问题。
我有一个本体论(http://cabas.ugr.es/ontology/ugr),其中我定义了一对属性,代表了特定性别的学生人数:
<http://cabas.ugr.es/ontology/ugr#hombres>
a owl:DatatypeProperty, owl:FunctionalProperty, rdf:Property ;
rdfs:label
"hombres"@es,
"men"@en ;
rdfs:comment
"Número de estudiantes hombres."@es,
"Number of male students."@en ;
rdfs:range xsd:nonNegativeInteger ;
rdfs:isDefinedBy <http://cabas.ugr.es/ontology/ugr#> ;
owl:sameAs <http://cabas.ugr.es/ontology/ugr#hombres> ;
owl:inverseOf <http://cabas.ugr.es/ontology/ugr#mujeres> ;
ns1:term_status "stable" .
<http://cabas.ugr.es/ontology/ugr#mujeres>
a owl:DatatypeProperty, owl:FunctionalProperty, rdf:Property ;
rdfs:label
"mujeres"@es,
"women"@en ;
rdfs:comment
"Número de estudiantes mujeres."@es,
"Number of female students."@en ;
rdfs:range xsd:nonNegativeInteger ;
rdfs:isDefinedBy <http://cabas.ugr.es/ontology/ugr#> ;
owl:sameAs <http://cabas.ugr.es/ontology/ugr#mujeres> ;
owl:inverseOf <http://cabas.ugr.es/ontology/ugr#hombres> ;
ns1:term_status "stable" .
我在Virtuoso(http://cabas.ugr.es:8890/sparql)上安装了SPARQL端点,我在其中输入以下查询:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ugr: <http://cabas.ugr.es/ontology/ugr#>
SELECT ?X ?titulacion ?rama ?hombres ?mujeres
WHERE {
?X ugr:Titulación ?titulacion .
?X ugr:RamaConocimiento ?rama .
?X ugr:hombres ?hombres .
?X ugr:mujeres ?mujeres
}
(与this link对应)
它返回所有记录,但字段&#34; hombres&#34; 和&#34; mujeres&#34; 将它们返回给我,就好像它一样是字符串而不是数字值,因此例如,不可能应用像FILTER (?hombres > 500)
这样的过滤器。知道我错了什么吗?
顺便说一句,可以通过以下链接访问本体和具有值的资源:
本体:
资源:
答案 0 :(得分:5)
In order to treat the numbers as numbers, you need to define them as such.
Right now you define them as strings:
<http://cabas.ugr.es/resources/MatriculasGrado1516#21>
ns0:hombres "91" ;
ns0:mujeres "68" .
To define them as integers, you need to set their type to xsd:integer
:
<http://cabas.ugr.es/resources/MatriculasGrado1516#21>
ns0:hombres "91"^^xsd:integer ;
ns0:mujeres "68"^^xsd:integer .
Strings can also be cast to integer in queries, if needed. For example:
FILTER(xsd:integer(?hombres) > 500)