Class Namespaces

java.lang.Object
laas.openrobots.ontology.helpers.Namespaces

public class Namespaces extends Object
This class provides several static method for namespace manipulation (expansion, contraction, SPARQL prefixes header...).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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
    format(String resource)
    Formats a resource's namespace, adding the default one if none is specified.
    This method is actually a simple shortcut for a call to both addDefault(String) and expand(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
    Convert namespace shortcut in their expanded form (which includes a trailing #).
    For instance:
    Namespaces.getNamespace("oro") returns http://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#") returns oro
    static void
     
    static String
    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 uses contract(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)
    Applies toLightString(RDFNode) to each members of a statement.

    Methods inherited from class java.lang.Object

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

    • owl_ns

      public static final String owl_ns
      Standard OWL namespace ("http://www.w3.org/2002/07/owl#")
      See Also:
    • rdf_ns

      public static final String rdf_ns
      Standard RDF namespace ("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
      See Also:
    • rdfs_ns

      public static final String rdfs_ns
      Standard RDFS namespace ("http://www.w3.org/2000/01/rdf-schema#")
      See Also:
    • xsd_ns

      public static final String xsd_ns
      Standard XML Schema namespace ("http://www.w3.org/2001/XMLSchema#")
      See Also:
    • DEFAULT_NS

      public static String 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

      public 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.
      Returns:
      The PREFIX part of a SPARQL request.
    • getNamespace

      public static String getNamespace(String ns)
      Convert namespace shortcut in their expanded form (which includes a trailing #).
      For instance:
      Namespaces.getNamespace("oro") returns http://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

      public static String getPrefix(String ns)
      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#") returns oro
      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

      public static String expand(String uri)
      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 into true^^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

      public static String contract(String uri)
      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 to expand(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

      public 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 uses contract(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

      public static String toLightString(com.hp.hpl.jena.rdf.model.Statement stmt)
      Applies toLightString(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

      public static 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.
      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

      public static String format(String resource)
      Formats a resource's namespace, adding the default one if none is specified.
      This method is actually a simple shortcut for a call to both addDefault(String) and expand(String).
      Parameters:
      resource - A string representating a resource (its lexical form).
      Returns:
      The formatted namespace.
      See Also:
    • setDefault

      public 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).
      Parameters:
      defaultNS - The expanded namespace.
      See Also:
    • loadNamespaces

      public static void loadNamespaces(Properties parameters)
    • 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.