diff --git a/src/prefixmaps/data/merged.csv b/src/prefixmaps/data/merged.csv index 0b31e20..d2d2bab 100644 --- a/src/prefixmaps/data/merged.csv +++ b/src/prefixmaps/data/merged.csv @@ -1,4 +1,4 @@ -context,prefix,namespace,status,source +context,prefix,namespace,status,expansion_source merged,3DMET,http://identifiers.org/3dmet/,canonical,bioregistry merged,4DN,http://identifiers.org/4dn/,namespace_alias,bioregistry merged,4DN.BIOSOURCE,http://identifiers.org/4dn/,canonical,bioregistry diff --git a/src/prefixmaps/data/merged.oak.csv b/src/prefixmaps/data/merged.oak.csv index 68f2fde..36d6296 100644 --- a/src/prefixmaps/data/merged.oak.csv +++ b/src/prefixmaps/data/merged.oak.csv @@ -1,4 +1,4 @@ -context,prefix,namespace,status,source +context,prefix,namespace,status,expansion_source merged.oak,3DMET,http://identifiers.org/3dmet/,canonical,bioregistry merged.oak,4DN,http://identifiers.org/4dn/,namespace_alias,bioregistry merged.oak,4DN.BIOSOURCE,http://identifiers.org/4dn/,canonical,bioregistry diff --git a/src/prefixmaps/datamodel/context.py b/src/prefixmaps/datamodel/context.py index 71a0e31..099ce6c 100644 --- a/src/prefixmaps/datamodel/context.py +++ b/src/prefixmaps/datamodel/context.py @@ -71,7 +71,7 @@ class PrefixExpansion: status: StatusType """Indicates whether the expansion is canonical, a prefix alias, a namespace alias, or both.""" - source: Optional[str] = None + expansion_source: Optional[str] = None """Indicates the source of the prefix expansion.""" def canonical(self) -> bool: @@ -156,7 +156,7 @@ def combine(self, context: "Context"): :return: """ for pe in context.prefix_expansions: - self.add_prefix(pe.prefix, pe.namespace, pe.status, source=context.name) + self.add_prefix(pe.prefix, pe.namespace, pe.status, expansion_source=context.name) def add_prefix( self, @@ -164,7 +164,7 @@ def add_prefix( namespace: NAMESPACE, status: StatusType = StatusType.canonical, preferred: bool = False, - source: Optional[str] = None, + expansion_source: Optional[str] = None, ): """ Adds a prefix expansion to this context. @@ -180,7 +180,7 @@ def add_prefix( :param namespace: namespace to be added :param status: the status of the prefix being added :param preferred: - :param source: An optional annotation to be used when merging contexts together. + :param expansion_source: An optional annotation to be used when merging contexts together. The source will keep track of the original context that a given prefix expansion came from. This is used in :meth:`Context.combine`. :return: @@ -210,7 +210,7 @@ def add_prefix( prefix=prefix, namespace=namespace, status=status, - source=source, + expansion_source=expansion_source, ) ) diff --git a/src/prefixmaps/ingest/etl_runner.py b/src/prefixmaps/ingest/etl_runner.py index 1ba769f..d9fa1d7 100644 --- a/src/prefixmaps/ingest/etl_runner.py +++ b/src/prefixmaps/ingest/etl_runner.py @@ -90,7 +90,7 @@ def run_etl(output_directory: Union[str, Path]) -> None: # Write all contexts for name, context in contexts.items(): with output_directory.joinpath(f"{name}.csv").open("w", encoding="UTF-8") as file: - context_to_file(context, file, include_source=context.name in COMBINED) + context_to_file(context, file, include_expansion_source=context.name in COMBINED) @click.command diff --git a/src/prefixmaps/io/writer.py b/src/prefixmaps/io/writer.py index 518fd5b..586f3f6 100644 --- a/src/prefixmaps/io/writer.py +++ b/src/prefixmaps/io/writer.py @@ -15,25 +15,27 @@ def _key(pe: PrefixExpansion): return pe.prefix.casefold(), STATUS_TYPE_ORDER[pe.status] -def context_to_file(context: Context, file: TextIO, *, include_source: bool = False) -> None: +def context_to_file( + context: Context, file: TextIO, *, include_expansion_source: bool = False +) -> None: """ Writes a context to a file :param context: :param file: - :param include_source: If true, include a "source" column. This is useful for + :param include_expansion_source: If true, include a "source" column. This is useful for writing merged contexts since it says the highest priority simple context from which the row corresponding to a :class:`PrefixExpansion` came. :return: """ field_names = ["context", "prefix", "namespace", "status"] - if include_source: - field_names.append("source") + if include_expansion_source: + field_names.append("expansion_source") writer = DictWriter(file, fieldnames=field_names) writer.writeheader() for pe in sorted(context.prefix_expansions, key=_key): row = vars(pe) row["status"] = pe.status.value - if not include_source: - row.pop("source", None) + if not include_expansion_source: + row.pop("expansion_source", None) writer.writerow(row)