Class QueryOperation

    • Constructor Summary

      Constructors 
      Constructor Description
      QueryOperation()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static org.semanticweb.owlapi.model.OWLOntology convertModel​(org.apache.jena.rdf.model.Model model)
      static org.semanticweb.owlapi.model.OWLOntology convertModel​(org.apache.jena.rdf.model.Model model, IOHelper ioHelper, String catalogPath)
      Given a Model, an IOHelper, and a path to an XML catalog, convert the model to an OWLOntology object.
      static int countResults​(org.apache.jena.query.ResultSet results)
      Count results.
      static org.apache.jena.query.Dataset createEmptyDataset()  
      static org.apache.jena.rdf.model.Model execConstruct​(org.apache.jena.query.Dataset dataset, String query)
      Execute a SPARQL CONSTRUCT query on a dataset and return a model.
      static org.apache.jena.rdf.model.Model execConstruct​(org.apache.jena.sparql.core.DatasetGraph dsg, String query)
      Deprecated.
      static org.apache.jena.query.ResultSet execQuery​(org.apache.jena.query.Dataset dataset, String query)
      Execute a SPARQL SELECT query on a dataset and return a result set.
      static org.apache.jena.query.ResultSet execQuery​(org.apache.jena.sparql.core.DatasetGraph dsg, String query)
      Deprecated.
      static void execUpdate​(org.apache.jena.rdf.model.Model model, String updateString)
      Given a Model and a SPARQL update (as string), update the model.
      static boolean execVerify​(Map<File,​Tuple<org.apache.jena.query.ResultSetRewindable,​OutputStream>> queriesResults)
      Deprecated.
      previously used as test method.
      static boolean execVerify​(org.apache.jena.query.Dataset dataset, String ruleName, String query)
      Given a dataset to query, a rule name, and the query string, execute the query over the dataset.
      static boolean execVerify​(org.apache.jena.sparql.core.DatasetGraph dsg, String ruleName, String query)
      Deprecated.
      static String getDefaultFormatName​(String query)
      Given a SPARQL query, return its default file format as a string.
      static String getDefaultFormatName​(org.apache.jena.query.Query query)
      Given a SPARQL query, return its default file format as a string.
      static org.apache.jena.riot.Lang getFormatLang​(String formatName)
      Convert a format name string to a language code.
      static String getQueryTypeName​(String queryString)
      Given a SPARQL query, return its type as a string: ASK, CONSTRUCT, DESCRIBE, or SELECT.
      static boolean hasResult​(org.apache.jena.query.ResultSet result)
      If a result set has results, return true, otherwise false.
      static boolean hasResult​(org.apache.jena.rdf.model.Model result)
      If a model has statements, return true, otherwise false.
      static org.apache.jena.sparql.core.DatasetGraph loadOntology​(org.semanticweb.owlapi.model.OWLOntology ontology)
      Deprecated.
      static org.apache.jena.query.Dataset loadOntologyAsDataset​(org.semanticweb.owlapi.model.OWLOntology ontology)
      Given an ontology, return a dataset containing that ontology as the only graph.
      static org.apache.jena.query.Dataset loadOntologyAsDataset​(org.semanticweb.owlapi.model.OWLOntology ontology, boolean useGraphs)
      Given an ontology and a boolean indicating if imports should be included as graphs, return a dataset either with just the ontology, or the ontology and its imports as separate graphs.
      static org.apache.jena.rdf.model.Model loadOntologyAsModel​(org.semanticweb.owlapi.model.OWLOntology ontology)
      Given an OWLOntology, return the Model representation of the axioms.
      static org.apache.jena.query.Dataset loadTriplesAsDataset​(String inputPath, String tdbDir)
      static boolean maybeWriteResult​(org.apache.jena.query.ResultSet result, String formatName, OutputStream output)
      If a result set has results, write to the output stream and return true.
      static boolean maybeWriteResult​(org.apache.jena.rdf.model.Model result, String formatName, OutputStream output)
      If a model has statements, write to the output stream and return true.
      static void runConstruct​(org.apache.jena.query.Dataset dataset, String query, File output, org.apache.jena.riot.Lang outputFormat)
      Run a CONSTRUCT query and write the result to a file.
      static void runQuery​(org.apache.jena.query.Dataset dataset, String query, File output, org.apache.jena.riot.Lang outputFormat)
      Run a SELECT query on a dataset and write the result to a file.
      static void runQuery​(org.apache.jena.sparql.core.DatasetGraph dsg, String query, File output, org.apache.jena.riot.Lang outputFormat)
      Deprecated.
      static boolean runSparqlQuery​(org.apache.jena.query.Dataset dataset, String queryString, String formatName, OutputStream output)
      Given a dataset, a query string, a format name, and an output stream, run the SPARQL query over the named graphs and write the output to the stream.
      static boolean runSparqlQuery​(org.apache.jena.query.QueryExecution qExec, String formatName, OutputStream output)
      Given a query execution, a format name, and an output stream, run the query and write to output.
      static boolean runSparqlQuery​(org.apache.jena.sparql.core.DatasetGraph dsg, String query, String formatName, OutputStream output)
      static void runUpdate​(org.apache.jena.rdf.model.Model model, String updateString, File output, org.apache.jena.riot.Lang outputFormat)
      Given a Model, a SPARQL update string, an output stream, and the output format, update the model and write it to the output.
      static boolean runVerify​(org.apache.jena.query.Dataset dataset, String ruleName, String query, Path outputPath, org.apache.jena.riot.Lang outputFormat)
      Run a SELECT query over the union of named graphs in a dataset and write the result to a file.
      static boolean runVerify​(org.apache.jena.sparql.core.DatasetGraph dsg, String ruleName, String query, Path outputPath, org.apache.jena.riot.Lang outputFormat)
      static void writeResult​(boolean result, OutputStream output)
      Write a boolean result to an output stream.
      static void writeResult​(org.apache.jena.query.ResultSet resultSet, String formatName, OutputStream output)
      Write a result set to an output stream.
      static void writeResult​(org.apache.jena.query.ResultSet resultSet, org.apache.jena.riot.Lang format, OutputStream output)
      Write a result set to an output stream.
      static void writeResult​(org.apache.jena.rdf.model.Model model, String formatName, OutputStream output)
      Write a model to an output stream.
      static void writeResult​(org.apache.jena.rdf.model.Model model, org.apache.jena.riot.Lang format, OutputStream output)
      Write a model to an output stream.
    • Constructor Detail

      • QueryOperation

        public QueryOperation()
    • Method Detail

      • loadOntology

        @Deprecated
        public static org.apache.jena.sparql.core.DatasetGraph loadOntology​(org.semanticweb.owlapi.model.OWLOntology ontology)
                                                                     throws org.semanticweb.owlapi.model.OWLOntologyStorageException
        Deprecated.
        Load an ontology into a DatasetGraph. The ontology is not changed.
        Parameters:
        ontology - The ontology to load into the graph
        Returns:
        A new DatasetGraph with the ontology loaded into the default graph
        Throws:
        org.semanticweb.owlapi.model.OWLOntologyStorageException - rarely
      • loadOntologyAsDataset

        public static org.apache.jena.query.Dataset loadOntologyAsDataset​(org.semanticweb.owlapi.model.OWLOntology ontology)
                                                                   throws org.semanticweb.owlapi.model.OWLOntologyStorageException
        Given an ontology, return a dataset containing that ontology as the only graph.
        Parameters:
        ontology - ontology to query
        Returns:
        dataset to query
        Throws:
        org.semanticweb.owlapi.model.OWLOntologyStorageException - on issue converting ontology Jena model
      • loadOntologyAsDataset

        public static org.apache.jena.query.Dataset loadOntologyAsDataset​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                          boolean useGraphs)
                                                                   throws org.semanticweb.owlapi.model.OWLOntologyStorageException
        Given an ontology and a boolean indicating if imports should be included as graphs, return a dataset either with just the ontology, or the ontology and its imports as separate graphs.
        Parameters:
        ontology - ontology to query
        useGraphs - if true, load imports as separate graphs
        Returns:
        dataset to query
        Throws:
        org.semanticweb.owlapi.model.OWLOntologyStorageException - on issue converting ontology Jena model
      • loadOntologyAsModel

        public static org.apache.jena.rdf.model.Model loadOntologyAsModel​(org.semanticweb.owlapi.model.OWLOntology ontology)
                                                                   throws org.semanticweb.owlapi.model.OWLOntologyStorageException
        Given an OWLOntology, return the Model representation of the axioms.
        Parameters:
        ontology - OWLOntology to convert to Model
        Returns:
        Model of axioms (imports ignored)
        Throws:
        org.semanticweb.owlapi.model.OWLOntologyStorageException - on issue rendering ontology to triples
      • loadTriplesAsDataset

        @Deprecated
        public static org.apache.jena.query.Dataset loadTriplesAsDataset​(String inputPath,
                                                                         String tdbDir)
        Given a path to an RDF/XML or TTL file and a RDF language, load the file as the default model of a TDB dataset backed by a directory to improve processing time. Return the new dataset.

        WARNING - this creates a directory at given tdbDir location!

        Parameters:
        inputPath - input path of RDF/XML or TTL file
        tdbDir - location to put TDB mappings
        Returns:
        Dataset instantiated with triples
      • convertModel

        @Deprecated
        public static org.semanticweb.owlapi.model.OWLOntology convertModel​(org.apache.jena.rdf.model.Model model)
                                                                     throws org.semanticweb.owlapi.model.OWLOntologyCreationException
        Given a Model, return the OWLOntology representation of the axioms.
        Parameters:
        model - Model to convert to OWLOntology
        Returns:
        OWLOntology of axioms
        Throws:
        org.semanticweb.owlapi.model.OWLOntologyCreationException - on issue loading ontology from byte array
      • convertModel

        public static org.semanticweb.owlapi.model.OWLOntology convertModel​(org.apache.jena.rdf.model.Model model,
                                                                            IOHelper ioHelper,
                                                                            String catalogPath)
                                                                     throws IOException
        Given a Model, an IOHelper, and a path to an XML catalog, convert the model to an OWLOntology object.
        Parameters:
        model - Model to convert to OWLOntology
        ioHelper - IOHelper to load ontology
        catalogPath - String path to XML catalog
        Returns:
        OWLOntology object version of model
        Throws:
        IOException - on issue loading ontology
      • countResults

        public static int countResults​(org.apache.jena.query.ResultSet results)
        Count results.
        Parameters:
        results - The result set to count.
        Returns:
        the size of the result set
      • createEmptyDataset

        public static org.apache.jena.query.Dataset createEmptyDataset()
      • execConstruct

        @Deprecated
        public static org.apache.jena.rdf.model.Model execConstruct​(org.apache.jena.sparql.core.DatasetGraph dsg,
                                                                    String query)
        Deprecated.
        Execute a SPARQL CONSTRUCT query on a graph and return the model.
        Parameters:
        dsg - the graph to construct in
        query - the SPARQL construct query string
        Returns:
        the result Model
      • execConstruct

        public static org.apache.jena.rdf.model.Model execConstruct​(org.apache.jena.query.Dataset dataset,
                                                                    String query)
        Execute a SPARQL CONSTRUCT query on a dataset and return a model.
        Parameters:
        dataset - the Dataset to construct in
        query - the SPARQL construct query string
        Returns:
        the result Model
      • execQuery

        @Deprecated
        public static org.apache.jena.query.ResultSet execQuery​(org.apache.jena.sparql.core.DatasetGraph dsg,
                                                                String query)
                                                         throws IOException
        Deprecated.
        Execute a SPARQL SELECT query on a graph and return a result set.
        Parameters:
        dsg - the graph to query
        query - the SPARQL query string
        Returns:
        the result set
        Throws:
        IOException - on query parse error
      • execQuery

        public static org.apache.jena.query.ResultSet execQuery​(org.apache.jena.query.Dataset dataset,
                                                                String query)
                                                         throws IOException
        Execute a SPARQL SELECT query on a dataset and return a result set.
        Parameters:
        dataset - the Dataset to query over
        query - the SPARQL query string
        Returns:
        the result set
        Throws:
        IOException - on query parse error
      • execUpdate

        public static void execUpdate​(org.apache.jena.rdf.model.Model model,
                                      String updateString)
        Given a Model and a SPARQL update (as string), update the model.
        Parameters:
        model - Model to update
        updateString - SPARQL update
      • execVerify

        @Deprecated
        public static boolean execVerify​(Map<File,​Tuple<org.apache.jena.query.ResultSetRewindable,​OutputStream>> queriesResults)
                                  throws IOException
        Deprecated.
        previously used as test method.
        Execute a verification. Writes to STDERR.
        Parameters:
        queriesResults - a map from files to query results and output streams
        Returns:
        true if there are any violations
        Throws:
        IOException - on file issues
      • execVerify

        @Deprecated
        public static boolean execVerify​(org.apache.jena.sparql.core.DatasetGraph dsg,
                                         String ruleName,
                                         String query)
                                  throws IOException
        Deprecated.
        Execute a SPARQL query and return true if there are any results, false otherwise.
        Parameters:
        dsg - the graph to query over
        ruleName - name of rule to verify
        query - the SPARQL query string
        Returns:
        true if the are results, false otherwise
        Throws:
        IOException - on query parse error
      • execVerify

        public static boolean execVerify​(org.apache.jena.query.Dataset dataset,
                                         String ruleName,
                                         String query)
                                  throws IOException
        Given a dataset to query, a rule name, and the query string, execute the query over the dataset.
        Parameters:
        dataset - Dataset to query
        ruleName - name of rule to verify
        query - the SPARQL query string
        Returns:
        true if there are results, false otherwise
        Throws:
        IOException - on query parse error
      • getDefaultFormatName

        public static String getDefaultFormatName​(String query)
        Given a SPARQL query, return its default file format as a string.
        Parameters:
        query - the SPARQL query string
        Returns:
        the format name
      • getDefaultFormatName

        public static String getDefaultFormatName​(org.apache.jena.query.Query query)
                                           throws IllegalArgumentException
        Given a SPARQL query, return its default file format as a string.
        Parameters:
        query - the SPARQL query
        Returns:
        the format name
        Throws:
        IllegalArgumentException - on bad query
      • getFormatLang

        public static org.apache.jena.riot.Lang getFormatLang​(String formatName)
        Convert a format name string to a language code.
        Parameters:
        formatName - the format name as a string
        Returns:
        the format language code or null
      • getQueryTypeName

        public static String getQueryTypeName​(String queryString)
        Given a SPARQL query, return its type as a string: ASK, CONSTRUCT, DESCRIBE, or SELECT.
        Parameters:
        queryString - the SPARQL query string
        Returns:
        the query type string
        Throws:
        IllegalArgumentException - on bad query
      • hasResult

        public static boolean hasResult​(org.apache.jena.query.ResultSet result)
        If a result set has results, return true, otherwise false.
        Parameters:
        result - the results to write
        Returns:
        true if there are results, false otherwise
      • hasResult

        public static boolean hasResult​(org.apache.jena.rdf.model.Model result)
        If a model has statements, return true, otherwise false.
        Parameters:
        result - the results to write
        Returns:
        true if there are statements, false otherwise
      • maybeWriteResult

        public static boolean maybeWriteResult​(org.apache.jena.query.ResultSet result,
                                               String formatName,
                                               OutputStream output)
        If a result set has results, write to the output stream and return true. Otherwise return false.
        Parameters:
        result - the results to write
        formatName - the name of the language to write in
        output - the output stream to write to
        Returns:
        true if there were results, false otherwise
      • maybeWriteResult

        public static boolean maybeWriteResult​(org.apache.jena.rdf.model.Model result,
                                               String formatName,
                                               OutputStream output)
        If a model has statements, write to the output stream and return true. Otherwise return false.
        Parameters:
        result - the Model to write
        formatName - the name of the language to write in
        output - the output stream to write to
        Returns:
        true if there were statements, false otherwise
      • runConstruct

        public static void runConstruct​(org.apache.jena.query.Dataset dataset,
                                        String query,
                                        File output,
                                        org.apache.jena.riot.Lang outputFormat)
                                 throws FileNotFoundException
        Run a CONSTRUCT query and write the result to a file.
        Parameters:
        dataset - the Dataset to construct in.
        query - The SPARQL construct query string.
        output - The file to write to.
        outputFormat - The file format.
        Throws:
        FileNotFoundException - if output file is not found
      • runQuery

        @Deprecated
        public static void runQuery​(org.apache.jena.sparql.core.DatasetGraph dsg,
                                    String query,
                                    File output,
                                    org.apache.jena.riot.Lang outputFormat)
                             throws IOException
        Deprecated.
        Run a SELECT query on a graph and write the results to a file.
        Parameters:
        dsg - the graph to query
        query - The SPARQL query string.
        output - The file to write to.
        outputFormat - The file format.
        Throws:
        IOException - if output file is not found or query cannot be parsed
      • runQuery

        public static void runQuery​(org.apache.jena.query.Dataset dataset,
                                    String query,
                                    File output,
                                    org.apache.jena.riot.Lang outputFormat)
                             throws IOException
        Run a SELECT query on a dataset and write the result to a file.
        Parameters:
        dataset - The dataset to query over.
        query - The SPARQL query string.
        output - The file to write to.
        outputFormat - The file format.
        Throws:
        IOException - if output file is not found or query cannot be parsed
      • runSparqlQuery

        @Deprecated
        public static boolean runSparqlQuery​(org.apache.jena.sparql.core.DatasetGraph dsg,
                                             String query,
                                             String formatName,
                                             OutputStream output)
                                      throws IOException
        Run a SPARQL query and return true if there were results, false otherwise.
        Parameters:
        dsg - the graph to query over
        query - the SPARQL query string
        formatName - the name of the output format
        output - the OutputStream to write to
        Returns:
        true if results, false if otherwise
        Throws:
        IOException - on issue parsing query
      • runSparqlQuery

        public static boolean runSparqlQuery​(org.apache.jena.query.Dataset dataset,
                                             String queryString,
                                             String formatName,
                                             OutputStream output)
                                      throws IOException
        Given a dataset, a query string, a format name, and an output stream, run the SPARQL query over the named graphs and write the output to the stream.
        Parameters:
        dataset - Dataset to query over
        queryString - query to run
        formatName - format of output
        output - output stream to write to
        Returns:
        true if successful
        Throws:
        IOException - on issue parsing query
      • runSparqlQuery

        public static boolean runSparqlQuery​(org.apache.jena.query.QueryExecution qExec,
                                             String formatName,
                                             OutputStream output)
        Given a query execution, a format name, and an output stream, run the query and write to output.
        Parameters:
        qExec - QueryExecution to run
        formatName - format of output
        output - output stream to write to
        Returns:
        true if there are results
      • runUpdate

        public static void runUpdate​(org.apache.jena.rdf.model.Model model,
                                     String updateString,
                                     File output,
                                     org.apache.jena.riot.Lang outputFormat)
                              throws FileNotFoundException
        Given a Model, a SPARQL update string, an output stream, and the output format, update the model and write it to the output.
        Parameters:
        model - Model to update
        updateString - SPARQL update
        output - output stream to write to
        outputFormat - the file format
        Throws:
        FileNotFoundException - if output file cannot be found
      • runVerify

        @Deprecated
        public static boolean runVerify​(org.apache.jena.sparql.core.DatasetGraph dsg,
                                        String ruleName,
                                        String query,
                                        Path outputPath,
                                        org.apache.jena.riot.Lang outputFormat)
                                 throws IOException
        Run a SELECT query over the graph and write the result to a file. Prints violations to STDERR.
        Parameters:
        dsg - The graph to query over.
        ruleName - name of the rule
        query - The SPARQL query string.
        outputPath - The file path to write to, if there are results
        outputFormat - The file format.
        Returns:
        true if the are results (so file is written), false otherwise
        Throws:
        IOException - if output file is not found or query cannot be parsed
      • runVerify

        public static boolean runVerify​(org.apache.jena.query.Dataset dataset,
                                        String ruleName,
                                        String query,
                                        Path outputPath,
                                        org.apache.jena.riot.Lang outputFormat)
                                 throws IOException
        Run a SELECT query over the union of named graphs in a dataset and write the result to a file. Prints violations to STDERR.
        Parameters:
        dataset - The dataset to query over.
        ruleName - The name of the rule to verify.
        query - The SPARQL query string.
        outputPath - The file path to write to, if there are results
        outputFormat - The file format.
        Returns:
        true if the are results (so file is written), false otherwise
        Throws:
        IOException - if output file is not found or query cannot be parsed
      • writeResult

        public static void writeResult​(boolean result,
                                       OutputStream output)
        Write a boolean result to an output stream.
        Parameters:
        result - the boolean to write
        output - the output stream to write to
      • writeResult

        public static void writeResult​(org.apache.jena.query.ResultSet resultSet,
                                       String formatName,
                                       OutputStream output)
        Write a result set to an output stream.
        Parameters:
        resultSet - the results to write
        formatName - the name of the language to write in
        output - the output stream to write to
      • writeResult

        public static void writeResult​(org.apache.jena.query.ResultSet resultSet,
                                       org.apache.jena.riot.Lang format,
                                       OutputStream output)
        Write a result set to an output stream.
        Parameters:
        resultSet - the results to write
        format - the language to write in (if null, CSV)
        output - the output stream to write to
      • writeResult

        public static void writeResult​(org.apache.jena.rdf.model.Model model,
                                       String formatName,
                                       OutputStream output)
        Write a model to an output stream.
        Parameters:
        model - the Model to write
        formatName - the name of the language to write in
        output - the output stream to write to
      • writeResult

        public static void writeResult​(org.apache.jena.rdf.model.Model model,
                                       org.apache.jena.riot.Lang format,
                                       OutputStream output)
        Write a model to an output stream.
        Parameters:
        model - the Model to write
        format - the language to write in (if null, TTL)
        output - the output stream to write to