Skip to content

Commit

Permalink
update model, fix backend test
Browse files Browse the repository at this point in the history
  • Loading branch information
glass-ships committed Aug 22, 2023
1 parent 854c7b6 commit 21f58fb
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 45 deletions.
181 changes: 136 additions & 45 deletions backend/src/monarch_py/datamodels/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from enum import Enum
from typing import List, Dict, Optional, Any, Union
from pydantic import BaseModel as BaseModel, Field
from linkml_runtime.linkml_model import Decimal
import sys

if sys.version_info >= (3, 8):
Expand Down Expand Up @@ -48,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 label or name for the first 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 @@ -64,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 label or name for the second 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 @@ -98,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 @@ -113,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 @@ -126,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 @@ -139,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 @@ -200,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 label or name for the first 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 @@ -216,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 label or name for the second 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 @@ -250,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 @@ -265,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 @@ -278,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 @@ -291,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 @@ -323,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 @@ -379,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 @@ -397,7 +454,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 @@ -454,16 +513,24 @@ 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[str] = Field(
None, description="""Abstract base slot for different kinds of scores"""
)
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 @@ -504,25 +571,49 @@ 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 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"""
)
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""",
)
cosine_similarity: Optional[float] = Field(
None,
description="""the dot product of two node embeddings divided by the product of their lengths""",
)
dice_similarity: Optional[float] = Field(None)
phenodigm_score: Optional[float] = Field(
None,
Expand Down
2 changes: 2 additions & 0 deletions backend/tests/unit/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def test_autocomplete(autocomplete):

def test_compare(compare):
tsps = TermSetPairwiseSimilarity(**compare)
import pprint
pprint.PrettyPrinter(indent=2).pprint(tsps.dict())
assert len(tsps.subject_best_matches) != 0


Expand Down
2 changes: 2 additions & 0 deletions frontend/src/api/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ export interface TermPairwiseSimilarity extends PairwiseSimilarity {
ancestor_information_content?: string,
/** The number of concepts in the intersection divided by the number in the union */
jaccard_similarity?: string,
/** the dot product of two node embeddings divided by the product of their lengths */
cosine_similarity?: number,
dice_similarity?: string,
/** the geometric mean of the jaccard similarity and the information content */
phenodigm_score?: string,
Expand Down

0 comments on commit 21f58fb

Please sign in to comment.