Package com.epimorphics.rdfutil
Class RDFNodeWrapper
- java.lang.Object
-
- com.epimorphics.rdfutil.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 Summary
Fields Modifier and Type Field Description protected ModelWrappermodelwprotected org.apache.jena.rdf.model.RDFNodenode
-
Constructor Summary
Constructors Constructor Description RDFNodeWrapper(ModelWrapper modelw, org.apache.jena.rdf.model.RDFNode node)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<RDFNodeWrapper>asList()Return the contents of the RDF list as a list of wrapped nodesorg.apache.jena.rdf.model.LiteralasLiteral()Return as a Jena Literal objectorg.apache.jena.rdf.model.RDFNodeasRDFNode()Return unwrapped Jena RDFNodeorg.apache.jena.rdf.model.ResourceasResource()Return as a Jena Resource objectStringasTurtle()Format a wrapped node as though it was being serialise as Turtle.protected StringasTurtle(org.apache.jena.rdf.model.RDFNode val, org.apache.jena.shared.PrefixMapping prefixes)ModelWrapperclosure()Return a wrapped memory model containing the bNode closure of this resourceModelWrapperclosure(ModelWrapper target)Added the bNode closure of this resource into the given (wrapped) modelList<RDFNodeWrapper>connectedNodes(String path)Return the list nodes which link to this one via a SPARQL property pathbooleanequals(Object other)RDFNodeWrapperfirstValueOf(String props)Check each property in a comma-separated list of named properties and return the value of the first that has a valueRDFNodeWrapperget(Object prop)Return a single value for the property of null if there is none, property can be specified using URI strings, curies or nodesRDFNodeWrappergetDatatype()If this is a literal return its datatype as a wrapped node, otherwise return nullStringgetLanguage()If this is a literal return its language, otherwise return nullStringgetLexicalForm()Return the lexical form for a literal, the URI of a resource, the anonID of a bNodeStringgetLocalizedValue(Object prop)Return a string value for the given property, selecting one in the model's locale language if possibleModelWrappergetModelW()StringgetName()RDFNodeWrappergetPropertyValue(Object prop)Return a single value for the property of null if there is none, property can be specified using URI strings, curies or nodesStringgetShortURI()Return the shortform curi for the URI if possible, else the full URIStringgetURI()Return the URIObjectgetValue()If this is a literal return the literal value as a java object, otherwise returns selfinthashCode()booleanhasResourceValue(Object prop, Object value)Return true if the property has the given valuebooleanisAnon()Return true if this is an anonymous resourcebooleanisList()Return true if the node is an RDF listbooleanisLiteral()tests true of the node is a literalbooleanisResource()Return true if this is an RDF resourceList<PropertyValue>listInLinks()Return the set of nodes which point to usList<RDFNodeWrapper>listInLinks(Object prop)Return list of nodes that point to us by the given propertyList<PropertyValue>listProperties()Return the set of property values of this node as a ordered list of value bindingsList<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 nodesprotected StringtokeniseWords(String name)Tokenise the input string into words based on camelCase boundaries and hyphen characters.org.apache.jena.rdf.model.PropertytoProperty(Object prop)Return the RDF property object identified by the givenprop.StringtoString()
-
-
-
Field Detail
-
node
protected org.apache.jena.rdf.model.RDFNode node
-
modelw
protected ModelWrapper modelw
-
-
Constructor Detail
-
RDFNodeWrapper
public RDFNodeWrapper(ModelWrapper modelw, org.apache.jena.rdf.model.RDFNode node)
-
-
Method Detail
-
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)
-
getModelW
public ModelWrapper getModelW()
-
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 givenprop. Cases:propis the URI of the property in fullpropis the URI of the property in prefix:name formpropis an RDFPropertyobjectpropis an RDFResourceobjectpropis anRDFNodeWrapper, in which case the property denoted is that denoted by the wrapped RDF node
- Parameters:
prop- An object identifying a property- Returns:
- The RDF
Propertyobject, 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
-
-