Class JenaUtil

java.lang.Object
org.topbraid.jenax.util.JenaUtil

public class JenaUtil extends Object
Some convenience methods to operate on Jena Models. These methods are not as stable as the rest of the API, but they may be of general use.
Author:
Holger Knublauch
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addTransitiveObjects(Set<org.apache.jena.rdf.model.Resource> results, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Populates a result set of resources reachable from a subject via zero or more steps with a given predicate.
    static org.apache.jena.sparql.engine.binding.Binding
    asBinding(org.apache.jena.query.QuerySolution map)
    Turns a QuerySolution into a Binding.
    static org.apache.jena.rdf.model.Property
    asProperty(org.apache.jena.rdf.model.Resource resource)
    Casts a Resource into a Property.
    static org.apache.jena.query.QuerySolutionMap
    asQuerySolutionMap(org.apache.jena.sparql.engine.binding.Binding binding)
    Turns a Binding into a QuerySolutionMap.
    static org.apache.jena.graph.Graph
    asReadOnlyGraph(org.apache.jena.graph.Graph g)
    This indicates that no further changes to the graph are needed.
    static org.apache.jena.rdf.model.Model
    asReadOnlyModel(org.apache.jena.rdf.model.Model m)
    This indicates that no further changes to the model are needed.
    static void
    collectBaseGraphs(org.apache.jena.graph.Graph graph, Set<org.apache.jena.graph.Graph> baseGraphs)
     
    static org.apache.jena.graph.Graph
    Creates a new Graph.
    static org.apache.jena.rdf.model.Model
    Wraps the result of createDefaultGraph() into a Model and initializes namespaces.
    static org.apache.jena.graph.Graph
    Creates a memory Graph with no reification.
    static org.apache.jena.rdf.model.Model
    Creates a memory Model with no reification.
    static org.apache.jena.graph.compose.MultiUnion
     
    static org.apache.jena.graph.compose.MultiUnion
    createMultiUnion(Iterator<org.apache.jena.graph.Graph> graphs)
     
    static org.apache.jena.graph.compose.MultiUnion
    createMultiUnion(org.apache.jena.graph.Graph[] graphs)
     
    static org.apache.jena.ontology.OntModel
    createOntologyModel(org.apache.jena.ontology.OntModelSpec spec, org.apache.jena.rdf.model.Model base)
     
    static org.apache.jena.graph.Graph
    deepCloneForReadOnlyThreadSafe(org.apache.jena.graph.Graph g)
    Ensure that we there is a read-only, thread safe version of the graph.
    static Set<org.apache.jena.rdf.model.Resource>
    getAllInstances(org.apache.jena.rdf.model.Resource cls)
    Gets all instances of a given class and its subclasses.
    static Set<org.apache.jena.rdf.model.Resource>
    getAllSubClasses(org.apache.jena.rdf.model.Resource cls)
     
    static Set<org.apache.jena.rdf.model.Resource>
    getAllSubClassesStar(org.apache.jena.rdf.model.Resource cls)
    Returns a set consisting of a given class and all its subclasses.
    static Set<org.apache.jena.rdf.model.Resource>
    getAllSubProperties(org.apache.jena.rdf.model.Property superProperty)
     
    static Set<org.apache.jena.rdf.model.Resource>
    getAllSuperClasses(org.apache.jena.rdf.model.Resource cls)
     
    static Set<org.apache.jena.rdf.model.Resource>
    getAllSuperClassesStar(org.apache.jena.rdf.model.Resource cls)
    Returns a set consisting of a given class and all its superclasses.
    static Set<org.apache.jena.rdf.model.Resource>
    getAllSuperProperties(org.apache.jena.rdf.model.Property subProperty)
     
    static Set<org.apache.jena.rdf.model.Resource>
    getAllTransitiveObjects(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns a set of resources reachable from a subject via one or more steps with a given predicate.
    static Set<org.apache.jena.rdf.model.Resource>
    getAllTransitiveSubjects(org.apache.jena.rdf.model.Resource object, org.apache.jena.rdf.model.Property predicate, ProgressMonitor monitor)
    Returns a set of resources reachable from an object via one or more reversed steps with a given predicate.
    static Set<org.apache.jena.rdf.model.Resource>
    getAllTypes(org.apache.jena.rdf.model.Resource instance)
     
    static org.apache.jena.graph.Graph
    getBaseGraph(org.apache.jena.graph.Graph graph)
     
    static org.apache.jena.graph.Graph
    getBaseGraph(org.apache.jena.rdf.model.Model model)
    Gets the "base graph" of a Model, walking into MultiUnions if needed.
    static org.apache.jena.rdf.model.Model
    getBaseModel(org.apache.jena.rdf.model.Model model)
     
    static org.apache.jena.rdf.model.Literal
    getBestStringLiteral(org.apache.jena.rdf.model.Resource resource, List<String> langs, Iterable<org.apache.jena.rdf.model.Property> properties)
    For a given subject resource and a given collection of (label/comment) properties this finds the most suitable value of either property for a given list of languages (usually from the current user's preferences).
    static org.apache.jena.rdf.model.Literal
    getBestStringLiteral(org.apache.jena.rdf.model.Resource resource, List<String> langs, Iterable<org.apache.jena.rdf.model.Property> properties, BiFunction<org.apache.jena.rdf.model.Resource,org.apache.jena.rdf.model.Property,org.apache.jena.util.iterator.ExtendedIterator<org.apache.jena.rdf.model.Statement>> getter)
     
    static boolean
    getBooleanProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
     
    static Double
    getDoubleProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
     
    static double
    getDoubleProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, double defaultValue)
     
    static org.apache.jena.rdf.model.Resource
    getFirstDirectRange(org.apache.jena.rdf.model.Resource property)
    Gets the "first" declared rdfs:range of a given property.
    static org.apache.jena.rdf.model.Resource
    getFirstRange(org.apache.jena.rdf.model.Resource property)
    Gets the "first" declared rdfs:range of a given property.
    static final JenaUtilHelper
    Gets the current helper object.
    static Set<org.apache.jena.rdf.model.Resource>
    getImports(org.apache.jena.rdf.model.Resource graph)
     
    static Integer
    getIntegerProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
     
    static org.apache.jena.rdf.model.RDFList
    getListProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
     
    static List<org.apache.jena.rdf.model.Literal>
    getLiteralProperties(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
     
    static <T> T
    getNearest(org.apache.jena.rdf.model.Resource cls, Function<org.apache.jena.rdf.model.Resource,T> function)
    Walks up the class hierarchy starting at a given class until one of them returns a value for a given Function.
    static String
    getNsPrefixURI(org.apache.jena.rdf.model.Model model, String prefix)
    Overcomes a design mismatch with Jena: if the base model does not declare a default namespace then the default namespace of an import is returned - this is not desirable for TopBraid-like scenarios.
    static org.apache.jena.rdf.model.RDFNode
    getProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
     
    static List<org.apache.jena.rdf.model.Resource>
    getResourceProperties(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
     
    static org.apache.jena.rdf.model.Resource
    getResourcePropertyWithType(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.Resource type)
     
    static String
    getStringProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
     
    static List<org.apache.jena.graph.Graph>
    getSubGraphs(org.apache.jena.graph.compose.MultiUnion union)
     
    static Collection<org.apache.jena.rdf.model.Resource>
    getSuperClasses(org.apache.jena.rdf.model.Resource subClass)
    Gets a Set of all superclasses (rdfs:subClassOf) of a given Resource.
    static org.apache.jena.rdf.model.Resource
    getType(org.apache.jena.rdf.model.Resource instance)
    Gets the "first" type of a given Resource.
    static List<org.apache.jena.rdf.model.Resource>
    getTypes(org.apache.jena.rdf.model.Resource instance)
    Gets a Set of all rdf:types of a given Resource.
    static List<org.apache.jena.rdf.model.Resource>
    getURIResourceProperties(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
     
    static org.apache.jena.rdf.model.Resource
    getURIResourceProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
     
    static boolean
    hasIndirectType(org.apache.jena.rdf.model.Resource instance, org.apache.jena.rdf.model.Resource expectedType)
    Checks whether a given Resource is an instance of a given type, or a subclass thereof.
    static boolean
    hasSuperClass(org.apache.jena.rdf.model.Resource subClass, org.apache.jena.rdf.model.Resource superClass)
    Checks whether a given class has a given (transitive) super class.
    static boolean
    hasSuperProperty(org.apache.jena.rdf.model.Property subProperty, org.apache.jena.rdf.model.Property superProperty)
    Checks whether a given property has a given (transitive) super property.
    static void
    initNamespaces(org.apache.jena.graph.Graph graph)
    Sets the usual default namespaces for rdf, rdfs, owl and xsd.
    static void
    initNamespaces(org.apache.jena.shared.PrefixMapping prefixMapping)
    Sets the usual default namespaces for rdf, rdfs, owl and xsd.
    static org.apache.jena.graph.Node
    invokeExpression(String expression, org.apache.jena.query.QuerySolution initialBinding, org.apache.jena.query.Dataset dataset)
    Calls a SPARQL expression and returns the result, using some initial bindings.
    static org.apache.jena.graph.Node
    invokeFunction0(org.apache.jena.rdf.model.Resource function, org.apache.jena.query.Dataset dataset)
    Calls a given SPARQL function with no arguments.
    static org.apache.jena.graph.Node
    invokeFunction1(org.apache.jena.rdf.model.Resource function, org.apache.jena.graph.Node argument, org.apache.jena.query.Dataset dataset)
     
    static org.apache.jena.graph.Node
    invokeFunction1(org.apache.jena.rdf.model.Resource function, org.apache.jena.rdf.model.RDFNode argument, org.apache.jena.query.Dataset dataset)
    Calls a given SPARQL function with one argument.
    static org.apache.jena.graph.Node
    invokeFunction2(org.apache.jena.rdf.model.Resource function, org.apache.jena.graph.Node argument1, org.apache.jena.graph.Node argument2, org.apache.jena.query.Dataset dataset)
     
    static org.apache.jena.graph.Node
    invokeFunction2(org.apache.jena.rdf.model.Resource function, org.apache.jena.rdf.model.RDFNode argument1, org.apache.jena.rdf.model.RDFNode argument2, org.apache.jena.query.Dataset dataset)
    Calls a given SPARQL function with two arguments.
    static org.apache.jena.graph.Node
    invokeFunction3(org.apache.jena.rdf.model.Resource function, org.apache.jena.graph.Node argument1, org.apache.jena.graph.Node argument2, org.apache.jena.graph.Node argument3, org.apache.jena.query.Dataset dataset)
     
    static org.apache.jena.graph.Node
    invokeFunction3(org.apache.jena.rdf.model.Resource function, org.apache.jena.rdf.model.RDFNode argument1, org.apache.jena.rdf.model.RDFNode argument2, org.apache.jena.rdf.model.RDFNode argument3, org.apache.jena.query.Dataset dataset)
     
    static boolean
    isMemoryGraph(org.apache.jena.graph.Graph graph)
    Checks whether a given graph (possibly a MultiUnion) only contains GraphMemBase instances.
    static org.apache.jena.rdf.model.StmtIterator
    listAllProperties(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Gets an Iterator over all Statements of a given property or its sub-properties at a given subject instance.
    static org.apache.jena.query.Query
    queryWithSubstitutions(org.apache.jena.query.Query query, Map<org.apache.jena.sparql.core.Var,org.apache.jena.graph.Node> substitutions)
    Temp patch for a bug in Jena's syntaxtransform, also applying substitutions on HAVING clauses.
    static void
    setGraphReadOptimization(boolean onOrOff)
    Allows some environments, e.g.
    Sets the helper which allows the behavior of some JenaUtil methods to be modified by the system using the SPIN library.
    static void
    sort(List<org.apache.jena.rdf.model.Resource> nodes)
     
    static org.apache.jena.rdf.model.RDFNode
    toRDFNode(org.apache.jena.graph.Node node)
     
    static String
     
    static String
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • JenaUtil

      public JenaUtil()
  • Method Details

    • setHelper

      public static JenaUtilHelper setHelper(JenaUtilHelper h)
      Sets the helper which allows the behavior of some JenaUtil methods to be modified by the system using the SPIN library. Note: Should not be used outside of TopBraid - not stable.
      Parameters:
      h - the JenaUtilHelper
      Returns:
      the old helper
    • getHelper

      public static final JenaUtilHelper getHelper()
      Gets the current helper object. Note: Should not be used outside of TopBraid - not stable.
      Returns:
      the helper
    • addTransitiveObjects

      public static void addTransitiveObjects(Set<org.apache.jena.rdf.model.Resource> results, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Populates a result set of resources reachable from a subject via zero or more steps with a given predicate. Implementation note: the results set need only implement Collection.add(Object).
      Parameters:
      results - The transitive objects reached from subject via triples with the given predicate
      subject - the subject to start traversal at
      predicate - the predicate to walk
    • asBinding

      public static org.apache.jena.sparql.engine.binding.Binding asBinding(org.apache.jena.query.QuerySolution map)
      Turns a QuerySolution into a Binding.
      Parameters:
      map - the input QuerySolution
      Returns:
      a Binding or null if the input is null
    • asQuerySolutionMap

      public static org.apache.jena.query.QuerySolutionMap asQuerySolutionMap(org.apache.jena.sparql.engine.binding.Binding binding)
      Turns a Binding into a QuerySolutionMap.
      Parameters:
      binding - the Binding to convert
      Returns:
      a QuerySolutionMap
    • getAllTransitiveSubjects

      public static Set<org.apache.jena.rdf.model.Resource> getAllTransitiveSubjects(org.apache.jena.rdf.model.Resource object, org.apache.jena.rdf.model.Property predicate, ProgressMonitor monitor)
      Returns a set of resources reachable from an object via one or more reversed steps with a given predicate.
      Parameters:
      object - the object to start traversal at
      predicate - the predicate to walk
      monitor - an optional progress monitor to allow cancelation
      Returns:
      the reached resources
    • asProperty

      public static org.apache.jena.rdf.model.Property asProperty(org.apache.jena.rdf.model.Resource resource)
      Casts a Resource into a Property.
      Parameters:
      resource - the Resource to cast
      Returns:
      resource as an instance of Property
    • collectBaseGraphs

      public static void collectBaseGraphs(org.apache.jena.graph.Graph graph, Set<org.apache.jena.graph.Graph> baseGraphs)
    • createDefaultGraph

      public static org.apache.jena.graph.Graph createDefaultGraph()
      Creates a new Graph. By default this will deliver a plain in-memory graph, but other implementations may deliver graphs with concurrency support and other features.
      Returns:
      a default graph
      See Also:
    • createDefaultModel

      public static org.apache.jena.rdf.model.Model createDefaultModel()
      Wraps the result of createDefaultGraph() into a Model and initializes namespaces.
      Returns:
      a default Model
      See Also:
    • createMemoryGraph

      public static org.apache.jena.graph.Graph createMemoryGraph()
      Creates a memory Graph with no reification.
      Returns:
      a new memory graph
    • createMemoryModel

      public static org.apache.jena.rdf.model.Model createMemoryModel()
      Creates a memory Model with no reification.
      Returns:
      a new memory Model
    • createMultiUnion

      public static org.apache.jena.graph.compose.MultiUnion createMultiUnion()
    • createMultiUnion

      public static org.apache.jena.graph.compose.MultiUnion createMultiUnion(org.apache.jena.graph.Graph[] graphs)
    • createMultiUnion

      public static org.apache.jena.graph.compose.MultiUnion createMultiUnion(Iterator<org.apache.jena.graph.Graph> graphs)
    • getAllInstances

      public static Set<org.apache.jena.rdf.model.Resource> getAllInstances(org.apache.jena.rdf.model.Resource cls)
      Gets all instances of a given class and its subclasses.
      Parameters:
      cls - the class to get the instances of
      Returns:
      the instances
    • getAllSubClasses

      public static Set<org.apache.jena.rdf.model.Resource> getAllSubClasses(org.apache.jena.rdf.model.Resource cls)
    • getAllSubClassesStar

      public static Set<org.apache.jena.rdf.model.Resource> getAllSubClassesStar(org.apache.jena.rdf.model.Resource cls)
      Returns a set consisting of a given class and all its subclasses. Similar to rdfs:subClassOf*.
      Parameters:
      cls - the class to return with its subclasses
      Returns:
      the Set of class resources
    • getAllSubProperties

      public static Set<org.apache.jena.rdf.model.Resource> getAllSubProperties(org.apache.jena.rdf.model.Property superProperty)
    • getAllSuperClasses

      public static Set<org.apache.jena.rdf.model.Resource> getAllSuperClasses(org.apache.jena.rdf.model.Resource cls)
    • getAllSuperClassesStar

      public static Set<org.apache.jena.rdf.model.Resource> getAllSuperClassesStar(org.apache.jena.rdf.model.Resource cls)
      Returns a set consisting of a given class and all its superclasses. Similar to rdfs:subClassOf*.
      Parameters:
      cls - the class to return with its superclasses
      Returns:
      the Set of class resources
    • getAllSuperProperties

      public static Set<org.apache.jena.rdf.model.Resource> getAllSuperProperties(org.apache.jena.rdf.model.Property subProperty)
    • getAllTransitiveObjects

      public static Set<org.apache.jena.rdf.model.Resource> getAllTransitiveObjects(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns a set of resources reachable from a subject via one or more steps with a given predicate.
      Parameters:
      subject - the subject to start at
      predicate - the predicate to traverse
      Returns:
      the reached resources
    • getAllTypes

      public static Set<org.apache.jena.rdf.model.Resource> getAllTypes(org.apache.jena.rdf.model.Resource instance)
    • getBaseGraph

      public static org.apache.jena.graph.Graph getBaseGraph(org.apache.jena.rdf.model.Model model)
      Gets the "base graph" of a Model, walking into MultiUnions if needed.
      Parameters:
      model - the Model to get the base graph of
      Returns:
      the base graph or null if the model contains a MultiUnion that doesn't declare one
    • getBaseGraph

      public static org.apache.jena.graph.Graph getBaseGraph(org.apache.jena.graph.Graph graph)
    • getBaseModel

      public static org.apache.jena.rdf.model.Model getBaseModel(org.apache.jena.rdf.model.Model model)
    • getBestStringLiteral

      public static org.apache.jena.rdf.model.Literal getBestStringLiteral(org.apache.jena.rdf.model.Resource resource, List<String> langs, Iterable<org.apache.jena.rdf.model.Property> properties)
      For a given subject resource and a given collection of (label/comment) properties this finds the most suitable value of either property for a given list of languages (usually from the current user's preferences). For example, if the user's languages are [ "en-AU" ] then the function will prefer "mate"@en-AU over "friend"@en and never return "freund"@de. The function falls back to literals that have no language if no better literal has been found.
      Parameters:
      resource - the subject resource
      langs - the allowed languages
      properties - the properties to check
      Returns:
      the best suitable value or null
    • getBestStringLiteral

      public static org.apache.jena.rdf.model.Literal getBestStringLiteral(org.apache.jena.rdf.model.Resource resource, List<String> langs, Iterable<org.apache.jena.rdf.model.Property> properties, BiFunction<org.apache.jena.rdf.model.Resource,org.apache.jena.rdf.model.Property,org.apache.jena.util.iterator.ExtendedIterator<org.apache.jena.rdf.model.Statement>> getter)
    • getFirstDirectRange

      public static org.apache.jena.rdf.model.Resource getFirstDirectRange(org.apache.jena.rdf.model.Resource property)
      Gets the "first" declared rdfs:range of a given property. If multiple ranges exist, the behavior is undefined. Note that this method does not consider ranges defined on super-properties.
      Parameters:
      property - the property to get the range of
      Returns:
      the "first" range Resource or null
    • getFirstRange

      public static org.apache.jena.rdf.model.Resource getFirstRange(org.apache.jena.rdf.model.Resource property)
      Gets the "first" declared rdfs:range of a given property. If multiple ranges exist, the behavior is undefined. This method walks up to super-properties if no direct match exists.
      Parameters:
      property - the property to get the range of
      Returns:
      the "first" range Resource or null
    • getImports

      public static Set<org.apache.jena.rdf.model.Resource> getImports(org.apache.jena.rdf.model.Resource graph)
    • getIntegerProperty

      public static Integer getIntegerProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    • getListProperty

      public static org.apache.jena.rdf.model.RDFList getListProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    • getLiteralProperties

      public static List<org.apache.jena.rdf.model.Literal> getLiteralProperties(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    • getNearest

      public static <T> T getNearest(org.apache.jena.rdf.model.Resource cls, Function<org.apache.jena.rdf.model.Resource,T> function)
      Walks up the class hierarchy starting at a given class until one of them returns a value for a given Function.
      Type Parameters:
      T - the requested result type
      Parameters:
      cls - the class to start at
      function - the Function to execute on each class
      Returns:
      the "first" non-null value, or null
    • getNsPrefixURI

      public static String getNsPrefixURI(org.apache.jena.rdf.model.Model model, String prefix)
      Overcomes a design mismatch with Jena: if the base model does not declare a default namespace then the default namespace of an import is returned - this is not desirable for TopBraid-like scenarios.
      Parameters:
      model - the Model to operate on
      prefix - the prefix to get the URI of
      Returns:
      the URI of prefix
    • getProperty

      public static org.apache.jena.rdf.model.RDFNode getProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    • getResourcePropertyWithType

      public static org.apache.jena.rdf.model.Resource getResourcePropertyWithType(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.Resource type)
    • getResourceProperties

      public static List<org.apache.jena.rdf.model.Resource> getResourceProperties(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    • getURIResourceProperty

      public static org.apache.jena.rdf.model.Resource getURIResourceProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    • getURIResourceProperties

      public static List<org.apache.jena.rdf.model.Resource> getURIResourceProperties(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    • getStringProperty

      public static String getStringProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    • getBooleanProperty

      public static boolean getBooleanProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    • getDoubleProperty

      public static Double getDoubleProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    • getDoubleProperty

      public static double getDoubleProperty(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, double defaultValue)
    • getSubGraphs

      public static List<org.apache.jena.graph.Graph> getSubGraphs(org.apache.jena.graph.compose.MultiUnion union)
    • getSuperClasses

      public static Collection<org.apache.jena.rdf.model.Resource> getSuperClasses(org.apache.jena.rdf.model.Resource subClass)
      Gets a Set of all superclasses (rdfs:subClassOf) of a given Resource.
      Parameters:
      subClass - the subClass Resource
      Returns:
      a Collection of class resources
    • getType

      public static org.apache.jena.rdf.model.Resource getType(org.apache.jena.rdf.model.Resource instance)
      Gets the "first" type of a given Resource.
      Parameters:
      instance - the instance to get the type of
      Returns:
      the type or null
    • getTypes

      public static List<org.apache.jena.rdf.model.Resource> getTypes(org.apache.jena.rdf.model.Resource instance)
      Gets a Set of all rdf:types of a given Resource.
      Parameters:
      instance - the instance Resource
      Returns:
      a Collection of type resources
    • hasIndirectType

      public static boolean hasIndirectType(org.apache.jena.rdf.model.Resource instance, org.apache.jena.rdf.model.Resource expectedType)
      Checks whether a given Resource is an instance of a given type, or a subclass thereof. Make sure that the expectedType parameter is associated with the right Model, because the system will try to walk up the superclasses of expectedType. The expectedType may have no Model, in which case the method will use the instance's Model.
      Parameters:
      instance - the Resource to test
      expectedType - the type that instance is expected to have
      Returns:
      true if resource has rdf:type expectedType
    • hasSuperClass

      public static boolean hasSuperClass(org.apache.jena.rdf.model.Resource subClass, org.apache.jena.rdf.model.Resource superClass)
      Checks whether a given class has a given (transitive) super class.
      Parameters:
      subClass - the sub-class
      superClass - the super-class
      Returns:
      true if subClass has superClass (somewhere up the tree)
    • hasSuperProperty

      public static boolean hasSuperProperty(org.apache.jena.rdf.model.Property subProperty, org.apache.jena.rdf.model.Property superProperty)
      Checks whether a given property has a given (transitive) super property.
      Parameters:
      subProperty - the sub-property
      superProperty - the super-property
      Returns:
      true if subProperty has superProperty (somewhere up the tree)
    • initNamespaces

      public static void initNamespaces(org.apache.jena.graph.Graph graph)
      Sets the usual default namespaces for rdf, rdfs, owl and xsd.
      Parameters:
      graph - the Graph to modify
    • initNamespaces

      public static void initNamespaces(org.apache.jena.shared.PrefixMapping prefixMapping)
      Sets the usual default namespaces for rdf, rdfs, owl and xsd.
      Parameters:
      prefixMapping - the Model to modify
    • isMemoryGraph

      public static boolean isMemoryGraph(org.apache.jena.graph.Graph graph)
      Checks whether a given graph (possibly a MultiUnion) only contains GraphMemBase instances.
      Parameters:
      graph - the Graph to test
      Returns:
      true if graph is a memory graph
    • listAllProperties

      public static org.apache.jena.rdf.model.StmtIterator listAllProperties(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Gets an Iterator over all Statements of a given property or its sub-properties at a given subject instance. Note that the predicate and subject should be both attached to a Model to avoid NPEs.
      Parameters:
      subject - the subject (may be null)
      predicate - the predicate
      Returns:
      a StmtIterator
    • asReadOnlyModel

      public static org.apache.jena.rdf.model.Model asReadOnlyModel(org.apache.jena.rdf.model.Model m)
      This indicates that no further changes to the model are needed. Some implementations may give runtime exceptions if this is violated.
      Parameters:
      m - the Model to get as a read-only variant
      Returns:
      A read-only model
    • asReadOnlyGraph

      public static org.apache.jena.graph.Graph asReadOnlyGraph(org.apache.jena.graph.Graph g)
      This indicates that no further changes to the graph are needed. Some implementations may give runtime exceptions if this is violated.
      Parameters:
      g - the Graph to get as a read-only variant
      Returns:
      a read-only graph
    • createOntologyModel

      public static org.apache.jena.ontology.OntModel createOntologyModel(org.apache.jena.ontology.OntModelSpec spec, org.apache.jena.rdf.model.Model base)
    • setGraphReadOptimization

      public static void setGraphReadOptimization(boolean onOrOff)
      Allows some environments, e.g. TopBraid, to prioritize a block of code for reading graphs, with no update occurring. The top of the block should call this with true with a matching call with false in a finally block. Note: Unstable - don't use outside of TopBraid.
      Parameters:
      onOrOff - true to switch on
    • deepCloneForReadOnlyThreadSafe

      public static org.apache.jena.graph.Graph deepCloneForReadOnlyThreadSafe(org.apache.jena.graph.Graph g)
      Ensure that we there is a read-only, thread safe version of the graph. If the graph is not, then create a deep clone that is both. Note: Unstable - don't use outside of TopBraid.
      Parameters:
      g - The given graph
      Returns:
      A read-only, thread safe version of the given graph.
    • invokeExpression

      public static org.apache.jena.graph.Node invokeExpression(String expression, org.apache.jena.query.QuerySolution initialBinding, org.apache.jena.query.Dataset dataset)
      Calls a SPARQL expression and returns the result, using some initial bindings.
      Parameters:
      expression - the expression to execute (must contain absolute URIs)
      initialBinding - the initial bindings for the unbound variables
      dataset - the query Dataset or null for default
      Returns:
      the result or null
    • invokeFunction0

      public static org.apache.jena.graph.Node invokeFunction0(org.apache.jena.rdf.model.Resource function, org.apache.jena.query.Dataset dataset)
      Calls a given SPARQL function with no arguments.
      Parameters:
      function - the URI resource of the function to call
      dataset - the Dataset to operate on or null for default
      Returns:
      the result of the function call
    • invokeFunction1

      public static org.apache.jena.graph.Node invokeFunction1(org.apache.jena.rdf.model.Resource function, org.apache.jena.rdf.model.RDFNode argument, org.apache.jena.query.Dataset dataset)
      Calls a given SPARQL function with one argument.
      Parameters:
      function - the URI resource of the function to call
      argument - the first argument
      dataset - the Dataset to operate on or null for default
      Returns:
      the result of the function call
    • invokeFunction1

      public static org.apache.jena.graph.Node invokeFunction1(org.apache.jena.rdf.model.Resource function, org.apache.jena.graph.Node argument, org.apache.jena.query.Dataset dataset)
    • invokeFunction2

      public static org.apache.jena.graph.Node invokeFunction2(org.apache.jena.rdf.model.Resource function, org.apache.jena.rdf.model.RDFNode argument1, org.apache.jena.rdf.model.RDFNode argument2, org.apache.jena.query.Dataset dataset)
      Calls a given SPARQL function with two arguments.
      Parameters:
      function - the URI resource of the function to call
      argument1 - the first argument
      argument2 - the second argument
      dataset - the Dataset to operate on or null for default
      Returns:
      the result of the function call
    • invokeFunction2

      public static org.apache.jena.graph.Node invokeFunction2(org.apache.jena.rdf.model.Resource function, org.apache.jena.graph.Node argument1, org.apache.jena.graph.Node argument2, org.apache.jena.query.Dataset dataset)
    • invokeFunction3

      public static org.apache.jena.graph.Node invokeFunction3(org.apache.jena.rdf.model.Resource function, org.apache.jena.rdf.model.RDFNode argument1, org.apache.jena.rdf.model.RDFNode argument2, org.apache.jena.rdf.model.RDFNode argument3, org.apache.jena.query.Dataset dataset)
    • invokeFunction3

      public static org.apache.jena.graph.Node invokeFunction3(org.apache.jena.rdf.model.Resource function, org.apache.jena.graph.Node argument1, org.apache.jena.graph.Node argument2, org.apache.jena.graph.Node argument3, org.apache.jena.query.Dataset dataset)
    • queryWithSubstitutions

      public static org.apache.jena.query.Query queryWithSubstitutions(org.apache.jena.query.Query query, Map<org.apache.jena.sparql.core.Var,org.apache.jena.graph.Node> substitutions)
      Temp patch for a bug in Jena's syntaxtransform, also applying substitutions on HAVING clauses.
      Parameters:
      query - the Query to transform
      substitutions - the variable bindings
      Returns:
      a new Query with the bindings applied
    • sort

      public static void sort(List<org.apache.jena.rdf.model.Resource> nodes)
    • toRDFNode

      public static org.apache.jena.rdf.model.RDFNode toRDFNode(org.apache.jena.graph.Node node)
    • withImports

      public static String withImports(String uri)
    • withoutImports

      public static String withoutImports(String uri)