Class SSSOMWriter

  • Direct Known Subclasses:
    JSONWriter, RDFWriter, TSVWriter

    public abstract class SSSOMWriter
    extends Object
    Base class to serialise a mapping set.

    This class should be derived into specialised classes that implement a precise serialisation format.

    • Constructor Detail

      • SSSOMWriter

        public SSSOMWriter()
    • Method Detail

      • setCurieMap

        public void setCurieMap​(Map<String,​String> map)
        Sets the Curie map to use to shorten identifiers. The Curie map associated with the mapping set (MappingSet.getCurieMap()) will then be completely ignored in favour of the specified map.
        Parameters:
        map - A map associating prefix names to prefixes.
      • setExtraMetadataPolicy

        public void setExtraMetadataPolicy​(ExtraMetadataPolicy policy)
        Sets the policy to deal with non-standard metadata in the mapping set to write.
        Parameters:
        policy - The policy instructing the writer about what to do with any non-standard metadata. The default policy is ExtraMetadataPolicy.NONE, meaning that no non-standard metadata is ever written.
      • setCondensationEnabled

        public void setCondensationEnabled​(boolean enabled)
        Enables or disables the condensation of "propagatable slots".
        Parameters:
        enabled - False to disable condensation; it is enabled by default.
      • setTargetVersion

        public void setTargetVersion​(Version targetVersion)
        Sets the highest version of the SSSOM specification that the written set must be compliant with.

        Any slot that is defined in a higher version will be forcibly removed.

        Parameters:
        targetVersion - The targeted SSSOM version. The default is the highest currently supported version.
      • setSortingEnabled

        public void setSortingEnabled​(boolean enabled)
        Enables or disables sorting the mappings when writing them.
        Parameters:
        enabled - False to disable sorting; it is enabled by default.
      • write

        public void write​(MappingSet mappingSet)
                   throws IOException
        Serialises a mapping set into the underlying file. This method performs some prelimiary steps that are common to all serialisers, then delegates the actual serialisation task to doWrite(MappingSet).
        Parameters:
        mappingSet - The mapping set to serialise.
        Throws:
        IOException - If an I/O error occurs.
      • doWrite

        protected abstract void doWrite​(MappingSet mappingSet)
                                 throws IOException
        Actually serialises a mapping set. This method should be overridden by derived classes to implement the serialisation in a specific format.
        Parameters:
        mappingSet - The mapping set to serialise.
        Throws:
        IOException - If an I/O error occurs.
      • getUsedPrefixes

        protected Set<String> getUsedPrefixes​(MappingSet mappingSet)
        Gets the prefix names that are actually used in the given set. This excludes prefix names that are considered builtin.
        Parameters:
        mappingSet - The mapping set to query for used prefix names.
        Returns:
        A set of all prefix names that are effectively needed to condense all identifiers in the mapping set.
      • getUsedPrefixes

        protected Set<String> getUsedPrefixes​(MappingSet mappingSet,
                                              boolean includeBuiltin)
        Gets the prefix names that are actually used in the given set, possibly including the builtin prefix names.
        Parameters:
        mappingSet - The mapping set to query for used prefix names.
        includeBuiltin - If true, builtin prefix names will be included.
        Returns:
        A set of all prefix names that are effectively needed to condense all identifiers in the mapping set.
      • condenseSet

        protected Set<String> condenseSet​(MappingSet mappingSet)
        Performs condensation of "propagatable slots" in a mapping set.

        If condensation is disabled (see setCondensationEnabled(boolean)), this is merely a no-op.

        Parameters:
        mappingSet - The mapping set whose slots should be condensed.
        Returns:
        A set of all mapping slot names that have been effectively condensed (may be empty if no slots have been condensed at all).