如何在 SPARQL 中过滤 DBpedia 结果

How to filter DBpedia results in SPARQL

我有个小问题... 如果我有这个简单的 SPARQL 查询

SELECT ?abstract 
WHERE {
<http://dbpedia.org/resource/Mitsubishi> <http://dbpedia.org/ontology/abstract> ?abstract.
FILTER langMatches( lang(?abstract), 'en')}

我有这样的结果: SPARQL Result 它有一个非英语字符... 有什么想法可以删除它们并只检索英文单词吗?

您需要准确定义结果中需要和不需要的字符,但您可以使用 replace 将范围外的字符替换为,例如, 空字符串。如果您想排除除 Basic Latin、Latin-1 Supplement、Latin Extended-A 和 Latin Extended-B 范围之外的所有范围(最终为 \u0000–\u024f),您可以执行以下操作:

SELECT ?abstract ?cleanAbstract
WHERE {
  dbpedia:Mitsubishi dbpedia-owl:abstract ?abstract 
  FILTER langMatches( lang(?abstract), 'en')
  bind(replace(?abstract,"[^\x{0000}-\x{024f}]","") as ?cleanAbstract)
}

SPARQL results

或者更简单:

SELECT (replace(?abstract_,"[^\x{0000}-\x{024f}]","") as ?abstract)
WHERE {
  dbpedia:Mitsubishi dbpedia-owl:abstract ?abstract_
  FILTER langMatches(lang(?abstract_), 'en')
}

SPARQL results

The Mitsubishi Group (, Mitsubishi Gurūpu) (also known as the Mitsubishi Group of Companies or Mitsubishi Companies) is a group of autonomous Japanese multinational companies covering a range of businesses which share the Mitsubishi brand, trademark, and legacy.The Mitsubishi group of companies form a loose entity, the Mitsubishi Keiretsu, which is often referenced in Japanese and US media and official reports; in general these companies all descend from the zaibatsu of the same name. The top 25 companies are also members of the Mitsubishi Kin'yōkai, or "Friday Club", and meet monthly. In addition the Mitsubishi.com Committee exists to facilitate communication and access of the Mitsubishi brand through a portal web site.

您可能会发现 Latin script in Unicode 维基百科文章很有用。