SPARQL-Anything / sparql.anything

SPARQL Anything is a system for Semantic Web re-engineering that allows users to ... query anything with SPARQL.
https://sparql-anything.cc/
Apache License 2.0
222 stars 11 forks source link

bind(somefunctions()) interferes with outer service #241

Open justin2004 opened 2 years ago

justin2004 commented 2 years ago

This works as expected:

PREFIX  fx:   <http://sparql.xyz/facade-x/ns/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX  xyz:  <http://sparql.xyz/facade-x/data/>

SELECT  *
WHERE
  { SERVICE <x-sparql-anything:>
      { SERVICE <x-sparql-anything:>
          { fx:properties
                      fx:command     "echo 4,5,6" ;
                      fx:media-type  "text/csv" .
            ?s        ?p             ?num .
            # BIND(bnode() AS ?bob)           # breaks
            # BIND(struuid() AS ?bob)         # breaks
            # BIND(concat("a","b") AS ?bob)   # works
            # BIND("lala" AS ?bob)            # works
          }
        BIND(concat("seq ", ?num) AS ?second_cmd)
        fx:properties
                  fx:command     ?second_cmd ;
                  fx:media-type  "text/plain" ;
                  fx:txt.split   "\n" .
        ?ss       ?pp            ?oo
      }
  }

but if you uncomment the calls to bind() one at a time some of them cause the outer service to not return any results. That is, all the results come from the inner service.

justin2004 commented 2 years ago

here is the expected output:

s p num bob second_cmd ss pp oo
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_1 4 lala seq 4 _:b1 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#type http://sparql\.xyz/facade\-x/ns/root
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_1 4 lala seq 4 _:b1 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_1 1
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_1 4 lala seq 4 _:b1 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_2 2
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_1 4 lala seq 4 _:b1 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_3 3
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_1 4 lala seq 4 _:b1 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_4 4
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_2 5 lala seq 5 _:b2 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#type http://sparql\.xyz/facade\-x/ns/root
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_2 5 lala seq 5 _:b2 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_1 1
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_2 5 lala seq 5 _:b2 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_2 2
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_2 5 lala seq 5 _:b2 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_3 3
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_2 5 lala seq 5 _:b2 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_4 4
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_2 5 lala seq 5 _:b2 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_5 5
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_3 6 lala seq 6 _:b3 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#type http://sparql\.xyz/facade\-x/ns/root
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_3 6 lala seq 6 _:b3 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_1 1
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_3 6 lala seq 6 _:b3 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_2 2
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_3 6 lala seq 6 _:b3 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_3 3
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_3 6 lala seq 6 _:b3 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_4 4
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_3 6 lala seq 6 _:b3 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_5 5
_:b0 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_3 6 lala seq 6 _:b3 http://www\.w3\.org/1999/02/22\-rdf\-syntax\-ns\#\_6 6
justin2004 commented 2 years ago

The reason I think this should work is that the calls to bind() in this query don't alter the results of the outer service.

PREFIX  xyz:  <http://sparql.xyz/facade-x/data/>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
PREFIX  fx:   <http://sparql.xyz/facade-x/ns/>
PREFIX  ex:   <http://example.com/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX wd:       <http://www.wikidata.org/entity/>         # Wikibase entity - item or property. 
PREFIX wdt:      <http://www.wikidata.org/prop/direct/>    # Truthy assertions about the data, links entity to value directly. 
select *
WHERE
  { SERVICE <https://query.wikidata.org/sparql>
      {
        SERVICE <https://query.wikidata.org/sparql>{
        wd:Q1 wdt:P1889 ?o .
        bind(bnode() as ?a)
        bind(struuid() as ?b)
        }
        ?o ?p wd:Q1426992 .
      }
  } limit 50
luigi-asprino commented 1 year ago

I've investigated a little bit the issue without figuring out the problem! I've just modified the query a bit to make it work, but this is very strange. I doubt that it can depend on sparql anything.

justin2004 commented 1 year ago

I've investigated a little bit the issue without figuring out the problem!

haha. love that cheerfulness.

I doubt that it can depend on sparql anything.

ah, you think it is a jena bug?

enridaga commented 1 year ago

The query posted originally by @justin2004 https://github.com/SPARQL-Anything/sparql.anything/issues/241#issue-1190925086 doesn't work on v0.9-DEV -- I get SO:

$ fx -q issue241_retrying.sparql 
[main] INFO io.github.sparqlanything.model.Triplifier - Running command: bash -c echo 4,5,6
[main] INFO io.github.sparqlanything.model.Triplifier - Command stderr: 
[main] INFO io.github.sparqlanything.model.Triplifier - Running command: bash -c echo 4,5,6
[main] INFO io.github.sparqlanything.model.Triplifier - Command stderr: 
[main] INFO io.github.sparqlanything.model.Triplifier - Running command: bash -c echo 4,5,6
[main] INFO io.github.sparqlanything.model.Triplifier - Command stderr: 
[main] INFO io.github.sparqlanything.model.Triplifier - Running command: bash -c echo 4,5,6
[main] INFO io.github.sparqlanything.model.Triplifier - Command stderr: 
s,p,num,second_cmd,ss,pp,oo
Exception in thread "main" java.lang.StackOverflowError
    at org.apache.jena.sparql.engine.binding.BindingBase.get(BindingBase.java:111)
enridaga commented 1 year ago

In addition, explain -e does not show anything, I wanted to check the algebra...

luigi-asprino commented 1 year ago

I've investigated a little bit the issue without figuring out the problem!

haha. love that cheerfulness.

:-D

I doubt that it can depend on sparql anything.

ah, you think it is a jena bug?

Not sure, but the query breaks when BNODE or strUUID functions are used in BIND. SA engine does operate on extend operations and BNODE strUUID are standard SPARQL functions.

The query posted originally by @justin2004 #241 (comment) doesn't work on v0.9-DEV -- I get SO:

Maybe because ?num matches with URIs (fx:root) and container blank nodes. This is then concatenated with seq some strange behaviour.

enridaga commented 1 year ago

Maybe because ?num matches with URIs (fx:root) and container blank nodes. This is then concatenated with seq some strange behaviour.

Actually, the following change makes it work:

PREFIX  fx:   <http://sparql.xyz/facade-x/ns/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX  xyz:  <http://sparql.xyz/facade-x/data/>

SELECT  *
WHERE
  { 
     SERVICE <x-sparql-anything:>
     { 
          SERVICE <x-sparql-anything:>
          { fx:properties
                      fx:command     "echo 4,5,6" ;
                      fx:media-type  "text/csv" .
            [] fx:anySlot [ ?p             ?num ] .
            # BIND(bnode() AS ?bob)           # breaks
            # BIND(struuid() AS ?bob)         # breaks
            # BIND(concat("a","b") AS ?bob)   # works
            # BIND("lala" AS ?bob)            # works
          }
        BIND(concat("seq ", ?num) AS ?second_cmd)
        fx:properties
            fx:command     ?second_cmd ;
            fx:media-type  "text/plain" ;
            fx:txt.split   "\n" .
        ?ss       ?pp            ?oo
     }
  }
luigi-asprino commented 1 year ago

It is similar to that included via 9ddd3ee

enridaga commented 1 year ago

It is similar to that included via 9ddd3ee

Oh I didn't notice you went through it already

luigi-asprino commented 1 year ago

No problem, hope you will figure out the problem.