Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve DKG assembly of physical constants #263

Merged
merged 8 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions mira/dkg/askemo/askemo.climate.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@
],
"type": "class"
},
{
"description": "",
"id": "askem.climate:0000202",
"name": "Lie derivative",
"parents": [
"askem.climate:0000009"
],
"part_ofs": [
"askem.climate:0001006"
],
"synonyms": [
{
"type": "referenced_by_symbol",
"value": "ℒ"
}
],
"type": "class"
},
{
"description": "",
"id": "askem.climate:0001001",
Expand Down Expand Up @@ -144,12 +162,33 @@
"description": "",
"id": "askem.climate:0001004",
"name": "Momentum conservation equation",
"parents": [
"askem.climate:0000006"
],
"type": "class"
},
{
"description": "",
"id": "askem.climate:0001005",
"name": "tracer conservation",
"parents": [
"askem.climate:0000006"
],
"type": "class"
},
{
"description": "Vegetation dynamics in semi-arid environments",
"id": "askem.climate:0001006",
"name": "Klausmeier",
"type": "class"
},
{
"description": "Composition of Halfar + Glen's law",
"id": "askem.climate:0001007",
"name": "Ice Dynamics",
"parents": [
"askem.climate:0000006"
],
"type": "class"
},
{
Expand Down Expand Up @@ -283,6 +322,26 @@
],
"type": "class"
},
{
"description": "Water growth and dispursion in semi-arid environments",
"dimensionality": "kg m^-2",
"id": "askem.climate:0002010",
"name": "hydrodynamics",
"part_ofs": [
"askem.climate:0001006"
],
"type": "class"
},
{
"description": "Plant growth and dynamics in semi-arid environments",
"dimensionality": "kg m^-2",
"id": "askem.climate:0002011",
"name": "phytodynamics",
"part_ofs": [
"askem.climate:0001006"
],
"type": "class"
},
{
"description": "A coordinate representing the amount north or south of the equator on Earth",
"dimensionality": "radians",
Expand Down Expand Up @@ -1022,5 +1081,117 @@
}
],
"type": "class"
},
{
"description": "How much water is there in some area",
"dimensionality": "kg m^-2",
"id": "askem.climate:0003046",
"name": "water density",
"part_ofs": [
"askem.climate:0002010"
],
"synonyms": [
{
"type": "referenced_by_symbol",
"value": "w"
}
],
"type": "class"
},
{
"description": "Water input to the model",
"dimensionality": "kg m^-2",
"id": "askem.climate:0003047",
"name": "water input",
"part_ofs": [
"askem.climate:0002010"
],
"synonyms": [
{
"type": "referenced_by_symbol",
"value": "a"
}
],
"type": "class"
},
{
"description": "Also called water flow speed",
"dimensionality": "m s^-1",
"id": "askem.climate:0003048",
"name": "rate of water flow downhill",
"part_ofs": [
"askem.climate:0002010"
],
"synonyms": [
{
"type": "referenced_by_symbol",
"value": "ν"
}
],
"type": "class"
},
{
"description": "",
"id": "askem.climate:0003049",
"name": "change in water density in downhill direction",
"part_ofs": [
"askem.climate:0002010"
],
"synonyms": [
{
"type": "referenced_by_symbol",
"value": "ℒ(dX, w)"
}
],
"type": "class"
},
{
"description": "How much vegetable mass there is in some area",
"dimensionality": "kg m^-2",
"id": "askem.climate:0003050",
"name": "vegetation density",
"part_ofs": [
"askem.climate:0002011",
"askem.climate:0002010"
],
"synonyms": [
{
"type": "referenced_by_symbol",
"value": "n"
}
],
"type": "class"
},
{
"description": "Contributors to plant death, linear in plant density",
"dimensionality": "unitless",
"id": "askem.climate:0003051",
"name": "plant loss coefficient",
"part_ofs": [
"askem.climate:0002011"
],
"synonyms": [
{
"type": "referenced_by_symbol",
"value": "m"
}
],
"type": "class"
},
{
"description": "",
"dimensionality": "kg m^-2",
"id": "askem.climate:0003052",
"name": "diffusion of vegetation",
"part_ofs": [
"askem.climate:0002011"
],
"synonyms": [
{
"type": "referenced_by_symbol",
"value": "Δ(n)"
}
],
"type": "class"
}
]
3 changes: 1 addition & 2 deletions mira/dkg/askemo/askemo_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

def get_askem_climate_terms() -> Dict[str, Term]:
"""Get ASKEM Climate ontology terms."""
# df = pd.read_csv(URL, sep="\t")
df = pd.read_excel("/Users/cthoyt/Downloads/ASKEM Climate Ontology.xlsx")
df = pd.read_csv(URL, sep="\t")
df = df[df["curie"].notna()]
df.columns = [c.lower() for c in df.columns]

Expand Down
34 changes: 25 additions & 9 deletions mira/dkg/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def construct(
xref.type or "oboinowl:hasDbXref" for xref in term.xrefs or []
),
synonym_types=";".join(
synonym.type or "skos:exactMatch" for synonym in term.synonyms or []
synonym.type or "oboInOwl:hasExactSynonym" for synonym in term.synonyms or []
),
)
for parent_curie in term.parents:
Expand Down Expand Up @@ -548,28 +548,44 @@ def construct(
)

click.secho("Physical Constants", fg="green", bold=True)
for wikidata_id, label, description, synonyms, xrefs, _value, _formula, _symbols in tqdm(
for wikidata_id, label, description, synonyms, xrefs, value, formula, symbols in tqdm(
get_physical_constant_terms(), desc="Physical Constants"
):
# TODO how to model value, formula?
# TODO process mathml and make readable
curie = f"wikidata:{wikidata_id}"
node_sources[curie].add("wikidata")

prop_predicates, prop_values = [], []
if value:
prop_predicates.append("debio:0000042")
prop_values.append(str(value))
# TODO process mathml and make readable
# if formula:
# prop_predicates.append("debio:0000043")
# prop_values.append(str(formula))

synonym_types, synonym_values = [], []
for syn in synonyms:
synonym_values.append(syn)
synonym_types.append("oboInOwl:hasExactSynonym")
for symbol in symbols:
synonym_values.append(symbol)
synonym_types.append("debio:0000031")

nodes[curie] = NodeInfo(
curie=curie,
prefix="wikidata;constant",
label=label,
synonyms=";".join(synonyms),
synonyms=";".join(synonym_values),
synonym_types=";".join(synonym_types),
deprecated="false",
type="class",
definition=description,
xrefs=";".join(xrefs),
xref_types=";".join("oboinowl:hasDbXref" for _ in xrefs),
alts="",
version="",
property_predicates="",
property_values="",
synonym_types="",
property_predicates=";".join(prop_predicates),
property_values=";".join(prop_values),
)

def _get_edge_name(curie_: str, strict: bool = False) -> str:
Expand Down Expand Up @@ -1050,7 +1066,7 @@ def get_node_info(term: pyobo.Term, type: EntityType = "class"):
property_values="",
xref_types="",
synonym_types=";".join(
synonym.type.curie if synonym.type is not None else "skos:exactMatch"
synonym.type.curie if synonym.type is not None else "oboInOwl:hasExactSynonym"
for synonym in term.synonyms or []
),
)
Expand Down
4 changes: 3 additions & 1 deletion mira/dkg/resources/cso.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pyobo import Obo
from pyobo.reader import from_obo_path
from pystow.utils import download
import bioregistry
Expand All @@ -12,7 +13,7 @@
URL = "https://raw.githubusercontent.com/cthoyt/Climate-System-Ontology-CSO/main/cso.obo"


def get_cso_obo():
def get_cso_obo() -> Obo:
bioregistry.manager.synonyms["cso"] = "cso"
bioregistry.manager.registry["cso"] = bioregistry.Resource(
name="Climate Systems Ontology",
Expand All @@ -21,6 +22,7 @@ def get_cso_obo():
description="An ontology for climate systems",
)
download(url=URL, path=PATH)
# use https://github.com/pyobo/pyobo/pull/159
return from_obo_path(PATH, prefix="cso", default_prefix="cso", strict=False)


Expand Down