Class Namespaces

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_NS
      The default namespace.
      static java.lang.String owl_ns
      Standard OWL namespace ("http://www.w3.org/2002/07/owl#")
      static java.lang.String rdf_ns
      Standard RDF namespace ("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
      static java.lang.String rdfs_ns
      Standard RDFS namespace ("http://www.w3.org/2000/01/rdf-schema#")
      static java.lang.String xsd_ns
      Standard XML Schema namespace ("http://www.w3.org/2001/XMLSchema#")
    • Constructor Summary

      Constructors 
      Constructor Description
      Namespaces()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String addDefault​(java.lang.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 java.lang.String contract​(java.lang.String uri)
      Try to replace a complete namespace by its prefix (if known) or remove the namespace if it's the default one.
      static java.lang.String expand​(java.lang.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.
      static java.lang.String format​(java.lang.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> getDefaultNsFilter()
      Returns a filter to keep only properties in the default ORO namespace, thus removing properties inferred from RDF or OWL models.
      static java.lang.String getNamespace​(java.lang.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#
      static java.lang.String getPrefix​(java.lang.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
      static void loadNamespaces​(java.util.Properties parameters)  
      static java.lang.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​(java.lang.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 java.lang.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 java.lang.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 Detail

      • owl_ns

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

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

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

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

        public static java.lang.String DEFAULT_NS
        The default namespace. This static field is set up at runtime from the configuration file.
    • Constructor Detail

      • Namespaces

        public Namespaces()
    • Method Detail

      • prefixes

        public static java.lang.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 java.lang.String getNamespace​(java.lang.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(String)
      • getPrefix

        public static java.lang.String getPrefix​(java.lang.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:
        getNamespace(String)
      • expand

        public static java.lang.String expand​(java.lang.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 java.lang.String contract​(java.lang.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 java.lang.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 java.lang.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 java.lang.String addDefault​(java.lang.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:
        DEFAULT_NS, setDefault(String)
      • format

        public static java.lang.String format​(java.lang.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:
        addDefault(String), expand(String)
      • setDefault

        public static void setDefault​(java.lang.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:
        addDefault(String), DEFAULT_NS
      • loadNamespaces

        public static void loadNamespaces​(java.util.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.