java.lang.Object
org.apache.jena.ontapi.utils.StdModels
A class-helper to work with
Jena Model
s and its related objects and components:
Jena RDF Node
, Jena Literal
, Jena Resource
and
Jena Statement
.-
Field Summary
Modifier and TypeFieldDescriptionstatic 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
-
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 ofNode
s from the collection ofRDF Node
s.static boolean
containsURI
(org.apache.jena.rdf.model.RDFNode node, String uri) Answerstrue
if the givennode
contains the specifieduri
.static boolean
containsURI
(org.apache.jena.rdf.model.Statement statement, String uri) Answerstrue
if the givenuri
is a part of the givenstatement
.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 thestart
resource to theend
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) Answerstrue
iff the givenSPO
correspondsTriple.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) Answerstrue
iff 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 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.
-
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
-model
in which the []-list is createdtype
-Resource
the type for new []-listmembers
- Collection ofRDFNode
s- 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:rest
andrdf:nil
predicates), 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) Answerstrue
iff 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
Set
ofStatement
s
-
toString
Returns a string representation of the given Jena statement.- Parameters:
inModel
-Statement
, notnull
- Returns:
String
-
containsURI
Answerstrue
if the givennode
contains the specifieduri
.- Parameters:
node
-RDFNode
, notnull
uri
-String
, notnull
- Returns:
- boolean
-
containsURI
Answerstrue
if the givenuri
is a part of the givenstatement
.- Parameters:
statement
-Statement
, notnull
uri
-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
-ExtendedIterator
ofTriple
smap
- 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 ofNode
s from the collection ofRDF Node
s. Placed here as it is widely used.- Parameters:
nodes
- Collection ofRDFNode
s- 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) Answerstrue
iff the givenSPO
correspondsTriple.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 thestart
resource to theend
RDF node, such that every step on the path is accepted by the given filter. A path is aList
of RDFStatement
s. The subject of the first statement in the list isstart
, and the object of the last statement in the list isend
.The
onPath
argument is aPredicate
, which accepts a statement and returnstrue
if the statement should be considered to be on the path. To search for an unconstrained path, pass()->true
ornull
as an argument. If there is more than one path of minimal length fromstart
toend
, 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, notnull
start
- the starting resource, notnull
end
- the end, or goal, node, notnull
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 isend
, empty if no such path exists
-