java.lang.Object
org.apache.jena.riot.other.G
A library of functions for working with
Graph
. Internally all
ExtendedIterators
used, run to completion or have
.close()
called. Any ExtendedIterators
returned
by functions in this library must be used in the same way-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Add triples into the destination (arg 1) from the source (arg 2)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?Return a set of all subjects for predicate-objectReturn a set of all objects for subject-predicateallTypesOfNodeRDFS
(Graph graph, Node node) List all the types of a node, including super-classes.static void
Apply an action to every triple of a graph.static void
apply
(ExtendedIterator<Triple> iter, Consumer<Triple> action) Apply an action to every triple of an iterator.static String
Get a string, assuming the node is an xsd:string literal.static <X> X
atMostOne
(X... objects) Is one or none of the arguments non-null?static <X> X
Execute a graph transaction and result result if the graph supports transactions else execute and return without a transaction wrapper.static void
Clear graph.static boolean
Does the graph match the s/p/o pattern?static boolean
containsBySameTerm
(Graph graph, Node s, Node p, Node o) Test whether a graph contains by "same term", regardless of whether the graph implements "same value" or "same term".static boolean
containsBySameTerm
(Graph graph, Triple triple) Test whether a graph contains by "same term", regardless of whether the graph implements "same value" or "same term".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 occurrences of the pattern.static <X> int
countNonNulls
(X... objects) Count non-nullsstatic long
Count matches of predicate-object (which can be wildcards).static long
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 void
Execute a graph transaction if the graph supports transactions else apply without a transaction wrapper.static ExtendedIterator<Triple>
Graph.find(Node, Node, Node)
as a function.static ExtendedIterator<Triple>
Graph.find()
as a function.static void
Find triples and execute an action on each triple found.static Triple
Get triple if there is exactly one to match the s/p/o, else throw RDFDataException.static Quad
Get quad if there is exactly one to match the s/p/o, else throw RDFDataException.getOneOrList
(Graph graph, Node node) Return a java list where thenode
is an RDF list of nodes or a single node (returned a singleton list).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
Get the subject for predicate-object.static Node
Get object for subject-predicate.static Node
Get the subject, given predicate and object.static Node
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
hasDatatype
(Node n, RDFDatatype datatype) Return true if n is a literal and it has the given datatype, else return false.static boolean
Test whether there is exactly one subject for the predicate-object.static boolean
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
Does the node x have the given type (non-RDFS - no rdfs:subclassOf considered)?static boolean
static boolean
static boolean
static boolean
isNodeGraph
(Node n) static boolean
isNodeTriple
(Node n) static boolean
isNullOrAny
(Node n) static boolean
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
static boolean
iterObjects
(Graph graph) List the objects in a graph (no duplicates)iterObjectsOfPredicate
(Graph graph, Node predicate) List the objects in a graph (no duplicates)static ExtendedIterator<Node>
ExtendedIterator
of subjects where the triple matches for predicate and object (which can be wildcards).iterPredicates
(Graph graph) List the predicates in a graph (no duplicates)static ExtendedIterator<Node>
ExtendedIterator
of objects where the triple matches for subject and predicate (which can be wildcards).iterSubjects
(Graph graph) List the subjects in a graph (no duplicates)iterSubjectsOfPredicate
(Graph graph, Node predicate) List the subjects of a predicate in a graph (no duplicates)listNodesOfTypeRDFS
(Graph graph, Node type) List all the nodes of type, including nodes of sub-classes.listObjects
(Graph graph) Deprecated.List of subjects matching the predicate-object (which can be wildcards).listPredicates
(Graph graph) Deprecated.List of objects matching the subject-predicate (which can be wildcards).listSubClasses
(Graph graph, Node type) List the subclasses of a type, including itself.listSubjects
(Graph graph) Deprecated.listSuperClasses
(Graph graph, Node type) List the super-classes of a type, including itself.listTypesOfNodeRDFS
(Graph graph, Node node) List the types of a node, following rdfs:subClassOf for super classes.nodesOfTypeAsList
(Graph graph, Node type) List the subjects with exactlytype
.nodesOfTypeAsSet
(Graph graph, Node type) Set of nodes with exactlytype
.static Node
Convert null to Node.ANYstatic Node
Convert null to some default Nodestatic Node
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
Return the predicate of a triple, or null if the triple is null.quad2graphName
(Iterator<Quad> iter) Project quad to graph namequad2object
(Iterator<Quad> iter) Project quad to objectquad2predicate
(Iterator<Quad> iter) Project quad to predicatequad2subject
(Iterator<Quad> iter) Project quad to subjectstatic org.apache.jena.atlas.iterator.Iter<Triple>
quads2triples
(Iterator<Quad> iter) Project quads to triplesReturn a java list for an RDF list of data.static boolean
sameTermMatch
(Node match, Node data) Match a node, which can be a wildcard (ANY or null) against a ground RDF Term (ANY and variables are considered ground terms in the data term).static boolean
sameTermMatch
(Node matchSubj, Node matchPred, Node matchObj, Triple dataTriple) Match S/P/O which can be wildcards (ANY or null), against a ground triple (even ANY and variables are considered ground terms in the data triple).subClasses
(Graph graph, Node type) Set of the subclasses of a type, including itself.static Node
Return the subject of a triple, or null if the triple is null.superClasses
(Graph graph, Node type) Set of the subclasses of a type, including itself.triple2object
(Iterator<Triple> iter) Project triple to objecttriple2predicate
(Iterator<Triple> iter) Project triple to predicatetriple2subject
(Iterator<Triple> iter) Project triple to subjectstatic org.apache.jena.atlas.iterator.Iter<Quad>
triples2quads
(Node graphNode, Iterator<Triple> iter) Convert an iterator of triples into quads for the specified graph name.static org.apache.jena.atlas.iterator.Iter<Quad>
triples2quadsDftGraph
(Iterator<Triple> iter) Convert an iterator of triples into quads for the default graph.typesOfNodeAsList
(Graph graph, Node node) List the types of a node/subject.typesOfNodeAsSet
(Graph graph, Node node) Set of exact types of a node.
-
Method Details
-
subject
Return the subject of a triple, or null if the triple is null. -
predicate
Return the predicate of a triple, or null if the triple is null. -
object
Return the object of a triple, or null if the triple is null. -
isURI
-
isBlank
-
isLiteral
-
isResource
-
isNodeTriple
-
isNodeGraph
-
isNullOrAny
-
hasDatatype
Return true if n is a literal and it has the given datatype, else return false. -
isString
-
isBoolean
-
nullAsAny
Convert null to Node.ANY -
nullAsDft
Convert null to some default Node -
asString
Get a string, assuming the node is an xsd:string literal. -
contains
Does the graph match the s/p/o pattern? -
containsNode
Does the graph use the node anywhere as a subject, predicate or object? -
isOfType
Test whether the node has the type or one of its types is an rdfs:subclassOf the type. -
hasType
Does the node x have the given type (non-RDFS - no rdfs:subclassOf considered)? -
hasProperty
Does nodes
have propertyp
in graphg
? -
containsOne
Contains exactly one. -
getSP
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
Get object for subject-predicate. Must be exactly one object; exception RDFDataException thrown when none or more than one. -
hasOneSP
Test whether there is exactly one object for the subject-predicate. -
getZeroOrOneSP
Get object for subject-predicate. Return null for none, object for one, and exception RDFDataException if more than one. -
getPO
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
Get the subject for predicate-object. Must be exactly one subject; exception RDFDataException thrown when none or more than one. -
hasOnePO
Test whether there is exactly one subject for the predicate-object. -
getZeroOrOnePO
Get the subject for predicate-object. Return null for none, subject for one, throw exception RDFDataException if more than one. -
getOne
Get triple if there is exactly one to match the s/p/o, else throw RDFDataException. -
getZeroOrOne
Get triple if there is exactly one to match the s/p/o; return null if none; throw RDFDataException if more than one. -
getOneOrNull
Get triple if there is exactly one to match the s/p/o; else return null if none or more than one. -
getOne
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
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
List of objects matching the subject-predicate (which can be wildcards). -
countSP
Count matches of subject-predicate (which can be wildcards). -
iterPO
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
List of subjects matching the predicate-object (which can be wildcards). -
countPO
Count matches of predicate-object (which can be wildcards). -
listSubjects
Deprecated. -
listPredicates
Deprecated. -
listObjects
Deprecated. -
iterSubjects
List the subjects in a graph (no duplicates) -
iterPredicates
List the predicates in a graph (no duplicates) -
iterObjects
List the objects in a graph (no duplicates) -
iterSubjectsOfPredicate
List the subjects of a predicate in a graph (no duplicates)Use
iterPO(predicate, null)
for "with duplicates." -
iterObjectsOfPredicate
List the objects in a graph (no duplicates)Use
iterSP(null, predicate)
for "with duplicates." -
nodesOfTypeAsList
List the subjects with exactlytype
. SeelistNodesOfTypeRDFS(Graph, Node)
, which does include sub-classes. -
typesOfNodeAsList
List the types of a node/subject. SeelistTypesOfNodeRDFS(Graph, Node)
, which does include super-classes. -
nodesOfTypeAsSet
Set of nodes with exactlytype
. SeeallNodesOfTypeRDFS(Graph, Node)
, which does include sub-classes. -
typesOfNodeAsSet
Set of exact types of a node.See
allTypesOfNodeRDFS(Graph, Node)
, which does include super-classes. -
rdfList
Return a java list for an RDF list of data. -
getOneOrList
Return a java list where thenode
is an RDF list of nodes or a single node (returned a singleton list). -
listSubClasses
List the subclasses of a type, including itself. This is?x rdfs:subClassOf* type
. The list does not contain duplicates. -
listSuperClasses
List the super-classes of a type, including itself. This istype rdfs:subClassOf* ?x
. The list does not contain duplicates. -
subClasses
Set of the subclasses of a type, including itself. This is?x rdfs:subClassOf* type
. -
superClasses
Set of the subclasses of a type, including itself. This is?x rdfs:subClassOf* type
. -
listTypesOfNodeRDFS
List the types of a node, following rdfs:subClassOf for super classes. -
listNodesOfTypeRDFS
List all the nodes of type, including nodes of sub-classes. -
allTypesOfNodeRDFS
List all the types of a node, including super-classes. -
allNodesOfTypeRDFS
List all the node of type, including considering rdfs:subClassOf -
allSP
Return a set of all objects for subject-predicate -
allPO
Return a set of all subjects for predicate-object -
objectConnectiveness
Count the number of in-arc to an object -
oneConnected
Test whether an object has exactly one in-arc. -
count
Count occurrences of the pattern. -
find
Graph.find(Node, Node, Node)
as a function. -
findAll
Graph.find()
as a function. -
allNonNull
Are all the arguments non-null? -
exactlyOneSet
Is one and only one argument non-null? -
atMostOne
Is one or none of the arguments non-null? -
countNonNulls
Count non-nulls -
quads2triples
Project quads to triples -
quad2graphName
Project quad to graph name -
quad2subject
Project quad to subject -
quad2predicate
Project quad to predicate -
quad2object
Project quad to object -
triple2subject
Project triple to subject -
triple2predicate
Project triple to predicate -
triple2object
Project triple to object -
copyGraphSrcToDst
Add src to dst - assumes transaction. src and dst must not overlap. Copies "left to right" --src into dst
- Parameters:
src
-dst
-
-
clear
Clear graph. -
apply
Apply an action to every triple of a graph. The action must not attempt to modify the graph but it can read it. -
apply
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
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, 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(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. -
execTxn
Execute a graph transaction if the graph supports transactions else apply without a transaction wrapper. -
calcTxn
Execute a graph transaction and result result if the graph supports transactions else execute and return without a transaction wrapper. -
findExec
Find triples and execute an action on each triple found. -
addInto
Add triples into the destination (arg 1) from the source (arg 2) -
containsBySameTerm
Test whether a graph contains by "same term", regardless of whether the graph implements "same value" or "same term". -
containsBySameTerm
Test whether a graph contains by "same term", regardless of whether the graph implements "same value" or "same term". -
sameTermMatch
public static boolean sameTermMatch(Node matchSubj, Node matchPred, Node matchObj, Triple dataTriple) Match S/P/O which can be wildcards (ANY or null), against a ground triple (even ANY and variables are considered ground terms in the data triple). -
sameTermMatch
Match a node, which can be a wildcard (ANY or null) against a ground RDF Term (ANY and variables are considered ground terms in the data term). Language tags compare case-insensitively.
-
iterObjects(Graph)