Lyo Store - OSLC Query with SPARQL, issues with the where clause

Hello,

I am trying to use the Lyo Store library to implement OSLC Query capability in my OSLC adapter. I managed to setup the Store, and getting individual resources or querying for all resources works fine. However, I am unable to get any results when using queries with a where clause. The result always contains zero resources.
I am using Lyo.store 2.4.0.M1 (also tried the 4.0.0-SNAPSHOT), and I am using Apache Jena Fuseki as the SPARQL server (also tried RDF4J Server).

When I do a query for all resources (with no where clause), like this: http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/queryAutomationResult
I get a response with a list of AutomationResult resources. One of which contains a property <dcterms:identifier>0</dcterms:identifier>
But when I do another query with a where clause to find the resource with identifier equal to zero, like this:
http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/queryAutomationResult?oslc.prefix=dcterms=<http://purl.org/dc/terms/>&oslc.where=dcterms:identifier="0"
The response returns zero resources found.

This is what my implementation of the query capability generated by Lyo looks like:

public static List<AutomationResult> queryAutomationResults(HttpServletRequest httpServletRequest, final String serviceProviderId, String where, int page, int limit)
{
    List<AutomationResult> resources = null;
    
    // Start of user code queryAutomationResults
    try {
    	if (where == null)
    		where = "";

		String oslcPrefixes = httpServletRequest.getParameter("oslc.prefix");
    	Model jenaModel = store.getResources(new URI("http://autoResults"), oslcPrefixes, where, limit, page);
    	resources = getResourcesFromModel(jenaModel, AutomationResult.class);

	} catch (StoreAccessException | ModelUnmarshallingException | URISyntaxException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
    // End of user code
    return resources;
}

I would like to kindly ask for help with this issue. Any suggestions on what am I doing wrong or what could cause the problem are greatly appreciated.

Thanks!

1 Like

Hi,

Thanks for giving Lyo Store a try! Initially, it was not designed to support OSLC Query but experimental support has been added by @jad. Hopefully he can help you. He will likely need more info, so I have added a log statement into the getResources method to help you: https://github.com/eclipse/lyo.store/commit/112e45ef9afcd0a737cfb09bcb1d6b71c92bbff9

Just re-run your code with Store 4.0.0-SNAPSHOT and logger at the TRACE level to see what kind of SPARQL query is generated by Lyo Store to see where the problem lies.

Happy Easter!

Cheers,
Andrew

1 Like

Thanks for the reply.

I see, so the OSLC Query support is still experimental. It is very useful feature to have in the Store, as it allowed me to add persistence and query capabilities to my OSLC adapter with minimal effort. Hope the implementation eventually gets finished.

I already have logs of the query from the Jena Fuseki server logger and they look like this (after url decoding):

[2019-04-20 20:53:57] Fuseki     INFO  [26] GET http://localhost:8081/fuseki/anaconda_automation/query?query=ASK
WHERE
  { GRAPH <http://automation_resources>
      { ?s  ?p  ?o }
  }

[2019-04-20 20:53:57] Fuseki     INFO  [26] Query = ASK WHERE   { GRAPH <http://automation_resources>       { ?s  ?p  ?o }   } 
[2019-04-20 20:53:57] Fuseki     INFO  [26] 200 OK (2 ms)
[2019-04-20 20:53:57] Fuseki     INFO  [27] GET http://localhost:8081/fuseki/anaconda_automation/query?query=PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX  dcterms: <http://purl.org/dc/terms/>

DESCRIBE ?s
WHERE
  { GRAPH <http://automation_resources>
      { ?s  ?p  ?o
        { SELECT DISTINCT  ?s
          WHERE
            { ?s  ?p                  ?o ;
                  dcterms:identifier  0 ;
                  rdf:type            <http://open-services.net/ns/auto#AutomationResult>
            }
          LIMIT   20
        }
      }
  }

[2019-04-20 20:53:57] Fuseki     INFO  [27] Query = PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX  dcterms: <http://purl.org/dc/terms/>  DESCRIBE ?s WHERE   { GRAPH <http://automation_resources>       { ?s  ?p  ?o         { SELECT DISTINCT  ?s           WHERE             { ?s  ?p                  ?o ;                   dcterms:identifier  0 ;                   rdf:type            <http://open-services.net/ns/auto#AutomationResult>             }           LIMIT   20         }       }   } 
[2019-04-20 20:53:57] Fuseki     INFO  [27] 200 OK (6 ms)

Is this log fine, or should I make a new one using the log statement you have added?

I have switched to Store 4.0.0-SNAPSHOT already and started using oslc.searchTerms which works fine. Still cant get oslc.where to work though. My implementation of the Lyo query capability has changed like this (a bit cleaner and straight forward):

if (where == null)
    where = "";
    	
String oslcPrefixes = httpServletRequest.getParameter("oslc.prefix");
String searchTerms = httpServletRequest.getParameter("oslc.searchTerms");
return store.getResources(namedGraph, clazz, oslcPrefixes, where, searchTerms, limit, page);

To be honest, I dont know much about SPARQL and getting the oslc.where to work is not essential for me right now. So I will be happy if @jad could just confirm whether oslc.where is currently working in Lyo Store, and maybe give me a simple example of a query GET request for Lyo Store.

Thanks again, any help is much appreciated!

Hi

The fact that you are getting a SPARQL query is a good sign. we just need to fine-tune it to make it respond to your query.

Could you please do the following for me:

  1. Run the sparql query without the 8th line ( dcterms:identifier 0 ;).
  2. From the response you receive, can you please post to me one or two resources that you believe should have been included in your query.

Although you are expecting dcterms:identifier to be 0, I wonder if the paramter is being sent in the most appropriate way. For example, should you be sending (a) dcterms:identifier=“0” or (b) dcterms:identifier=0 or © dcterms:identifier=“0”^^http://www.w3.org/2001/XMLSchema#integer

The formatting for the query parameters is unfortuantly not so well documented, and I myself normally need to reverse-engineering the SPARQL query to work out how to best set my OSLC-query paramters.

and BTW, the query capability is as experimental/mature as the rest of the Store. And I use it quite often as well. It is experimental in the sense that it does not cover (yet) the full OSLC Query language. I am only expanding it as the needs for it arise.

1 Like

Hi,

I am using option (a) dcterms:identifier=“0”. When I tried using option (b) I get an exception saying: "only support for terms of type Comparisons, where the operator is 'EQUALS', and the operand is either a String or a URI".
And as for option © I am not sure what you mean by ^^http://www.w3.org/2001/XMLSchema#integer

Here are two resources returned by a query with no query parameters.

    <rdfs:member>
        <oslc_auto:AutomationResult rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/automationResults/0">
            <oslc_auto:verdict rdf:resource="http://open-services.net/ns/auto#passed"/>
            <dcterms:creator rdf:resource="https://pajda.fit.vutbr.cz/xvasic"/>
            <oslc_auto:inputParameter>
                <oslc_auto:ParameterInstance rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/parameterInstances/0-0"/>
            </oslc_auto:inputParameter>
            <dcterms:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2019-04-13T18:46:00.516Z</dcterms:modified>
            <oslc_auto:inputParameter>
                <oslc_auto:ParameterInstance rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/parameterInstances/0-1"/>
            </oslc_auto:inputParameter>
            <oslc_auto:inputParameter>
                <oslc_auto:ParameterInstance rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/parameterInstances/0-2"/>
            </oslc_auto:inputParameter>
            <dcterms:title rdf:parseType="Literal">Result - Test Request</dcterms:title>
            <oslc_auto:inputParameter>
                <oslc_auto:ParameterInstance rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/parameterInstances/0-3"/>
            </oslc_auto:inputParameter>
            <oslc_auto:reportsOnAutomationPlan rdf:resource="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/automationPlans/0"/>
            <oslc:instanceShape rdf:resource="http://localhost:8080/AnacondaOSLC/services/resourceShapes/automationResult"/>
            <dcterms:identifier>0</dcterms:identifier>
            <oslc:serviceProvider rdf:resource="http://localhost:8080/AnacondaOSLC/services/Automation/A0"/>
            <oslc_auto:inputParameter>
                <oslc_auto:ParameterInstance rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/parameterInstances/0-4"/>
            </oslc_auto:inputParameter>
            <oslc_auto:producedByAutomationRequest rdf:resource="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/automationRequests/0"/>
            <dcterms:created rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2019-04-13T18:45:58.382Z</dcterms:created>
            <oslc_auto:contribution>
                <anaconda:OutputLog rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/outputLogs/0-0"/>
            </oslc_auto:contribution>
            <oslc_auto:state rdf:resource="http://open-services.net/ns/auto#complete"/>
            <oslc_auto:desiredState rdf:resource="http://open-services.net/ns/auto#complete"/>
        </oslc_auto:AutomationResult>
    </rdfs:member>
    <rdfs:member>
        <oslc_auto:AutomationResult rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/automationResults/7">
            <dcterms:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2019-04-13T18:46:07.197Z</dcterms:modified>
            <oslc:serviceProvider rdf:resource="http://localhost:8080/AnacondaOSLC/services/Automation/A0"/>
            <oslc_auto:verdict rdf:resource="http://open-services.net/ns/auto#passed"/>
            <dcterms:title rdf:parseType="Literal">Result - Test Request</dcterms:title>
            <oslc_auto:inputParameter>
                <oslc_auto:ParameterInstance rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/parameterInstances/7-2"/>
            </oslc_auto:inputParameter>
            <oslc_auto:inputParameter>
                <oslc_auto:ParameterInstance rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/parameterInstances/7-0"/>
            </oslc_auto:inputParameter>
            <dcterms:creator rdf:resource="https://pajda.fit.vutbr.cz/xvasic"/>
            <dcterms:identifier>7</dcterms:identifier>
            <oslc_auto:producedByAutomationRequest rdf:resource="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/automationRequests/7"/>
            <oslc_auto:reportsOnAutomationPlan rdf:resource="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/automationPlans/0"/>
            <oslc_auto:contribution>
                <anaconda:OutputLog rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/outputLogs/7-0"/>
            </oslc_auto:contribution>
            <oslc_auto:inputParameter>
                <oslc_auto:ParameterInstance rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/parameterInstances/7-3"/>
            </oslc_auto:inputParameter>
            <oslc_auto:desiredState rdf:resource="http://open-services.net/ns/auto#complete"/>
            <oslc_auto:inputParameter>
                <oslc_auto:ParameterInstance rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/parameterInstances/7-4"/>
            </oslc_auto:inputParameter>
            <dcterms:created rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2019-04-13T18:46:05.851Z</dcterms:created>
            <oslc_auto:inputParameter>
                <oslc_auto:ParameterInstance rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/parameterInstances/7-1"/>
            </oslc_auto:inputParameter>
            <oslc_auto:state rdf:resource="http://open-services.net/ns/auto#complete"/>
            <oslc:instanceShape rdf:resource="http://localhost:8080/AnacondaOSLC/services/resourceShapes/automationResult"/>
        </oslc_auto:AutomationResult>
    </rdfs:member>

Thanks!

Hi!
(There are problems with the email notifications on the forum, so please correspond to me via email for the time being. We can then post the end results here, once we found an answer. You can find my contact details on https://www.kth.se/profile/jad?l=en)

There is a bit of a confusion first (at least I am).

Let’s put the Store library aside, and focus on the SPARQL Queries first. If you are running the query (notice that I removed the 8th line)

DESCRIBE ?s
WHERE
  { GRAPH <http://automation_resources>
      { ?s  ?p  ?o
        { SELECT DISTINCT  ?s
          WHERE
            { ?s  ?p                  ?o ;
                  rdf:type            <http://open-services.net/ns/auto#AutomationResult>
            }
          LIMIT   20
        }
      }
  }

you should be getting a list of AutomationResult. But your posted results is showing a hierachy of AutomationResult within “rdfs:member”.

<rdfs:member>
        <oslc_auto:AutomationResult rdf:about="http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/automationResults/0">
			...
            <dcterms:creator rdf:resource="https://pajda.fit.vutbr.cz/xvasic"/>
			...
            <dcterms:identifier>0</dcterms:identifier>
			...
        </oslc_auto:AutomationResult>
</rdfs:member>

Can you please confirm what the SPARQL query is returning first?

@andrew! @axel.reichwein! @jamsden! Just to test, is any of you receiving email notifications from this forum?

@jad @andrew should be fixed now.

yes it is working. thanks @andrew.

Lyo.store indeed constructed the wrong SPARQL queries for String values that happen to be integers. That is, if you are queries for the value “S-123”, lyo.store produces the expected sparql-where
dcterms:identifier "S-123". But for the value “123”, it produced dcterms:identifier 123

This is fixed in the new pull-request https://github.com/eclipse/lyo.store/pull/54.

Please test by cloning and building your local version. Or, hopefully the request is reviewed and merged into master soon by our Lyo committers.

Yes that issue is fixed now. Thanks!

I do have one more question regarding the where clause. How do I query for a value which looks like this in the triplestore?
"Result - Test Request"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>
Could you give me an example of the where parameter, please?

Hi

The easiest way to figure it out is to make your SPARQL query work as expected, and then work your way backwards.
Unfortunatly, Lyo.store is not yet so intuitive that one needs not know SPARQL. Currently, it is more of a convenient interface to help you write the SPARQL query.

Something like this might work?

dcterms:yourProp  "Result - Test Request"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> ;

You can even try and see if you get away with this

dcterms:yourProp  "Result - Test Request";

Finally, have you considered the searchTerm parameter?

Hi

Yes, the searchTerms parameter works. I was just trying to achieve the same thing using the where parameter.

The query works directly in the triplestore when submitted like this:
dcterms:title "Result - Test Request"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> ;

The other option (below) gives no results.
dcterms:title "Result - Test Request";

If I use Lyo Store with these values as prefix and where parameters:
prefix="rdf=<http://www.w3.org/1999/02/22-rdf-syntax-ns>,dcterms=<http://purl.org/dc/terms/>"
where="dcterms:title="Result - Test Request"^^rdf:XMLLiteral"
I get the exception "only support for terms of type Comparisons, where the operator is 'EQUALS', and the operand is either a String, an Integer or a URI"
So does that mean Lyo Store only supports plain strings, and does not support typed strings?

Hi

The Where term is for an exact match of a string, while searchTerms is for more free-text search. So it depends on your needs.

You are sending the correct where paramter to LyoStore. But just like support for Integers, I just have not implemented support for typedStrings. Both due to laziness, but also because for such XMLLiterals, I speculdate that Free-text search is more likely what you, rather than an exact match?

The exception is produced by me, as you can see in the code https://github.com/eclipse/lyo.store/blob/ee066ce1d0373d5e7f095d2343941bd5a7527141/src/store-core/src/main/java/org/eclipse/lyo/store/internals/SparqlStoreImpl.java#L565

It’s just about changing the “switch” statement to handle typed strings. Any chance you want to give it a go? I am happy to support you.
How the query should look like is pretty clear from teh “case(String)”. Just about catching what the operandType is.

Hi

I was just exploring the current capabilities of Lyo Store. I dont have any specific needs for the where parameter to support more value types right now. I will let you know if a need for more datatypes arises.

Thanks very much for Your assistance!

1 Like