Package org.incenp.obofoundry.sssom
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 Summary
Constructors Constructor Description YAMLConverter()Creates a new YAML converter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MappingconvertMapping(Map<String,Object> rawMap)Converts a generic dictionary (as may have been obtained from a YAML or JSON parser) into aMappingobject.MappingconvertMapping(Map<String,Object> rawMap, Version targetVersion)Converts a generic dictionary (as may have been obtained from a YAML or JSON parser) into aMappingobject.MappingSetconvertMappingSet(Map<String,Object> rawMap)Converts a generic dictionary (as may have been obtained from a YAML or JSON parser) into aMappingSetobject.PrefixManagergetPrefixManager()Gets the prefix manager used by this object to expand shortened entity references in values.static booleanisListOf(Object value, Class<?> type)Checks that an object is a list containing items of a given type.static booleanisMapOf(Object value, Class<?> type)Checks that an object is a dictionary with string keys and values of a given type.voidpostMappings(MappingSet ms)Finalise the conversion of a set.voidsetAssumedVersion(Version version)Sets the version of the SSSOM specification that a set should be assumed to be compliant with, in the absence of an explicitsssom_versionslot.voidsetExtraMetadataPolicy(ExtraMetadataPolicy policy)Sets the policy to deal with non-standard metadata in the input file.
-
-
-
Method Detail
-
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 isExtraMetadataPolicy.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 explicitsssom_versionslot.- 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:
trueif the object is aListwhose items are of the expected type, otherwisefalse.
-
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.
-
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 aMappingSetobject.- 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 aMappingobject.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 aMappingobject.- 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 toconvertMapping(Map). There is no need to call this method if the mappings were already present in the raw map passed toconvertMappingSet(Map).- Parameters:
ms- The mapping set to finalise.
-
-