Skip to content

Commit

Permalink
Merge branch 'main' into allow-lucene-syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinschaper committed Nov 2, 2023
2 parents c8e6df0 + 029186a commit e896e7a
Show file tree
Hide file tree
Showing 56 changed files with 16,573 additions and 14,317 deletions.
1,796 changes: 931 additions & 865 deletions backend/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ python = "^3.9"
pydantic = "^1.10.2"
curies = "<1"
linkml = "^1.6.1"
prefixmaps = "^0.1.6"
prefixmaps = "^0.1.7"

requests = "^2.28.1"
typer = "^0.7.0"
Expand Down
45 changes: 41 additions & 4 deletions backend/src/monarch_py/datamodels/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class Association(ConfiguredBaseModel):
default_factory=list,
description="""List of ExpandedCuries with id and url for evidence""",
)
grouping_key: Optional[str] = Field(
None,
description="""A concatenation of fields used to group associations with the same essential/defining properties""",
)
provided_by: Optional[str] = Field(None)
provided_by_link: Optional[ExpandedCurie] = Field(
None,
Expand All @@ -105,6 +109,19 @@ class Association(ConfiguredBaseModel):
onset_qualifier: Optional[str] = Field(None)
sex_qualifier: Optional[str] = Field(None)
stage_qualifier: Optional[str] = Field(None)
qualifiers_label: Optional[str] = Field(None, description="""The name of the frequency_qualifier entity""")
qualifiers_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the frequency_qualifier entity"""
)
qualifiers_category: Optional[str] = Field(None, description="""The category of the frequency_qualifier entity""")
qualifiers_closure: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing frequency_qualifier id and the ids of all of it's ancestors""",
)
qualifiers_closure_label: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing frequency_qualifier name and the names of all of it's ancestors""",
)
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 Down Expand Up @@ -250,6 +267,10 @@ class DirectionalAssociation(Association):
default_factory=list,
description="""List of ExpandedCuries with id and url for evidence""",
)
grouping_key: Optional[str] = Field(
None,
description="""A concatenation of fields used to group associations with the same essential/defining properties""",
)
provided_by: Optional[str] = Field(None)
provided_by_link: Optional[ExpandedCurie] = Field(
None,
Expand All @@ -265,6 +286,19 @@ class DirectionalAssociation(Association):
onset_qualifier: Optional[str] = Field(None)
sex_qualifier: Optional[str] = Field(None)
stage_qualifier: Optional[str] = Field(None)
qualifiers_label: Optional[str] = Field(None, description="""The name of the frequency_qualifier entity""")
qualifiers_namespace: Optional[str] = Field(
None, description="""The namespace/prefix of the frequency_qualifier entity"""
)
qualifiers_category: Optional[str] = Field(None, description="""The category of the frequency_qualifier entity""")
qualifiers_closure: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing frequency_qualifier id and the ids of all of it's ancestors""",
)
qualifiers_closure_label: Optional[List[str]] = Field(
default_factory=list,
description="""Field containing frequency_qualifier name and the names of all of it's ancestors""",
)
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 Down Expand Up @@ -349,6 +383,7 @@ class Entity(ConfiguredBaseModel):
)
symbol: Optional[str] = Field(None)
synonym: Optional[List[str]] = Field(default_factory=list)
uri: Optional[str] = Field(None, description="""The URI of the entity""")


class FacetValue(ConfiguredBaseModel):
Expand Down Expand Up @@ -394,10 +429,10 @@ class Mapping(ConfiguredBaseModel):
A minimal class to hold a SSSOM mapping
"""

subject_id: str = Field(..., description="""The first of the two entities being compared""")
subject_id: str = Field(...)
subject_label: Optional[str] = Field(None, description="""The name of the subject entity""")
predicate_id: str = Field(...)
object_id: Optional[str] = Field(None, description="""The second of the two entities being compared""")
object_id: str = Field(...)
object_label: Optional[str] = Field(None, description="""The name of the object entity""")
mapping_justification: Optional[str] = Field(None)

Expand Down Expand Up @@ -439,6 +474,7 @@ class Node(Entity):
provided_by: Optional[str] = Field(None)
symbol: Optional[str] = Field(None)
synonym: Optional[List[str]] = Field(default_factory=list)
uri: Optional[str] = Field(None, description="""The URI of the entity""")


class NodeHierarchy(ConfiguredBaseModel):
Expand Down Expand Up @@ -530,6 +566,7 @@ class SearchResult(Entity):
)
symbol: Optional[str] = Field(None)
synonym: Optional[List[str]] = Field(default_factory=list)
uri: Optional[str] = Field(None, description="""The URI of the entity""")


class SearchResults(Results):
Expand Down Expand Up @@ -564,10 +601,10 @@ 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_id: str = Field(...)
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_id: str = Field(...)
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(
Expand Down
34 changes: 30 additions & 4 deletions backend/src/monarch_py/datamodels/model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ classes:
- evidence_count
- has_evidence
- has_evidence_links
- grouping_key
- provided_by
- provided_by_link
- publications
Expand Down Expand Up @@ -172,6 +173,7 @@ classes:
- in_taxon_label
- symbol
- synonym
- uri
EntityResults:
is_a: Results
slots:
Expand Down Expand Up @@ -456,6 +458,8 @@ slots:
xref:
multivalued: true
range: string
uri:
description: The URI of the entity
url:
range: string
subject_label:
Expand Down Expand Up @@ -496,6 +500,24 @@ slots:
is_a: in_taxon
object_taxon_label:
is_a: in_taxon_label

# this whole block will be renamed to qualifer_ after we bring in the next biolink model release
qualifiers_label:
is_a: name
description: The name of the frequency_qualifier entity
qualifiers_namespace:
range: string
description: The namespace/prefix of the frequency_qualifier entity
qualifiers_category:
is_a: category
description: The category of the frequency_qualifier entity
qualifiers_closure:
multivalued: true
description: Field containing frequency_qualifier id and the ids of all of it's ancestors
qualifiers_closure_label:
multivalued: true
description: Field containing frequency_qualifier name and the names of all of it's ancestors

frequency_qualifier_label:
is_a: name
description: The name of the frequency_qualifier entity
Expand Down Expand Up @@ -557,12 +579,16 @@ slots:
multivalued: true
description: Field containing stage_qualifier name and the names of all of it's ancestors
# sssom slots
# subject_id already exists in similarity.yaml
subject_id:
range: string
required: true
# subject label is already included in this schema
predicate_id:
range: string
required: true
# object_id already exists in similarity.yaml
range: string
required: true
object_id:
range: string
required: true
# object label is already included in this schema
mapping_justification:
range: string
18 changes: 9 additions & 9 deletions backend/src/monarch_py/datamodels/similarity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ types:
minimum_value: 0

slots:
subject_id:
slot_uri: sssom:subject_id
required: true
range: uriorcurie
description: The first of the two entities being compared
# subject_id:
# slot_uri: sssom:subject_id
# required: true
# range: uriorcurie
# description: The first of the two entities being compared
# Excluded, since it conflicts with subject_label from this schema
# subject_label:
# slot_uri: sssom:subject_label
# description: the label or name for the first entity
subject_source:
slot_uri: sssom:subject_source
description: the source for the first entity
object_id:
slot_uri: sssom:object_id
range: uriorcurie
description: The second of the two entities being compared
# object_id:
# slot_uri: sssom:object_id
# range: uriorcurie
# description: The second of the two entities being compared
# Excluded, since it conflicts with object_label from this schema
# object_label:
# slot_uri: sssom:object_label
Expand Down
2 changes: 2 additions & 0 deletions backend/src/monarch_py/implementations/solr/solr_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from monarch_py.datamodels.solr import HistoPhenoKeys, SolrQueryResult
from monarch_py.utils.association_type_utils import get_association_type_mapping_by_query_string
from monarch_py.utils.entity_utils import get_uri
from monarch_py.utils.utils import get_links_for_field, get_provided_by_link

####################
Expand Down Expand Up @@ -85,6 +86,7 @@ def parse_association_counts(query_result: SolrQueryResult, entity: str) -> Asso
def parse_entity(solr_document: Dict) -> Entity:
try:
entity = Entity(**solr_document)
entity.uri = get_uri(entity.id)
except ValidationError:
logger.error(f"Validation error for {solr_document}")
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

import pystow
from loguru import logger
from pydantic import ValidationError

from monarch_py.datamodels.model import Association, AssociationResults, Entity, Node, NodeHierarchy
from monarch_py.interfaces.association_interface import AssociationInterface
from monarch_py.interfaces.entity_interface import EntityInterface
from monarch_py.utils.entity_utils import get_uri
from monarch_py.utils.utils import SQL_DATA_URL, dict_factory
from pydantic import ValidationError

monarchstow = pystow.module("monarch")

Expand Down Expand Up @@ -49,6 +51,7 @@ def get_entity(self, id: str, update: bool = False, extra: bool = False) -> Enti
"in_taxon": sql_data["in_taxon"],
"symbol": sql_data["symbol"],
"synonym": sql_data["synonym"].split("|"),
"uri": get_uri(sql_data["id"]),
}
try:
results["source"] = sql_data["source"]
Expand Down
6 changes: 6 additions & 0 deletions backend/src/monarch_py/utils/entity_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from monarch_py.service.curie_service import CurieService


def get_uri(id: str) -> str:
"""Returns the URI for the given CURIE."""
return CurieService().expand(id)
Loading

0 comments on commit e896e7a

Please sign in to comment.