Class SparqlUtil

java.lang.Object
org.eclipse.lyo.trs.client.util.SparqlUtil

public class SparqlUtil extends Object
* 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 Details

    • SparqlUtil

      public SparqlUtil()
  • Method Details

    • createGraphQuery

      public static String createGraphQuery(String namedGraphUrl)
      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

      public static String createGraphQuery(URI namedGraphUrl)
    • dropGraphQuery

      public static String dropGraphQuery(String namedGraphUrl)
      returns the query deleting silently the graph with the given name
      Parameters:
      namedGraphUrl - the name of the graph to be deleted
      Returns:
      the deletion query as a string
    • removeAllTriplesInGraphQuery

      public static String removeAllTriplesInGraphQuery(String namedGraphUrl)
      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

      public static 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 graph
      Parameters:
      namedGraphUrl - named graph to which the statements shall be added
      jenaModel - the rdf model of which statements are to be added to the named graph
      Returns:
      the sparql update
    • addTriplesToGraphQuery

      public static String addTriplesToGraphQuery(URI namedGraphUrl, Model jenaModel)
    • addTriplesToGraphQuery

      public static 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 graph
      Parameters:
      namedGraphUrl - named graph to which the statements shall be added
      triples - statements to be added to the named graph
      Returns:
      the sparql update
    • getChangeEventQuery

      public static String getChangeEventQuery(ChangeEvent changeEvent, Model model)
      For a change event return a sparql update reflecting the change event.
      Parameters:
      changeEvent - the change event for which the sparql update is created
      model - 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

      public static String getModificationEventQuery(ChangeEvent changeEvent, Model model)
      For a modification event return a sparql update relfecting the change event.
      Parameters:
      changeEvent - the change event for which the sparql update is created
      model - the rdf model corresponding to the updated representation of the changed resource
      Returns:
      the sparql update
    • getModificationEventQuery

      public static String getModificationEventQuery(ChangeEvent changeEvent, String triples)
      For a modification event return a sparql update relfecting the change event.
      Parameters:
      changeEvent - the change event for which the sparql update is created
      triples - the rdf model in n triples corresponding to the updated representation of the changed resource
      Returns:
      the sparql update
    • getModificationEventQuery

      public static String getModificationEventQuery(String changeEventTarget, String triples)
      For a modification event target return a sparql update relfecting the change event.
      Parameters:
      changeEventTarget - the change resource for which the sparql update is created
      triples - the rdf model in n triples corresponding to the updated representation of the changed resource
      Returns:
      the sparql update
    • getCreationEventQuery

      public static String getCreationEventQuery(ChangeEvent changeEvent, Model model)
      * For a creation event return a sparql update reflecting the change event.
      Parameters:
      changeEvent - change event for which update will be created
      model - updated rdf representation of the changed resource
      Returns:
    • getDeletionEventQuery

      public static String getDeletionEventQuery(ChangeEvent changeEvent)
      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

      public static 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 url
      Parameters:
      namedGraphUrl - name of the graph to be created
      serviceUrl - sparql update endpoint url
    • dropGraph

      public static void dropGraph(String namedGraphUrl, String serviceUrl)
      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 deleted
      serviceUrl - sparql update endpoint url
    • addTriplesToNamedGraph

      public 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 endpoint
      Parameters:
      jenaModel - the triples to be added to the named graph
      namedGraphUrl - the named graph to which the triples shall be added
      serviceUrl - the sparql update endpoint
    • removeAllTriplesInNamedGraph

      public static 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
      Parameters:
      namedGraphUrl - the named graph that shall be emptied
      serviceUrl - the sparql update endpoint
    • processChangeEvent

      public 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 endpoint
      Parameters:
      changeEvent - the change event to be processed
      model - the updated representation of the changed resource if applicable
      serviceUrl - the sparql update endpoint
    • processQuery

      public static void processQuery(String query, String serviceUrl)
      Send the given sparql update to the sparql update service using the jena arq libraries
      Parameters:
      query - sparql update to be processeda
      serviceUrl - sparql update endpoint for processing the sparql update
    • appendSparqldQuery

      public static String appendSparqldQuery(String appending, String appended)
      append a sparql update to another
      Parameters:
      appending - the original sparql update
      appended - the sparql update to be appended
      Returns:
      the concatnated sparql update
    • linkTriple

      public static 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. This is a convenience for enabling the creation of links in a generic way
      Parameters:
      src - source of the link
      dst - destination of the link
      linkType - type of the link
      Returns:
      the rdf triple as n triple