ger*_*aan 1 rdf semantic-web ontology sparql linked-data
处理数值数据类型时,我遇到了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" .
Run Code Online (Sandbox Code Playgroud)
我在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
}
Run Code Online (Sandbox Code Playgroud)
(这与此链接相对应)
它返回所有记录,但字段"hombres"和"mujeres"将它们返回给我,好像它是一个字符串而不是数字值,所以例如,不可能应用像这样的过滤器FILTER (?hombres > 500).知道我错了什么吗?
顺便说一下,可以通过以下链接访问本体和具有值的资源:
本体论:
资源:
为了将数字视为数字,您需要将它们定义为数字.
现在你将它们定义为字符串:
<http://cabas.ugr.es/resources/MatriculasGrado1516#21>
ns0:hombres "91" ;
ns0:mujeres "68" .
Run Code Online (Sandbox Code Playgroud)
要将它们定义为整数,您需要将其类型设置为xsd:integer:
<http://cabas.ugr.es/resources/MatriculasGrado1516#21>
ns0:hombres "91"^^xsd:integer ;
ns0:mujeres "68"^^xsd:integer .
Run Code Online (Sandbox Code Playgroud)
如果需要,字符串也可以在查询中强制转换为整数.例如:
FILTER(xsd:integer(?hombres) > 500)
Run Code Online (Sandbox Code Playgroud)