如何在 SPARQL 中通过 url 前缀过滤查询结果?

How to filter query results by url prefix in SPARQL?

这是我的查询,

PREFIX dbr: <http://dbpedia.org/resource/>

SELECT ?p ?x
WHERE
{ 
  dbr:Australia ?p ?x 
}

我只需要结果中的 URI。 xp应该是http://dbpedia.org/resource/somethinghttp://dbpedia.org/property/something的格式。请帮我解决这个问题。

This will get what you're asking for--

PREFIX dbr: <http://dbpedia.org/resource/>

SELECT ?p ?x
WHERE
{ 
  dbr:Australia ?p ?x 
  FILTER ( STRSTARTS ( STR ( ?p ), "http://dbpedia.org/property/" ) )
  FILTER ( STRSTARTS ( STR ( ?x ), "http://dbpedia.org/resource/" ) )
}
ORDER BY ?p ?x

results of the following might be better, though it doesn't restrict all URIs to the two prefixes you've wished for. Note that the next update of the DBpedia dataset (partially visible now on the DBpedia-Live endpoint) 将更改大部分数据,http://dbpedia.org/property/ 将不再是澳大利亚大多数 attributes/predicates --

的前缀
PREFIX dbr: <http://dbpedia.org/resource/>

SELECT ?p ?x
WHERE
{ 
  dbr:Australia ?p ?x 
  FILTER ( ISURI ( ?p ) )
  FILTER ( ISURI ( ?x ) )
}
ORDER BY ?p ?x