Package org.apache.jena.riot.other
Class G
- java.lang.Object
-
- org.apache.jena.riot.other.G
-
public class G extends java.lang.Object
A library of functions for working withGraph
. Internally allExtendedIterators
used, run to completion or have.close()
called. AnyExtendedIterators
returned by functions in this library must be used in the same way
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Set<Node>
allNodesOfTypeRDFS(Graph graph, Node type)
List all the node of type, including considering rdfs:subClassOfstatic <X> boolean
allNonNull(X... objects)
Are all the arguments non-null?static java.util.Set<Node>
allPO(Graph graph, Node predicate, Node object)
Return a set of all subjects for predicate-objectstatic java.util.Set<Node>
allSP(Graph graph, Node subject, Node predicate)
Return a set of all objects for subject-predicatestatic java.util.Set<Node>
allTypesOfNodeRDFS(Graph graph, Node node)
List all the types of a node, including super-classes.static void
apply(Graph src, java.util.function.Consumer<Triple> action)
Apply an action to every triple of a graph.static void
apply(ExtendedIterator<Triple> iter, java.util.function.Consumer<Triple> action)
Apply an action to every triple of an iterator.static <X> X
atMostOne(X... objects)
Is one or none of the arguments non-null?static void
clear(Graph graph)
Clear graph.static boolean
contains(Graph graph, Node subject, Node predicate, Node object)
Does the graph match the s/p/o pattern?static boolean
containsNode(Graph graph, Node node)
Does the graph use the node anywhere as a subject, predicate or object?static boolean
containsOne(Graph graph, Node subject, Node predicate, Node object)
Contains exactly one.static void
copyGraphSrcToDst(Graph src, Graph dst)
Add src to dst - assumes transaction.static long
count(Graph graph, Node subject, Node predicate, Node object)
Count occurrences of the pattern.static <X> int
countNonNulls(X... objects)
Count non-nullsstatic long
countPO(Graph graph, Node predicate, Node object)
Count matches of predicate-object (which can be wildcards).static long
countSP(Graph graph, Node subject, Node predicate)
Count matches of subject-predicate (which can be wildcards).static void
deleteModify(Graph modify, Graph srcGraph)
Delete triples in the graph-to-modify (arg 1) that are in the source (arg 2).static <X> boolean
exactlyOneSet(X... objects)
Is one and only one argument non-null?static ExtendedIterator<Triple>
find(Graph graph, Node subject, Node predicate, Node object)
Graph.find(Node, Node, Node)
as a function.static ExtendedIterator<Triple>
findAll(Graph graph)
Graph.find()
as a function.static Triple
getOne(Graph graph, Node subject, Node predicate, Node object)
Get triple if there is exactly one to match the s/p/o, else throw RDFDataException.static Quad
getOne(DatasetGraph dsg, Node graph, Node subject, Node predicate, Node object)
Get quad if there is exactly one to match the s/p/o, else throw RDFDataException.static Triple
getOneOrNull(Graph graph, Node subject, Node predicate, Node object)
Get triple if there is exactly one to match the s/p/o; else return null if none or more than one.static Quad
getOneOrNull(DatasetGraph dsg, Node graph, Node subject, Node predicate, Node object)
Get triple if there is exactly one to match the s/p/o; else return null if none or more than one.static Node
getOnePO(Graph graph, Node predicate, Node object)
Get the subject for predicate-object.static Node
getOneSP(Graph graph, Node subject, Node predicate)
Get object for subject-predicate.static Node
getPO(Graph graph, Node predicate, Node object)
Get the subject, given predicate and object.static Node
getSP(Graph graph, Node subject, Node predicate)
Get object, given subject and predicate.static Triple
getZeroOrOne(Graph graph, Node subject, Node predicate, Node object)
Get triple if there is exactly one to match the s/p/o; return null if none; throw RDFDataException if more than one.static Quad
getZeroOrOne(DatasetGraph dsg, Node graph, Node subject, Node predicate, Node object)
Get triple if there is exactly one to match the s/p/o; return null if none; throw RDFDataException if more than one.static Node
getZeroOrOnePO(Graph graph, Node predicate, Node object)
Get the subject for predicate-object.static Node
getZeroOrOneSP(Graph graph, Node subject, Node predicate)
Get object for subject-predicate.static boolean
hasOnePO(Graph graph, Node predicate, Node object)
Test whether there is exactly one subject for the predicate-object.static boolean
hasOneSP(Graph graph, Node subject, Node predicate)
Test whether there is exactly one object for the subject-predicate.static boolean
hasProperty(Graph graph, Node subject, Node predicate)
Does nodes
have propertyp
in graphg
?static boolean
hasType(Graph graph, Node node, Node type)
Does the node x have the given type (non-RDFS - no rdfs:subclassOf considered)?static boolean
isBlank(Node n)
static boolean
isLiteral(Node n)
static boolean
isNodeGraph(Node n)
static boolean
isNodeTriple(Node n)
static boolean
isOfType(Graph graph, Node node, Node type)
Test whether the node has the type or one of its types is an rdfs:subclassOf the type.static boolean
isResource(Node n)
static boolean
isURI(Node n)
static ExtendedIterator<Node>
iterPO(Graph graph, Node predicate, Node object)
ExtendedIterator
of subjects where the triple matches for predicate and object (which can be wildcards).static ExtendedIterator<Node>
iterSP(Graph graph, Node subject, Node predicate)
ExtendedIterator
of objects where the triple matches for subject and predicate (which can be wildcards).static java.util.List<Node>
listNodesOfTypeRDFS(Graph graph, Node type)
List all the nodes of type, including node of sub-classes.static java.util.Iterator<Node>
listObjects(Graph graph)
List the objects in a graph (no duplicates)static java.util.List<Node>
listPO(Graph graph, Node predicate, Node object)
List of subjects matching the predicate-object (which can be wildcards).static java.util.Iterator<Node>
listPredicates(Graph graph)
List the predicates in a graph (no duplicates)static java.util.List<Node>
listSP(Graph graph, Node subject, Node predicate)
List of objects matching the subject-predicate (which can be wildcards).static java.util.List<Node>
listSubClasses(Graph graph, Node type)
List the subclasses of a type, including itself.static java.util.Iterator<Node>
listSubjects(Graph graph)
List the subjects in a graph (no duplicates)static java.util.List<Node>
listSuperClasses(Graph graph, Node type)
List the super-classes of a type, including itself.static java.util.List<Node>
listTypesOfNodeRDFS(Graph graph, Node node)
List the types of a node, following rdfs:subClassOf for super classes.static java.util.List<Node>
nodesOfTypeAsList(Graph graph, Node type)
List the subjects with exactlytype
.static java.util.Set<Node>
nodesOfTypeAsSet(Graph graph, Node type)
Set of nodes with exactlytype
.static Node
nullAsAny(Node x)
Convert null to Node.ANYstatic Node
nullAsDft(Node x, Node dft)
Convert null to some default Nodestatic Node
object(Triple triple)
Return the object of a triple, or null if the triple is null.static long
objectConnectiveness(Graph graph, Node object)
Count the number of in-arc to an objectstatic boolean
oneConnected(Graph graph, Node object)
Test whether an object has exactly one in-arc.static Node
predicate(Triple triple)
Return the predicate of a triple, or null if the triple is null.static java.util.Iterator<Node>
quad2graphName(java.util.Iterator<Quad> iter)
Project quad to graph namestatic java.util.Iterator<Node>
quad2object(java.util.Iterator<Quad> iter)
Project quad to objectstatic java.util.Iterator<Node>
quad2predicate(java.util.Iterator<Quad> iter)
Project quad to predicatestatic java.util.Iterator<Node>
quad2subject(java.util.Iterator<Quad> iter)
Project quad to subjectstatic org.apache.jena.atlas.iterator.Iter<Triple>
quads2triples(java.util.Iterator<Quad> iter)
Project quads to triplesstatic java.util.List<Node>
rdfList(Graph graph, Node node)
Return a java list for an RDF list of data.static java.util.Set<Node>
subClasses(Graph graph, Node type)
Set of the subclasses of a type, including itself.static Node
subject(Triple triple)
Return the subject of a triple, or null if the triple is null.static java.util.Set<Node>
superClasses(Graph graph, Node type)
Set of the subclasses of a type, including itself.static java.util.Iterator<Node>
triple2object(java.util.Iterator<Triple> iter)
Project triple to objectstatic java.util.Iterator<Node>
triple2predicate(java.util.Iterator<Triple> iter)
Project triple to predicatestatic java.util.Iterator<Node>
triple2subject(java.util.Iterator<Triple> iter)
Project triple to subjectstatic org.apache.jena.atlas.iterator.Iter<Quad>
triples2quads(Node graphNode, java.util.Iterator<Triple> iter)
Convert an iterator of triples into quads for the specified graph name.static org.apache.jena.atlas.iterator.Iter<Quad>
triples2quadsDftGraph(java.util.Iterator<Triple> iter)
Convert an iterator of triples into quads for the default graph.static java.util.List<Node>
typesOfNodeAsList(Graph graph, Node node)
List the types of a node/subject.static java.util.Set<Node>
typesOfNodeAsSet(Graph graph, Node node)
Set of exact types of a node.
-
-
-
Method Detail
-
subject
public static Node subject(Triple triple)
Return the subject of a triple, or null if the triple is null.
-
predicate
public static Node predicate(Triple triple)
Return the predicate of a triple, or null if the triple is null.
-
object
public static Node object(Triple triple)
Return the object of a triple, or null if the triple is null.
-
isURI
public static boolean isURI(Node n)
-
isBlank
public static boolean isBlank(Node n)
-
isLiteral
public static boolean isLiteral(Node n)
-
isResource
public static boolean isResource(Node n)
-
isNodeTriple
public static boolean isNodeTriple(Node n)
-
isNodeGraph
public static boolean isNodeGraph(Node n)
-
contains
public static boolean contains(Graph graph, Node subject, Node predicate, Node object)
Does the graph match the s/p/o pattern?
-
containsNode
public static boolean containsNode(Graph graph, Node node)
Does the graph use the node anywhere as a subject, predicate or object?
-
isOfType
public static boolean isOfType(Graph graph, Node node, Node type)
Test whether the node has the type or one of its types is an rdfs:subclassOf the type.
-
hasType
public static boolean hasType(Graph graph, Node node, Node type)
Does the node x have the given type (non-RDFS - no rdfs:subclassOf considered)?
-
hasProperty
public static boolean hasProperty(Graph graph, Node subject, Node predicate)
Does nodes
have propertyp
in graphg
?
-
containsOne
public static boolean containsOne(Graph graph, Node subject, Node predicate, Node object)
Contains exactly one.
-
getSP
public static Node getSP(Graph graph, Node subject, Node predicate)
Get object, given subject and predicate. Returns one (non-deterministically) or null. See alsogetOneSP(org.apache.jena.graph.Graph, org.apache.jena.graph.Node, org.apache.jena.graph.Node)
andgetZeroOrOneSP(org.apache.jena.graph.Graph, org.apache.jena.graph.Node, org.apache.jena.graph.Node)
.
-
getOneSP
public static Node getOneSP(Graph graph, Node subject, Node predicate)
Get object for subject-predicate. Must be exactly one object; exception RDFDataException thrown when none or more than one.
-
hasOneSP
public static boolean hasOneSP(Graph graph, Node subject, Node predicate)
Test whether there is exactly one object for the subject-predicate.
-
getZeroOrOneSP
public static Node getZeroOrOneSP(Graph graph, Node subject, Node predicate)
Get object for subject-predicate. Return null for none, object for one, and exception RDFDataException if more than one.
-
getPO
public static Node getPO(Graph graph, Node predicate, Node object)
Get the subject, given predicate and object. Returns one (non-deterministically) or null. See alsogetOnePO(org.apache.jena.graph.Graph, org.apache.jena.graph.Node, org.apache.jena.graph.Node)
andgetZeroOrOnePO(org.apache.jena.graph.Graph, org.apache.jena.graph.Node, org.apache.jena.graph.Node)
.
-
getOnePO
public static Node getOnePO(Graph graph, Node predicate, Node object)
Get the subject for predicate-object. Must be exactly one subject; exception RDFDataException thrown when none or more than one.
-
hasOnePO
public static boolean hasOnePO(Graph graph, Node predicate, Node object)
Test whether there is exactly one subject for the predicate-object.
-
getZeroOrOnePO
public static Node getZeroOrOnePO(Graph graph, Node predicate, Node object)
Get the subject for predicate-object. Return null for none, subject for one, throw exception RDFDataException if more than one.
-
getOne
public static Triple getOne(Graph graph, Node subject, Node predicate, Node object)
Get triple if there is exactly one to match the s/p/o, else throw RDFDataException.
-
getZeroOrOne
public static Triple getZeroOrOne(Graph graph, Node subject, Node predicate, Node object)
Get triple if there is exactly one to match the s/p/o; return null if none; throw RDFDataException if more than one.
-
getOneOrNull
public static Triple getOneOrNull(Graph graph, Node subject, Node predicate, Node object)
Get triple if there is exactly one to match the s/p/o; else return null if none or more than one.
-
getOne
public static Quad getOne(DatasetGraph dsg, Node graph, Node subject, Node predicate, Node object)
Get quad if there is exactly one to match the s/p/o, else throw RDFDataException.
-
getZeroOrOne
public static Quad getZeroOrOne(DatasetGraph dsg, Node graph, Node subject, Node predicate, Node object)
Get triple if there is exactly one to match the s/p/o; return null if none; throw RDFDataException if more than one.
-
getOneOrNull
public static Quad getOneOrNull(DatasetGraph dsg, Node graph, Node subject, Node predicate, Node object)
Get triple if there is exactly one to match the s/p/o; else return null if none or more than one.
-
iterSP
public static ExtendedIterator<Node> iterSP(Graph graph, Node subject, Node predicate)
ExtendedIterator
of objects where the triple matches for subject and predicate (which can be wildcards). TheExtendedIterator
must be fully used or explicitly closed. It is preferable uselistSP(org.apache.jena.graph.Graph, org.apache.jena.graph.Node, org.apache.jena.graph.Node)
which handles this condition.
-
listSP
public static java.util.List<Node> listSP(Graph graph, Node subject, Node predicate)
List of objects matching the subject-predicate (which can be wildcards).
-
countSP
public static long countSP(Graph graph, Node subject, Node predicate)
Count matches of subject-predicate (which can be wildcards).
-
iterPO
public static ExtendedIterator<Node> iterPO(Graph graph, Node predicate, Node object)
ExtendedIterator
of subjects where the triple matches for predicate and object (which can be wildcards). TheExtendedIterator
must be fully used or explicitly closed. It is preferable uselistSP(org.apache.jena.graph.Graph, org.apache.jena.graph.Node, org.apache.jena.graph.Node)
which handles this condition.
-
listPO
public static java.util.List<Node> listPO(Graph graph, Node predicate, Node object)
List of subjects matching the predicate-object (which can be wildcards).
-
countPO
public static long countPO(Graph graph, Node predicate, Node object)
Count matches of predicate-object (which can be wildcards).
-
listSubjects
public static java.util.Iterator<Node> listSubjects(Graph graph)
List the subjects in a graph (no duplicates)
-
listPredicates
public static java.util.Iterator<Node> listPredicates(Graph graph)
List the predicates in a graph (no duplicates)
-
listObjects
public static java.util.Iterator<Node> listObjects(Graph graph)
List the objects in a graph (no duplicates)
-
nodesOfTypeAsList
public static java.util.List<Node> nodesOfTypeAsList(Graph graph, Node type)
List the subjects with exactlytype
. SeelistNodesOfTypeRDFS(Graph, Node)
, which does include sub-classes.
-
typesOfNodeAsList
public static java.util.List<Node> typesOfNodeAsList(Graph graph, Node node)
List the types of a node/subject. SeelistTypesOfNodeRDFS(Graph, Node)
, which does include super-classes.
-
nodesOfTypeAsSet
public static java.util.Set<Node> nodesOfTypeAsSet(Graph graph, Node type)
Set of nodes with exactlytype
. SeeallNodesOfTypeRDFS(Graph, Node)
, which does include sub-classes.
-
typesOfNodeAsSet
public static java.util.Set<Node> typesOfNodeAsSet(Graph graph, Node node)
Set of exact types of a node.See
allTypesOfNodeRDFS(Graph, Node)
, which does include super-classes.
-
rdfList
public static java.util.List<Node> rdfList(Graph graph, Node node)
Return a java list for an RDF list of data.
-
listSubClasses
public static java.util.List<Node> listSubClasses(Graph graph, Node type)
List the subclasses of a type, including itself. This is ?x rdfs:subClassOf* type. The list does not contain duplicates.
-
listSuperClasses
public static java.util.List<Node> listSuperClasses(Graph graph, Node type)
List the super-classes of a type, including itself. This is type rdfs:subClassOf* ?x. The list does not contain duplicates.
-
subClasses
public static java.util.Set<Node> subClasses(Graph graph, Node type)
Set of the subclasses of a type, including itself. This is ?x rdfs:subClassOf* type.
-
superClasses
public static java.util.Set<Node> superClasses(Graph graph, Node type)
Set of the subclasses of a type, including itself. This is ?x rdfs:subClassOf* type.
-
listTypesOfNodeRDFS
public static java.util.List<Node> listTypesOfNodeRDFS(Graph graph, Node node)
List the types of a node, following rdfs:subClassOf for super classes.
-
listNodesOfTypeRDFS
public static java.util.List<Node> listNodesOfTypeRDFS(Graph graph, Node type)
List all the nodes of type, including node of sub-classes.
-
allTypesOfNodeRDFS
public static java.util.Set<Node> allTypesOfNodeRDFS(Graph graph, Node node)
List all the types of a node, including super-classes.
-
allNodesOfTypeRDFS
public static java.util.Set<Node> allNodesOfTypeRDFS(Graph graph, Node type)
List all the node of type, including considering rdfs:subClassOf
-
allSP
public static java.util.Set<Node> allSP(Graph graph, Node subject, Node predicate)
Return a set of all objects for subject-predicate
-
allPO
public static java.util.Set<Node> allPO(Graph graph, Node predicate, Node object)
Return a set of all subjects for predicate-object
-
objectConnectiveness
public static long objectConnectiveness(Graph graph, Node object)
Count the number of in-arc to an object
-
oneConnected
public static boolean oneConnected(Graph graph, Node object)
Test whether an object has exactly one in-arc.
-
count
public static long count(Graph graph, Node subject, Node predicate, Node object)
Count occurrences of the pattern.
-
find
public static ExtendedIterator<Triple> find(Graph graph, Node subject, Node predicate, Node object)
Graph.find(Node, Node, Node)
as a function.
-
findAll
public static ExtendedIterator<Triple> findAll(Graph graph)
Graph.find()
as a function.
-
allNonNull
@SafeVarargs public static <X> boolean allNonNull(X... objects)
Are all the arguments non-null?
-
exactlyOneSet
@SafeVarargs public static <X> boolean exactlyOneSet(X... objects)
Is one and only one argument non-null?
-
atMostOne
@SafeVarargs public static <X> X atMostOne(X... objects)
Is one or none of the arguments non-null?
-
countNonNulls
@SafeVarargs public static <X> int countNonNulls(X... objects)
Count non-nulls
-
quads2triples
public static org.apache.jena.atlas.iterator.Iter<Triple> quads2triples(java.util.Iterator<Quad> iter)
Project quads to triples
-
quad2graphName
public static java.util.Iterator<Node> quad2graphName(java.util.Iterator<Quad> iter)
Project quad to graph name
-
quad2subject
public static java.util.Iterator<Node> quad2subject(java.util.Iterator<Quad> iter)
Project quad to subject
-
quad2predicate
public static java.util.Iterator<Node> quad2predicate(java.util.Iterator<Quad> iter)
Project quad to predicate
-
quad2object
public static java.util.Iterator<Node> quad2object(java.util.Iterator<Quad> iter)
Project quad to object
-
triple2subject
public static java.util.Iterator<Node> triple2subject(java.util.Iterator<Triple> iter)
Project triple to subject
-
triple2predicate
public static java.util.Iterator<Node> triple2predicate(java.util.Iterator<Triple> iter)
Project triple to predicate
-
triple2object
public static java.util.Iterator<Node> triple2object(java.util.Iterator<Triple> iter)
Project triple to object
-
copyGraphSrcToDst
public static void copyGraphSrcToDst(Graph src, Graph dst)
Add src to dst - assumes transaction. src and dst must not overlap. Copies "left to right" --src into dst
- Parameters:
src
-dst
-
-
clear
public static void clear(Graph graph)
Clear graph.
-
apply
public static void apply(Graph src, java.util.function.Consumer<Triple> action)
Apply an action to every triple of a graph. The action must not attempt to modify the graph but it can read it.
-
apply
public static void apply(ExtendedIterator<Triple> iter, java.util.function.Consumer<Triple> action)
Apply an action to every triple of an iterator. If the iterator is attracted to a graph, the action must not attempt to modify the graph but it can read it.
-
deleteModify
public static void deleteModify(Graph modify, Graph srcGraph)
Delete triples in the graph-to-modify (arg 1) that are in the source (arg 2).- Parameters:
modify
-srcGraph
-
-
triples2quads
public static org.apache.jena.atlas.iterator.Iter<Quad> triples2quads(Node graphNode, java.util.Iterator<Triple> iter)
Convert an iterator of triples into quads for the specified graph name.
-
triples2quadsDftGraph
public static org.apache.jena.atlas.iterator.Iter<Quad> triples2quadsDftGraph(java.util.Iterator<Triple> iter)
Convert an iterator of triples into quads for the default graph. This isQuad.defaultGraphIRI
, notQuad.defaultGraphNodeGenerated
, which is for quads outside a dataset, usually the output of parsers.
-
-