Package org.eclipse.lyo.trs.client.util
Class SparqlUtil
java.lang.Object
org.eclipse.lyo.trs.client.util.SparqlUtil
* A utility class with static methods enabling the processing of trs tasks as
sparql update requests e.g. A sparql update corresponding to the removal of
the old statements of a resource and the addition of the statements of its
update representation can be returned in exchange for a TRS Modification
Event
- Author:
- Omar
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
addTriplesToGraphQuery
(String namedGraphUrl, String triples) Gets a set of statements and a named graph as arguments and returns a sparql query for adding the statements to the named graphstatic String
addTriplesToGraphQuery
(String namedGraphUrl, Model jenaModel) Gets an rdf model and a named graph as arguments and returns a sparql query for adding the statements of the rdf model to the named graphstatic String
addTriplesToGraphQuery
(URI namedGraphUrl, Model jenaModel) static void
addTriplesToNamedGraph
(Model jenaModel, String namedGraphUrl, String serviceUrl) create a spaql update adding the triples in the given rdf model to the graph with the given name and send it to the specified sparql update endpointstatic String
appendSparqldQuery
(String appending, String appended) append a sparql update to anotherstatic void
createGraph
(String namedGraphUrl, String serviceUrl) create a graph creation of the graph with the specified name sparql update and post it to the given service urlstatic String
createGraphQuery
(String namedGraphUrl) returns the sparql query for the creation of the named graph with the given name as a Stringstatic String
createGraphQuery
(URI namedGraphUrl) static void
create a graph creation of the graph with the specified name sparql update and post it to the given service urlstatic String
dropGraphQuery
(String namedGraphUrl) returns the query deleting siltently the graph with the given namestatic org.eclipse.rdf4j.query.TupleQueryResult
evaluate the given sparql query against the given sparql query endpointstatic org.eclipse.rdf4j.query.TupleQueryResult
evaluate the given sparql query using the sesame repository connection objectstatic void
evalUpdate
(org.eclipse.rdf4j.repository.RepositoryConnection conn, String sparqlQuery) evaluate the given sparql update using the sesame repository connection objectstatic String
getChangeEventQuery
(ChangeEvent changeEvent, Model model) For a change event return a sparql update relfecting the change event.static String
getCreationEventQuery
(ChangeEvent changeEvent, Model model) * For a creation event return a sparql update reflecting the change event.static String
getDeletionEventQuery
(ChangeEvent changeEvent) For a deletion event return a sparql update relfecting the change event.static String
getModificationEventQuery
(String changeEventTarget, String triples) For a modification event target return a sparql update relfecting the change event.static String
getModificationEventQuery
(ChangeEvent changeEvent, String triples) For a modification event return a sparql update relfecting the change event.static String
getModificationEventQuery
(ChangeEvent changeEvent, Model model) For a modification event return a sparql update relfecting the change event.static org.eclipse.rdf4j.repository.RepositoryConnection
getRepoConnection
(String queryEndpoint, String user, String pwd) return the repo connection object in order to be able to use the sesame client librariesstatic org.eclipse.rdf4j.repository.RepositoryConnection
getRepoConnection
(String queryEndpoint, String updateEndPoint, String user, String pwd) return the repo connection object in order to be able to use the sesame client librariesstatic String
linkTriple
(String src, String dst, String linkType) Create a triple with the link type as a predicate the src as subject and destination as object.static void
processChangeEvent
(ChangeEvent changeEvent, Model model, String serviceUrl) create a spaql update reflecting the given change event and send it to the sparql update endpointstatic void
processQuery
(String query, String serviceUrl) Send the given sparql update to the sparql update service using the jena arq librariesstatic void
processQuery_sesame
(String query, String serviceUrl, String user, String pwd) Send the given sparql update to the sparql update service using the sesame librariesstatic void
processQuery_sesame
(String query, org.eclipse.rdf4j.repository.RepositoryConnection conn) Send the given sparql update to the sparql update service using the sesame librariesvoid
processTripleAdditionQuery
(org.eclipse.rdf4j.repository.RepositoryConnection conn, String triples, String graphName) Create a sparql update ading the triples to the named graph with the specified name and send it to the sparql update endpoint specified using the given repo connection object.static String
removeAllTriplesInGraphQuery
(String namedGraphUrl) returns the sparql query removing all the triples in the requested graph as a stringstatic void
removeAllTriplesInNamedGraph
(String namedGraphUrl, String serviceUrl) create a spaql update removing all triples from the graph with the given name and send it to the specified sparql update endpoint
-
Constructor Details
-
SparqlUtil
public SparqlUtil()
-
-
Method Details
-
createGraphQuery
returns the sparql query for the creation of the named graph with the given name as a String- Parameters:
namedGraphUrl
- name of the named graph to be created- Returns:
- the graph creation sparql query as a string
-
createGraphQuery
-
dropGraphQuery
returns the query deleting siltently the graph with the given name- Parameters:
namedGraphUrl
- the name of the graph to be deleted- Returns:
- the deletion query as a string
-
removeAllTriplesInGraphQuery
returns the sparql query removing all the triples in the requested graph as a string- Parameters:
namedGraphUrl
- graph to be emptied- Returns:
- the query for emptying the graph
-
addTriplesToGraphQuery
Gets an rdf model and a named graph as arguments and returns a sparql query for adding the statements of the rdf model to the named graph- Parameters:
namedGraphUrl
- named graph to which the statements shall be addedjenaModel
- the rdf model of which statements are to be added to the named graph- Returns:
- the sparql update
-
addTriplesToGraphQuery
-
addTriplesToGraphQuery
Gets a set of statements and a named graph as arguments and returns a sparql query for adding the statements to the named graph- Parameters:
namedGraphUrl
- named graph to which the statements shall be addedtriples
- statements to be added to the named graph- Returns:
- the sparql update
-
getChangeEventQuery
For a change event return a sparql update relfecting the change event.- Parameters:
changeEvent
- the change event for which the sparql update is createdmodel
- the rdf model corresponding to the updated representation of the changed resource if applicable ( no rdf model is needed for a deletion event)- Returns:
- the sparql update
-
getModificationEventQuery
For a modification event return a sparql update relfecting the change event.- Parameters:
changeEvent
- the change event for which the sparql update is createdmodel
- the rdf model corresponding to the updated representation of the changed resource- Returns:
- the sparql update
-
getModificationEventQuery
For a modification event return a sparql update relfecting the change event.- Parameters:
changeEvent
- the change event for which the sparql update is createdtriples
- the rdf model in n triples corresponding to the updated representation of the changed resource- Returns:
- the sparql update
-
getModificationEventQuery
For a modification event target return a sparql update relfecting the change event.- Parameters:
changeEventTarget
- the change resource for which the sparql update is createdtriples
- the rdf model in n triples corresponding to the updated representation of the changed resource- Returns:
- the sparql update
-
getCreationEventQuery
* For a creation event return a sparql update reflecting the change event.- Parameters:
changeEvent
- change event for which update will be createdmodel
- updated rdf representation of the changed resource- Returns:
-
getDeletionEventQuery
For a deletion event return a sparql update relfecting the change event.- Parameters:
changeEvent
- the deletion change event for which the sparql update is created- Returns:
- the sparql update
-
createGraph
create a graph creation of the graph with the specified name sparql update and post it to the given service url- Parameters:
namedGraphUrl
- name of the graph to be createdserviceUrl
- sparql update endpoint url
-
dropGraph
create a graph creation of the graph with the specified name sparql update and post it to the given service url- Parameters:
namedGraphUrl
- name of the graph to be deletedserviceUrl
- sparql update endpoint url
-
addTriplesToNamedGraph
create a spaql update adding the triples in the given rdf model to the graph with the given name and send it to the specified sparql update endpoint- Parameters:
jenaModel
- the triples to be added to the named graphnamedGraphUrl
- the named graph to which the triples shall be addedserviceUrl
- the sparql update endpoint
-
removeAllTriplesInNamedGraph
create a spaql update removing all triples from the graph with the given name and send it to the specified sparql update endpoint- Parameters:
namedGraphUrl
- the named graph that shall be emptiedserviceUrl
- the sparql update endpoint
-
processChangeEvent
create a spaql update reflecting the given change event and send it to the sparql update endpoint- Parameters:
changeEvent
- the change event to be processedmodel
- the updated representation of the changed resource if applicableserviceUrl
- the sparql update endpoint
-
processQuery
Send the given sparql update to the sparql update service using the jena arq libraries- Parameters:
query
- sparql update to be processedaserviceUrl
- sparql update endpoint for processing the sparql update
-
processQuery_sesame
Send the given sparql update to the sparql update service using the sesame libraries- Parameters:
query
- sparql update to be processedaserviceUrl
- sparql update endpoint for processing the sparql updateuser
- username for authentication if applicablepwd
- password for authentication if applicable
-
processQuery_sesame
public static void processQuery_sesame(String query, org.eclipse.rdf4j.repository.RepositoryConnection conn) Send the given sparql update to the sparql update service using the sesame libraries- Parameters:
query
- sparql update to be processedaconn
- the repository connection object holding credentials and the sparql update endpoint
-
getRepoConnection
public static org.eclipse.rdf4j.repository.RepositoryConnection getRepoConnection(String queryEndpoint, String user, String pwd) return the repo connection object in order to be able to use the sesame client libraries- Parameters:
queryEndpoint
- the sparl query endpointuser
- username for authentication if applicablepwd
- password for authentication if applicable- Returns:
-
getRepoConnection
public static org.eclipse.rdf4j.repository.RepositoryConnection getRepoConnection(String queryEndpoint, String updateEndPoint, String user, String pwd) return the repo connection object in order to be able to use the sesame client libraries- Parameters:
queryEndpoint
- the sparl query endpointuser
- username for authentication if applicablepwd
- password for authentication if applicable- Returns:
-
evalQuery
public static org.eclipse.rdf4j.query.TupleQueryResult evalQuery(String queryEndpoint, String user, String pwd, String query) evaluate the given sparql query against the given sparql query endpoint- Parameters:
queryEndpoint
- sparql query endpointuser
- username for authentication if applicablepwd
- password for authentication if applicablequery
- sparql query- Returns:
- the result of the querie's evaluation
-
evalUpdate
public static void evalUpdate(org.eclipse.rdf4j.repository.RepositoryConnection conn, String sparqlQuery) evaluate the given sparql update using the sesame repository connection object- Parameters:
conn
- repo connection sesame objectsparqlQuery
- sparql update to evaluate
-
evalQuery
public static org.eclipse.rdf4j.query.TupleQueryResult evalQuery(org.eclipse.rdf4j.repository.RepositoryConnection conn, String sparqlQuery) evaluate the given sparql query using the sesame repository connection object- Parameters:
conn
- repo connection sesame objectsparqlQuery
- sparql query to evaluate- Returns:
- the queri's evaluation result
-
appendSparqldQuery
append a sparql update to another- Parameters:
appending
- the original sparql updateappended
- the sparql update to be appended- Returns:
- the concatnated sparql update
-
processTripleAdditionQuery
public void processTripleAdditionQuery(org.eclipse.rdf4j.repository.RepositoryConnection conn, String triples, String graphName) Create a sparql update ading the triples to the named graph with the specified name and send it to the sparql update endpoint specified using the given repo connection object. Uses the sesame libraries- Parameters:
conn
- sesame repo connection objecttriples
- triples to be added to the named graphgraphName
- named graph to which the triples shall be added
-
linkTriple
Create a triple with the link type as a predicate the src as subject and destination as object. This is a conveniece for enabling the creation of links in a ageneric way- Parameters:
src
- source of the linkdst
- destination of the linklinkType
- type of the link- Returns:
- the rdf triple as n triple
-