仅当对象是文字时才按语言过滤 [英] Filter by language only if the object is a literal

查看:98
本文介绍了仅当对象是文字时才按语言过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了以下查询:

  SELECT DISTINCT 
?谓词
?object
?label
WHERE {
VALUES?subject {< http://dbpedia.org/resource/Hercules_(1997_film)> }
?subject?predicate?object。
?谓词rdfs:label?label。
FILTER(langMatches(lang(?object),EN))
}
LIMIT 100

当我以这种方式写入 FILTER 行时,我已经过滤掉所有非文字( side问题:



那么,如何保留我的所有结果并过滤掉非英语字面

解决方案

您可以使用 isLiteral 函数仅将语言限制应用于文字对象。 p>

x隐含y 可以用SPARQL运算符表示为!x || y ,因此您可以这样写下您的查询:

  SELECT DISTINCT 
?谓词
?object
?label
WHERE {
VALUES?subject {< http://dbpedia.org/resource/Hercules_(1997_film)> }
?subject?predicate?object。
?谓词rdfs:label?label。
FILTER(!isLiteral(?object)|| langMatches(lang(?object),EN))
}
LIMIT 100
/ pre>

至于您的次要问题,来自RDF概念和摘要的语言标记的描述仅提及作为纯文字的一部分出现的语言标记。同样,SPARQL 1.1规范中的语法使用 LANGTAG 非终止 =http://www.w3.org/TR/sparql11-query/#rRDFLiteral =nofollow> RDFLiteral 生产作为独家替代品而不是数据类型IRI。


I've written the following query:

SELECT DISTINCT
  ?predicate
  ?object
  ?label
WHERE {
  VALUES        ?subject     { <http://dbpedia.org/resource/Hercules_(1997_film)> }
  ?subject      ?predicate   ?object .
  ?predicate    rdfs:label   ?label .
  FILTER(langMatches(lang(?object), "EN"))
}
LIMIT 100

When I write the FILTER line this way, I've essentially filtered out all non-literals (side question: are literals the only type that can have a language tag?)

So, how do I keep all of my results and filter out non-english literals only?

解决方案

You could use the isLiteral function to apply the language restriction only to objects that are literals.

x implies y can be expressed with SPARQL operators as !x || y, so you could write your query like this:

SELECT DISTINCT
  ?predicate
  ?object
  ?label
WHERE {
  VALUES        ?subject     { <http://dbpedia.org/resource/Hercules_(1997_film)> }
  ?subject      ?predicate   ?object .
  ?predicate    rdfs:label   ?label .
  FILTER(!isLiteral(?object) || langMatches(lang(?object), "EN"))
}
LIMIT 100

As for your secondary question, the description for language tags from the RDF concepts and abstracts only mentions language tags to appear as a part of plain literals. Likewise, the grammar in the SPARQL 1.1 specification uses the LANGTAG nonterminal only in the RDFLiteral production as an exclusive alternative instead of a datatype IRI.

这篇关于仅当对象是文字时才按语言过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆