java.lang.Object
org.apache.jena.riot.other.G

public class G extends Object
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 Details

    • 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)
    • nullAsAny

      public static Node nullAsAny(Node x)
      Convert null to Node.ANY
    • nullAsDft

      public static Node nullAsDft(Node x, Node dft)
      Convert null to some default Node
    • 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 node s have property p in graph g?
    • 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)
    • 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)
    • 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). The ExtendedIterator must be fully used or explicitly closed. It is preferable use listSP(org.apache.jena.graph.Graph, org.apache.jena.graph.Node, org.apache.jena.graph.Node) which handles this condition.
    • listSP

      public static 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). The ExtendedIterator must be fully used or explicitly closed. It is preferable use listSP(org.apache.jena.graph.Graph, org.apache.jena.graph.Node, org.apache.jena.graph.Node) which handles this condition.
    • listPO

      public static 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 Iterator<Node> listSubjects(Graph graph)
      List the subjects in a graph (no duplicates)
    • listPredicates

      public static Iterator<Node> listPredicates(Graph graph)
      List the predicates in a graph (no duplicates)
    • listObjects

      public static Iterator<Node> listObjects(Graph graph)
      List the objects in a graph (no duplicates)
    • nodesOfTypeAsList

      public static List<Node> nodesOfTypeAsList(Graph graph, Node type)
      List the subjects with exactly type. See listNodesOfTypeRDFS(Graph, Node), which does include sub-classes.
    • typesOfNodeAsList

      public static List<Node> typesOfNodeAsList(Graph graph, Node node)
      List the types of a node/subject. See listTypesOfNodeRDFS(Graph, Node), which does include super-classes.
    • nodesOfTypeAsSet

      public static Set<Node> nodesOfTypeAsSet(Graph graph, Node type)
      Set of nodes with exactly type. See allNodesOfTypeRDFS(Graph, Node), which does include sub-classes.
    • typesOfNodeAsSet

      public static 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 List<Node> rdfList(Graph graph, Node node)
      Return a java list for an RDF list of data.
    • listSubClasses

      public static 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 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 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 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 List<Node> listTypesOfNodeRDFS(Graph graph, Node node)
      List the types of a node, following rdfs:subClassOf for super classes.
    • listNodesOfTypeRDFS

      public static List<Node> listNodesOfTypeRDFS(Graph graph, Node type)
      List all the nodes of type, including node of sub-classes.
    • allTypesOfNodeRDFS

      public static Set<Node> allTypesOfNodeRDFS(Graph graph, Node node)
      List all the types of a node, including super-classes.
    • allNodesOfTypeRDFS

      public static Set<Node> allNodesOfTypeRDFS(Graph graph, Node type)
      List all the node of type, including considering rdfs:subClassOf
    • allSP

      public static Set<Node> allSP(Graph graph, Node subject, Node predicate)
      Return a set of all objects for subject-predicate
    • allPO

      public static 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)
    • 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(Iterator<Quad> iter)
      Project quads to triples
    • quad2graphName

      public static Iterator<Node> quad2graphName(Iterator<Quad> iter)
      Project quad to graph name
    • quad2subject

      public static Iterator<Node> quad2subject(Iterator<Quad> iter)
      Project quad to subject
    • quad2predicate

      public static Iterator<Node> quad2predicate(Iterator<Quad> iter)
      Project quad to predicate
    • quad2object

      public static Iterator<Node> quad2object(Iterator<Quad> iter)
      Project quad to object
    • triple2subject

      public static Iterator<Node> triple2subject(Iterator<Triple> iter)
      Project triple to subject
    • triple2predicate

      public static Iterator<Node> triple2predicate(Iterator<Triple> iter)
      Project triple to predicate
    • triple2object

      public static Iterator<Node> triple2object(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, 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, 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, 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 is Quad.defaultGraphIRI, not Quad.defaultGraphNodeGenerated, which is for quads outside a dataset, usually the output of parsers.
    • execTxn

      public static void execTxn(Graph graph, Runnable action)
      Execute a graph transaction if the graph supports transactions else apply without a transaction wrapper.
    • calcTxn

      public static <X> X calcTxn(Graph graph, Supplier<X> action)
      Execute a graph transaction and result result if the graph supports transactions else execute and return without a transaction wrapper.