Package laas.openrobots.ontology.helpers
Class Namespaces
java.lang.Object
laas.openrobots.ontology.helpers.Namespaces
This class provides several static method for namespace manipulation (expansion, contraction, SPARQL prefixes header...).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic String
The default namespace.static final String
Standard OWL namespace ("http://www.w3.org/2002/07/owl#")static final String
Standard RDF namespace ("http://www.w3.org/1999/02/22-rdf-syntax-ns#")static final String
Standard RDFS namespace ("http://www.w3.org/2000/01/rdf-schema#")static final String
Standard XML Schema namespace ("http://www.w3.org/2001/XMLSchema#") -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
addDefault
(String resource) Add the default namespace to a resource.
This method is really naive: it will prefix a string with the default namespace if the string does not contain the characters ":" or "#".
If the URI already contains a prefix, the URI is returned as it.static String
Try to replace a complete namespace by its prefix (if known) or remove the namespace if it's the default one.static String
Replace the namespace prefix with its expanded form, when known.
For instance,"xsd:boolean"
will be returned as"http://www.w3.org/2001/XMLSchema#boolean"
.
If the URI doesn't contain any prefix or if the prefix is unknow, the URI is returned as it.static String
Formats a resource's namespace, adding the default one if none is specified.
This method is actually a simple shortcut for a call to bothaddDefault(String)
andexpand(String)
.static com.hp.hpl.jena.util.iterator.Filter<com.hp.hpl.jena.ontology.OntProperty>
Returns a filter to keep only properties in the default ORO namespace, thus removing properties inferred from RDF or OWL models.static String
getNamespace
(String ns) Convert namespace shortcut in their expanded form (which includes a trailing#
).
For instance:
Namespaces.getNamespace("oro")
returnshttp://www.owl-ontologies.com/openrobots.owl#
static String
Convert expanded namespace to their shortcut (prefix) followed by ":" or to nothing if the namespace is the default namespace.
For instance:
Namespaces.getPrefix("http://www.owl-ontologies.com/openrobots.owl#")
returnsoro
static void
loadNamespaces
(Properties parameters) static String
prefixes()
Returns a list of commons namespace prefixes (currently, OWL, RDF, RDFS, XSD, LAAS OpenRobots), in SPARQL format, to be included in SPARQL queries.static void
setDefault
(String defaultNS) Set the default namespace.
This method is meant to be called at least once at application startup, to define a default namespace (from a configuration file, for instance).static String
toLightString
(com.hp.hpl.jena.rdf.model.RDFNode res) Convert a resource to its string representation and try to replace the namespace by its prefix (or remove it if it's the default one).
It usescontract(String)
to replace or remove the namespace.
If the prefix for the namespace is unknown, complete URI is returned.static String
toLightString
(com.hp.hpl.jena.rdf.model.Statement stmt) AppliestoLightString(RDFNode)
to each members of a statement.
-
Field Details
-
owl_ns
Standard OWL namespace ("http://www.w3.org/2002/07/owl#")- See Also:
-
rdf_ns
Standard RDF namespace ("http://www.w3.org/1999/02/22-rdf-syntax-ns#")- See Also:
-
rdfs_ns
Standard RDFS namespace ("http://www.w3.org/2000/01/rdf-schema#")- See Also:
-
xsd_ns
Standard XML Schema namespace ("http://www.w3.org/2001/XMLSchema#")- See Also:
-
DEFAULT_NS
The default namespace. This static field is set up at runtime from the configuration file.
-
-
Constructor Details
-
Namespaces
public Namespaces()
-
-
Method Details
-
prefixes
Returns a list of commons namespace prefixes (currently, OWL, RDF, RDFS, XSD, LAAS OpenRobots), in SPARQL format, to be included in SPARQL queries.- Returns:
- The
PREFIX
part of a SPARQL request.
-
getNamespace
Convert namespace shortcut in their expanded form (which includes a trailing#
).
For instance:
Namespaces.getNamespace("oro")
returnshttp://www.owl-ontologies.com/openrobots.owl#
- Parameters:
ns
- One of the known namespace shortcut ("owl" for OWL namespace, "rdf" and "rdfs" for RDF, "xsd" for XML Schema, "oro" for OpenRobots)- Returns:
- The expanded namespace or, if the shortcut is not known, the shortcut itself, followed by ":"
- See Also:
-
getPrefix
Convert expanded namespace to their shortcut (prefix) followed by ":" or to nothing if the namespace is the default namespace.
For instance:
Namespaces.getPrefix("http://www.owl-ontologies.com/openrobots.owl#")
returnsoro
- Parameters:
ns
- One of the known namespace (ending with "#").- Returns:
- The corresponding namespace prefix suffixed with ":", or nothing if the namespace is the default namespace, or, if the namespace is not known, the namespace itself.
- See Also:
-
expand
Replace the namespace prefix with its expanded form, when known.
For instance,"xsd:boolean"
will be returned as"http://www.w3.org/2001/XMLSchema#boolean"
.
If the URI doesn't contain any prefix or if the prefix is unknow, the URI is returned as it. It can be used as well to expand prefixes in string representation of literals ("true^^xsd:boolean"
will be transformed intotrue^^http://www.w3.org/2001/XMLSchema#boolean"
- Parameters:
uri
- The resource URI with (or without) a namespace prefix, or the string representation of a literal.- Returns:
- The URI (or literal) with an expanded namespace.
-
contract
Try to replace a complete namespace by its prefix (if known) or remove the namespace if it's the default one. This method does the opposite toexpand(String)
.
If the prefix for the namespace is unknown, complete URI is returned.- Parameters:
uri
- The resource to output as a string.- Returns:
- The literal representation of the resource, with an short namespace (or no namespace if it is the default one).
-
toLightString
Convert a resource to its string representation and try to replace the namespace by its prefix (or remove it if it's the default one).
It usescontract(String)
to replace or remove the namespace.
If the prefix for the namespace is unknown, complete URI is returned.- Parameters:
res
- The RDFNode which is to output as a string.- Returns:
- The literal representation of the resource, with short namespace (or no namespace if it is the default one).
-
toLightString
AppliestoLightString(RDFNode)
to each members of a statement.- Parameters:
stmt
- The statement to output as a string.- Returns:
- The literal representation of the statement, with short namespaces (or no namespace if it is the default one).
-
addDefault
Add the default namespace to a resource.
This method is really naive: it will prefix a string with the default namespace if the string does not contain the characters ":" or "#".
If the URI already contains a prefix, the URI is returned as it.- Parameters:
resource
- The resource URI with (or without) a namespace prefix, or the string representation of a literal.- Returns:
- The resource prefixed with the default namespace.
- See Also:
-
format
Formats a resource's namespace, adding the default one if none is specified.
This method is actually a simple shortcut for a call to bothaddDefault(String)
andexpand(String)
.- Parameters:
resource
- A string representating a resource (its lexical form).- Returns:
- The formatted namespace.
- See Also:
-
setDefault
Set the default namespace.
This method is meant to be called at least once at application startup, to define a default namespace (from a configuration file, for instance).- Parameters:
defaultNS
- The expanded namespace.- See Also:
-
loadNamespaces
-
getDefaultNsFilter
public static com.hp.hpl.jena.util.iterator.Filter<com.hp.hpl.jena.ontology.OntProperty> getDefaultNsFilter()Returns a filter to keep only properties in the default ORO namespace, thus removing properties inferred from RDF or OWL models.
-