Class PrefixManager


  • public class PrefixManager
    extends Object
    Helper class to shorten/expand identifiers based on a prefix map.

    This class is used internally by the TSVReader and TSVWriter classes. It automatically handles the prefixes that the SSSOM specification considers “built-in”.

    • Constructor Detail

      • PrefixManager

        public PrefixManager()
        Creates a new instance.
    • Method Detail

      • add

        public void add​(String prefixName,
                        String prefix)
        Adds a new prefix.
        Parameters:
        prefixName - The short name of the prefix, as it would appear in a CURIE. It should not include the colon.
        prefix - The expanded URL prefix;
      • add

        public void add​(Map<? extends String,​? extends String> map)
        Adds new prefixes.
        Parameters:
        map - A map associating prefix names to prefixes.
      • getPrefixMap

        public Map<String,​String> getPrefixMap()
        Gets the underlying map of prefix names to URL prefixes.
        Returns:
        The prefix map used by this prefix manager.
      • getUnresolvedPrefixNames

        public Set<String> getUnresolvedPrefixNames()
        Gets the prefix names that this resolver could not expand.
        Returns:
        The set of all prefixes encountered in the lifetime of this object that could not be expanded because the prefix was unknown.
      • getUnshortenedIRIs

        public Set<String> getUnshortenedIRIs()
        Gets the IRIs that could not be shortened by shortenIdentifier(String) for lack of a suitable prefix declaration.
        Returns:
        The set of all IRIs encountered in the lifetime of this object that could not be shortened.
      • getPrefix

        public String getPrefix​(String prefixName)
        Gets the prefix associated with the given prefix name.
        Parameters:
        prefixName - The name of the prefix to retrieve.
        Returns:
        The corresponding prefix, or null if the name is not the name of a registered prefix.
      • getPrefixName

        public String getPrefixName​(String iri)
        Gets the name of the best (longest) prefix for a given identifier.
        Parameters:
        iri - The identifier for which to search the longest prefix.
        Returns:
        The name of the best prefix, or null if no registered prefix is suitable for the given identifier.
      • getLocalName

        public String getLocalName​(String iri)
        Gets the local part of the shortened form of given identifier.
        Parameters:
        iri - The identifier for which to get the local part.
        Returns:
        The local name of the identifier, that is, everything after the longest matching prefix; or null if the original identifier could not be shortened.
      • shortenIdentifier

        public String shortenIdentifier​(String iri)
        Shortens an identifier according to the prefix map.
        Parameters:
        iri - The identifier to shorten.
        Returns:
        The shortened identifier, or the original identifier if it could not be shortened.
      • shortenIdentifiers

        public List<String> shortenIdentifiers​(List<String> iris)
        Shortens all identifiers in the given list. The original list is left untouched.
        Parameters:
        iris - The list of identifiers to shorten.
        Returns:
        A new list with the shortened identifiers.
      • shortenIdentifiers

        public List<String> shortenIdentifiers​(List<String> iris,
                                               boolean inPlace)
        Shortens all identifiers in the given list.
        Parameters:
        iris - The list of identifiers to shorten.
        inPlace - If true, the original list is modified; otherwise it is left untouched and a new list is returned.
        Returns:
        A list with the shortened identifiers. If inPlace is true, this is the original list.
      • expandIdentifier

        public String expandIdentifier​(String curie)
        Expands a shortened identifier into its long, canonical form.
        Parameters:
        curie - The short identifier to expand.
        Returns:
        The full-length identifier, or the original identifier if it was not in CURIE form or the prefix name is unknown.
      • expandIdentifiers

        public List<String> expandIdentifiers​(List<String> curies)
        Expands all identifiers in the given list. The original list is left untouched.
        Parameters:
        curies - The list of short identifiers to expand.
        Returns:
        A new list with the expanded identifiers..
      • expandIdentifiers

        public List<String> expandIdentifiers​(List<String> curies,
                                              boolean inPlace)
        Expands all identifiers in the given list.
        Parameters:
        curies - The list of short identifiers to expand.
        inPlace - If true, the original list is modified; otherwise it is left untouched and a new list is returned.
        Returns:
        A list with the expanded identifiers. If inPlace is true, this is the original list.