Class SparqlQueries


  • public class SparqlQueries
    extends Object
    This class provides static SPRAQL queries that are loaded from predefined resources.
    Author:
    Michael Röder (roeder@informatik.uni-leipzig.de)
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • DEFAULT_MAX_UPDATE_QUERY_TRIPLES

        private static final int DEFAULT_MAX_UPDATE_QUERY_TRIPLES
        Default value of the maximum triples a single update query should have.
        See Also:
        Constant Field Values
      • EMPTY_MODEL

        private static final org.apache.jena.rdf.model.Model EMPTY_MODEL
        An empty RDF model instance.
      • GET_LICENSE_OF_DATASET

        private static final String GET_LICENSE_OF_DATASET
        A construct query for getting the licensing data of the specified dataset.
      • GET_ANALYSIS_RESULTS_OF_BENCHMARK

        private static final String GET_ANALYSIS_RESULTS_OF_BENCHMARK
        A construct query for getting the analysis results of all systems for a certain benchmark.
      • DELETE_ANALYSIS_RESULTS

        private static final String DELETE_ANALYSIS_RESULTS
        A construct query for getting the analysis results of all systems for a certain benchmark.
      • GET_CHALLENGE_GRAPH_QUERY

        private static final String GET_CHALLENGE_GRAPH_QUERY
        A construct query that retrieves the graph of a challenge.
      • GET_SHALLOW_CHALLENGE_GRAPH_QUERY

        private static final String GET_SHALLOW_CHALLENGE_GRAPH_QUERY
        A construct query that retrieves a shallow of a challenge.
      • GET_CHALLENGE_TASKS_QUERY

        private static final String GET_CHALLENGE_TASKS_QUERY
        A construct query that retrieves the tasks of a challenge.
      • GET_CHALLENGE_PUBLISH_INFO_QUERY

        private static final String GET_CHALLENGE_PUBLISH_INFO_QUERY
        A construct query that retrieves the graph of a challenge.
      • GET_REPEATABLE_CHALLENGE_INFO_QUERY

        private static final String GET_REPEATABLE_CHALLENGE_INFO_QUERY
        A construct query that retrieves the graph of a repeatable challenge.
      • CLOSE_CHALLENGE_UPDATE_QUERY

        private static final String CLOSE_CHALLENGE_UPDATE_QUERY
        An update query that closes a challenge.
      • DATE_OF_NEXT_EXECUTION_UPDATE_QUERY

        private static final String DATE_OF_NEXT_EXECUTION_UPDATE_QUERY
        An update query that changes next execution date for a repeatable challenge.
      • MOVE_CHALLENGE_SYSTEM_QUERY

        private static final String MOVE_CHALLENGE_SYSTEM_QUERY
        An update query that moves involvesSystem triples between graphs.
      • GET_EXPERIMENT_QUERY

        private static final String GET_EXPERIMENT_QUERY
        A construct query that selects the graph of an experiment.
      • GET_SHALLOW_EXPERIMENT_QUERY

        private static final String GET_SHALLOW_EXPERIMENT_QUERY
        A construct query that selects a shallow graph of an experiment.
      • GET_EXPERIMENT_OF_BENCHMARK_QUERY

        private static final String GET_EXPERIMENT_OF_BENCHMARK_QUERY
        A construct query that selects the graph of an experiment that is part of a given challenge task.
      • GET_EXPERIMENT_OF_TASK_QUERY

        private static final String GET_EXPERIMENT_OF_TASK_QUERY
        A construct query that selects the graph of an experiment that is part of a given challenge task.
      • CREATE_EXPERIMENT_FROM_CHALLENGE_TASK

        private static final String CREATE_EXPERIMENT_FROM_CHALLENGE_TASK
        A construct query that selects the subgraph of a challenge task that defines an experiment of this task.
      • DELETE_EXPERIMENT_GRAPH_QUERY

        private static final String DELETE_EXPERIMENT_GRAPH_QUERY
        An update query that deletes the graph of an experiment.
      • DELETE_CHALLENGE_GRAPH_QUERY

        private static final String DELETE_CHALLENGE_GRAPH_QUERY
        An update query that deletes the graph of a challenge.
      • CLEAN_UP_CHALLENGE_GRAPH_QUERY

        @Deprecated
        private static final String CLEAN_UP_CHALLENGE_GRAPH_QUERY
        Deprecated.
        An update query that cleans up the graph of containing challenges.
      • CLEAN_UP_CHALLENGE_GRAPH_QUERIES

        private static final String[] CLEAN_UP_CHALLENGE_GRAPH_QUERIES
        An update query that cleans up the graph of containing challenges.
      • CLEAN_UP_PRIVATE_GRAPH_QUERIES

        private static final String[] CLEAN_UP_PRIVATE_GRAPH_QUERIES
        An update query that cleans up the graph of containing challenges.
      • COUNT_EXP_OF_TASK_QUERY

        private static final String COUNT_EXP_OF_TASK_QUERY
        A select query for counting the number of experiments of a challenge task.
      • GET_CHALLENGE_TASK_ORGANIZER

        private static final String GET_CHALLENGE_TASK_ORGANIZER
        A construct query for getting the organizer of the challenge two which a given challenge tasks belong to.
    • Constructor Detail

      • SparqlQueries

        public SparqlQueries()
    • Method Detail

      • loadQuery

        private static final String loadQuery​(String resourceName)
        Loads the given resource, e.g., a SPARQL query, as String.
        Parameters:
        resourceName - name of the resource that should be loaded
        Returns:
        the resource as String or null if an error occurs
      • getLicenseOfDataset

        public static final String getLicenseOfDataset​(String graphUri)
        Returns a SPARQL CONSTRUCT query for getting the analysis results of all systems for a certain benchmark.
        Parameters:
        benchmarkUri - URI of the benchmark
        graphUri - URI of the graph the experiment is stored. null works like a wildcard.
        Returns:
        the SPARQL CONSTRUCT query that performs the retrieving or null if the query hasn't been loaded correctly
      • getAnalysisResultsOfBenchmark

        public static final String getAnalysisResultsOfBenchmark​(String benchmarkUri,
                                                                 String graphUri)
        Returns a SPARQL CONSTRUCT query for getting the analysis results of all systems for a certain benchmark.
        Parameters:
        benchmarkUri - URI of the benchmark
        graphUri - URI of the graph the experiment is stored. null works like a wildcard.
        Returns:
        the SPARQL CONSTRUCT query that performs the retrieving or null if the query hasn't been loaded correctly
      • deleteAnalysisResults

        public static final String deleteAnalysisResults​(String analysisResultSetUri,
                                                         String graphUri)
        Returns a SPARQL DELETE query for removing the analysis results set with the given URI.
        Parameters:
        analysisResultSetUri - URI of the analysis result set which should be removed
        graphUri - URI of the graph the analysis result set is stored.
        Returns:
        the SPARQL DELETE query that performs the removal or null if the query hasn't been loaded correctly
      • getChallengeGraphQuery

        public static final String getChallengeGraphQuery​(String challengeUri,
                                                          String graphUri)
        Returns a SPARQL query for retrieving the graph of a challenge.
        Parameters:
        challengeUri - URI of the challenge that should be retrieved. null works like a wildcard.
        graphUri - URI of the graph the challenge is stored. null works like a wildcard.
        Returns:
        the SPARQL construct query that performs the retrieving or null if the query hasn't been loaded correctly
      • getShallowChallengeGraphQuery

        public static final String getShallowChallengeGraphQuery​(String challengeUri,
                                                                 String graphUri)
        Returns a SPARQL query for retrieving a shallow graph of a challenge.
        Parameters:
        challengeUri - URI of the challenge that should be retrieved. null works like a wildcard.
        graphUri - URI of the graph the challenge is stored. null works like a wildcard.
        Returns:
        the SPARQL construct query that performs the retrieving or null if the query hasn't been loaded correctly
      • getChallengeTasksQuery

        public static final String getChallengeTasksQuery​(String challengeUri,
                                                          String graphUri)
        Returns a SPARQL query for retrieving the tasks of a challenge.
        Parameters:
        challengeUri - URI of the challenge that should be retrieved. null works like a wildcard.
        graphUri - URI of the graph the challenge is stored. null works like a wildcard.
        Returns:
        the SPARQL construct query that performs the retrieving or null if the query hasn't been loaded correctly
      • getChallengePublishInfoQuery

        public static final String getChallengePublishInfoQuery​(String challengeUri,
                                                                String graphUri)
        Returns a SPARQL query for retrieving a graph comprising the task URIs and the publication date of a challenge if this challenge is closed.
        Parameters:
        challengeUri - URI of the challenge that should be retrieved. null works like a wildcard.
        graphUri - URI of the graph the challenge is stored. null works like a wildcard.
        Returns:
        the SPARQL construct query that performs the retrieving or null if the query hasn't been loaded correctly
      • getRepeatableChallengeInfoQuery

        public static final String getRepeatableChallengeInfoQuery​(String challengeUri,
                                                                   String graphUri)
        Returns a SPARQL query for retrieving a graph comprising repeatable challenge properties if this challenge is closed.
        Parameters:
        challengeUri - URI of the challenge that should be retrieved. null works like a wildcard.
        graphUri - URI of the graph the challenge is stored. null works like a wildcard.
        Returns:
        the SPARQL construct query that performs the retrieving or null if the query hasn't been loaded correctly
      • getCloseChallengeQuery

        public static final String getCloseChallengeQuery​(String challengeUri,
                                                          String graphUri)
        Returns a SPARQL query for adding the closed triple to the challenge with the given URI.
        Parameters:
        challengeUri - URI of the challenge that should be closed. null works like a wildcard.
        graphUri - URI of the graph the challenge is stored. null works like a wildcard.
        Returns:
        the SPARQL update query that performs the insertion or null if the query hasn't been loaded correctly
      • getUpdateDateOfNextExecutionQuery

        public static final String getUpdateDateOfNextExecutionQuery​(String challengeUri,
                                                                     Calendar newValue,
                                                                     String graphUri)
        Returns a SPARQL query for updating the date of next execution for a repeatable challenge with given URI.
        Parameters:
        challengeUri - URI of the challenge that should be updated. null works like a wildcard.
        newValue - New value for date of next execution. null to remove the value.
        graphUri - URI of the graph the challenge is stored. null works like a wildcard.
        Returns:
        the SPARQL update query that performs the insertion or null if the query hasn't been loaded correctly
      • getMoveChallengeSystemQuery

        public static final String getMoveChallengeSystemQuery​(String challengeUri,
                                                               String graphUri,
                                                               String newGraphUri)
        Returns a SPARQL query for moving involvesSystem triples between graphs for a challenge with given URI.
        Parameters:
        challengeUri - URI of the challenge that should be updated. null works like a wildcard.
        graphUri - URI of the challenge definition graph.
        newGraphUri - URI of the public data graph.
        Returns:
        the SPARQL update query that performs the operation or null if the query hasn't been loaded correctly
      • getExperimentGraphQuery

        public static final String getExperimentGraphQuery​(String experimentUri,
                                                           String graphUri)
        Returns a SPARQL query for retrieving the graph of an experiment.
        Parameters:
        experimentUri - URI of the experiment that should be retrieved. null works like a wildcard.
        graphUri - URI of the graph the experiment is stored. null works like a wildcard.
        Returns:
        the SPARQL construct query that performs the retrieving or null if the query hasn't been loaded correctly
      • getShallowExperimentGraphQuery

        public static final String getShallowExperimentGraphQuery​(String experimentUri,
                                                                  String graphUri)
        Returns a SPARQL query for retrieving a shallow graph of an experiment containing the links to the system instance, the benchmark and the challenge task and the labels of them.
        Parameters:
        experimentUri - URI of the experiment that should be retrieved. null works like a wildcard.
        graphUri - URI of the graph the experiment is stored. null works like a wildcard.
        Returns:
        the SPARQL construct query that performs the retrieving or null if the query hasn't been loaded correctly
      • extendQuery

        private static final String extendQuery​(String query,
                                                String target,
                                                String extension)
        Extends a SPARQL query by inserting specified extension string every time a target string is found.
        Parameters:
        query - The original query.
        target - Target string to find.
        extension - Extension string to insert.
        Returns:
        the modified query or null if the query is invalid.
      • getExperimentGraphOfBenchmarksQuery

        public static final String getExperimentGraphOfBenchmarksQuery​(List<String> benchmarkUris,
                                                                       String graphUri)
        Returns a SPARQL query for retrieving the graphs of experiments that involve one of the given benchmarks.
        Parameters:
        benchmarkUris - URIs of the benchmarks that might be involved in the experiment.
        graphUri - URI of the graph the experiment is stored. null works like a wildcard.
        Returns:
        the SPARQL construct query that performs the retrieving or null if the query hasn't been loaded correctly
      • getExperimentGraphOfSystemsQuery

        public static final String getExperimentGraphOfSystemsQuery​(List<String> systemUris,
                                                                    String graphUri)
        Returns a SPARQL query for retrieving the graphs of experiments that involve one of the given systems.
        Parameters:
        systemUris - URIs of the systems that might be involved in the experiment.
        graphUri - URI of the graph the experiment is stored. null works like a wildcard.
        Returns:
        the SPARQL construct query that performs the retrieving or null if the query hasn't been loaded correctly
      • getExperimentGraphOfBenchmarkQuery

        public static final String getExperimentGraphOfBenchmarkQuery​(String benchmarkUri,
                                                                      String graphUri)
        Returns a SPARQL query for retrieving the graphs of experiments that involve the given benchmark.
        Parameters:
        benchmarkUri - URIs of the benchmark that might be involved in the experiment.
        graphUri - URI of the graph the experiment is stored. null works like a wildcard.
        Returns:
        the SPARQL construct query that performs the retrieving or null if the query hasn't been loaded correctly
      • getExperimentOfTaskQuery

        public static final String getExperimentOfTaskQuery​(String experimentUri,
                                                            String challengeTaskUri,
                                                            String graphUri)
        Returns a SPARQL query for retrieving the graph of an experiment that is part of the given challenge task.
        Parameters:
        experimentUri - URI of the experiment that should be retrieved. null works like a wildcard.
        challengeTaskUri - URI of the challenge task from which the experiment should be created. null works like a wildcard.
        graphUri - URI of the graph the experiment is stored. null works like a wildcard.
        Returns:
        the SPARQL construct query that performs the retrieving or null if the query hasn't been loaded correctly
      • getCreateExperimentFromTaskQuery

        public static final String getCreateExperimentFromTaskQuery​(String experimentUri,
                                                                    String challengeTaskUri,
                                                                    String systemUri,
                                                                    String graphUri)
        Returns a SPARQL query for creating a subgraph of a challenge task that defines an experiment of this task.
        Parameters:
        experimentUri - URI of the newly created experiment.
        challengeTaskUri - URI of the challenge task from which the experiment should be created. null works like a wildcard.
        systemUri - URI of the system of the experiment. null works like a wildcard.
        graphUri - URI of the graph the experiment is stored. null works like a wildcard.
        Returns:
        the SPARQL construct query that performs the retrieving or null if the query hasn't been loaded correctly
        Throws:
        IllegalArgumentException - if the given experimentUri is null
      • deleteExperimentGraphQuery

        public static final String deleteExperimentGraphQuery​(String experimentUri,
                                                              String graphUri)
        Returns a SPARQL update query for deleting the graph of an experiment.
        Parameters:
        experimentUri - URI of the experiment that should be retrieved. null works like a wildcard.
        graphUri - URI of the graph the challenge is stored.
        Returns:
        the SPARQL update query that performs the deletion or null if the query hasn't been loaded correctly
      • deleteChallengeGraphQuery

        public static final String deleteChallengeGraphQuery​(String challengeUri,
                                                             String graphUri)
        Returns a SPARQL update query for deleting the graph of a challenge.
        Parameters:
        challengeUri - URI of the challenge that should be retrieved. null works like a wildcard.
        graphUri - URI of the graph the challenge is stored.
        Returns:
        the SPARQL update query that performs the deletion or null if the query hasn't been loaded correctly
      • cleanUpChallengeGraphQuery

        @Deprecated
        public static final String cleanUpChallengeGraphQuery​(String graphUri)
        Deprecated.
        A single large query does not seem to be supported by all triple stores. Use cleanUpChallengeGraphQueries(String) instead.
        Returns a SPARQL update query for cleaning up the graph of a challenge configs.
        Parameters:
        graphUri - URI of the graph the challenge is stored. null works like a wildcard.
        Returns:
        the SPARQL update query that performs the deletion or null if the query hasn't been loaded correctly
      • cleanUpChallengeGraphQueries

        public static final String[] cleanUpChallengeGraphQueries​(String graphUri)
        Returns a SPARQL update query for cleaning up the graph of a challenge configs.
        Parameters:
        graphUri - URI of the challenge configuration graph.
        Returns:
        the SPARQL update query that performs the deletion or null if the query hasn't been loaded correctly
      • cleanUpPrivateGraphQueries

        public static final String[] cleanUpPrivateGraphQueries​(String graphUri)
        Returns a SPARQL update query for cleaning up the private result graph.
        Parameters:
        graphUri - URI of the private result graph.
        Returns:
        the SPARQL update query that performs the deletion or null if the query hasn't been loaded correctly
      • countExperimentsOfTaskQuery

        public static final String countExperimentsOfTaskQuery​(String challengeTaskUri,
                                                               String graphUri)
        Returns a SPARQL query for counting the number of experiments of a challenge task.
        Parameters:
        challengeTaskUri - URI of the challenge task
        graphUri - URI of the graph the experiment is stored. null works like a wildcard.
        Returns:
        the SPARQL select query that performs the retrieving or null if the query hasn't been loaded correctly
      • getChallengeTaskOrganizer

        public static final String getChallengeTaskOrganizer​(String challengeTaskUri,
                                                             String graphUri)
        Returns a SPARQL CONSTRUCT query for getting the organizer of the challenge two which a given challenge tasks belong to.
        Parameters:
        challengeTaskUri - URI of the challenge task
        graphUri - URI of the graph the experiment is stored. null works like a wildcard.
        Returns:
        the SPARQL CONSTRUCT query that performs the retrieving or null if the query hasn't been loaded correctly
      • replacePlaceholders

        private static final String replacePlaceholders​(String query,
                                                        String[] placeholders,
                                                        String[] replacements)
        Replaces the given placeholders in the given query with the given replacements. If a replacement is null, it is replaced by a variable.
        Parameters:
        query - the query containing placeholders
        placeholders - the placeholders that should be replaced
        replacements - the replacements that should be used to replace the placeholders.
        Returns:
        the newly created query or null if the given query was null.
      • getUpdateQueryFromDiff

        public static final String getUpdateQueryFromDiff​(org.apache.jena.rdf.model.Model original,
                                                          org.apache.jena.rdf.model.Model updated,
                                                          String graphUri)
        Generates a SPARQL UPDATE query based on the differences between the two given models. Triples that are present in the original model but not in the updated model will be put into the DELETE part of the query. Triples that are present in the updated model but can not be found in the original model will be put into the INSERT part of the query.

        Note that some stores might have a maximum number of triples that can be processed with a single query. In these cases getUpdateQueriesFromDiff(Model, Model, String, int) should be used.

        Parameters:
        original - the original RDF model
        updated - the updated RDF model
        graphUri - the URI of the graph to which the UPDATE query should be applied or null
        Returns:
        The SPARQL UPDATE query
      • getUpdateQueryFromStatements

        public static final String getUpdateQueryFromStatements​(List<org.apache.jena.rdf.model.Statement> deleted,
                                                                List<org.apache.jena.rdf.model.Statement> inserted,
                                                                org.apache.jena.shared.PrefixMapping mapping,
                                                                String graphUri)
        Generates a SPARQL UPDATE query based on the given list of statements that should be deleted and that should be added in the graph with the given URI.
        Parameters:
        deleted - statements that should be deleted from the graph
        inserted - statements that should be added to the graph
        mapping - A prefix mapping used for the query
        graphUri - the URI of the graph which should be updated with the generated query
        Returns:
        the update query
      • getUpdateQueriesFromDiff

        public static final String[] getUpdateQueriesFromDiff​(org.apache.jena.rdf.model.Model original,
                                                              org.apache.jena.rdf.model.Model updated,
                                                              String graphUri)
        Generates one or several SPARQL UPDATE queries based on the differences between the two given models. Triples that are present in the original model but not in the updated model will be put into the DELETE part of the query. Triples that are present in the updated model but can not be found in the original model will be put into the INSERT part of the query. The changes might be carried out using multiple queries if a single query could hit a maximum number of triples.
        Parameters:
        original - the original RDF model (null is interpreted as an empty model)
        updated - the updated RDF model (null is interpreted as an empty model)
        graphUri - the URI of the graph to which the UPDATE query should be applied or null
        Returns:
        The SPARQL UPDATE query
      • getUpdateQueriesFromDiff

        public static final String[] getUpdateQueriesFromDiff​(org.apache.jena.rdf.model.Model original,
                                                              org.apache.jena.rdf.model.Model updated,
                                                              String graphUri,
                                                              int maxTriplesPerQuery)
        Generates one or several SPARQL UPDATE queries based on the differences between the two given models. Triples that are present in the original model but not in the updated model will be put into the DELETE part of the query. Triples that are present in the updated model but can not be found in the original model will be put into the INSERT part of the query. The changes will be carried out using multiple queries if a single query would hit the given maximum number of triples per query.
        Parameters:
        original - the original RDF model (null is interpreted as an empty model)
        updated - the updated RDF model (null is interpreted as an empty model)
        graphUri - the URI of the graph to which the UPDATE query should be applied or null
        maxTriplesPerQuery - the maximum number of triples a single query should contain
        Returns:
        The SPARQL UPDATE query