java.lang.Object
org.apache.jena.ontapi.utils.StdModels
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
FieldsModifier and TypeFieldDescriptionstatic final org.apache.jena.rdf.model.RDFNodestatic final org.apache.jena.rdf.model.Literalstatic 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 -
Method Summary
Modifier and TypeMethodDescriptionstatic Set<org.apache.jena.graph.Node>asUnmodifiableNodeSet(Collection<? extends org.apache.jena.rdf.model.RDFNode> nodes) Creates an unmodifiable Set ofNodes from the collection ofRDF Nodes.static booleancontainsURI(org.apache.jena.rdf.model.RDFNode node, String uri) Answerstrueif the givennodecontains the specifieduri.static booleancontainsURI(org.apache.jena.rdf.model.Statement statement, String uri) Answerstrueif the givenuriis a part of the givenstatement.static org.apache.jena.rdf.model.StmtIteratorcreateStmtIterator(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.RDFListcreateTypedList(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.RDFListcreateTypedList(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 thestartresource to theendRDF 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 booleanisANY(org.apache.jena.rdf.model.Resource s, org.apache.jena.rdf.model.Property p, org.apache.jena.rdf.model.RDFNode o) Answerstrueiff the givenSPOcorrespondsTriple.ANY.static booleanisInList(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource candidate) Determines is s specified resource belongs to a list.static booleanisInList(org.apache.jena.rdf.model.Statement s) Answerstrueiff the given statement belongs to some []-list.setNsPrefixes(org.apache.jena.shared.PrefixMapping mapping, Map<String, String> prefixes) Replaces namespaces' map with new one.static StringtoString(org.apache.jena.rdf.model.Statement inModel) Returns a string representation of the given Jena statement.static StringtoString(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.
-
Field Details
-
RDF_NODE_COMPARATOR
-
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-modelin which the []-list is createdtype-Resourcethe type for new []-listmembers- Collection ofRDFNodes- 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, usingrdf:first,rdf:restandrdf:nilpredicates), but each item of this []-list has the specified type on predicaterdf:type. -
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- Modelcandidate- 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) Answerstrueiff the given statement belongs to some []-list.- Parameters:
s-Statement, notnull- 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, notnull- Returns:
- a
SetofStatements
-
toString
Returns a string representation of the given Jena statement.- Parameters:
inModel-Statement, notnull- Returns:
String
-
containsURI
Answerstrueif the givennodecontains the specifieduri.- Parameters:
node-RDFNode, notnulluri-String, notnull- Returns:
- boolean
-
containsURI
Answerstrueif the givenuriis a part of the givenstatement.- Parameters:
statement-Statement, notnulluri-String, notnull- 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-ExtendedIteratorofTriplesmap- a Function to mapTriple->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 ofNodes from the collection ofRDF Nodes. Placed here as it is widely used.- Parameters:
nodes- Collection ofRDFNodes- 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) Answerstrueiff the givenSPOcorrespondsTriple.ANY.- Parameters:
s-Resource, the subjectp-Property, the predicateo-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 thestartresource to theendRDF node, such that every step on the path is accepted by the given filter. A path is aListof RDFStatements. The subject of the first statement in the list isstart, and the object of the last statement in the list isend.The
onPathargument is aPredicate, which accepts a statement and returnstrueif the statement should be considered to be on the path. To search for an unconstrained path, pass()->trueornullas an argument. If there is more than one path of minimal length fromstarttoend, 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, notnullstart- the starting resource, notnullend- the end, or goal, node, notnullonPath- 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 isend, empty if no such path exists
-