Interface PrefixMapping

All Known Subinterfaces:
InfModel, Model, OntModel
All Known Implementing Classes:
InfModelImpl, ModelCom, MonitorModel, OntModelImpl, PolyadicPrefixMappingImpl, PrefixMappingImpl

public interface PrefixMapping
Methods for recording namespace prefix mappings and applying and unapplying them to URIs.

Note that a Model *is* a PrefixMapping, so all the PrefixMapping operations apply to Models, and a Model can be used to supply the PrefixMapping argument to setNsPrefixes.

  • Field Details

    • Standard

      static final PrefixMapping Standard
      A PrefixMapping that contains the "standard" prefixes we know about, viz rdf, rdfs, dc, rss, vcard, and owl.
    • Extended

      static final PrefixMapping Extended
      A PrefixMapping built on Standard with some extras
  • Method Details

    • setNsPrefix

      PrefixMapping setNsPrefix(String prefix, String uri)
      Specify the prefix name for a URI prefix string. Any existing use of that prefix name is overwritten. The result is this same prefixMapping. (The earlier restriction that adding second prefix for the same URI caused the earlier binding to be deleted has been withdrawn.)

      A prefix name must be a valid NCName, or the empty string. The empty string is reserved to mean "the default namespace".

      Need not check the RFC2396 validity of the URI. Bad URIs are either silently ignored or behave as if they were good. The earlier restriction that the URI should end with a non-NCName character has been removed.

      Note, in particular, that the prefix mapping can only be used if it includes the URI up to any '#' character because '#' is not legal in the local part of an NCName.

      prefix - the string to be used for the prefix.
      uri - the URI prefix to be named
      this PrefixMapping
      PrefixMapping.IllegalPrefixException - if the prefix is not an XML NCName
    • removeNsPrefix

      PrefixMapping removeNsPrefix(String prefix)
      Remove any existing maplet with the given prefix name and answer this mapping. If the prefix is the empty string, then this removes the default namespace. If the prefix is not a legal prefix string, or is not present in the mapping, nothing happens.

      The reverse URI-to-prefix mapping is updated, but if there are multiple prefixes for the removed URI it is unspecified which of them will be chosen.

      prefix - the prefix string to remove
      this PrefixMapping
    • clearNsPrefixMap

      PrefixMapping clearNsPrefixMap()
      Clear this prefix mapping of all mappings
    • setNsPrefixes

      PrefixMapping setNsPrefixes(PrefixMapping other)
      Copies the prefixes from other into this. Any existing binding of the same prefix is lost. The result is this same prefixMapping.
      other - the PrefixMapping to add
      this PrefixMapping
    • setNsPrefixes

      PrefixMapping setNsPrefixes(Map<String,String> map)
      Copies the prefix mapping from other into this. Illegal prefix mappings are detected. Existing binds of the same prefix are lost. The result is this same prefixMapping.
      map - the Map whose maplets are to be added
      this PrefixMapping
    • withDefaultMappings

      PrefixMapping withDefaultMappings(PrefixMapping map)
      Update this PrefixMapping with the bindings in map, only adding those (p, u) pairs for which neither p nor u appears in this mapping. Answer this PrefixMapping.
    • getNsPrefixURI

      String getNsPrefixURI(String prefix)
      Get the URI bound to a specific prefix, null if there isn't one.
      prefix - the prefix name to be looked up
      the most recent URI bound to that prefix name, null if none
    • getNsURIPrefix

      String getNsURIPrefix(String uri)
      Answer the prefix for the given URI, or null if there isn't one. If there is more than one, one of them will be picked. If possible, it will be the most recently added prefix. (The cases where it's not possible is when a binding has been removed.)
      uri - the uri whose prefix is to be found
      the prefix mapped to that uri, or null if there isn't one
    • getNsPrefixMap

      Map<String,String> getNsPrefixMap()
      Return a copy of the internal mapping from names to URI strings. Updating this copy will have no effect on the PrefixMap.
      a copy of the internal String -> String mapping
    • expandPrefix

      String expandPrefix(String prefixed)
      Expand the uri using the prefix mappings if possible. If prefixed has the form Foo:Bar, and Foo is a prefix bound to FooURI, return FooURI+Bar. Otherwise return prefixed unchanged.
      prefixed - a QName or URI
      the expanded string if possible, otherwise the original string
    • shortForm

      String shortForm(String uri)
      Compress the URI using the prefix mappings if possible. If there is a prefix mapping Name -> URIStart, and uri is URIStart+Tail, return Name:Tail; otherwise return uri unchanged. If there are multiple applicable mappings available, the "most recent" is chosen if that is possible, otherwise one is picked "at random".

      The result is primarily intended for human convenience: it is not necessarily a legal QName, as Tail need not be a legal NCName; and there's no way to tell a shortened name from a URI with an unusual scheme.

      uri - the URI string to try and prefix-compress
      the shortened form if possible, otherwise the unchanged argument
    • qnameFor

      String qnameFor(String uri)
      Answer a qname with the expansion of the given uri, or null if no such qname can be constructed using the mapping's prefixes.
    • lock

      Lock the PrefixMapping so that changes can no longer be made to it. Primarily intended to lock Standard against mutation.
      this mapping, locked against changes
    • hasNoMappings

      default boolean hasNoMappings()
      Return whether the prefix mapping has any defined prefixes.
    • numPrefixes

      int numPrefixes()
      Return the number of defined prefixes.
    • samePrefixMappingAs

      boolean samePrefixMappingAs(PrefixMapping other)
      Answer true iff this prefix-mappings are equal, that is, map the same prefixes to the same URIs; same as
      this.getNsPrefixMap().equals( other.getNsPrefixMap() )
      except that it may avoid unnecessary Map creations.