Skip to content

Commit

Permalink
fix conflicts, regen artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
sierra-moxon committed Dec 18, 2023
2 parents 4fa9318 + 80fadb9 commit 492b13f
Show file tree
Hide file tree
Showing 13 changed files with 58,094 additions and 10,395 deletions.
1,924 changes: 1,039 additions & 885 deletions poetry.lock

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "prefixmaps"
version = "0.1.6"
version = "0.1.8"
description = "A python library for retrieving semantic prefix maps"
readme = "README.md"
authors = ["cmungall <[email protected]>"]
Expand All @@ -24,19 +24,21 @@ homepage = "https://github.com/linkml/prefixmaps"


[tool.poetry.dependencies]
python = "^3.8.0"
python = "^3.9"
pyyaml = ">=5.3.1"
sphinx-rtd-theme = {version = "^1.0.0", extras = ["docs"]}
Sphinx = {version = "^5.3.0", extras = ["docs"]}
sphinx-autodoc-typehints = {version = "^1.19.4", extras = ["docs"]}
Sphinx = {version = "^7.2.6", extras = ["docs"]}
sphinx-autodoc-typehints = {version = "^1.23.4", extras = ["docs"]}
sphinx-click = {version = "^4.3.0", extras = ["docs"]}
myst-parser = {version = "^0.18.1", extras = ["docs"]}
myst-parser = {version = "^2.0.0", extras = ["docs"]}
click = ">=8.1.3"
requests = {version = "^2.28.1", extras = ["refresh"]}
bioregistry = {version = "^0.10.0", extras = ["refresh"]}
bioregistry = {version = "^0.10.65", extras = ["refresh"]}
rdflib = {version = "^6.2.0", extras = ["refresh"]}
curies = ">=0.5.3"
tox = "^4.11.3"
pydantic = "^2.5"


[tool.poetry.dev-dependencies]
pytest = ">=6.2"
Expand Down
11,938 changes: 11,918 additions & 20 deletions src/prefixmaps/data/bioregistry.csv

Large diffs are not rendered by default.

11,938 changes: 11,918 additions & 20 deletions src/prefixmaps/data/bioregistry.upper.csv

Large diffs are not rendered by default.

21,311 changes: 16,586 additions & 4,725 deletions src/prefixmaps/data/merged.csv

Large diffs are not rendered by default.

21,311 changes: 16,586 additions & 4,725 deletions src/prefixmaps/data/merged.oak.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/prefixmaps/data/obo.csv
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ obo,OBCS,http://purl.obolibrary.org/obo/OBCS_,canonical
obo,OBI,http://purl.obolibrary.org/obo/OBI_,canonical
obo,OBIB,http://purl.obolibrary.org/obo/OBIB_,canonical
obo,OBO_REL,http://purl.obolibrary.org/obo/OBO_REL_,canonical
obo,OCCO,http://purl.obolibrary.org/obo/OCCO_,canonical
obo,OGG,http://purl.obolibrary.org/obo/OGG_,canonical
obo,OGI,http://purl.obolibrary.org/obo/OGI_,canonical
obo,OGMS,http://purl.obolibrary.org/obo/OGMS_,canonical
Expand Down
6 changes: 4 additions & 2 deletions src/prefixmaps/data/prefixcc.csv
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ prefixcc,delta,http://www.w3.org/2004/delta#,canonical
prefixcc,demlab,http://www.demcare.eu/ontologies/demlab.owl#,canonical
prefixcc,dentsci,https://w3id.org/skgo/dentsci#,canonical
prefixcc,deo,http://purl.org/spar/deo/,canonical
prefixcc,deonta,https://deonta.linkedmodel.org/deonta/,canonical
prefixcc,deps,http://ontologi.es/doap-deps#,canonical
prefixcc,derecho,http://purl.org/derecho#,canonical
prefixcc,devuan,https://devuan.net.br/,canonical
Expand Down Expand Up @@ -935,7 +936,7 @@ prefixcc,gfo,http://www.onto-med.de/ontologies/gfo.owl#,canonical
prefixcc,gg,http://www.gemeentegeschiedenis.nl/gg-schema#,canonical
prefixcc,ggbn,http://data.ggbn.org/schemas/ggbn/terms/,canonical
prefixcc,ghga,http://w3id.org/ghga/,canonical
prefixcc,gist,http://ontologies.semanticarts.com/gist/,canonical
prefixcc,gist,http://ontologies.semanticarts.com/gist#,canonical
prefixcc,giving,http://ontologi.es/giving#,canonical
prefixcc,gl,http://schema.geolink.org/,canonical
prefixcc,gldp,http://www.w3.org/ns/people#,canonical
Expand Down Expand Up @@ -1077,6 +1078,7 @@ prefixcc,ifcowl,http://www.buildingsmart-tech.org/ifcOWL/IFC4_ADD2#,canonical
prefixcc,igeo,http://rdf.insee.fr/def/geo#,canonical
prefixcc,ignf,http://data.ign.fr/def/ignf#,canonical
prefixcc,ii,http://sparql.cwrc.ca/ontologies/ii#,canonical
prefixcc,iig,https://w3id.org/iicongraph/data/,canonical
prefixcc,iiif,http://iiif.io/api/image/2#,canonical
prefixcc,ilap,http://data.posccaesar.org/ilap/,canonical
prefixcc,im,http://imgpedia.dcc.uchile.cl/resource/,canonical
Expand Down Expand Up @@ -1563,7 +1565,7 @@ prefixcc,nxs,http://www.neclimateus.org/,canonical
prefixcc,nyt,http://data.nytimes.com/,canonical
prefixcc,nytimes,http://data.nytimes.com/elements/,canonical
prefixcc,oa,http://www.w3.org/ns/oa#,canonical
prefixcc,oac,http://www.openannotation.org/ns/,canonical
prefixcc,oac,https://w3id.org/oac#,canonical
prefixcc,oad,http://lod.xdams.org/reload/oad/,canonical
prefixcc,oae,http://www.ics.forth.gr/isl/oae/core#,canonical
prefixcc,oan,http://data.lirmm.fr/ontologies/oan/,canonical
Expand Down
7 changes: 7 additions & 0 deletions src/prefixmaps/data/w3id.csv
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ w3id,cramp-fdp,https://w3id.org/cramp-fdp/,canonical
w3id,credentials,https://w3id.org/credentials/,canonical
w3id,credit,https://w3id.org/credit/,canonical
w3id,cri,https://w3id.org/cri/,canonical
w3id,cro,https://w3id.org/cro/,canonical
w3id,cskg,https://w3id.org/cskg/,canonical
w3id,cso,https://w3id.org/cso/,canonical
w3id,csolink,https://w3id.org/csolink/,canonical
Expand Down Expand Up @@ -490,6 +491,7 @@ w3id,hpont,https://w3id.org/hpont/,canonical
w3id,hso,https://w3id.org/hso/,canonical
w3id,hsu-aut,https://w3id.org/hsu-aut/,canonical
w3id,htad-fdp,https://w3id.org/htad-fdp/,canonical
w3id,hto,https://w3id.org/hto/,canonical
w3id,http,https://w3id.org/http/,canonical
w3id,huml,https://w3id.org/huml/,canonical
w3id,hydra,https://w3id.org/hydra/,canonical
Expand All @@ -515,6 +517,7 @@ w3id,idpo,https://w3id.org/idpo/,canonical
w3id,idsa,https://w3id.org/idsa/,canonical
w3id,ieee,https://w3id.org/ieee/,canonical
w3id,ifc,https://w3id.org/ifc/,canonical
w3id,ifcc,https://w3id.org/ifcc/,canonical
w3id,ifcp,https://w3id.org/ifcp/,canonical
w3id,iicongraph,https://w3id.org/iicongraph/,canonical
w3id,iliad,https://w3id.org/iliad/,canonical
Expand Down Expand Up @@ -684,6 +687,7 @@ w3id,mtv,https://w3id.org/mtv/,canonical
w3id,MULTI,https://w3id.org/MULTI/,canonical
w3id,multidimensional-interface,https://w3id.org/multidimensional-interface/,canonical
w3id,multidimensional-quantity,https://w3id.org/multidimensional-quantity/,canonical
w3id,mumonut,https://w3id.org/mumonut/,canonical
w3id,musco,https://w3id.org/musco/,canonical
w3id,music-annotation,https://w3id.org/music-annotation/,canonical
w3id,music-circle,https://w3id.org/music-circle/,canonical
Expand Down Expand Up @@ -738,9 +742,11 @@ w3id,oebDataFormats,https://w3id.org/oebDataFormats/,canonical
w3id,oebDatasets,https://w3id.org/oebDatasets/,canonical
w3id,oerbase,https://w3id.org/oerbase/,canonical
w3id,ofo,https://w3id.org/ofo/,canonical
w3id,ogc,https://w3id.org/ogc/,canonical
w3id,oho,https://w3id.org/oho/,canonical
w3id,okg,https://w3id.org/okg/,canonical
w3id,okn,https://w3id.org/okn/,canonical
w3id,okp4,https://w3id.org/okp4/,canonical
w3id,olu,https://w3id.org/olu/,canonical
w3id,omg,https://w3id.org/omg/,canonical
w3id,omicron,https://w3id.org/omicron/,canonical
Expand Down Expand Up @@ -972,6 +978,7 @@ w3id,shp,https://w3id.org/shp/,canonical
w3id,simpathic,https://w3id.org/simpathic/,canonical
w3id,simulation,https://w3id.org/simulation/,canonical
w3id,sip,https://w3id.org/sip/,canonical
w3id,sirius,https://w3id.org/sirius/,canonical
w3id,situannotate,https://w3id.org/situannotate/,canonical
w3id,sketup,https://w3id.org/sketup/,canonical
w3id,sketx,https://w3id.org/sketx/,canonical
Expand Down
13 changes: 10 additions & 3 deletions src/prefixmaps/datamodel/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
PREFIX_RE = re.compile(r"^[\w\.]+$")
NAMESPACE_RE = re.compile(r"http[s]?://[\w\.\-\/]+[#/_:]$")

logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger = logging.getLogger(__name__)


class StatusType(Enum):
Expand Down Expand Up @@ -71,6 +70,9 @@ class PrefixExpansion:
status: StatusType
"""Indicates whether the expansion is canonical, a prefix alias, a namespace alias, or both."""

expansion_source: Optional[str] = None
"""Indicates the source of the prefix expansion."""

def canonical(self) -> bool:
"""
True if this is the canonical mapping in both directions.
Expand Down Expand Up @@ -153,14 +155,15 @@ def combine(self, context: "Context"):
:return:
"""
for pe in context.prefix_expansions:
self.add_prefix(pe.prefix, pe.namespace, pe.status)
self.add_prefix(pe.prefix, pe.namespace, pe.status, expansion_source=context.name)

def add_prefix(
self,
prefix: PREFIX,
namespace: NAMESPACE,
status: StatusType = StatusType.canonical,
preferred: bool = False,
expansion_source: Optional[str] = None,
):
"""
Adds a prefix expansion to this context.
Expand All @@ -176,6 +179,9 @@ def add_prefix(
:param namespace: namespace to be added
:param status: the status of the prefix being added
:param preferred:
: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:
"""
# TODO: check status
Expand Down Expand Up @@ -203,6 +209,7 @@ def add_prefix(
prefix=prefix,
namespace=namespace,
status=status,
expansion_source=expansion_source,
)
)

Expand Down
2 changes: 1 addition & 1 deletion src/prefixmaps/ingest/etl_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
context_to_file(context, file, include_expansion_source=context.name in COMBINED)


@click.command
Expand Down
10 changes: 4 additions & 6 deletions src/prefixmaps/ingest/ingest_bioregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ def from_bioregistry(upper=False, canonical_idorg=True, filter_dubious=True) ->
"obofoundry",
"miriam.legacy" if canonical_idorg else "miriam",
"default",
"bioportal",
"ols",
"n2t",
]
records = bioregistry.get_extended_prefix_map(
converter = bioregistry.get_converter(
uri_prefix_priority=priority, prefix_priority=prefix_priority
)
for record in tqdm(records):
for record in tqdm(converter.records):
if record.prefix in SKIP:
continue
if filter_dubious and not NAMESPACE_RE.match(record.uri_prefix):
Expand All @@ -82,7 +81,6 @@ def from_bioregistry(upper=False, canonical_idorg=True, filter_dubious=True) ->
if record.prefix not in PROBLEMATIC_CURIE_PREFIX_SYNONYMS_RECORDS:
for s in record.prefix_synonyms:
context.add_prefix(s, record.uri_prefix, preferred=preferred)
# TODO future, add URI prefix synonyms
# for s in record.uri_prefix_synonyms:
# context.add_prefix(record.prefix, s, status=StatusType.namespace_alias, preferred=preferred)
for s in record.uri_prefix_synonyms:
context.add_prefix(record.prefix, s, preferred=preferred)
return context
14 changes: 12 additions & 2 deletions src/prefixmaps/io/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,27 @@ def _key(pe: PrefixExpansion):
return pe.prefix.casefold(), STATUS_TYPE_ORDER[pe.status]


def context_to_file(context: Context, file: TextIO) -> 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_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:
"""
writer = DictWriter(file, fieldnames=["context", "prefix", "namespace", "status"])
field_names = ["context", "prefix", "namespace", "status"]
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_expansion_source:
row.pop("expansion_source", None)
writer.writerow(row)

0 comments on commit 492b13f

Please sign in to comment.