freme-project / e-services

Apache License 2.0
1 stars 1 forks source link

[e-link/templates] LIMIT as request param in template #15

Closed bgrusdt closed 8 years ago

bgrusdt commented 8 years ago

I would like to build an e-link/template that has a variable LIMIT such that the limit can be specified in a parameter in the request:

curl -d @example.ttl -X POST -H "Content-Type: text/turtle" "http://api-dev.freme-project.eu/current/e-link/documents?templateid=NEW_TEMPLATE&my_limit=5" 

I wanted to check the syntax in the template with id=116 since it is referenced to in the documentation, but it does not exist. The documentation says that LIMIT @@@my_limit@@@ can be used in the sparql construct query, but this did not work for me. Somehow it must be specified that the parameter is given as request param, how is this done?

An example turtle file for the curl request above would be:

@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix itsrdf: <http://www.w3.org/2005/11/its/rdf#> .
@prefix nif:   <http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#> .

<http://freme-project.eu/#char=0,33>
        a               nif:String , nif:Context , nif:RFC5147String ;
        nif:beginIndex  "0"^^xsd:int ;
        nif:endIndex    "33"^^xsd:int ;
        nif:isString    "London is the capital of England."^^xsd:string .

<http://freme-project.eu/#char=0,6>
        a                     nif:RFC5147String , nif:Word , nif:String , nif:Phrase ;
        nif:anchorOf          "London"^^xsd:string ;
        nif:beginIndex        "0"^^xsd:int ;
        nif:endIndex          "6"^^xsd:int ;
        nif:referenceContext  <http://freme-project.eu/#char=0,33> ;
        itsrdf:taClassRef     <http://dbpedia.org/ontology/PopulatedPlace> , <http://dbpedia.org/ontology/Place> , <http://dbpedia.org/ontology/Location> , <http://dbpedia.org/ontology/Settlement> , <http://nerd.eurecom.fr/ontology#Location> ;
        itsrdf:taConfidence   "0.9743245630333841"^^xsd:double ;
        itsrdf:taIdentRef     <http://dbpedia.org/resource/London> .

<http://freme-project.eu/#char=25,32>
        a                     nif:RFC5147String , nif:Phrase , nif:Word , nif:String ;
        nif:anchorOf          "England"^^xsd:string ;
        nif:beginIndex        "25"^^xsd:int ;
        nif:endIndex          "32"^^xsd:int ;
        nif:referenceContext  <http://freme-project.eu/#char=0,33> ;
        itsrdf:taClassRef     <http://nerd.eurecom.fr/ontology#Location> ;
        itsrdf:taConfidence   "0.9676871884641968"^^xsd:double ;
        itsrdf:taIdentRef     <http://dbpedia.org/resource/England> .
m1ci commented 8 years ago

@bgrusdt what is the template ID? do you use the dev or the production API endpoint?

bgrusdt commented 8 years ago

Do you mean the ID of the template that is supposed to include such a variable LIMIT ? In the documentation there is a curl example which refers to a template with id=116:

curl -v -d @example.ttl -X POST -H "Content-Type: text/turtle" "http://localhost:8080/e-link/documents?templateid=116&my_limit=5"

I used the dev API endpoint.

m1ci commented 8 years ago

There is no such template with ID=116, see http://api-dev.freme-project.eu/current/e-link/templates/116?outformat=json

bgrusdt commented 8 years ago

Yes, I mentioned template 116 because it is supposed to contain the syntax for the variable LIMIT parameter in the SPARQL construct query which I am looking for. I thought the template might maybe exist somewhere I am not aware of. How do I specify the limit as variable in the sparql construct query such that I can use a limit parameter in the request ? This is mentioned here, but I am not sure how to include the @@@my_limit@@@ in the sparql construct query such that it works properly. Thanks for your help!

m1ci commented 8 years ago

Here is an example of a query which takes the LIMIT as parameter:

CONSTRUCT {
  ?person  <http://rdvocab.info/ElementsGr2/placeOfBirth> <@@@entity_uri@@@> ;  
} WHERE {
  ?person  <http://rdvocab.info/ElementsGr2/placeOfBirth> <@@@entity_uri@@@> ;  
} LIMIT @@@my_limit@@@
m1ci commented 8 years ago

I added a modified version of template 1 with a parameterized LIMIT (via @@@my_limit@@@). It has the id 116. But this works for some values of my_limit only, moved to this issue.

@ArneBinder can you give an example for which values it works/does not work? Thx.

ArneBinder commented 8 years ago

@m1ci I figured out that this is not an issue of the user defined parameter. Sometimes (really randomly) I get a BadRequestExecption. I assume this is because the calculations are to slow and time out. Somehow this results in throwing this kind of exception. At the moment I do not know which is the initially thrown exception to catch it correctly.

ArneBinder commented 8 years ago

It seems to be HttpException: 502. I think we should return sth more meaningful than BadRequestException("It seems your SPARQL template is not correctly defined.").

m1ci commented 8 years ago

if it is timeout then it should be 504.

ArneBinder commented 8 years ago

@jnehring should we add the template 116 to the init-templates.sql script? I opened #22 for the BadRequestException bug.

ArneBinder commented 8 years ago

I tried template 116 with this data:

curl -v -d @test-for-template-1.ttl -X POST -H "Content-Type: text/turtle" "http://api.freme-project.eu/current/e-link/documents?templateid=116&my_limit=2"

and got strange behaviour for different values of my_limit:

my_limit count(museums)
1 1
2 2
3 3
4 4
5 4
6 4
7 4
8 5
9 6
10 7
... ...
20 17

@m1ci can you reproduce this and do you have any explanations?

jnehring commented 8 years ago

@jnehring should we add the template 116 to the init-templates.sql script?

What does template 116 do?

ArneBinder commented 8 years ago

What does template 116 do?

It is the same as template 1 except a parametrized LIMIT. See: http://api-dev.freme-project.eu/current/e-link/templates/116

m1ci commented 8 years ago

@ArneBinder

@m1ci can you reproduce this and do you have any explanations?

This seems to be caused by the timeout set by the sparql endpoint. This is a solution to the query within the constraints of a timeout. This Virtuoso feature is critical to enabling the whole world use the specific SPARQL endpint rather than specific queries monopolizing processing time.

See related discussion here https://github.com/openlink/virtuoso-opensource/issues/112

jnehring commented 8 years ago

@jnehring should we add the template 116 to the init-templates.sql script?

The information is necessary in the documentation. I think it is not necessary to add this to init-templates.sql.

ArneBinder commented 8 years ago

@m1ci thanks for your explanation! So this is not a real bug...

@jnehring

I think it is not necessary to add this to init-templates.sql.

ok

The information is necessary in the documentation.

at the moment there is a paragraph at the api-doc at POST /e-link/templates/ explaining the user defined parameter functionality. I think this is not the best place for this. Where should we put this? EDIT: I just noticed, there is already this issue.