2017-06-19 130 views
1

我在处理数字数据类型时遇到SPARQL问题。由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" . 

我已经安装在炫技一个SPARQL端点(http://cabas.ugr.es:8890/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对应)

它返回所有记录,但字段“hombres”“mujeres”将它们返回给我,就好像它是一个字符串而不是数字值,因此例如不可能应用像FILTER (?hombres > 500)这样的过滤器。任何想法我错了什么?

顺便说一句,本体与价值的资源是可通过这些链接:

+1

定义属性的范围是不够的。这也将通过将数据类型添加到每个文字来反映在实例数据中:':x:hombres“352”' - >':x:hombres“352”^^ xsd:nonNegativeInteger' – AKSW

回答

5

为了治疗的人数为数字,你需要将它们定义为此类。

现在你将它们定义为字符串:

<http://cabas.ugr.es/resources/MatriculasGrado1516#21> 
    ns0:hombres "91" ; 
    ns0:mujeres "68" . 

其定义为整数,你需要将其类型设置为xsd:integer

<http://cabas.ugr.es/resources/MatriculasGrado1516#21> 
    ns0:hombres "91"^^xsd:integer ; 
    ns0:mujeres "68"^^xsd:integer . 

字符串也可以转换为整数查询, 如果需要的话。例如:

FILTER(xsd:integer(?hombres) > 500) 
+0

这就是我需要添加的全部内容使其工作。谢谢! – germaaan