Class NodeUtils

java.lang.Object
org.aksw.jenax.arq.util.node.NodeUtils

public class NodeUtils extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.apache.jena.graph.Node
     
    static final String
     
    static final org.apache.jena.riot.out.NodeFormatter
     
    static final String
    Placeholder constants to denote a 'null' node - the absence of a value
    static final org.apache.jena.graph.Node
     
    static final String
     
    static final String
     
    static final String
    Constants for use with getDatatypeIri(Node) Conflates the term type into a datatype: Under this perspective, IRIs and blank nodes are simply literals with the rr:IRI or rr:BlankNode datatype.
    static final org.apache.jena.riot.out.NodeFormatter
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.apache.jena.graph.Node
    anyToNull(org.apache.jena.graph.Node n)
     
    static int
    compareAlways(org.apache.jena.graph.Node o1, org.apache.jena.graph.Node o2)
    Compare nodes via NodeValue.compareAlways(NodeValue, NodeValue)
    static org.apache.jena.graph.Node
    Returns the default graph for null or a blank string or 'default' (inoring case), otherwise creates an IRI from the argument
    static List<org.apache.jena.graph.Node>
     
    static org.apache.jena.graph.Node
    createTypedLiteral(org.apache.jena.datatypes.TypeMapper typeMapper, Object o)
    Create a typed literal for a java object by consulting jena's type mapper
    static org.apache.jena.graph.Node
     
    static List<org.apache.jena.graph.Node>
     
    static Set<org.apache.jena.graph.Node>
    getBnodesMentioned(Iterable<org.apache.jena.graph.Node> nodes)
    Filter an iterable of nodes to the set of contained bnodes
    static String
    getDatatypeIri(org.apache.jena.graph.Node node)
    Return a Node's datatype.
    static String
    getIriOrNull(org.apache.jena.graph.Node node)
    If the argument is an IRI-node return the IRI - otherwise return null.
    static String
    getIriOrString(org.apache.jena.graph.Node node)
     
    static String
    getLang(org.apache.jena.graph.Node node)
    Return the language of a node or null if the argument is not applicable
    static Number
    getNumber(org.apache.jena.graph.Node node)
     
    static Number
    getNumberNullable(org.apache.jena.graph.Node node)
     
    static String
    getUnquotedForm(org.apache.jena.graph.Node node)
    Returns the "unquoted form" of any Node depending on its type: null → "" literal → node.getLiteralLexicalForm() iri → node.getURI() bnode → node.getBlankNodeLabel() variable → node.getName() otherwise → NodeFmtLib.displayStr(node)
    static Set<org.apache.jena.sparql.core.Var>
    getVarsMentioned(Iterable<org.apache.jena.graph.Node> nodes)
    Filter an iterable of nodes to the set of contained variables
    static int
    hashCode(org.apache.jena.graph.Node node)
    Util method for use a sparql function -
    static boolean
    isNullOrAny(org.apache.jena.graph.Node node)
     
    static boolean
    isValid(String str, org.apache.jena.graph.Node node)
     
    static boolean
    isValid(org.apache.jena.graph.Node node)
    Serialize and deserialize (print/parse) a node.
    static org.apache.jena.graph.Node
    logicalAnd(org.apache.jena.graph.Node pattern, org.apache.jena.graph.Node b)
    Create a logical conjunction of two nodes: - Node.ANY, null or a variable matches everything - If any argument matches everything return the other argument (convert null to ANY) - if both arguments are concrete nodes then return one if them if they are equal - otherwise return null
    static org.apache.jena.graph.Node
    nullOrFluentToAny(org.apache.jena.graph.Node n)
    Method to canonicalize variables to Node.ANY
    static org.apache.jena.graph.Node
    nullOrVarToAny(org.apache.jena.graph.Node node)
    Similar to nullOrFluentToAny(Node) but specifically for variables.
    static org.apache.jena.graph.Node
    nullToAny(org.apache.jena.graph.Node n)
    Deprecated.
    static org.apache.jena.graph.Node
    Expect the string to parse as a single node.
    static <C extends Collection<? super org.apache.jena.graph.Node>>
    C
    parseNodes(String str, C segments)
    Parse a sequence of nodes into the provided collection
    static boolean
    put(org.apache.jena.sparql.engine.binding.BindingBuilder builder, org.apache.jena.graph.Node nodeOrVar, org.apache.jena.graph.Node node)
     
    static String
    strNodesWithUndef(BiConsumer<org.apache.jena.atlas.io.IndentedWriter,org.apache.jena.graph.Node> output, org.apache.jena.graph.Node... nodes)
    Variant of NodeFmtLib.strNodesNT(Node...) that yield nul as UNDEF
    static void
    validate(String str, org.apache.jena.graph.Node node)
     
    static void
    validate(org.apache.jena.graph.Node node)
    Throws an IllegalArgumentException if isValid(Node) returns false.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ntFormatter

      public static final org.apache.jena.riot.out.NodeFormatter ntFormatter
    • ttlFormatter

      public static final org.apache.jena.riot.out.NodeFormatter ttlFormatter
    • nullUri

      public static final String nullUri
      Placeholder constants to denote a 'null' node - the absence of a value
      See Also:
    • nullUriNode

      public static final org.apache.jena.graph.Node nullUriNode
    • ANY_IRI_STR

      public static final String ANY_IRI_STR
      See Also:
    • ANY_IRI

      public static final org.apache.jena.graph.Node ANY_IRI
    • R2RML_NS

      public static final String R2RML_NS
      Constants for use with getDatatypeIri(Node) Conflates the term type into a datatype: Under this perspective, IRIs and blank nodes are simply literals with the rr:IRI or rr:BlankNode datatype. This approach simplifies analytics for e.g. application in schema mapping
      See Also:
    • R2RML_IRI

      public static final String R2RML_IRI
      See Also:
    • R2RML_BlankNode

      public static final String R2RML_BlankNode
      See Also:
  • Constructor Details

    • NodeUtils

      public NodeUtils()
  • Method Details

    • hashCode

      public static int hashCode(org.apache.jena.graph.Node node)
      Util method for use a sparql function -
      <java:org.aksw.jenax.arq.util.node#hashCode>(?x)
    • compareAlways

      public static int compareAlways(org.apache.jena.graph.Node o1, org.apache.jena.graph.Node o2)
      Compare nodes via NodeValue.compareAlways(NodeValue, NodeValue)
    • getBnodesMentioned

      public static Set<org.apache.jena.graph.Node> getBnodesMentioned(Iterable<org.apache.jena.graph.Node> nodes)
      Filter an iterable of nodes to the set of contained bnodes
    • getVarsMentioned

      public static Set<org.apache.jena.sparql.core.Var> getVarsMentioned(Iterable<org.apache.jena.graph.Node> nodes)
      Filter an iterable of nodes to the set of contained variables
    • isNullOrAny

      public static boolean isNullOrAny(org.apache.jena.graph.Node node)
    • nullToAny

      @Deprecated public static org.apache.jena.graph.Node nullToAny(org.apache.jena.graph.Node n)
      Deprecated.
      Method now exists in Jena's NodeUtils. This method was private in Triple at least in jena 3.16
    • anyToNull

      public static org.apache.jena.graph.Node anyToNull(org.apache.jena.graph.Node n)
    • nullOrFluentToAny

      public static org.apache.jena.graph.Node nullOrFluentToAny(org.apache.jena.graph.Node n)
      Method to canonicalize variables to Node.ANY
    • nullOrVarToAny

      public static org.apache.jena.graph.Node nullOrVarToAny(org.apache.jena.graph.Node node)
      Similar to nullOrFluentToAny(Node) but specifically for variables.
    • logicalAnd

      public static org.apache.jena.graph.Node logicalAnd(org.apache.jena.graph.Node pattern, org.apache.jena.graph.Node b)
      Create a logical conjunction of two nodes: - Node.ANY, null or a variable matches everything - If any argument matches everything return the other argument (convert null to ANY) - if both arguments are concrete nodes then return one if them if they are equal - otherwise return null
    • getLang

      public static String getLang(org.apache.jena.graph.Node node)
      Return the language of a node or null if the argument is not applicable
      Parameters:
      node -
      Returns:
    • getIriOrNull

      public static String getIriOrNull(org.apache.jena.graph.Node node)
      If the argument is an IRI-node return the IRI - otherwise return null. Argument may be null.
    • getDatatypeIri

      public static String getDatatypeIri(org.apache.jena.graph.Node node)
      Return a Node's datatype. Thereby, IRIs are returned as rr:IRI and BlankNodes as rr:BlankNode Returns null for variables and unknown node types
      Parameters:
      node -
    • createTypedLiteral

      public static org.apache.jena.graph.Node createTypedLiteral(org.apache.jena.datatypes.TypeMapper typeMapper, Object o)
      Create a typed literal for a java object by consulting jena's type mapper
    • createUriOrNull

      public static org.apache.jena.graph.Node createUriOrNull(String uri)
    • fromUris

      public static List<org.apache.jena.graph.Node> fromUris(Iterable<String> uris)
    • createLiteralNodes

      public static List<org.apache.jena.graph.Node> createLiteralNodes(Iterable<String> strings)
    • getNumberNullable

      public static Number getNumberNullable(org.apache.jena.graph.Node node)
    • getNumber

      public static Number getNumber(org.apache.jena.graph.Node node)
    • strNodesWithUndef

      public static String strNodesWithUndef(BiConsumer<org.apache.jena.atlas.io.IndentedWriter,org.apache.jena.graph.Node> output, org.apache.jena.graph.Node... nodes)
      Variant of NodeFmtLib.strNodesNT(Node...) that yield nul as UNDEF
    • parseNode

      public static org.apache.jena.graph.Node parseNode(String str)
      Expect the string to parse as a single node.
    • parseNodes

      public static <C extends Collection<? super org.apache.jena.graph.Node>> C parseNodes(String str, C segments)
      Parse a sequence of nodes into the provided collection
    • createGraphNode

      public static org.apache.jena.graph.Node createGraphNode(String graphName)
      Returns the default graph for null or a blank string or 'default' (inoring case), otherwise creates an IRI from the argument
    • isValid

      public static boolean isValid(org.apache.jena.graph.Node node)
      Serialize and deserialize (print/parse) a node. Returns true iff the result is the same (term-equality) as the input.
    • isValid

      public static boolean isValid(String str, org.apache.jena.graph.Node node)
    • validate

      public static void validate(org.apache.jena.graph.Node node)
      Throws an IllegalArgumentException if isValid(Node) returns false.
    • validate

      public static void validate(String str, org.apache.jena.graph.Node node)
    • put

      public static boolean put(org.apache.jena.sparql.engine.binding.BindingBuilder builder, org.apache.jena.graph.Node nodeOrVar, org.apache.jena.graph.Node node)
    • getIriOrString

      public static String getIriOrString(org.apache.jena.graph.Node node)
    • getUnquotedForm

      public static String getUnquotedForm(org.apache.jena.graph.Node node)
      Returns the "unquoted form" of any Node depending on its type:
      • null → ""
      • literal → node.getLiteralLexicalForm()
      • iri → node.getURI()
      • bnode → node.getBlankNodeLabel()
      • variable → node.getName()
      • otherwise → NodeFmtLib.displayStr(node)