带过滤器的SPARQL前缀

时间:2017-05-24 13:07:26

标签: xml sparql

我正在尝试在data.admin.ch中使用SPARQL查询:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT distinct (?z as ?Variable) (?ptype as ?Bevoelkerungstyp) (?remuniuri as ?Meldegmeinde) ?age ?sex ?person
where  
{ 
?z <http://data.admin.ch/bfs/property/POPULATIONTYPE> ?ptype. 
?z <http://data.admin.ch/bfs/property/REPORTINGMUNICIPALITYID> ?remuniuri. 
?z <http://data.admin.ch/bfs/property/AGE> ?age.
?z <http://data.admin.ch/bfs/property/SEX> ?sex.

我需要将年龄限制在7-22,但它不起作用。

我试过了:

SELECT distinct (SUM(xsd:int(?number)) AS ?child_inhabitants) WHERE 

然后使用过滤器:

FILTER ((xsd:int(?pnumber)) <= 22 && (xsd:int(?agenumber)) <= 7) 

1 个答案:

答案 0 :(得分:2)

  • 您的查询似乎缺少结束}
  • 您的两个年龄段过滤器都小于
  • 如何?数字,?pnumber或?agenumber绑定到查询的顶部?

替代斯坦尼斯拉夫的答案,它不使用任何字符串操作

PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
PREFIX  skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT  *
WHERE
  { ?z    <http://data.admin.ch/bfs/property/POPULATIONTYPE>  ?ptype ;
          <http://data.admin.ch/bfs/property/REPORTINGMUNICIPALITYID>  ?remuniuri ;
          <http://data.admin.ch/bfs/property/AGE>  ?age ;
          <http://data.admin.ch/bfs/property/SEX>  ?sex .
    ?age  skos:notation         ?ageval
    FILTER ( ( xsd:int(?ageval) <= 22 ) && ( xsd:int(?ageval) >= 7 ) )
  }
LIMIT   99