diff --git a/src/sssom/cli.py b/src/sssom/cli.py index 83a9c641..19ab0506 100644 --- a/src/sssom/cli.py +++ b/src/sssom/cli.py @@ -28,7 +28,7 @@ from sssom.constants import ( DEFAULT_VALIDATION_TYPES, - PrefixMapModeType, + MergeMode, SchemaValidationType, _get_sssom_schema_object, ) @@ -172,7 +172,7 @@ def convert(input: str, output: TextIO, output_format: str): default="metadata_only", show_default=True, required=True, - type=click.Choice(get_args(PrefixMapModeType), case_sensitive=False), + type=click.Choice(get_args(MergeMode), case_sensitive=False), help="Defines whether the prefix map in the metadata should be extended or replaced with " "the SSSOM default prefix map.", ) @@ -205,7 +205,7 @@ def parse( input: str, input_format: str, metadata: str, - prefix_map_mode: PrefixMapModeType, + prefix_map_mode: MergeMode, clean_prefixes: bool, strict_clean_prefixes: bool, output: TextIO, @@ -218,7 +218,7 @@ def parse( output=output, input_format=input_format, metadata_path=metadata, - prefix_map_mode=prefix_map_mode, + merge_mode=prefix_map_mode, clean_prefixes=clean_prefixes, strict_clean_prefixes=strict_clean_prefixes, embedded_mode=embedded_mode, diff --git a/src/sssom/constants.py b/src/sssom/constants.py index 261923a0..84ecd18b 100644 --- a/src/sssom/constants.py +++ b/src/sssom/constants.py @@ -38,10 +38,10 @@ ] UNKNOWN_IRI = "http://w3id.org/sssom/unknown_prefix/" -PrefixMapModeType = Literal["metadata_only", "sssom_default_only", "merged"] -PREFIX_MAP_MODE_METADATA_ONLY: PrefixMapModeType = "metadata_only" -PREFIX_MAP_MODE_SSSOM_DEFAULT_ONLY: PrefixMapModeType = "sssom_default_only" -PREFIX_MAP_MODE_MERGED: PrefixMapModeType = "merged" +MergeMode = Literal["metadata_only", "sssom_default_only", "merged"] +PREFIX_MAP_MODE_METADATA_ONLY: MergeMode = "metadata_only" +PREFIX_MAP_MODE_SSSOM_DEFAULT_ONLY: MergeMode = "sssom_default_only" +PREFIX_MAP_MODE_MERGED: MergeMode = "merged" ENTITY_REFERENCE = "EntityReference" # Slot Constants diff --git a/src/sssom/io.py b/src/sssom/io.py index cf728b88..97187316 100644 --- a/src/sssom/io.py +++ b/src/sssom/io.py @@ -20,8 +20,8 @@ PREFIX_MAP_MODE_MERGED, PREFIX_MAP_MODE_METADATA_ONLY, PREFIX_MAP_MODE_SSSOM_DEFAULT_ONLY, + MergeMode, MetadataType, - PrefixMapModeType, SchemaValidationType, get_default_metadata, ) @@ -61,7 +61,7 @@ def parse_file( output: TextIO, input_format: Optional[str] = None, metadata_path: Optional[str] = None, - prefix_map_mode: Optional[PrefixMapModeType] = None, + merge_mode: Optional[MergeMode] = None, clean_prefixes: bool = True, strict_clean_prefixes: bool = True, embedded_mode: bool = True, @@ -74,7 +74,7 @@ def parse_file( :param input_format: The string denoting the input format. :param metadata_path: The path to a file containing the sssom metadata (including prefix_map) to be used during parse. - :param prefix_map_mode: Defines whether the prefix map in the metadata should be extended or replaced with + :param merge_mode: Defines whether the prefix map in the metadata should be extended or replaced with the SSSOM default prefix map. :param clean_prefixes: If True (default), records with unknown prefixes are removed from the SSSOM file. :param strict_clean_prefixes: If True (default), clean_prefixes() will be in strict mode. @@ -82,7 +82,7 @@ def parse_file( :param mapping_predicate_filter: Optional list of mapping predicates or filepath containing the same. """ raise_for_bad_path(input_path) - converter, meta = read_metadata(path=metadata_path, mode=prefix_map_mode) + converter, meta = read_metadata(path=metadata_path, merge_mode=merge_mode) parse_func = get_parsing_function(input_format, input_path) mapping_predicates = None # Get list of predicates of interest. @@ -134,13 +134,13 @@ def split_file(input_path: str, output_directory: Union[str, Path]) -> None: def read_metadata( - path: Union[None, str, Path] = None, *, mode: Optional[PrefixMapModeType] = None + path: Union[None, str, Path] = None, *, merge_mode: Optional[MergeMode] = None ) -> Tuple[Converter, MetadataType]: """ Load SSSOM metadata from a YAML file, and then augment it with default prefixes. :param path: The metadata file in YAML format - :param mode: one of metadata_only, sssom_default_only, merged + :param merge_mode: one of metadata_only, sssom_default_only, merged :return: A converter and remaining metadata from the YAML file """ if path is None: @@ -152,14 +152,14 @@ def read_metadata( metadata = dict(ChainMap(metadata, get_default_metadata())) converter = Converter.from_prefix_map(metadata.pop(CURIE_MAP, {})) - if mode is None or mode == PREFIX_MAP_MODE_METADATA_ONLY: + if merge_mode is None or merge_mode == PREFIX_MAP_MODE_METADATA_ONLY: converter = curies.chain([_get_built_in_prefix_map(), converter]) - elif mode == PREFIX_MAP_MODE_SSSOM_DEFAULT_ONLY: + elif merge_mode == PREFIX_MAP_MODE_SSSOM_DEFAULT_ONLY: converter = get_converter() - elif mode == PREFIX_MAP_MODE_MERGED: + elif merge_mode == PREFIX_MAP_MODE_MERGED: converter = curies.chain([_get_built_in_prefix_map(), converter, get_converter()]) else: - raise ValueError(f"Invalid prefix map mode: {mode}") + raise ValueError(f"Invalid prefix map mode: {merge_mode}") return converter, metadata diff --git a/tests/test_parsers.py b/tests/test_parsers.py index 513b82c3..47f376b5 100644 --- a/tests/test_parsers.py +++ b/tests/test_parsers.py @@ -329,7 +329,7 @@ def test_parse_obographs_merged(self): with open(outfile, "w") as f: parse_file( input_path=hp_json, - prefix_map_mode="merged", + merge_mode="merged", clean_prefixes=True, input_format="obographs-json", metadata_path=hp_meta,