Submit Feedback/Bug Report

myExperiment Logo How To SPARQL

            Back to Contents Page

1. Using the SPARQL Endpoint

1.1. Useful Prefixes

The myExperiment SPARQL endpoint has a number of features to assist in its use. As explained in the PREFIX page, both the PREFIX and BASE clauses facilitate writing more succinct and easier to follow queries. If you need to include any prefixes in your query just use the PREFIX as defined in Useful Prefixes (e.g. rdfs, mebase etc.) and the PREFIX line will be prepended to the query before it is executed.

1.2. Formatting

myExperiment's triplestore to which the SPARQL endpoint queries is updated with the previous day's data between 08:10 and 08:30 each morning UK time. The endpoint provides information about the time the latest snapshot was taken and the number of triples, so you can be sure how current the data is.

SPARQL results can be rendered in a number of formats:

An example of a use for the CSV Matrix format is for friendships:

PREFIX mebase: <http://rdf.myexperiment.org/ontologies/base/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?requester ?accepter
WHERE{
  ?friendship rdf:type mebase:Friendship ;
    mebase:accepted-at ?accepted_time ;
    mebase:has-requester ?requester ;
    mebase:has-accepter ?accepter .
}
[Run]
[Hide Example Results]
Friendship CVS Matrix Results

1.3. Soft Limit

The Soft Limit option determines the amount of resources dedicated to returning all the matching results. In general 1% is sufficient. However, if all the results are not returned then a warning message will be displayed and you can try re-running the query with a greater Soft Limit percentage.

1.4. Reasoning

The Enable RDFS Reasoning option allows you to make use of 4Store Reasoner, an RDFS reasoner addition to 4Store. This will perform query-time RDFS reasoning on RDFS subClassOf, subPropertyOf, domain and range properties. The following query will return more results if RDFS reasoning is enabled because all the super classes of Workflow:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?type 
WHERE { 
  <http://www.myexperiment.org/workflows/16> rdf:type ?type 
}
[Run (Without Reasoning)] [Run (With Reasoning)]
[Hide Example Results]

Without Reasoning

type
http://rdf.myexperiment.org/ontologies/contributions/Workflow
    

With Reasoning

type
b139c71020000004f
http://rdf.myexperiment.org/ontologies/base/Submission
http://rdf.myexperiment.org/ontologies/attrib_credit/Attributable
http://rdf.myexperiment.org/ontologies/annotations/Favouritable
http://rdf.myexperiment.org/ontologies/annotations/Commentable
http://rdf.myexperiment.org/ontologies/attrib_credit/Creditable
http://rdf.myexperiment.org/ontologies/base/Upload
http://rdf.myexperiment.org/ontologies/annotations/Taggable
http://rdf.myexperiment.org/ontologies/annotations/Citationable
http://rdf.myexperiment.org/ontologies/contributions/Workflow
http://rdf.myexperiment.org/ontologies/annotations/Rateable
http://rdf.myexperiment.org/ontologies/base/Annotatable
http://rdf.myexperiment.org/ontologies/base/Contribution
http://rdf.myexperiment.org/ontologies/base/Interface
http://rdf.myexperiment.org/ontologies/base/Versionable
http://rdf.myexperiment.org/ontologies/contributions/AbstractWorkflow
http://rdf.myexperiment.org/ontologies/experiments/Runnable
http://rdf.myexperiment.org/ontologies/annotations/Reviewable

1.5. Automated Querying

If you wish to write automated queries rather than using the endpoint form you can insert the query (in URL encoded format) into the URL as the query parameter in the HTTP GET header. If you have built a query using the endpoint form and want to use it as an automated service in something such as a workflow, instead of clicking "Submit Query", click on "Generate Service from Query". This will take you to a page with a link something like the one below, that you can copy and paste into your workflow or HTTP request capable application.

http://rdf.myexperiment.org/sparql?query=PREFIX+mebase%3A+%3Chttp%3A%2F%2Frdf.myexperiment.org%2Fontologies%2Fbase%2F%3E%0D%0APREFIX+rdf%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0D%0ASELECT+%3Frequester+%3Faccepter+%0D%0AWHERE%7B+%0D%0A++%3Ffriendship+rdf%3Atype+mebase%3AFriendship+%3B%0D%0A++++mebase%3Aaccepted-at+%3Faccepted_time+%3B+%0D%0A++++mebase%3Ahas-requester+%3Frequester+%3B%0D%0A++++mebase%3Ahas-accepter+%3Faccepter+%0D%0A%7D

As you will notice is you click on the link above this will return results is raw SPARQL results XML format. If you wish to get the results in a different format you can also set the formatting parameter in the GET header:

http://rdf.myexperiment.org/sparql?query=PREFIX+mebase%3A+%3Chttp%3A%2F%2Frdf.myexperiment.org%2Fontologies%2Fbase%2F%3E%0D%0APREFIX+rdf%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0D%0ASELECT+%3Frequester+%3Faccepter+%0D%0AWHERE%7B+%0D%0A++%3Ffriendship+rdf%3Atype+mebase%3AFriendship+%3B%0D%0A++++mebase%3Aaccepted-at+%3Faccepted_time+%3B+%0D%0A++++mebase%3Ahas-requester+%3Frequester+%3B%0D%0A++++mebase%3Ahas-accepter+%3Faccepter+%0D%0A%7D&formatting=HTML Table

The options for the formatting parameter are:

The Soft Limit can also be set as an integer between 1 (default) and 100 by using the GET header parameter softlimit:

http://rdf.myexperiment.org/sparql?query=PREFIX+mebase%3A+%3Chttp%3A%2F%2Frdf.myexperiment.org%2Fontologies%2Fbase%2F%3E%0D%0APREFIX+rdf%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0D%0ASELECT+%3Frequester+%3Faccepter+%0D%0AWHERE%7B+%0D%0A++%3Ffriendship+rdf%3Atype+mebase%3AFriendship+%3B%0D%0A++++mebase%3Aaccepted-at+%3Faccepted_time+%3B+%0D%0A++++mebase%3Ahas-requester+%3Frequester+%3B%0D%0A++++mebase%3Ahas-accepter+%3Faccepter+%0D%0A%7D&formatting=HTML Table&softlimit=5

Finally reasoning can be enabled by setting the reasoning parameter to 1, yes, or true in the GET header:

http://rdf.myexperiment.org/sparql?query=PREFIX+mebase%3A+%3Chttp%3A%2F%2Frdf.myexperiment.org%2Fontologies%2Fbase%2F%3E%0D%0APREFIX+rdf%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0D%0ASELECT+%3Frequester+%3Faccepter+%0D%0AWHERE%7B+%0D%0A++%3Ffriendship+rdf%3Atype+mebase%3AFriendship+%3B%0D%0A++++mebase%3Aaccepted-at+%3Faccepted_time+%3B+%0D%0A++++mebase%3Ahas-requester+%3Frequester+%3B%0D%0A++++mebase%3Ahas-accepter+%3Faccepter+%0D%0A%7D&formatting=HTML Table&reasoning=1

            Back to Contents Page