Filter language only if type is literal

This is probably almost the same question as: Filter by language only if the object is a literal

The problem is that the answer there does not work in my case.

I have this query:

SELECT ?property ?value WHERE { <http://dbpedia.org/resource/Facebook> ?property ?value FILTER(STRSTARTS(STR(?property), "http://dbpedia.org/property") || STRSTARTS(STR(?property), "http://dbpedia.org/ontology"))} 

Result at Virtuoso

There you will see a list of properties, including "alexa rating 2" and "abstract" in many languages.

If then I try the proposed solution in the question mentioned above:

 SELECT ?property ?value WHERE { <http://dbpedia.org/resource/Facebook> ?property ?value FILTER(STRSTARTS(STR(?property), "http://dbpedia.org/property") || STRSTARTS(STR(?property), "http://dbpedia.org/ontology")) FILTER(!isLiteral(?value) || langMatches(lang(?value), "EN"))} 

Result at Virtuoso

Now you will see that there is only an English version of "abstract", but "alexa rating 2" and many other non-string values โ€‹โ€‹have disappeared.

Anyone who knows how to get all properties, as in the first query, and then for literals, only filter out the English language?

+7
dbpedia sparql
source share
2 answers

The second query filters literals with a language tag other than English. There are three types of literals in RDF 1.0:

  • simple literals (no data type and language tag)
  • tagged language words (string and language tag)
  • data type literals (lexical form and data type)

So, the Alexa rating, which has a value of 2 , is a literal, and it does not have a language tag, so the language tag is certainly not "EN" (and, more importantly, not match "EN" ; langMatches does a few more complex checks) . You want to filter out literals with tags that are not related to the English language. It's not hard; you just need to add lang(?value) = "" to the filter (since lang returns "" for literals without a language tag):

 SELECT ?property ?value WHERE { <http://dbpedia.org/resource/Facebook> ?property ?value FILTER(STRSTARTS(STR(?property), "http://dbpedia.org/property") || STRSTARTS(STR(?property), "http://dbpedia.org/ontology")) FILTER(!isLiteral(?value) || lang(?value) = "" || langMatches(lang(?value), "EN"))} 

SPARQL Results

The way to read this filter is:

Keep values โ€‹โ€‹that

  • are not literals; or
  • are literals but do not have a language tag; or
  • are literals with a language tag that matches "en".
+9
source share

So you just want to invert the filter condition in the language?

In this case, you just need to invert the langMatches call by adding ! before it adds the not operator to it:

 SELECT ?property ?value WHERE { <http://dbpedia.org/resource/Facebook> ?property ?value FILTER(STRSTARTS(STR(?property), "http://dbpedia.org/property") || STRSTARTS(STR(?property), "http://dbpedia.org/ontology")) FILTER(!isLiteral(?value) || !langMatches(lang(?value), "EN"))} 

Result in DBPedia

With this simple change, the English entries are now eliminated, and I only see entries other than English.

0
source share

All Articles