Class YAMLConverter

java.lang.Object
org.incenp.obofoundry.sssom.YAMLConverter

public class YAMLConverter extends Object
A helper class to convert generic YAML dictionaries into SSSOM objects.
  • Constructor Details

    • YAMLConverter

      public YAMLConverter()
      Creates a new YAML converter.
  • Method Details

    • setExtraMetadataPolicy

      public void setExtraMetadataPolicy(ExtraMetadataPolicy policy)
      Sets the policy to deal with non-standard metadata in the input file.
      Parameters:
      policy - The policy instructing the parser about what to do when encountering non-standard metadata. The default policy is ExtraMetadataPolicy.NONE.
    • setAssumedVersion

      public void setAssumedVersion(Version version)
      Sets the version of the SSSOM specification that a set should be assumed to be compliant with, in the absence of an explicit sssom_version slot.
      Parameters:
      version - The assumed default version.
    • isListOf

      public static boolean isListOf(Object value, Class<?> type)
      Checks that an object is a list containing items of a given type.
      Parameters:
      value - The object whose runtime type is to be checked.
      type - The expected runtime type of the list's values.
      Returns:
      true if the object is a List whose items are of the expected type, otherwise false.
    • isMapOf

      public static boolean isMapOf(Object value, Class<?> type)
      Checks that an object is a dictionary with string keys and values of a given type.
      Parameters:
      value - The object whose runtime type is to be checked.
      type - The expected runtime of the dictionary's values.
      Returns:
      true if the object is a Map whose keys are String and whose values are of the expected type, otherwise false.
    • getPrefixManager

      public PrefixManager getPrefixManager()
      Gets the prefix manager used by this object to expand shortened entity references in values.
      Returns:
      The prefix manager.
    • convertMappingSet

      public MappingSet convertMappingSet(Map<String,Object> rawMap) throws SSSOMFormatException
      Converts a generic dictionary (as may have been obtained from a YAML or JSON parser) into a MappingSet object.
      Parameters:
      rawMap - The dictionary to convert.
      Returns:
      The corresponding mapping set object.
      Throws:
      SSSOMFormatException - If the contents of the dictionary does not match the SSSOM format and data model, even after compatibility processing.
    • convertMapping

      public Mapping convertMapping(Map<String,Object> rawMap) throws SSSOMFormatException
      Converts a generic dictionary (as may have been obtained from a YAML or JSON parser) into a Mapping object.

      This method assumes the mapping is compliant with the highest supported version of the specification.

      Parameters:
      rawMap - The dictionary to convert.
      Returns:
      The corresponding mapping object.
      Throws:
      SSSOMFormatException - If the contents of the dictionary does not match the SSSOM format and data model, even after compatibility processing.
    • convertMapping

      public Mapping convertMapping(Map<String,Object> rawMap, Version targetVersion) throws SSSOMFormatException
      Converts a generic dictionary (as may have been obtained from a YAML or JSON parser) into a Mapping object.
      Parameters:
      rawMap - The dictionary to convert.
      targetVersion - The version of the SSSOM specification the mapping is compliant with.
      Returns:
      The corresponding mapping object.
      Throws:
      SSSOMFormatException - If the contents of the dictionary does not match the SSSOM format and data model, even after compatibility processing.
    • postMappings

      public void postMappings(MappingSet ms)
      Finalise the conversion of a set. This method should be called once all individual mappings have been converted through calls to convertMapping(Map). There is no need to call this method if the mappings were already present in the raw map passed to convertMappingSet(Map).
      Parameters:
      ms - The mapping set to finalise.