Skip to content

Commit

Permalink
NamedThing -> NamedEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
caufieldjh committed Dec 8, 2023
1 parent a9cbf6b commit 011d5c4
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 2 deletions.
186 changes: 186 additions & 0 deletions src/ontogpt/templates/dietician_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
from __future__ import annotations
from datetime import datetime, date
from enum import Enum
from typing import List, Dict, Optional, Any, Union
from pydantic import BaseModel as BaseModel, ConfigDict, Field
import sys
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal


metamodel_version = "None"
version = "None"

class ConfiguredBaseModel(BaseModel):
model_config = ConfigDict(
validate_assignment=True,
validate_default=True,
extra='forbid',
arbitrary_types_allowed=True,
use_enum_values = True)


class NullDataOptions(str, Enum):


UNSPECIFIED_METHOD_OF_ADMINISTRATION = "UNSPECIFIED_METHOD_OF_ADMINISTRATION"

NOT_APPLICABLE = "NOT_APPLICABLE"

NOT_MENTIONED = "NOT_MENTIONED"



class MalnutritionObservations(ConfiguredBaseModel):

malnutrition_presence: Optional[bool] = Field(None)
severity: Optional[str] = Field(None)
diagnosis: Optional[str] = Field(None)


class ExtractionResult(ConfiguredBaseModel):
"""
A result of extracting knowledge on text
"""
input_id: Optional[str] = Field(None)
input_title: Optional[str] = Field(None)
input_text: Optional[str] = Field(None)
raw_completion_output: Optional[str] = Field(None)
prompt: Optional[str] = Field(None)
extracted_object: Optional[Any] = Field(None, description="""The complex objects extracted from the text""")
named_entities: Optional[List[Any]] = Field(default_factory=list, description="""Named entities extracted from the text""")


class NamedEntity(ConfiguredBaseModel):

id: str = Field(..., description="""A unique identifier for the named entity""")
label: Optional[str] = Field(None, description="""The label (name) of the named thing""")


class ClinicalObservationSet(NamedEntity):

observations: Optional[List[str]] = Field(default_factory=list)
id: str = Field(..., description="""A unique identifier for the named entity""")
label: Optional[str] = Field(None, description="""The label (name) of the named thing""")


class ClinicalObservations(NamedEntity):

is_pediatric: Optional[bool] = Field(None)
patient_height: Optional[QuantitativeValue] = Field(None)
patient_weight: Optional[QuantitativeValue] = Field(None)
malnutrition_status: Optional[MalnutritionObservations] = Field(None)
diet_supplementation: Optional[List[str]] = Field(default_factory=list)
nutrition_support: Optional[List[str]] = Field(default_factory=list)
id: str = Field(..., description="""A unique identifier for the named entity""")
label: Optional[str] = Field(None, description="""The label (name) of the named thing""")


class DietSupplementation(NamedEntity):

id: str = Field(..., description="""A unique identifier for the named entity""")
label: Optional[str] = Field(None, description="""The label (name) of the named thing""")


class NutritionSupport(NamedEntity):

id: str = Field(..., description="""A unique identifier for the named entity""")
label: Optional[str] = Field(None, description="""The label (name) of the named thing""")


class Disease(NamedEntity):

id: str = Field(..., description="""A unique identifier for the named entity""")
label: Optional[str] = Field(None, description="""The label (name) of the named thing""")


class Unit(NamedEntity):

id: str = Field(..., description="""A unique identifier for the named entity""")
label: Optional[str] = Field(None, description="""The label (name) of the named thing""")


class CompoundExpression(ConfiguredBaseModel):

None


class QuantitativeValue(CompoundExpression):

value: Optional[str] = Field(None, description="""the value of the quantity""")
unit: Optional[str] = Field(None, description="""the unit of the quantity, e.g. grams, cups, etc.""")


class Triple(CompoundExpression):
"""
Abstract parent for Relation Extraction tasks
"""
subject: Optional[str] = Field(None)
predicate: Optional[str] = Field(None)
object: Optional[str] = Field(None)
qualifier: Optional[str] = Field(None, description="""A qualifier for the statements, e.g. \"NOT\" for negation""")
subject_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the subject of the statement, e.g. \"high dose\" or \"intravenously administered\"""")
object_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the object of the statement, e.g. \"severe\" or \"with additional complications\"""")


class TextWithTriples(ConfiguredBaseModel):
"""
A text containing one or more relations of the Triple type.
"""
publication: Optional[Publication] = Field(None)
triples: Optional[List[Triple]] = Field(default_factory=list)


class TextWithEntity(ConfiguredBaseModel):
"""
A text containing one or more instances of a single type of entity.
"""
publication: Optional[Publication] = Field(None)
entities: Optional[List[str]] = Field(default_factory=list)


class RelationshipType(NamedEntity):

id: str = Field(..., description="""A unique identifier for the named entity""")
label: Optional[str] = Field(None, description="""The label (name) of the named thing""")


class Publication(ConfiguredBaseModel):

id: Optional[str] = Field(None, description="""The publication identifier""")
title: Optional[str] = Field(None, description="""The title of the publication""")
abstract: Optional[str] = Field(None, description="""The abstract of the publication""")
combined_text: Optional[str] = Field(None)
full_text: Optional[str] = Field(None, description="""The full text of the publication""")


class AnnotatorResult(ConfiguredBaseModel):

subject_text: Optional[str] = Field(None)
object_id: Optional[str] = Field(None)
object_text: Optional[str] = Field(None)



# Model rebuild
# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model
MalnutritionObservations.model_rebuild()
ExtractionResult.model_rebuild()
NamedEntity.model_rebuild()
ClinicalObservationSet.model_rebuild()
ClinicalObservations.model_rebuild()
DietSupplementation.model_rebuild()
NutritionSupport.model_rebuild()
Disease.model_rebuild()
Unit.model_rebuild()
CompoundExpression.model_rebuild()
QuantitativeValue.model_rebuild()
Triple.model_rebuild()
TextWithTriples.model_rebuild()
TextWithEntity.model_rebuild()
RelationshipType.model_rebuild()
Publication.model_rebuild()
AnnotatorResult.model_rebuild()

5 changes: 3 additions & 2 deletions src/ontogpt/templates/dietician_notes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ classes:
multivalued: true

ClinicalObservations:
is_a: NamedEntity
attributes:
is_pediatric:
range: boolean
Expand Down Expand Up @@ -70,15 +71,15 @@ classes:

# TODO: consider MAXO terms; children of MAXO:0000009
DietSupplementation:
is_a: NamedThing
is_a: NamedEntity
id_prefixes:
- FOODON
annotations:
annotators: sqlite:obo:foodon

# TODO: consider MAXO terms; children of MAXO:0000009
NutritionSupport:
is_a: NamedThing
is_a: NamedEntity
id_prefixes:
- MAXO
annotations:
Expand Down

0 comments on commit 011d5c4

Please sign in to comment.