Class ResourceUtils
- java.lang.Object
-
- org.apache.jena.util.ResourceUtils
-
public class ResourceUtils extends java.lang.Object
General utility methods that operate on RDF resources, but which are not specific to a given model.
-
-
Constructor Summary
Constructors Constructor Description ResourceUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Resource>
java.util.List<T>maximalLowerElements(java.util.Collection<T> resources, Property rel, boolean inverse)
Answer the maximal lower elements of the given collection, given the partial orderingrel
.static <T extends Resource>
java.util.List<T>maximalLowerElements(java.util.Iterator<T> resources, Property rel, boolean inverse)
Given a collection of resources, and a relation defining a partial order over those resources, answer the sub-collection that contains only those elements that appear in the maximal generator of the relation.static <T extends Resource>
java.util.List<java.util.List<T>>partition(java.util.List<T> l, Property p)
Answer a list of lists, which is a partition of the given input list of resources.static Model
reachableClosure(Resource root)
Answer a model that contains all of the resources reachable from a given resource by any property, transitively.static <T extends Resource>
java.util.List<T>removeEquiv(java.util.List<T> l, Property p, Resource ref)
Remove from the given list l ofResources
, any Resource that is equivalent to the reference resourceref
under the relationp
.static Resource
renameResource(Resource old, java.lang.String uri)
Answer a new resource that occupies the same position in the graph as the current resourceold
, but that has the given URI.
-
-
-
Method Detail
-
maximalLowerElements
public static <T extends Resource> java.util.List<T> maximalLowerElements(java.util.Collection<T> resources, Property rel, boolean inverse)
Answer the maximal lower elements of the given collection, given the partial ordering
rel
. SeemaximalLowerElements( Iterator, Property, boolean )
for details.- Parameters:
resources
- A collection of resourcesrel
- A property defining a partial-ordering onresources
inverse
- If true, we invert the given property (by reversing the order of the arguments), which allows us to use eg subClassOf as a partial order operator for both sub-class and super-class relationships- Returns:
- The collection that contains only those
resources
are not greater than another resource under the partial order.
-
maximalLowerElements
public static <T extends Resource> java.util.List<T> maximalLowerElements(java.util.Iterator<T> resources, Property rel, boolean inverse)
Given a collection of resources, and a relation defining a partial order over those resources, answer the sub-collection that contains only those elements that appear in the maximal generator of the relation. Specifically, a resource
x
is excluded from the return value if there is another resourcey
in the input collection such thaty Rel x
holds.- Parameters:
resources
- An iterator over a collection of resourcesrel
- A property defining a partial-ordering onresources
inverse
- If true, we invert the given property (by reversing the order of the arguments), which allows us to use eg subClassOf as a partial order operator for both sub-class and super-class relationships- Returns:
- The list that contains only those
resources
are not greater than another resource under the partial order.
-
removeEquiv
public static <T extends Resource> java.util.List<T> removeEquiv(java.util.List<T> l, Property p, Resource ref)
Remove from the given list l of
Resources
, any Resource that is equivalent to the reference resourceref
under the relationp
. Typically,p
will beowl:subClassOf
orowl:subPropertyOf
or some similar predicate. A resource R is defined to be equivalent toref
iffR p ref
is true andref p R
is true.The equivalent resources are removed from list
l
in place, the return value is the list of removed resources.- Parameters:
l
- A list of resources from which the resources equivalent to ref will be removedp
- An equivalence predicateref
- A reference resource- Returns:
- A list of the resources removed from the parameter list l
-
partition
public static <T extends Resource> java.util.List<java.util.List<T>> partition(java.util.List<T> l, Property p)
Answer a list of lists, which is a partition of the given input list of resources. The equivalence relation is the predicate p. So, two resources
a
andb
will be in the same partition iff(a p b) && (b p a)
.- Type Parameters:
T
-- Parameters:
l
- A list of resourcesp
- An equivalence predicate- Returns:
- A list of lists which are the partitions of
l
underp
-
renameResource
public static Resource renameResource(Resource old, java.lang.String uri)
Answer a new resource that occupies the same position in the graph as the current resource
old
, but that has the given URI. In the process, the existing statements referring toold
are removed. Since Jena does not allow the identity of a resource to change, this is the closest approximation to a rename operation that works.Renaming a resource to its own URI is a no-op. Resources in the predicate position of statements are not renamed. Intermediate store for the triples mentioning
old
is required.NoteThis implementation is a general and simple approach, and in given applications it may be possible to do this operation more efficiently.
- Parameters:
old
- An existing resource in a given modeluri
- A new URI for resource old, ornull
to rename old to a bNode- Returns:
- A new resource that occupies the same position in the graph as old, but which has the new given URI.
-
reachableClosure
public static Model reachableClosure(Resource root)
Answer a model that contains all of the resources reachable from a given resource by any property, transitively. The returned graph is the sub-graph of the parent graph of root, whose root node is the given root. Cycles are permitted in the sub-graph.
- Parameters:
root
- The root node of the sub-graph to extract- Returns:
- A model containing all reachable RDFNodes from root by any property.
-
-