Class StdModels

java.lang.Object
org.apache.jena.ontapi.utils.StdModels

public class StdModels extends Object
A class-helper to work with Jena Models and its related objects and components: Jena RDF Node, Jena Literal, Jena Resource and Jena Statement.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.apache.jena.rdf.model.RDFNode
     
    static final org.apache.jena.rdf.model.Literal
     
    static final Comparator<org.apache.jena.rdf.model.RDFNode>
     
    static final Comparator<org.apache.jena.rdf.model.Statement>
     
    static final Comparator<org.apache.jena.rdf.model.Statement>
     
    static final org.apache.jena.rdf.model.Literal
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Set<org.apache.jena.graph.Node>
    asUnmodifiableNodeSet(Collection<? extends org.apache.jena.rdf.model.RDFNode> nodes)
    Creates an unmodifiable Set of Nodes from the collection of RDF Nodes.
    static boolean
    containsURI(org.apache.jena.rdf.model.RDFNode node, String uri)
    Answers true if the given node contains the specified uri.
    static boolean
    containsURI(org.apache.jena.rdf.model.Statement statement, String uri)
    Answers true if the given uri is a part of the given statement.
    static org.apache.jena.rdf.model.StmtIterator
    createStmtIterator(org.apache.jena.util.iterator.ExtendedIterator<org.apache.jena.graph.Triple> triples, Function<org.apache.jena.graph.Triple,org.apache.jena.rdf.model.Statement> map)
    Creates an iterator which returns RDF Statements based on the given extended iterator of triples.
    static org.apache.jena.rdf.model.RDFList
    createTypedList(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource type, Collection<? extends org.apache.jena.rdf.model.RDFNode> members)
    Creates a typed []-list with the given type containing the resources from the given collection.
    static org.apache.jena.rdf.model.RDFList
    createTypedList(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource type, Iterator<? extends org.apache.jena.rdf.model.RDFNode> members)
    Creates a typed list with the given type containing the resources from the given iterator.
    static List<org.apache.jena.rdf.model.Statement>
    findShortestPath(org.apache.jena.rdf.model.Model m, org.apache.jena.rdf.model.Resource start, org.apache.jena.rdf.model.RDFNode end, Predicate<org.apache.jena.rdf.model.Statement> onPath)
    Answers the shortest path from the start resource to the end RDF node, such that every step on the path is accepted by the given filter.
    static Set<org.apache.jena.rdf.model.Statement>
    getListStatements(org.apache.jena.rdf.model.RDFList list)
    Answers a set of all the RDF statements whose subject is one of the cells of the given list.
    static boolean
    isANY(org.apache.jena.rdf.model.Resource s, org.apache.jena.rdf.model.Property p, org.apache.jena.rdf.model.RDFNode o)
    Answers true iff the given SPO corresponds Triple.ANY.
    static boolean
    isInList(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource candidate)
    Determines is s specified resource belongs to a list.
    static boolean
    isInList(org.apache.jena.rdf.model.Statement s)
    Answers true iff the given statement belongs to some []-list.
    static Map<String,String>
    setNsPrefixes(org.apache.jena.shared.PrefixMapping mapping, Map<String,String> prefixes)
    Replaces namespaces' map with new one.
    static String
    toString(org.apache.jena.rdf.model.Statement inModel)
    Returns a string representation of the given Jena statement.
    static String
    toString(org.apache.jena.rdf.model.Statement st, org.apache.jena.shared.PrefixMapping pm)
    Returns a string representation of the given Jena statement taking into account PrefixMapping.

    Methods inherited from class java.lang.Object

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

    • RDF_NODE_COMPARATOR

      public static final Comparator<org.apache.jena.rdf.model.RDFNode> RDF_NODE_COMPARATOR
    • STATEMENT_COMPARATOR

      public static final Comparator<org.apache.jena.rdf.model.Statement> STATEMENT_COMPARATOR
    • BLANK

      public static final org.apache.jena.rdf.model.RDFNode BLANK
    • STATEMENT_COMPARATOR_IGNORE_BLANK

      public static final Comparator<org.apache.jena.rdf.model.Statement> STATEMENT_COMPARATOR_IGNORE_BLANK
    • TRUE

      public static final org.apache.jena.rdf.model.Literal TRUE
    • FALSE

      public static final org.apache.jena.rdf.model.Literal FALSE
  • Constructor Details

    • StdModels

      public StdModels()
  • Method Details

    • createTypedList

      public static org.apache.jena.rdf.model.RDFList createTypedList(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource type, Collection<? extends org.apache.jena.rdf.model.RDFNode> members)
      Creates a typed []-list with the given type containing the resources from the given collection.
      Parameters:
      model - model in which the []-list is created
      type - Resource the type for new []-list
      members - Collection of RDFNodes
      Returns:
      anonymous resource - the header of the typed []-list
      See Also:
    • createTypedList

      public static org.apache.jena.rdf.model.RDFList createTypedList(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource type, Iterator<? extends org.apache.jena.rdf.model.RDFNode> members)
      Creates a typed list with the given type containing the resources from the given iterator. A typed list is an anonymous resource created using the same rules as the standard []-list (that is, using rdf:first, rdf:rest and rdf:nil predicates), but each item of this []-list has the specified type on predicate rdf:type.
      Parameters:
      model - model in which the []-list is created
      type - Resource the type for new []-list
      members - Iterator of RDFNodes
      Returns:
      anonymous resource - the header of the typed []-list
      See Also:
    • isInList

      public static boolean isInList(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource candidate)
      Determines is s specified resource belongs to a list.
      Parameters:
      model - Model
      candidate - Resource to test
      Returns:
      true if specified resource is a member of some rdf:List
    • isInList

      public static boolean isInList(org.apache.jena.rdf.model.Statement s)
      Answers true iff the given statement belongs to some []-list.
      Parameters:
      s - Statement, not null
      Returns:
      boolean
    • getListStatements

      public static Set<org.apache.jena.rdf.model.Statement> getListStatements(org.apache.jena.rdf.model.RDFList list)
      Answers a set of all the RDF statements whose subject is one of the cells of the given list.
      Parameters:
      list - []-list, not null
      Returns:
      a Set of Statements
    • setNsPrefixes

      public static Map<String,String> setNsPrefixes(org.apache.jena.shared.PrefixMapping mapping, Map<String,String> prefixes)
      Replaces namespaces' map with new one.
      Parameters:
      mapping - Prefix Mapping to modify
      prefixes - java Map of new prefixes to set
      Returns:
      a Map of previously associated prefixes
    • toString

      public static String toString(org.apache.jena.rdf.model.Statement st, org.apache.jena.shared.PrefixMapping pm)
      Returns a string representation of the given Jena statement taking into account PrefixMapping.
      Parameters:
      st - Statement, not null
      pm - PrefixMapping, not null
      Returns:
      String
    • toString

      public static String toString(org.apache.jena.rdf.model.Statement inModel)
      Returns a string representation of the given Jena statement.
      Parameters:
      inModel - Statement, not null
      Returns:
      String
    • containsURI

      public static boolean containsURI(org.apache.jena.rdf.model.RDFNode node, String uri)
      Answers true if the given node contains the specified uri.
      Parameters:
      node - RDFNode, not null
      uri - String, not null
      Returns:
      boolean
    • containsURI

      public static boolean containsURI(org.apache.jena.rdf.model.Statement statement, String uri)
      Answers true if the given uri is a part of the given statement.
      Parameters:
      statement - Statement, not null
      uri - String, not null
      Returns:
      boolean
    • createStmtIterator

      public static org.apache.jena.rdf.model.StmtIterator createStmtIterator(org.apache.jena.util.iterator.ExtendedIterator<org.apache.jena.graph.Triple> triples, Function<org.apache.jena.graph.Triple,org.apache.jena.rdf.model.Statement> map)
      Creates an iterator which returns RDF Statements based on the given extended iterator of triples.
      Parameters:
      triples - ExtendedIterator of Triples
      map - a Function to map Triple -> Statement
      Returns:
      StmtIterator
      See Also:
      • IteratorFactory.asStmtIterator(Iterator, org.apache.jena.rdf.model.impl.ModelCom)
    • asUnmodifiableNodeSet

      public static Set<org.apache.jena.graph.Node> asUnmodifiableNodeSet(Collection<? extends org.apache.jena.rdf.model.RDFNode> nodes)
      Creates an unmodifiable Set of Nodes from the collection of RDF Nodes. Placed here as it is widely used.
      Parameters:
      nodes - Collection of RDFNodes
      Returns:
      Set of Node
    • isANY

      public static boolean isANY(org.apache.jena.rdf.model.Resource s, org.apache.jena.rdf.model.Property p, org.apache.jena.rdf.model.RDFNode o)
      Answers true iff the given SPO corresponds Triple.ANY.
      Parameters:
      s - Resource, the subject
      p - Property, the predicate
      o - RDFNode, the object
      Returns:
      boolean
    • findShortestPath

      public static List<org.apache.jena.rdf.model.Statement> findShortestPath(org.apache.jena.rdf.model.Model m, org.apache.jena.rdf.model.Resource start, org.apache.jena.rdf.model.RDFNode end, Predicate<org.apache.jena.rdf.model.Statement> onPath)
      Answers the shortest path from the start resource to the end RDF node, such that every step on the path is accepted by the given filter. A path is a List of RDF Statements. The subject of the first statement in the list is start, and the object of the last statement in the list is end.

      The onPath argument is a Predicate, which accepts a statement and returns true if the statement should be considered to be on the path. To search for an unconstrained path, pass ()->true or null as an argument. If there is more than one path of minimal length from start to end, this method returns an arbitrary one. The algorithm is blind breadth-first search, with loop detection.

      Parameters:
      m - the model in which we are seeking a path, not null
      start - the starting resource, not null
      end - the end, or goal, node, not null
      onPath - a filter which determines whether a given statement can be considered part of the path
      Returns:
      a path, consisting of a list of statements whose first subject is start, and whose last object is end, empty if no such path exists