Class RDFNodeWrapper


  • public class RDFNodeWrapper
    extends Object
    Provides a wrapper round an RDFNode from some model in some dataset. The wrapper provides uniform use of transaction/locking for safe access plus automatic prefix expansion to simplify use from scripting languages.
    Author:
    Dave Reynolds
    • Field Detail

      • node

        protected org.apache.jena.rdf.model.RDFNode node
    • Constructor Detail

      • RDFNodeWrapper

        public RDFNodeWrapper​(ModelWrapper modelw,
                              org.apache.jena.rdf.model.RDFNode node)
    • Method Detail

      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • asTurtle

        public String asTurtle()
        Format a wrapped node as though it was being serialise as Turtle. Useful for embedding a node into, for example, a SPARQL query.
        Returns:
        The formatted node
      • asTurtle

        protected String asTurtle​(org.apache.jena.rdf.model.RDFNode val,
                                  org.apache.jena.shared.PrefixMapping prefixes)
      • asRDFNode

        public org.apache.jena.rdf.model.RDFNode asRDFNode()
        Return unwrapped Jena RDFNode
      • isLiteral

        public boolean isLiteral()
        tests true of the node is a literal
      • asLiteral

        public org.apache.jena.rdf.model.Literal asLiteral()
        Return as a Jena Literal object
      • isList

        public boolean isList()
        Return true if the node is an RDF list
      • asList

        public List<RDFNodeWrapper> asList()
        Return the contents of the RDF list as a list of wrapped nodes
      • getLexicalForm

        public String getLexicalForm()
        Return the lexical form for a literal, the URI of a resource, the anonID of a bNode
      • getName

        public String getName()
        Returns:
        A name for the resource. By preference, this will be a label property of the resource. Otherwise, a curie or localname will be used if no naming property is found.
      • tokeniseWords

        protected String tokeniseWords​(String name)
        Tokenise the input string into words based on camelCase boundaries and hyphen characters. If the input string is already tokenised into words (determined by whether it contains a space character or not), return the string unchanged.
        Parameters:
        name - The input name to tokenise
        Returns:
        The input string, with camel-case boundaries, hyphens and underscores replaced by spaces.
      • getLanguage

        public String getLanguage()
        If this is a literal return its language, otherwise return null
      • getValue

        public Object getValue()
        If this is a literal return the literal value as a java object, otherwise returns self
      • getDatatype

        public RDFNodeWrapper getDatatype()
        If this is a literal return its datatype as a wrapped node, otherwise return null
      • isResource

        public boolean isResource()
        Return true if this is an RDF resource
      • isAnon

        public boolean isAnon()
        Return true if this is an anonymous resource
      • asResource

        public org.apache.jena.rdf.model.Resource asResource()
        Return as a Jena Resource object
      • getURI

        public String getURI()
        Return the URI
      • getShortURI

        public String getShortURI()
        Return the shortform curi for the URI if possible, else the full URI
      • toProperty

        public org.apache.jena.rdf.model.Property toProperty​(Object prop)
        Return the RDF property object identified by the given prop. Cases:
        • prop is the URI of the property in full
        • prop is the URI of the property in prefix:name form
        • prop is an RDF Property object
        • prop is an RDF Resource object
        • prop is an RDFNodeWrapper, in which case the property denoted is that denoted by the wrapped RDF node
        Parameters:
        prop - An object identifying a property
        Returns:
        The RDF Property object, or null
      • get

        public RDFNodeWrapper get​(Object prop)
        Return a single value for the property of null if there is none, property can be specified using URI strings, curies or nodes
      • getPropertyValue

        public RDFNodeWrapper getPropertyValue​(Object prop)
        Return a single value for the property of null if there is none, property can be specified using URI strings, curies or nodes
      • getLocalizedValue

        public String getLocalizedValue​(Object prop)
        Return a string value for the given property, selecting one in the model's locale language if possible
      • hasResourceValue

        public boolean hasResourceValue​(Object prop,
                                        Object value)
        Return true if the property has the given value
      • listPropertyValues

        public List<RDFNodeWrapper> listPropertyValues​(Object prop)
        Return the value of the given property as a list of literal values or wrapped nodes, property can be specified using URI strings, curies or nodes
      • listProperties

        public List<PropertyValue> listProperties()
        Return the set of property values of this node as a ordered list of value bindings
      • listInLinks

        public List<RDFNodeWrapper> listInLinks​(Object prop)
        Return list of nodes that point to us by the given property
      • listInLinks

        public List<PropertyValue> listInLinks()
        Return the set of nodes which point to us
      • firstValueOf

        public RDFNodeWrapper firstValueOf​(String props)
        Check each property in a comma-separated list of named properties and return the value of the first that has a value
      • connectedNodes

        public List<RDFNodeWrapper> connectedNodes​(String path)
        Return the list nodes which link to this one via a SPARQL property path
      • closure

        public ModelWrapper closure()
        Return a wrapped memory model containing the bNode closure of this resource
      • closure

        public ModelWrapper closure​(ModelWrapper target)
        Added the bNode closure of this resource into the given (wrapped) model