linkeddata / rdflib.js

Linked Data API for JavaScript
http://linkeddata.github.io/rdflib.js/doc/
Other
564 stars 143 forks source link

SPARQL filter #535

Open sinanatra opened 2 years ago

sinanatra commented 2 years ago

Which SPARQL filter are supported now?

FILTER(contains(?var, "value to match)) does not filter anything.

TallTed commented 2 years ago

Well... You're missing a closing quotation mark. But maybe this isn't the FILTER clause you're actually using. So maybe show us the clause you're actually using, and the value you're expecting it to match?

sinanatra commented 2 years ago

ops, yes it should have been FILTER(contains(?var, "value to match")). Anyway, i want to filter all the E12_Production which contains a specific string in the P3_has_note, e.g. Datierung Kleidung. This is the property in my turtle

@prefix crm: <http://erlangen-crm.org/200717/>.

<_:b2>
    a crm:E12_Production;
    crm:P3_has_note
    "Datierung Kleidung (Modewissenschaftliche Einsch\\u00e4tzung)";
    crm:P4_has_time-span <_:b3>;
    crm:P70i_is_documented_in items:6076.
<_:b3> a crm:E52_Time-Span; crm:P82_at_some_time_within "01.01.1550 - 31.12.1599".

Launching this query i don't get any filtering:

PREFIX crm: <http://erlangen-crm.org/200717/>.
SELECT *
WHERE {
   ?productionEvent a crm:E12_Production ;
    crm:P4_has_time-span  ?timeSpan .

    ?productionEvent a crm:E12_Production ;
    crm:P3_has_note ?note 
    FILTER(contains(?note, "Datierung Kleidung")) .

    ?timeSpan  crm:P82_at_some_time_within ?time . 
}
Screenshot 2021-12-15 at 09 40 57
TallTed commented 2 years ago

OK, that looks more like what I was expecting to see, and it does look like you should get the desired result. What is the target SPARQL engine (name, version, and platform; all may matter)? Is it a publicly accessible endpoint (such that we can experiment)?

sinanatra commented 2 years ago

So far it's not public. I am fetching data from the API (structured in json-ld) of our Omeka S server, which i then parse with $rdf.parse and i am now trying to query with $rdf.SPARQLToQuery.

TallTed commented 2 years ago

My best guess from the limited information at hand is a bug in the SPARQL processor. A log from it, and possibly logs from any other components involved that can produce them, may help confirm that and/or pinpoint what the issue is.

jeff-zucker commented 2 years ago

The SPARQL engine in rdflib is not fully SPARQL 1.1 compliant and is also, unfortunately, not very well documented. It does NOT support Filter.

sinanatra commented 2 years ago

is the support planned for the future?

jeff-zucker commented 2 years ago

We are considering options on SPARQL, possibly piggy-backing on another engine such as @RubenVerborgh's SPARQL.js . Rdflib's parsing may be weak but excels in loading (handles CORS, alternate formats) and following (loading all documents in a query, not assuming a single triplestore). It's possible to use comunica or sparql.js in conjunction with rdlib though it requires some dumping of quads from one format to the other. But no, sorry, no specific plans on FILTER.

RubenVerborgh commented 2 years ago

@jeff-zucker That's great. Note that both the loading and the link following are part of Comunica as well. Comunica has extended format support (also parsing JSON-LD inside of HTML, for instance) and extensive configurations for different kinds of traversal. So I can recommend it for more advanced SPARQL queries.