AKSW / jekyll-rdf

📃 A Jekyll plugin to include RDF data in your static site or build a complete site for your RDF graph
http://aksw.org/Projects/JekyllRDF
Other
57 stars 10 forks source link

sparql_query does not bind ?resourceUri correctly #185

Closed white-gecko closed 6 years ago

white-gecko commented 6 years ago

The sparql_query filter does not bind the input to ?resourceUri.

Template:

<?xml version="1.0" encoding="UTF-8"?>
<schedule>
    {%- assign lswt = "<https://www.leds-projekt.de/lswt2018.html#event>" | rdf_get -%}
    {%- assign results = lswt | sparql_query: "SELECT distinct ?subEvent WHERE {?resourceUri <http://schema.org/subEvent> ?subEvent }" -%}
    {%- for row in results -%}
        {% assign event = row.subEvent %}
        <list name="{{ event }}">
        {%- assign rooms = event | sparql_query: "SELECT ?room WHERE {?resourceUri <http://schema.org/location> ?room }" -%}
        {%- for row in rooms -%}
            <event.location>{{ event | rdf_property: "<http://schema.org/location>" }}</event.location>
            <row.room>{{row.room}}</row.room>
        {% endfor %}
        </list>
    {% endfor %}
</schedule>

graph.ttl

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix schema: <http://schema.org/> .
@prefix lswt: <https://www.leds-projekt.de/lswt2018.html#> .

lswt:event a schema:Event ;
    schema:subEvent lswt:begruessung, lswt:keynotesoeren, lswt:dbpedia, lswt:jekyllrdf .

lswt:begruessung a schema:Event ;
    schema:location lswt:vortragsraum .

lswt:keynotesoeren a schema:Event ;
    schema:location lswt:vortragsraum .

lswt:dbpedia a schema:Event ;
    schema:location lswt:tutorialraum .

lswt:jekyllrdf a schema:Event ;
    schema:location lswt:tutorialraum .

Actual Output:

<?xml version="1.0" encoding="UTF-8"?>
<schedule>
        <list name="https://www.leds-projekt.de/lswt2018.html#keynotesoeren"><event.location>https://www.leds-projekt.de/lswt2018.html#vortragsraum</event.location>
            <row.room>https://www.leds-projekt.de/lswt2018.html#vortragsraum</row.room>
        </list>
        <list name="https://www.leds-projekt.de/lswt2018.html#jekyllrdf"><event.location>https://www.leds-projekt.de/lswt2018.html#tutorialraum</event.location>
            <row.room>https://www.leds-projekt.de/lswt2018.html#vortragsraum</row.room>
        </list>
        <list name="https://www.leds-projekt.de/lswt2018.html#dbpedia"><event.location>https://www.leds-projekt.de/lswt2018.html#tutorialraum</event.location>
            <row.room>https://www.leds-projekt.de/lswt2018.html#vortragsraum</row.room>
        </list>
        <list name="https://www.leds-projekt.de/lswt2018.html#begruessung"><event.location>https://www.leds-projekt.de/lswt2018.html#vortragsraum</event.location>
            <row.room>https://www.leds-projekt.de/lswt2018.html#vortragsraum</row.room>
        </list>
</schedule>

Expected Output

<?xml version="1.0" encoding="UTF-8"?>
<schedule>
        <list name="https://www.leds-projekt.de/lswt2018.html#keynotesoeren"><event.location>https://www.leds-projekt.de/lswt2018.html#vortragsraum</event.location>
            <row.room>https://www.leds-projekt.de/lswt2018.html#vortragsraum</row.room>
        </list>
        <list name="https://www.leds-projekt.de/lswt2018.html#jekyllrdf"><event.location>https://www.leds-projekt.de/lswt2018.html#tutorialraum</event.location>
            <row.room>https://www.leds-projekt.de/lswt2018.html#tutorialraum</row.room>
        </list>
        <list name="https://www.leds-projekt.de/lswt2018.html#dbpedia"><event.location>https://www.leds-projekt.de/lswt2018.html#tutorialraum</event.location>
            <row.room>https://www.leds-projekt.de/lswt2018.html#tutorialraum</row.room>
        </list>
        <list name="https://www.leds-projekt.de/lswt2018.html#begruessung"><event.location>https://www.leds-projekt.de/lswt2018.html#vortragsraum</event.location>
            <row.room>https://www.leds-projekt.de/lswt2018.html#vortragsraum</row.room>
        </list>
</schedule>
Simaris commented 6 years ago

I could actually reproduce this bug, but it seems to be a problem with the liquid engine. I went ahead and added the following line in the first line of sparql_query

def sparql_query(resource = nil, query)
    Jekyll.logger.info "resource:    #{resource}\nquery:       #{query}"

the console result is:

resource:    https://www.leds-projekt.de/lswt2018.html#dbpedia
query:       SELECT ?room WHERE {?resourceUri <http://schema.org/location> ?room } 
resource:    https://www.leds-projekt.de/lswt2018.html#begruessung
query:       SELECT ?room WHERE {<https://www.leds-projekt.de/lswt2018.html#dbpedia> <http://schema.org/location> ?room } 
resource:    https://www.leds-projekt.de/lswt2018.html#jekyllrdf
query:       SELECT ?room WHERE {<https://www.leds-projekt.de/lswt2018.html#dbpedia> <http://schema.org/location> ?room } 

resource:    https://www.leds-projekt.de/lswt2018.html#keynotesoeren
query:       SELECT ?room WHERE {<https://www.leds-projekt.de/lswt2018.html#dbpedia> <http://schema.org/location> ?room } 

it seems like the query parameter is set only one time and after that liquid seems to refeed the same (edited) varaiable over and over.

I`m unsure what we can do about it.

white-gecko commented 6 years ago

But how is this possible, since we could show that the variable is changed in the scope outside of the filter method. And if I'm not completely wrong, it works for other filters to receive and compute different values. So where is the variable actually changing its value?

Simaris commented 6 years ago

There is an easy way to force liquid to reinit the sparql string in each iteration, by using prepend.

---
---
<?xml version="1.0" encoding="UTF-8"?>
<schedule>
    {%- assign lswt = "<https://www.leds-projekt.de/lswt2018.html#event>" | rdf_get -%}
    {%- assign results = lswt | sparql_query: "SELECT distinct ?subEvent WHERE {?resourceUri <http://schema.org/subEvent> ?subEvent }" -%}
    {%- for row in results -%}
        {% assign event = row.subEvent %}
        <list name="{{ event }}">
        {% assign query = "SELECT ?room WHERE {?resourceUri <http://schema.org/location> ?room }" | prepend: "" %}
        {%- assign rooms = event | sparql_query: query -%}
        {%- for row in rooms -%}
            <event.location>{{ event | rdf_property: "<http://schema.org/location>" }}</event.location>
            <row.room>{{row.room}}</row.room>
        {% endfor %}
        </list>
    {% endfor %}
</schedule>

leads to

<?xml version="1.0" encoding="UTF-8"?>
<schedule>
        <list name="https://www.leds-projekt.de/lswt2018.html#keynotesoeren">
        <event.location>https://www.leds-projekt.de/lswt2018.html#vortragsraum</event.location>
            <row.room>https://www.leds-projekt.de/lswt2018.html#vortragsraum</row.room>
        </list>
        <list name="https://www.leds-projekt.de/lswt2018.html#begruessung">
        <event.location>https://www.leds-projekt.de/lswt2018.html#vortragsraum</event.location>
            <row.room>https://www.leds-projekt.de/lswt2018.html#vortragsraum</row.room>
        </list>
        <list name="https://www.leds-projekt.de/lswt2018.html#dbpedia">
        <event.location>https://www.leds-projekt.de/lswt2018.html#tutorialraum</event.location>
            <row.room>https://www.leds-projekt.de/lswt2018.html#tutorialraum</row.room>
        </list>
        <list name="https://www.leds-projekt.de/lswt2018.html#jekyllrdf">
        <event.location>https://www.leds-projekt.de/lswt2018.html#tutorialraum</event.location>
            <row.room>https://www.leds-projekt.de/lswt2018.html#tutorialraum</row.room>
        </list>
</schedule>
Simaris commented 6 years ago

After realising this, the fix is a simple matter of working on a copy of the static string