Class G


  • public class G
    extends java.lang.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 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)
      • 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.
      • 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.
      • 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.
      • 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.
      • 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.
      • 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).
      • 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)
      • 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.
      • 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 is Quad.defaultGraphIRI, not Quad.defaultGraphNodeGenerated, which is for quads outside a dataset, usually the output of parsers.