Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gravsearch: filter inside Optional is ignored #879

Closed
tobiasschweizer opened this issue Jun 5, 2018 · 1 comment
Closed

Gravsearch: filter inside Optional is ignored #879

tobiasschweizer opened this issue Jun 5, 2018 · 1 comment
Assignees
Labels
API/V2 bug something isn't working
Milestone

Comments

@tobiasschweizer
Copy link
Contributor

Consider the following query:

PREFIX beol: <http://0.0.0.0:3333/ontology/0801/beol/simple/v2#>
PREFIX knora-api: <http://api.knora.org/ontology/knora-api/simple/v2#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

    CONSTRUCT {
        ?letter knora-api:isMainResource true .

        ?letter beol:creationDate ?date .

        ?letter ?linkingProp1  ?person1 .

        ?person1 beol:hasFamilyName ?name .

    } WHERE {
        ?letter a knora-api:Resource .
        ?letter a beol:letter .

        ?letter beol:creationDate ?date .

        beol:creationDate knora-api:objectType knora-api:Date .
        ?date a knora-api:Date .

        ?letter ?linkingProp1 ?person1 .

        ?person1 a knora-api:Resource .

        ?linkingProp1 knora-api:objectType knora-api:Resource .
        FILTER(?linkingProp1 = beol:hasAuthor || ?linkingProp1 = beol:hasRecipient )

      	OPTIONAL {
        ?person1 beol:hasFamilyName ?name .

        beol:hasFamilyName knora-api:objectType xsd:string .
        ?name a xsd:string .

        FILTER(?name = "Meier")
    }

    } ORDER BY ?date

The prequery looks like follows:

 SELECT DISTINCT ?letter (GROUP_CONCAT(DISTINCT(?person1); SEPARATOR='') AS ?person1Concat) (GROUP_CONCAT(DISTINCT(?date); SEPARATOR='') AS ?dateConcat) (GROUP_CONCAT(DISTINCT(?name); SEPARATOR='') AS ?nameConcat) (GROUP_CONCAT(DISTINCT(?person1__LinkValue); SEPARATOR='') AS ?person1__LinkValueConcat)
 WHERE {
 ?letter <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.knora.org/ontology/knora-base#Resource> .
 GRAPH <http://www.ontotext.com/explicit> {
     ?letter <http://www.knora.org/ontology/knora-base#isDeleted> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
 }
 ?letter <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.knora.org/ontology/0801/beol#letter> .
 ?letter <http://www.knora.org/ontology/0801/beol#creationDate> ?date .
 GRAPH <http://www.ontotext.com/explicit> {
     ?date <http://www.knora.org/ontology/knora-base#isDeleted> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
 }
 ?letter ?linkingProp1 ?person1 .
 ?letter ?linkingProp1__hasLinkToValue ?person1__LinkValue .
 GRAPH <http://www.ontotext.com/explicit> {
     ?person1__LinkValue <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.knora.org/ontology/knora-base#LinkValue> .
 }
 GRAPH <http://www.ontotext.com/explicit> {
     ?person1__LinkValue <http://www.knora.org/ontology/knora-base#isDeleted> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
 }
 GRAPH <http://www.ontotext.com/explicit> {
     ?person1__LinkValue <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> ?letter .
 }
 GRAPH <http://www.ontotext.com/explicit> {
     ?person1__LinkValue <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> ?person1 .
 }
 ?person1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.knora.org/ontology/knora-base#Resource> .
 GRAPH <http://www.ontotext.com/explicit> {
     ?person1 <http://www.knora.org/ontology/knora-base#isDeleted> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
 }
 OPTIONAL {
 ?person1 <http://www.knora.org/ontology/0801/beol#hasFamilyName> ?name .
 GRAPH <http://www.ontotext.com/explicit> {
     ?name <http://www.knora.org/ontology/knora-base#isDeleted> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
 }
 }
 FILTER((((?linkingProp1 = <http://www.knora.org/ontology/0801/beol#hasAuthor>) && (?linkingProp1__hasLinkToValue = <http://www.knora.org/ontology/0801/beol#hasAuthorValue>)) || ((?linkingProp1 = <http://www.knora.org/ontology/0801/beol#hasRecipient>) && (?linkingProp1__hasLinkToValue = <http://www.knora.org/ontology/0801/beol#hasRecipientValue>))))
 GRAPH <http://www.ontotext.com/explicit> {
     ?date <http://www.knora.org/ontology/knora-base#valueHasStartJDN> ?date__valueHasStartJDN .
 }
 }
 
 GROUP BY ?letter ?date__valueHasStartJDN
 ORDER BY ASC(?date__valueHasStartJDN) ASC(?letter)
 OFFSET 0
 LIMIT 25

The filter inside the OPTIONAL is not regenerated in the prequery.

The result is this:

{
  "@id" : "http://rdfh.ch/0801/_B3lQa6tSymIq7_7SowBsA",
  "@type" : "beol:letter",
  "beol:creationDate" : {
    "@id" : "http://rdfh.ch/0801/_B3lQa6tSymIq7_7SowBsA/values/L2gv0paYSymiENk1c0fAAQ",
    "@type" : "knora-api:DateValue",
    "knora-api:dateValueHasCalendar" : "GREGORIAN",
    "knora-api:dateValueHasEndDay" : 4,
    "knora-api:dateValueHasEndEra" : "CE",
    "knora-api:dateValueHasEndMonth" : 6,
    "knora-api:dateValueHasEndYear" : 2018,
    "knora-api:dateValueHasStartDay" : 4,
    "knora-api:dateValueHasStartEra" : "CE",
    "knora-api:dateValueHasStartMonth" : 6,
    "knora-api:dateValueHasStartYear" : 2018,
    "knora-api:valueAsString" : "GREGORIAN:2018-06-04 CE"
  },
  "beol:hasAuthorValue" : {
    "@id" : "http://rdfh.ch/0801/_B3lQa6tSymIq7_7SowBsA/values/Cvp07eTqQQSnYdcvqlWW_g",
    "@type" : "knora-api:LinkValue",
    "knora-api:linkValueHasTarget" : {
      "@id" : "http://rdfh.ch/0801/VvYVIy-FSbOJBsh2d9ZFJw",
      "@type" : "beol:person",
      "beol:hasFamilyName" : {
        "@id" : "http://rdfh.ch/0801/VvYVIy-FSbOJBsh2d9ZFJw/values/5K24YxlwQ9OXcYjB0jRR4Q",
        "@type" : "knora-api:TextValue",
        "knora-api:valueAsString" : "Meier"
      },
      "rdfs:label" : "Testperson2"
    }
  },
  "beol:hasRecipientValue" : {
    "@id" : "http://rdfh.ch/0801/_B3lQa6tSymIq7_7SowBsA/values/DVqPKuBBSIauVqjUC7bNvA",
    "@type" : "knora-api:LinkValue",
    "knora-api:linkValueHasTarget" : {
      "@id" : "http://rdfh.ch/0801/H7s3FmuWTkaCXa54eFANOA",
      "@type" : "beol:person",
      "beol:hasFamilyName" : {
        "@id" : "http://rdfh.ch/0801/H7s3FmuWTkaCXa54eFANOA/values/7LhL_JdpTA-E0oQ1hdtPDQ",
        "@type" : "knora-api:TextValue",
        "knora-api:valueAsString" : "Muster"
      },
      "rdfs:label" : "Testperson1"
    }
  },
  "rdfs:label" : "Testbrief1",
  "@context" : {
    "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
    "knora-api" : "http://api.knora.org/ontology/knora-api/v2#",
    "beol" : "http://0.0.0.0:3333/ontology/0801/beol/v2#"
  }
}

I would expect that the name is only returned if it is "Meier". But therefore we need the filter.

@benjamingeer
Copy link

The parser never returns the FILTER in the OPTIONAL. Let me see if I can find out why.

@benjamingeer benjamingeer added this to the v1.6.0 milestone Jun 5, 2018
benjamingeer pushed a commit that referenced this issue Jun 5, 2018
* fix (Gravsearch): Allow the use of the lang function in an AND or OR.

- Require the match function to be the top-level expression in a FILTER.
- Rename things to use the name Gravsearch.

* feature (webapi): Accept Gravsearch queries as POST requests.

* docs (webapi): Update README.md.

* feature (webapi): Accept Gravsearch queries where the main resource is an IRI (ongoing).

* feature (webapi): Undo first attempt at accepting Gravsearch query with IRI for main resource.

* tests (gravsearch): add tests involving dcterms properties

* fix (gravsearch): Don't use IRIs from type inspector to check for presence of dependent resources.

* tests (gravsearch): add tests for link objects

* tests (gravsearch): add a test for a variable representing a property and restrict it with a filter

* feature (gravsearch): Allow BIND in Gravsearch.

* test (gravsearch): Add test for BIND.

* feature (gravsearch): Use DISTINCT in GROUP_CONCAT.

* tests (gravsearch): search for a person using foaf entities

* feature (gravsearch): If object of statement is variable also used in ORDER BY, ensure subject is main resource.

* fix (incoming links): handle case of several instances of a property

* tests (gravsearch): check for several incoming links

* tests (gravserach): remove comments

* tests (gravsearch): add test data

* tests (gravsearch): add a test for multi-level references

* tests (gravsearch): add test for a letter that links to a person with a certain name

* fix (webapi): Fix parsing of FILTER in OPTIONAL (#879).

* tests (gravsearch): add test with filter in an Optional clause

* docs (gravsearch): Update docs and release notes.

* docs (gravsearch): Fix typo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API/V2 bug something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants