Skip to content

Commit

Permalink
Bring in similarty through copy & paste instead of import (#346)
Browse files Browse the repository at this point in the history
Initially this PR started off with just pulling the schema and seeing if
we could minimally just move to using a Dict for now, but since the
frontend was using the typescript interfaces for the similarity classes,
I ended up just bringing the schema in minus the three conflicting
slots...which is actually the most minimal change.
  • Loading branch information
kevinschaper authored Sep 26, 2023
1 parent 853a2f6 commit 4af15c0
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 60 deletions.
2 changes: 1 addition & 1 deletion backend/src/monarch_py/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def compare(
"""Compare two entities using semantic similarity via OAK"""
subjects = subjects.split(",")
objects = objects.split(",")
response = oak.compare(subjects, objects)
response = oak().compare(subjects, objects)
format_output(fmt, response, output)


Expand Down
174 changes: 130 additions & 44 deletions backend/src/monarch_py/datamodels/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ class Association(ConfiguredBaseModel):
id: str = Field(...)
subject: str = Field(...)
original_subject: Optional[str] = Field(None)
subject_namespace: Optional[str] = Field(None, description="""The namespace/prefix of the subject entity""")
subject_category: Optional[str] = Field(None, description="""The category of the subject entity""")
subject_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the subject entity"""
)
subject_category: Optional[str] = Field(
None, description="""The category of the subject entity"""
)
subject_closure: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing subject id and the ids of all of it's ancestors""",
)
subject_label: Optional[str] = Field(None, description="""the label or name for the first entity""")
subject_label: Optional[str] = Field(
None, description="""The name of the subject entity"""
)
subject_closure_label: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing subject name and the names of all of it's ancestors""",
Expand All @@ -63,13 +69,19 @@ class Association(ConfiguredBaseModel):
predicate: str = Field(...)
object: str = Field(...)
original_object: Optional[str] = Field(None)
object_namespace: Optional[str] = Field(None, description="""The namespace/prefix of the object entity""")
object_category: Optional[str] = Field(None, description="""The category of the object entity""")
object_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the object entity"""
)
object_category: Optional[str] = Field(
None, description="""The category of the object entity"""
)
object_closure: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing object id and the ids of all of it's ancestors""",
)
object_label: Optional[str] = Field(None, description="""the label or name for the second entity""")
object_label: Optional[str] = Field(
None, description="""The name of the object entity"""
)
object_closure_label: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing object name and the names of all of it's ancestors""",
Expand Down Expand Up @@ -97,7 +109,9 @@ class Association(ConfiguredBaseModel):
description="""count of supporting documents, evidence codes, and sources supplying evidence""",
)
pathway: Optional[str] = Field(None)
frequency_qualifier_label: Optional[str] = Field(None, description="""The name of the frequency_qualifier entity""")
frequency_qualifier_label: Optional[str] = Field(
None, description="""The name of the frequency_qualifier entity"""
)
frequency_qualifier_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the frequency_qualifier entity"""
)
Expand All @@ -112,11 +126,15 @@ class Association(ConfiguredBaseModel):
default_factory=list,
description="""Field containing frequency_qualifier name and the names of all of it's ancestors""",
)
onset_qualifier_label: Optional[str] = Field(None, description="""The name of the onset_qualifier entity""")
onset_qualifier_label: Optional[str] = Field(
None, description="""The name of the onset_qualifier entity"""
)
onset_qualifier_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the onset_qualifier entity"""
)
onset_qualifier_category: Optional[str] = Field(None, description="""The category of the onset_qualifier entity""")
onset_qualifier_category: Optional[str] = Field(
None, description="""The category of the onset_qualifier entity"""
)
onset_qualifier_closure: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing onset_qualifier id and the ids of all of it's ancestors""",
Expand All @@ -125,11 +143,15 @@ class Association(ConfiguredBaseModel):
default_factory=list,
description="""Field containing onset_qualifier name and the names of all of it's ancestors""",
)
sex_qualifier_label: Optional[str] = Field(None, description="""The name of the sex_qualifier entity""")
sex_qualifier_label: Optional[str] = Field(
None, description="""The name of the sex_qualifier entity"""
)
sex_qualifier_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the sex_qualifier entity"""
)
sex_qualifier_category: Optional[str] = Field(None, description="""The category of the sex_qualifier entity""")
sex_qualifier_category: Optional[str] = Field(
None, description="""The category of the sex_qualifier entity"""
)
sex_qualifier_closure: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing sex_qualifier id and the ids of all of it's ancestors""",
Expand All @@ -138,11 +160,15 @@ class Association(ConfiguredBaseModel):
default_factory=list,
description="""Field containing sex_qualifier name and the names of all of it's ancestors""",
)
stage_qualifier_label: Optional[str] = Field(None, description="""The name of the stage_qualifier entity""")
stage_qualifier_label: Optional[str] = Field(
None, description="""The name of the stage_qualifier entity"""
)
stage_qualifier_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the stage_qualifier entity"""
)
stage_qualifier_category: Optional[str] = Field(None, description="""The category of the stage_qualifier entity""")
stage_qualifier_category: Optional[str] = Field(
None, description="""The category of the stage_qualifier entity"""
)
stage_qualifier_closure: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing stage_qualifier id and the ids of all of it's ancestors""",
Expand Down Expand Up @@ -199,13 +225,19 @@ class DirectionalAssociation(Association):
id: str = Field(...)
subject: str = Field(...)
original_subject: Optional[str] = Field(None)
subject_namespace: Optional[str] = Field(None, description="""The namespace/prefix of the subject entity""")
subject_category: Optional[str] = Field(None, description="""The category of the subject entity""")
subject_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the subject entity"""
)
subject_category: Optional[str] = Field(
None, description="""The category of the subject entity"""
)
subject_closure: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing subject id and the ids of all of it's ancestors""",
)
subject_label: Optional[str] = Field(None, description="""the label or name for the first entity""")
subject_label: Optional[str] = Field(
None, description="""The name of the subject entity"""
)
subject_closure_label: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing subject name and the names of all of it's ancestors""",
Expand All @@ -215,13 +247,19 @@ class DirectionalAssociation(Association):
predicate: str = Field(...)
object: str = Field(...)
original_object: Optional[str] = Field(None)
object_namespace: Optional[str] = Field(None, description="""The namespace/prefix of the object entity""")
object_category: Optional[str] = Field(None, description="""The category of the object entity""")
object_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the object entity"""
)
object_category: Optional[str] = Field(
None, description="""The category of the object entity"""
)
object_closure: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing object id and the ids of all of it's ancestors""",
)
object_label: Optional[str] = Field(None, description="""the label or name for the second entity""")
object_label: Optional[str] = Field(
None, description="""The name of the object entity"""
)
object_closure_label: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing object name and the names of all of it's ancestors""",
Expand Down Expand Up @@ -249,7 +287,9 @@ class DirectionalAssociation(Association):
description="""count of supporting documents, evidence codes, and sources supplying evidence""",
)
pathway: Optional[str] = Field(None)
frequency_qualifier_label: Optional[str] = Field(None, description="""The name of the frequency_qualifier entity""")
frequency_qualifier_label: Optional[str] = Field(
None, description="""The name of the frequency_qualifier entity"""
)
frequency_qualifier_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the frequency_qualifier entity"""
)
Expand All @@ -264,11 +304,15 @@ class DirectionalAssociation(Association):
default_factory=list,
description="""Field containing frequency_qualifier name and the names of all of it's ancestors""",
)
onset_qualifier_label: Optional[str] = Field(None, description="""The name of the onset_qualifier entity""")
onset_qualifier_label: Optional[str] = Field(
None, description="""The name of the onset_qualifier entity"""
)
onset_qualifier_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the onset_qualifier entity"""
)
onset_qualifier_category: Optional[str] = Field(None, description="""The category of the onset_qualifier entity""")
onset_qualifier_category: Optional[str] = Field(
None, description="""The category of the onset_qualifier entity"""
)
onset_qualifier_closure: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing onset_qualifier id and the ids of all of it's ancestors""",
Expand All @@ -277,11 +321,15 @@ class DirectionalAssociation(Association):
default_factory=list,
description="""Field containing onset_qualifier name and the names of all of it's ancestors""",
)
sex_qualifier_label: Optional[str] = Field(None, description="""The name of the sex_qualifier entity""")
sex_qualifier_label: Optional[str] = Field(
None, description="""The name of the sex_qualifier entity"""
)
sex_qualifier_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the sex_qualifier entity"""
)
sex_qualifier_category: Optional[str] = Field(None, description="""The category of the sex_qualifier entity""")
sex_qualifier_category: Optional[str] = Field(
None, description="""The category of the sex_qualifier entity"""
)
sex_qualifier_closure: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing sex_qualifier id and the ids of all of it's ancestors""",
Expand All @@ -290,11 +338,15 @@ class DirectionalAssociation(Association):
default_factory=list,
description="""Field containing sex_qualifier name and the names of all of it's ancestors""",
)
stage_qualifier_label: Optional[str] = Field(None, description="""The name of the stage_qualifier entity""")
stage_qualifier_label: Optional[str] = Field(
None, description="""The name of the stage_qualifier entity"""
)
stage_qualifier_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the stage_qualifier entity"""
)
stage_qualifier_category: Optional[str] = Field(None, description="""The category of the stage_qualifier entity""")
stage_qualifier_category: Optional[str] = Field(
None, description="""The category of the stage_qualifier entity"""
)
stage_qualifier_closure: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing stage_qualifier id and the ids of all of it's ancestors""",
Expand Down Expand Up @@ -322,11 +374,15 @@ class Entity(ConfiguredBaseModel):
id: str = Field(...)
category: Optional[str] = Field(None)
name: Optional[str] = Field(None)
full_name: Optional[str] = Field(None, description="""The long form name of an entity""")
full_name: Optional[str] = Field(
None, description="""The long form name of an entity"""
)
description: Optional[str] = Field(None)
xref: Optional[List[str]] = Field(default_factory=list)
provided_by: Optional[str] = Field(None)
in_taxon: Optional[str] = Field(None, description="""The biolink taxon that the entity is in the closure of.""")
in_taxon: Optional[str] = Field(
None, description="""The biolink taxon that the entity is in the closure of."""
)
in_taxon_label: Optional[str] = Field(
None,
description="""The label of the biolink taxon that the entity is in the closure of.""",
Expand Down Expand Up @@ -378,7 +434,9 @@ class Node(Entity):
UI container class extending Entity with additional information
"""

in_taxon: Optional[str] = Field(None, description="""The biolink taxon that the entity is in the closure of.""")
in_taxon: Optional[str] = Field(
None, description="""The biolink taxon that the entity is in the closure of."""
)
in_taxon_label: Optional[str] = Field(
None,
description="""The label of the biolink taxon that the entity is in the closure of.""",
Expand All @@ -404,7 +462,9 @@ class Node(Entity):
id: str = Field(...)
category: Optional[str] = Field(None)
name: Optional[str] = Field(None)
full_name: Optional[str] = Field(None, description="""The long form name of an entity""")
full_name: Optional[str] = Field(
None, description="""The long form name of an entity"""
)
description: Optional[str] = Field(None)
xref: Optional[List[str]] = Field(default_factory=list)
provided_by: Optional[str] = Field(None)
Expand Down Expand Up @@ -460,16 +520,22 @@ class EntityResults(Results):

class SearchResult(Entity):

highlight: Optional[str] = Field(None, description="""matching text snippet containing html tags""")
score: Optional[str] = Field(None, description="""Abstract base slot for different kinds of scores""")
highlight: Optional[str] = Field(
None, description="""matching text snippet containing html tags"""
)
score: Optional[float] = Field(None)
id: str = Field(...)
category: str = Field(...)
name: str = Field(...)
full_name: Optional[str] = Field(None, description="""The long form name of an entity""")
full_name: Optional[str] = Field(
None, description="""The long form name of an entity"""
)
description: Optional[str] = Field(None)
xref: Optional[List[str]] = Field(default_factory=list)
provided_by: Optional[str] = Field(None)
in_taxon: Optional[str] = Field(None, description="""The biolink taxon that the entity is in the closure of.""")
in_taxon: Optional[str] = Field(
None, description="""The biolink taxon that the entity is in the closure of."""
)
in_taxon_label: Optional[str] = Field(
None,
description="""The label of the biolink taxon that the entity is in the closure of.""",
Expand Down Expand Up @@ -510,21 +576,41 @@ class TermPairwiseSimilarity(PairwiseSimilarity):
A simple pairwise similarity between two atomic concepts/terms
"""

subject_id: str = Field(..., description="""The first of the two entities being compared""")
subject_label: Optional[str] = Field(None, description="""the label or name for the first entity""")
subject_source: Optional[str] = Field(None, description="""the source for the first entity""")
object_id: Optional[str] = Field(None, description="""The second of the two entities being compared""")
object_label: Optional[str] = Field(None, description="""the label or name for the second entity""")
object_source: Optional[str] = Field(None, description="""the source for the second entity""")
subject_id: str = Field(
..., description="""The first of the two entities being compared"""
)
subject_label: Optional[str] = Field(
None, description="""The name of the subject entity"""
)
subject_source: Optional[str] = Field(
None, description="""the source for the first entity"""
)
object_id: Optional[str] = Field(
None, description="""The second of the two entities being compared"""
)
object_label: Optional[str] = Field(
None, description="""The name of the object entity"""
)
object_source: Optional[str] = Field(
None, description="""the source for the second entity"""
)
ancestor_id: Optional[str] = Field(
None,
description="""the most recent common ancestor of the two compared entities. If there are multiple MRCAs then the most informative one is selected""",
)
ancestor_label: Optional[str] = Field(None, description="""the name or label of the ancestor concept""")
ancestor_label: Optional[str] = Field(
None, description="""the name or label of the ancestor concept"""
)
ancestor_source: Optional[str] = Field(None)
object_information_content: Optional[float] = Field(None, description="""The IC of the object""")
subject_information_content: Optional[float] = Field(None, description="""The IC of the subject""")
ancestor_information_content: Optional[float] = Field(None, description="""The IC of the object""")
object_information_content: Optional[float] = Field(
None, description="""The IC of the object"""
)
subject_information_content: Optional[float] = Field(
None, description="""The IC of the subject"""
)
ancestor_information_content: Optional[float] = Field(
None, description="""The IC of the object"""
)
jaccard_similarity: Optional[float] = Field(
None,
description="""The number of concepts in the intersection divided by the number in the union""",
Expand Down
4 changes: 1 addition & 3 deletions backend/src/monarch_py/datamodels/model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ description: Data models for the Monarch Initiative data access library
prefixes:
linkml: https://w3id.org/linkml/
biolink: https://w3id.org/biolink/vocab/
oak: https://w3id.org/oak/
imports:
- linkml:types
- oak:similarity
- similarity
default_range: string


Expand Down Expand Up @@ -239,7 +238,6 @@ classes:
items:
range: SearchResult


slots:
aggregator_knowledge_source:
multivalued: true
Expand Down
Loading

0 comments on commit 4af15c0

Please sign in to comment.