diff --git a/src/ontogpt/templates/biological_process.py b/src/ontogpt/templates/biological_process.py index 71bc44842..fbbe579f0 100644 --- a/src/ontogpt/templates/biological_process.py +++ b/src/ontogpt/templates/biological_process.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -38,6 +39,7 @@ class GeneMolecularActivityRelationship(ConfiguredBaseModel): gene: Optional[str] = Field(None) molecular_activity: Optional[str] = Field(None) + class ExtractionResult(ConfiguredBaseModel): """ @@ -51,12 +53,14 @@ class ExtractionResult(ConfiguredBaseModel): 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 BiologicalProcess(NamedEntity): @@ -71,29 +75,41 @@ class BiologicalProcess(NamedEntity): gene_activities: Optional[List[GeneMolecularActivityRelationship]] = Field(default_factory=list, description="""semicolon-separated list of gene to molecular activity relationships""") id: str = Field(..., description="""A unique identifier for the named entity""") + class Gene(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 CellType(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 MolecularActivity(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 ChemicalEntity(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 Triple(CompoundExpression): """ @@ -106,18 +122,32 @@ class Triple(CompoundExpression): 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): @@ -127,6 +157,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -134,6 +165,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -143,12 +175,14 @@ class AnnotatorResult(ConfiguredBaseModel): NamedEntity.model_rebuild() BiologicalProcess.model_rebuild() Gene.model_rebuild() +CellType.model_rebuild() MolecularActivity.model_rebuild() ChemicalEntity.model_rebuild() CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/biotic_interaction.py b/src/ontogpt/templates/biotic_interaction.py index 33c0bc5c3..93ff8a619 100644 --- a/src/ontogpt/templates/biotic_interaction.py +++ b/src/ontogpt/templates/biotic_interaction.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -37,6 +38,7 @@ class Container(ConfiguredBaseModel): interactions: Optional[List[BioticInteraction]] = Field(default_factory=list) + class BioticInteraction(ConfiguredBaseModel): @@ -44,6 +46,7 @@ class BioticInteraction(ConfiguredBaseModel): target_taxon: Optional[str] = Field(None, description="""the taxon that is the object of the interaction""") interaction_type: Optional[str] = Field(None, description="""the type of interaction""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -57,29 +60,34 @@ class ExtractionResult(ConfiguredBaseModel): 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 Taxon(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 InteractionType(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 Triple(CompoundExpression): """ @@ -92,18 +100,32 @@ class Triple(CompoundExpression): 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): @@ -113,6 +135,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -120,6 +143,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -133,7 +157,8 @@ class AnnotatorResult(ConfiguredBaseModel): CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/cell_type.py b/src/ontogpt/templates/cell_type.py index 3346de17e..bdc731f03 100644 --- a/src/ontogpt/templates/cell_type.py +++ b/src/ontogpt/templates/cell_type.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,16 +14,16 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +class ConfiguredBaseModel(BaseModel): + model_config = ConfigDict( + validate_assignment=True, + validate_default=True, + extra = 'forbid', + arbitrary_types_allowed=True, + use_enum_values = True) -class BrainRegionIdentifier(str, Enum): +class BrainRegionIdentifier(str): """ Brain region (or for now, any nervous system part) """ @@ -30,7 +31,7 @@ class BrainRegionIdentifier(str, Enum): dummy = "dummy" -class NeurotransmitterIdentifier(str, Enum): +class NeurotransmitterIdentifier(str): dummy = "dummy" @@ -51,7 +52,7 @@ class CellType(ConfiguredBaseModel): """ Represents a cell type """ - id: Optional[str] = Field(None) + id: str = Field(...) label: Optional[str] = Field(None, description="""the concise name of the cell type""") equivalent_to: Optional[str] = Field(None, description="""the the cell type described""") definition: Optional[str] = Field(None) @@ -62,6 +63,7 @@ class CellType(ConfiguredBaseModel): diseases: Optional[List[str]] = Field(default_factory=list) roles: Optional[List[str]] = Field(default_factory=list) + class ImmuneCell(CellType): @@ -77,6 +79,7 @@ class ImmuneCell(CellType): diseases: Optional[List[str]] = Field(default_factory=list) roles: Optional[List[str]] = Field(default_factory=list) + class Neuron(CellType): @@ -92,6 +95,7 @@ class Neuron(CellType): diseases: Optional[List[str]] = Field(default_factory=list) roles: Optional[List[str]] = Field(default_factory=list) + class Interneuron(Neuron): @@ -108,6 +112,7 @@ class Interneuron(Neuron): diseases: Optional[List[str]] = Field(default_factory=list) roles: Optional[List[str]] = Field(default_factory=list) + class ExtractionResult(ConfiguredBaseModel): """ @@ -121,83 +126,97 @@ class ExtractionResult(ConfiguredBaseModel): 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 Gene(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 ProteinOrComplex(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 BiologicalProcess(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 Pathway(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 AnatomicalStructure(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 ChemicalEntity(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 Neurotransmitter(ChemicalEntity): 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 BrainRegion(AnatomicalStructure): 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 CellOntologyTerm(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 Drug(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 Triple(CompoundExpression): """ @@ -210,18 +229,32 @@ class Triple(CompoundExpression): 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): @@ -231,6 +264,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -238,6 +272,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -262,7 +297,8 @@ class AnnotatorResult(ConfiguredBaseModel): CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/class_enrichment.py b/src/ontogpt/templates/class_enrichment.py index 17e6f50ee..9034b9356 100644 --- a/src/ontogpt/templates/class_enrichment.py +++ b/src/ontogpt/templates/class_enrichment.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +class ConfiguredBaseModel(BaseModel): + model_config = ConfigDict( + validate_assignment=True, + validate_default=True, + extra = 'forbid', + arbitrary_types_allowed=True, + use_enum_values = True) class SortFieldEnum(str, Enum): @@ -39,6 +40,7 @@ class ClassEnrichmentConfiguration(ConfiguredBaseModel): """ p_value_cutoff: float = Field(..., description="""p-value cutoff for enrichment""") + class ClassEnrichmentResultSet(ConfiguredBaseModel): """ @@ -46,6 +48,7 @@ class ClassEnrichmentResultSet(ConfiguredBaseModel): """ results: Optional[List[ClassEnrichmentResult]] = Field(default_factory=list, description="""The enrichment results""") + class ClassEnrichmentResult(ConfiguredBaseModel): """ @@ -66,6 +69,7 @@ class ClassEnrichmentResult(ConfiguredBaseModel): ancestor_of_more_informative_result: Optional[bool] = Field(None, description="""This term is more general than a previously reported result""") descendant_of_more_informative_result: Optional[bool] = Field(None, description="""This term is more specific than a previously reported result""") + # Model rebuild @@ -73,4 +77,4 @@ class ClassEnrichmentResult(ConfiguredBaseModel): ClassEnrichmentConfiguration.model_rebuild() ClassEnrichmentResultSet.model_rebuild() ClassEnrichmentResult.model_rebuild() - + diff --git a/src/ontogpt/templates/composite_disease.py b/src/ontogpt/templates/composite_disease.py index c922ab912..b723fd310 100644 --- a/src/ontogpt/templates/composite_disease.py +++ b/src/ontogpt/templates/composite_disease.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,46 +14,46 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +class ConfiguredBaseModel(BaseModel): + model_config = ConfigDict( + validate_assignment=True, + validate_default=True, + extra = 'forbid', + arbitrary_types_allowed=True, + use_enum_values = True) -class NCITDrugType(str, Enum): +class NCITDrugType(str): dummy = "dummy" -class NCITTreatmentType(str, Enum): +class NCITTreatmentType(str): dummy = "dummy" -class NCITTActivityType(str, Enum): +class NCITTActivityType(str): dummy = "dummy" -class MAXOActionType(str, Enum): +class MAXOActionType(str): dummy = "dummy" -class MESHTherapeuticType(str, Enum): +class MESHTherapeuticType(str): dummy = "dummy" -class CHEBIDrugType(str, Enum): +class CHEBIDrugType(str): dummy = "dummy" @@ -79,6 +80,7 @@ class CompositeDisease(ConfiguredBaseModel): treatment_efficacies: Optional[List[TreatmentEfficacy]] = Field(default_factory=list, description="""semicolon-separated list of treatment to efficacy associations, e.g. Imatinib*effective""") treatment_adverse_effects: Optional[List[TreatmentAdverseEffect]] = Field(default_factory=list, description="""semicolon-separated list of treatment to adverse effect associations, e.g. Imatinib*nausea""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -92,77 +94,90 @@ class ExtractionResult(ConfiguredBaseModel): 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 Gene(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 Symptom(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 AdverseEffect(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 Treatment(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 Mechanism(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 Drug(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 TreatmentMechanism(CompoundExpression): treatment: Optional[str] = Field(None) mechanism: Optional[str] = Field(None) + class TreatmentAdverseEffect(CompoundExpression): treatment: Optional[str] = Field(None) adverse_effects: Optional[List[str]] = Field(default_factory=list) + class TreatmentEfficacy(CompoundExpression): treatment: Optional[str] = Field(None) efficacy: Optional[str] = Field(None) + class Triple(CompoundExpression): """ @@ -175,18 +190,32 @@ class Triple(CompoundExpression): 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): @@ -196,6 +225,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -203,6 +233,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -223,7 +254,8 @@ class AnnotatorResult(ConfiguredBaseModel): TreatmentEfficacy.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/core.py b/src/ontogpt/templates/core.py index 2a46a3ffa..d17845d12 100644 --- a/src/ontogpt/templates/core.py +++ b/src/ontogpt/templates/core.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -45,17 +46,20 @@ class ExtractionResult(ConfiguredBaseModel): 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 CompoundExpression(ConfiguredBaseModel): None + class Triple(CompoundExpression): """ @@ -68,6 +72,7 @@ class Triple(CompoundExpression): 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): """ @@ -76,6 +81,7 @@ class TextWithTriples(ConfiguredBaseModel): publication: Optional[Publication] = Field(None) triples: Optional[List[Triple]] = Field(default_factory=list) + class TextWithEntity(ConfiguredBaseModel): """ @@ -84,12 +90,14 @@ class TextWithEntity(ConfiguredBaseModel): 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): @@ -99,6 +107,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -106,6 +115,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -119,4 +129,4 @@ class AnnotatorResult(ConfiguredBaseModel): RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/ctd.py b/src/ontogpt/templates/ctd.py index e532e0ccc..f0e5f8085 100644 --- a/src/ontogpt/templates/ctd.py +++ b/src/ontogpt/templates/ctd.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,22 +14,22 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +class ConfiguredBaseModel(BaseModel): + model_config = ConfigDict( + validate_assignment=True, + validate_default=True, + extra = 'forbid', + arbitrary_types_allowed=True, + use_enum_values = True) -class MeshChemicalIdentifier(str, Enum): +class MeshChemicalIdentifier(str): dummy = "dummy" -class MeshDiseaseIdentifier(str, Enum): +class MeshDiseaseIdentifier(str): dummy = "dummy" @@ -57,29 +58,58 @@ class ExtractionResult(ConfiguredBaseModel): 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: Optional[str] = Field(None, description="""A unique identifier for the named entity""") + 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""") + + @field_validator('id') + def pattern_id(cls, v): + pattern=re.compile(r"^MESH:[CD][0-9]{6}$") + if isinstance(v,list): + for element in v: + if not pattern.match(element): + raise ValueError(f"Invalid id format: {element}") + elif isinstance(v,str): + if not pattern.match(v): + raise ValueError(f"Invalid id format: {v}") + return v + class Chemical(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""") + + @field_validator('id') + def pattern_id(cls, v): + pattern=re.compile(r"^MESH:[CD][0-9]{6}$") + if isinstance(v,list): + for element in v: + if not pattern.match(element): + raise ValueError(f"Invalid id format: {element}") + elif isinstance(v,str): + if not pattern.match(v): + raise ValueError(f"Invalid id format: {v}") + return v + class CompoundExpression(ConfiguredBaseModel): None + class Triple(CompoundExpression): """ @@ -92,6 +122,7 @@ class Triple(CompoundExpression): 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 ChemicalToDiseaseRelationship(Triple): """ @@ -104,12 +135,16 @@ class ChemicalToDiseaseRelationship(Triple): subject_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the chemical, e.g. \"high dose\" or \"intravenously administered\"""") object_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the disease, 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 ChemicalToDiseaseDocument(TextWithTriples): """ @@ -118,12 +153,23 @@ class ChemicalToDiseaseDocument(TextWithTriples): publication: Optional[Publication] = Field(None) triples: Optional[List[ChemicalToDiseaseRelationship]] = 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 ChemicalToDiseasePredicate(RelationshipType): """ @@ -132,6 +178,7 @@ class ChemicalToDiseasePredicate(RelationshipType): 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): @@ -141,6 +188,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -148,6 +196,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -161,8 +210,9 @@ class AnnotatorResult(ConfiguredBaseModel): ChemicalToDiseaseRelationship.model_rebuild() TextWithTriples.model_rebuild() ChemicalToDiseaseDocument.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() ChemicalToDiseasePredicate.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/ctd_ner.py b/src/ontogpt/templates/ctd_ner.py index b25c614fd..576ffccb2 100644 --- a/src/ontogpt/templates/ctd_ner.py +++ b/src/ontogpt/templates/ctd_ner.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,22 +14,22 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +class ConfiguredBaseModel(BaseModel): + model_config = ConfigDict( + validate_assignment=True, + validate_default=True, + extra = 'forbid', + arbitrary_types_allowed=True, + use_enum_values = True) -class MeshChemicalIdentifier(str, Enum): +class MeshChemicalIdentifier(str): dummy = "dummy" -class MeshDiseaseIdentifier(str, Enum): +class MeshDiseaseIdentifier(str): dummy = "dummy" @@ -57,29 +58,58 @@ class ExtractionResult(ConfiguredBaseModel): 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 Chemical(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""") + + @field_validator('id') + def pattern_id(cls, v): + pattern=re.compile(r"^MESH:[CD][0-9]{6}$") + if isinstance(v,list): + for element in v: + if not pattern.match(element): + raise ValueError(f"Invalid id format: {element}") + elif isinstance(v,str): + if not pattern.match(v): + raise ValueError(f"Invalid id format: {v}") + return v + 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""") + + @field_validator('id') + def pattern_id(cls, v): + pattern=re.compile(r"^MESH:[CD][0-9]{6}$") + if isinstance(v,list): + for element in v: + if not pattern.match(element): + raise ValueError(f"Invalid id format: {element}") + elif isinstance(v,str): + if not pattern.match(v): + raise ValueError(f"Invalid id format: {v}") + return v + class CompoundExpression(ConfiguredBaseModel): None + class Triple(CompoundExpression): """ @@ -92,6 +122,7 @@ class Triple(CompoundExpression): 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): """ @@ -100,6 +131,7 @@ class TextWithTriples(ConfiguredBaseModel): publication: Optional[Publication] = Field(None) triples: Optional[List[Triple]] = Field(default_factory=list) + class TextWithEntity(ConfiguredBaseModel): """ @@ -108,6 +140,7 @@ class TextWithEntity(ConfiguredBaseModel): publication: Optional[Publication] = Field(None) entities: Optional[List[str]] = Field(default_factory=list) + class ChemicalToDiseaseDocument(TextWithEntity): """ @@ -118,12 +151,14 @@ class ChemicalToDiseaseDocument(TextWithEntity): 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): @@ -133,6 +168,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -140,6 +176,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -156,4 +193,4 @@ class AnnotatorResult(ConfiguredBaseModel): RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/datasheet.py b/src/ontogpt/templates/datasheet.py index 64d4b2a7c..015348f36 100644 --- a/src/ontogpt/templates/datasheet.py +++ b/src/ontogpt/templates/datasheet.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -45,12 +46,14 @@ class ExtractionResult(ConfiguredBaseModel): 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: Optional[str] = Field(None, description="""A unique identifier for the named entity""") + 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 Dataset(NamedEntity): """ @@ -69,17 +72,20 @@ class Dataset(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 Organization(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 Triple(CompoundExpression): """ @@ -92,18 +98,32 @@ class Triple(CompoundExpression): 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): @@ -113,6 +133,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -120,6 +141,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -131,7 +153,8 @@ class AnnotatorResult(ConfiguredBaseModel): CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/desiccation.py b/src/ontogpt/templates/desiccation.py new file mode 100644 index 000000000..ca92d9d16 --- /dev/null +++ b/src/ontogpt/templates/desiccation.py @@ -0,0 +1,167 @@ +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, field_validator +import re +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 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 EntityContainingDocument(NamedEntity): + + environmental_conditions: Optional[List[str]] = Field(default_factory=list, description="""A semicolon-separated list of environmental terms.""") + taxa: Optional[List[str]] = Field(default_factory=list, description="""A semicolon-separated list of taxonomic terms of living things.""") + traits: Optional[List[str]] = Field(default_factory=list, description="""A semicolon-separated list of plant traits.""") + 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 EnvironmentalCondition(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 Taxon(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 Trait(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 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 +ExtractionResult.model_rebuild() +NamedEntity.model_rebuild() +EntityContainingDocument.model_rebuild() +EnvironmentalCondition.model_rebuild() +Taxon.model_rebuild() +Trait.model_rebuild() +CompoundExpression.model_rebuild() +Triple.model_rebuild() +TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() +RelationshipType.model_rebuild() +Publication.model_rebuild() +AnnotatorResult.model_rebuild() + diff --git a/src/ontogpt/templates/desiccation.yaml b/src/ontogpt/templates/desiccation.yaml new file mode 100644 index 000000000..88f78e2b4 --- /dev/null +++ b/src/ontogpt/templates/desiccation.yaml @@ -0,0 +1,67 @@ +id: http://w3id.org/ontogpt/desiccation +name: desiccation +title: desiccationTemplate +description: >- + A template for extracting ChEBI, GO, NCBITAXON, PO, TO, PECO +license: https://creativecommons.org/publicdomain/zero/1.0/ +prefixes: + linkml: https://w3id.org/linkml/ + desiccation: http://w3id.org/ontogpt/desiccation + +default_prefix: desiccation +default_range: string + +imports: + - linkml:types + - core + +classes: + EntityContainingDocument: + tree_root: true + is_a: NamedEntity + attributes: + environmental_conditions: + range: EnvironmentalCondition + multivalued: true + description: >- + A semicolon-separated list of environmental terms. + taxa: + range: Taxon + multivalued: true + description: >- + A semicolon-separated list of taxonomic terms of living things. + traits: + range: Trait + multivalued: true + description: >- + A semicolon-separated list of plant traits. + + EnvironmentalCondition: + is_a: NamedEntity + id_prefixes: + - PECO + annotations: + annotators: sqlite:obo:peco + prompt: >- + the name of an environmental treatment. + Examples are drought, salt stress, cold tolerance. + + Taxon: + is_a: NamedEntity + id_prefixes: + - NCBITaxon + annotations: + annotators: sqlite:obo:ncbitaxon + prompt: >- + the name of a taxonomic name or species. + Examples are Bacillus subtilus, Bos taurus, blue whale. + + Trait: + is_a: NamedEntity + id_prefixes: + - TO + annotations: + annotators: sqlite:obo:to + prompt: >- + the description of a plant trait. + Examples of trait categories are germination ratio, fruit hollowness, arid region exposure. \ No newline at end of file diff --git a/src/ontogpt/templates/diagnostic_procedure.py b/src/ontogpt/templates/diagnostic_procedure.py index 4f97cce9c..f4adaff0c 100644 --- a/src/ontogpt/templates/diagnostic_procedure.py +++ b/src/ontogpt/templates/diagnostic_procedure.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -45,24 +46,28 @@ class ExtractionResult(ConfiguredBaseModel): 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: Optional[str] = Field(None, description="""A unique identifier for the named entity""") + 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 DiagnosticProcedure(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 Phenotype(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 ClinicalAttribute(NamedEntity): @@ -70,23 +75,27 @@ class ClinicalAttribute(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 Quality(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 Triple(CompoundExpression): """ @@ -99,6 +108,7 @@ class Triple(CompoundExpression): 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 DiagnosticProceduretoPhenotypeAssociation(Triple): """ @@ -111,6 +121,7 @@ class DiagnosticProceduretoPhenotypeAssociation(Triple): subject_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the procedure.""") object_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the phenotype.""") + class DiagnosticProceduretoAttributeAssociation(Triple): """ @@ -123,18 +134,32 @@ class DiagnosticProceduretoAttributeAssociation(Triple): subject_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the procedure.""") object_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the phenotype.""") + 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 ProcedureToPhenotypePredicate(RelationshipType): """ @@ -143,6 +168,7 @@ class ProcedureToPhenotypePredicate(RelationshipType): 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 ProcedureToAttributePredicate(RelationshipType): """ @@ -151,6 +177,7 @@ class ProcedureToAttributePredicate(RelationshipType): 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): @@ -160,6 +187,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -167,6 +195,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -183,9 +212,10 @@ class AnnotatorResult(ConfiguredBaseModel): DiagnosticProceduretoPhenotypeAssociation.model_rebuild() DiagnosticProceduretoAttributeAssociation.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() ProcedureToPhenotypePredicate.model_rebuild() ProcedureToAttributePredicate.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/drug.py b/src/ontogpt/templates/drug.py index ad98ce255..4f18d6d7d 100644 --- a/src/ontogpt/templates/drug.py +++ b/src/ontogpt/templates/drug.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -41,6 +42,7 @@ class DrugMechanism(ConfiguredBaseModel): references: Optional[List[str]] = Field(default_factory=list) source_text: Optional[str] = Field(None) + class ExtractionResult(ConfiguredBaseModel): """ @@ -54,41 +56,48 @@ class ExtractionResult(ConfiguredBaseModel): 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 MechanismElement(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 Drug(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 Predicate(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 MechanismLink(CompoundExpression): @@ -96,6 +105,7 @@ class MechanismLink(CompoundExpression): predicate: Optional[str] = Field(None) object: Optional[str] = Field(None) + class Triple(CompoundExpression): """ @@ -108,18 +118,32 @@ class Triple(CompoundExpression): 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): @@ -129,6 +153,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -136,6 +161,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -151,7 +177,8 @@ class AnnotatorResult(ConfiguredBaseModel): MechanismLink.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/emapa_simple.py b/src/ontogpt/templates/emapa_simple.py index e4071fef8..8b4337c9d 100644 --- a/src/ontogpt/templates/emapa_simple.py +++ b/src/ontogpt/templates/emapa_simple.py @@ -2,7 +2,8 @@ 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 +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -45,12 +46,14 @@ class ExtractionResult(ConfiguredBaseModel): 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 OntologyTermSet(NamedEntity): @@ -58,17 +61,20 @@ class OntologyTermSet(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 OntologyTerm(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 Triple(CompoundExpression): """ @@ -81,6 +87,7 @@ class Triple(CompoundExpression): 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): """ @@ -89,6 +96,7 @@ class TextWithTriples(ConfiguredBaseModel): publication: Optional[Publication] = Field(None) triples: Optional[List[Triple]] = Field(default_factory=list) + class TextWithEntity(ConfiguredBaseModel): """ @@ -97,12 +105,14 @@ class TextWithEntity(ConfiguredBaseModel): 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): @@ -112,6 +122,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -119,6 +130,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild diff --git a/src/ontogpt/templates/environmental_metadata.py b/src/ontogpt/templates/environmental_metadata.py index 8d08f30ff..dbc136283 100644 --- a/src/ontogpt/templates/environmental_metadata.py +++ b/src/ontogpt/templates/environmental_metadata.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -42,6 +43,7 @@ class Dataset(ConfiguredBaseModel): environments: Optional[List[str]] = Field(default_factory=list, description="""the environmental context in which the study was conducted""") methods: Optional[List[str]] = Field(default_factory=list) + class ExtractionResult(ConfiguredBaseModel): """ @@ -55,47 +57,55 @@ class ExtractionResult(ConfiguredBaseModel): 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 Topic(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 Location(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 EnvironmentalMaterial(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 Environment(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 Method(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 Triple(CompoundExpression): """ @@ -108,18 +118,32 @@ class Triple(CompoundExpression): 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): @@ -129,6 +153,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -136,6 +161,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -151,7 +177,8 @@ class AnnotatorResult(ConfiguredBaseModel): CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/environmental_sample.py b/src/ontogpt/templates/environmental_sample.py index caea36ae9..f92ca1a24 100644 --- a/src/ontogpt/templates/environmental_sample.py +++ b/src/ontogpt/templates/environmental_sample.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -42,6 +43,7 @@ class Study(ConfiguredBaseModel): variables: Optional[List[str]] = Field(default_factory=list) measurements: Optional[List[Measurement]] = Field(default_factory=list) + class ExtractionResult(ConfiguredBaseModel): """ @@ -55,59 +57,69 @@ class ExtractionResult(ConfiguredBaseModel): 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 Location(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 EnvironmentalMaterial(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 Environment(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 Variable(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 Measurement(CompoundExpression): value: Optional[str] = Field(None, description="""the value of the measurement""") unit: Optional[str] = Field(None, description="""the unit of the measurement""") + class CausalRelationship(CompoundExpression): cause: Optional[str] = Field(None, description="""the variable that is the cause of the effect""") effect: Optional[str] = Field(None, description="""the things that is affected""") + class Triple(CompoundExpression): """ @@ -120,18 +132,32 @@ class Triple(CompoundExpression): 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): @@ -141,6 +167,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -148,6 +175,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -165,7 +193,8 @@ class AnnotatorResult(ConfiguredBaseModel): CausalRelationship.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/figure.py b/src/ontogpt/templates/figure.py index e56dc35dd..6c3eaa644 100644 --- a/src/ontogpt/templates/figure.py +++ b/src/ontogpt/templates/figure.py @@ -2,8 +2,8 @@ from datetime import datetime, date 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 +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -14,17 +14,13 @@ metamodel_version = "None" version = "None" -class WeakRefShimBaseModel(BaseModel): - __slots__ = '__weakref__' - -class ConfiguredBaseModel(WeakRefShimBaseModel, - validate_assignment = True, - validate_all = True, - underscore_attrs_are_private = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -45,7 +41,7 @@ class FigureCaption(ConfiguredBaseModel): title: Optional[str] = Field(None, description="""the overall title of the figure caption""") subpanel: Optional[List[SubPanel]] = Field(default_factory=list, description="""a subpanel of the figure""") - + class SubPanel(ConfiguredBaseModel): """ @@ -55,7 +51,7 @@ class SubPanel(ConfiguredBaseModel): text: Optional[str] = Field(None, description="""The text associated with this figure subpanel""") info: Optional[str] = Field(None, description="""any information from the overall figure caption that applies to that subpanel (which may be duplicated across other subpanels).""") - + class ExtractionResult(ConfiguredBaseModel): """ @@ -69,20 +65,20 @@ class ExtractionResult(ConfiguredBaseModel): 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: Optional[str] = Field(None, description="""A unique identifier for the named entity""") + 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 Triple(CompoundExpression): """ @@ -95,21 +91,32 @@ class Triple(CompoundExpression): 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): @@ -119,7 +126,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") - + class AnnotatorResult(ConfiguredBaseModel): @@ -127,19 +134,20 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) - - - -# Update forward refs -# see https://pydantic-docs.helpmanual.io/usage/postponed_annotations/ -FigureCaption.update_forward_refs() -SubPanel.update_forward_refs() -ExtractionResult.update_forward_refs() -NamedEntity.update_forward_refs() -CompoundExpression.update_forward_refs() -Triple.update_forward_refs() -TextWithTriples.update_forward_refs() -RelationshipType.update_forward_refs() -Publication.update_forward_refs() -AnnotatorResult.update_forward_refs() + + + +# Model rebuild +# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model +FigureCaption.model_rebuild() +SubPanel.model_rebuild() +ExtractionResult.model_rebuild() +NamedEntity.model_rebuild() +CompoundExpression.model_rebuild() +Triple.model_rebuild() +TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() +RelationshipType.model_rebuild() +Publication.model_rebuild() +AnnotatorResult.model_rebuild() diff --git a/src/ontogpt/templates/gene_description_term.py b/src/ontogpt/templates/gene_description_term.py index fec9aa0ca..6312a4828 100644 --- a/src/ontogpt/templates/gene_description_term.py +++ b/src/ontogpt/templates/gene_description_term.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -41,6 +42,7 @@ class GeneDescription(ConfiguredBaseModel): narrative_summary: Optional[str] = Field(None, description="""A free text summary describing the function of the gene""") terms: Optional[List[str]] = Field(default_factory=list, description="""A semicolon separated list of controlled terms drawn from the Gene Ontology that describe the function of the gene""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -54,29 +56,34 @@ class ExtractionResult(ConfiguredBaseModel): 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 Gene(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 GeneDescriptionTerm(NamedEntity): label: Optional[str] = Field(None, description="""the name of the GO term""") id: str = Field(..., description="""A unique identifier for the named entity""") + class CompoundExpression(ConfiguredBaseModel): None + class Triple(CompoundExpression): """ @@ -89,18 +96,32 @@ class Triple(CompoundExpression): 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): @@ -110,6 +131,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -117,6 +139,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -129,7 +152,8 @@ class AnnotatorResult(ConfiguredBaseModel): CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/genesummary.py b/src/ontogpt/templates/genesummary.py new file mode 100644 index 000000000..ca21c9ffc --- /dev/null +++ b/src/ontogpt/templates/genesummary.py @@ -0,0 +1,140 @@ +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, field_validator +import re +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 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 Gene(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 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 +ExtractionResult.model_rebuild() +NamedEntity.model_rebuild() +Gene.model_rebuild() +CompoundExpression.model_rebuild() +Triple.model_rebuild() +TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() +RelationshipType.model_rebuild() +Publication.model_rebuild() +AnnotatorResult.model_rebuild() + diff --git a/src/ontogpt/templates/go_simple.py b/src/ontogpt/templates/go_simple.py index ae74e5470..47a0f6e3d 100644 --- a/src/ontogpt/templates/go_simple.py +++ b/src/ontogpt/templates/go_simple.py @@ -2,7 +2,8 @@ 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 +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -45,12 +46,14 @@ class ExtractionResult(ConfiguredBaseModel): 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 OntologyTermSet(NamedEntity): @@ -58,17 +61,20 @@ class OntologyTermSet(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 OntologyTerm(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 Triple(CompoundExpression): """ @@ -81,6 +87,7 @@ class Triple(CompoundExpression): 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): """ @@ -89,6 +96,7 @@ class TextWithTriples(ConfiguredBaseModel): publication: Optional[Publication] = Field(None) triples: Optional[List[Triple]] = Field(default_factory=list) + class TextWithEntity(ConfiguredBaseModel): """ @@ -97,12 +105,14 @@ class TextWithEntity(ConfiguredBaseModel): 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): @@ -112,6 +122,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -119,6 +130,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild diff --git a/src/ontogpt/templates/go_terms.py b/src/ontogpt/templates/go_terms.py index 06498fffb..e3714a0f2 100644 --- a/src/ontogpt/templates/go_terms.py +++ b/src/ontogpt/templates/go_terms.py @@ -2,7 +2,8 @@ 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 +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -17,7 +18,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra='forbid', + extra = 'forbid', arbitrary_types_allowed=True, use_enum_values = True) @@ -63,35 +64,41 @@ class ExtractionResult(ConfiguredBaseModel): 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 BiologicalProcess(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 CellularComponent(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 MolecularFunction(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 Triple(CompoundExpression): """ @@ -104,6 +111,7 @@ class Triple(CompoundExpression): 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): """ @@ -112,6 +120,7 @@ class TextWithTriples(ConfiguredBaseModel): publication: Optional[Publication] = Field(None) triples: Optional[List[Triple]] = Field(default_factory=list) + class TextWithEntity(ConfiguredBaseModel): """ @@ -120,6 +129,7 @@ class TextWithEntity(ConfiguredBaseModel): publication: Optional[Publication] = Field(None) entities: Optional[List[str]] = Field(default_factory=list) + class Document(TextWithEntity): """ @@ -131,12 +141,14 @@ class Document(TextWithEntity): 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): @@ -146,6 +158,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -153,6 +166,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild diff --git a/src/ontogpt/templates/go_terms_relational.py b/src/ontogpt/templates/go_terms_relational.py index b16cb2070..c5fbf8501 100644 --- a/src/ontogpt/templates/go_terms_relational.py +++ b/src/ontogpt/templates/go_terms_relational.py @@ -2,7 +2,8 @@ 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 +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -17,7 +18,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra='forbid', + extra = 'forbid', arbitrary_types_allowed=True, use_enum_values = True) @@ -45,29 +46,34 @@ class ExtractionResult(ConfiguredBaseModel): 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 Protein(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 GOTerm(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 Triple(CompoundExpression): """ @@ -80,6 +86,7 @@ class Triple(CompoundExpression): 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 ProteinToGORelationship(Triple): """ @@ -92,6 +99,7 @@ class ProteinToGORelationship(Triple): subject_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the protein.""") object_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the GO term.""") + class TextWithTriples(ConfiguredBaseModel): """ @@ -100,6 +108,7 @@ class TextWithTriples(ConfiguredBaseModel): publication: Optional[Publication] = Field(None) triples: Optional[List[Triple]] = Field(default_factory=list) + class Document(TextWithTriples): """ @@ -108,6 +117,7 @@ class Document(TextWithTriples): publication: Optional[Publication] = Field(None) triples: Optional[List[ProteinToGORelationship]] = Field(default_factory=list) + class TextWithEntity(ConfiguredBaseModel): """ @@ -116,12 +126,14 @@ class TextWithEntity(ConfiguredBaseModel): 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 ProteinToGOPredicate(RelationshipType): """ @@ -130,6 +142,7 @@ class ProteinToGOPredicate(RelationshipType): 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): @@ -139,6 +152,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -146,6 +160,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild diff --git a/src/ontogpt/templates/gocam.py b/src/ontogpt/templates/gocam.py index 053cb1d86..c1ebd5ea3 100644 --- a/src/ontogpt/templates/gocam.py +++ b/src/ontogpt/templates/gocam.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,28 +14,28 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +class ConfiguredBaseModel(BaseModel): + model_config = ConfigDict( + validate_assignment=True, + validate_default=True, + extra = 'forbid', + arbitrary_types_allowed=True, + use_enum_values = True) -class GeneLocationEnum(str, Enum): +class GeneLocationEnum(str): dummy = "dummy" -class GOCellComponentType(str, Enum): +class GOCellComponentType(str): dummy = "dummy" -class CellType(str, Enum): +class CellType(str): dummy = "dummy" @@ -63,6 +64,7 @@ class GoCamAnnotations(ConfiguredBaseModel): gene_gene_interactions: Optional[List[GeneGeneInteraction]] = Field(default_factory=list, description="""semicolon-separated list of gene to gene interactions""") gene_localizations: Optional[List[GeneSubcellularLocalizationRelationship]] = Field(default_factory=list, description="""semicolon-separated list of genes plus their location in the cell; for example, \"gene1 / cytoplasm; gene2 / mitochondrion\"""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -76,71 +78,83 @@ class ExtractionResult(ConfiguredBaseModel): 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 Gene(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 Pathway(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 CellularProcess(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 MolecularActivity(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 GeneLocation(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 Organism(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 Molecule(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 GeneOrganismRelationship(CompoundExpression): gene: Optional[str] = Field(None) organism: Optional[str] = Field(None) + class GeneMolecularActivityRelationship(CompoundExpression): gene: Optional[str] = Field(None) molecular_activity: Optional[str] = Field(None) + class GeneMolecularActivityRelationship2(CompoundExpression): @@ -148,18 +162,21 @@ class GeneMolecularActivityRelationship2(CompoundExpression): molecular_activity: Optional[str] = Field(None) target: Optional[str] = Field(None) + class GeneSubcellularLocalizationRelationship(CompoundExpression): gene: Optional[str] = Field(None) location: Optional[str] = Field(None) + class GeneGeneInteraction(CompoundExpression): gene1: Optional[str] = Field(None) gene2: Optional[str] = Field(None) + class Triple(CompoundExpression): """ @@ -172,18 +189,32 @@ class Triple(CompoundExpression): 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): @@ -193,6 +224,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -200,6 +232,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -222,7 +255,8 @@ class AnnotatorResult(ConfiguredBaseModel): GeneGeneInteraction.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/halo.py b/src/ontogpt/templates/halo.py index 37a8cabb5..505a08053 100644 --- a/src/ontogpt/templates/halo.py +++ b/src/ontogpt/templates/halo.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -37,6 +38,7 @@ class Ontology(ConfiguredBaseModel): elements: Optional[List[OntologyElement]] = Field(default_factory=list) + class OntologyElement(ConfiguredBaseModel): @@ -51,6 +53,7 @@ class OntologyElement(ConfiguredBaseModel): parts: Optional[List[str]] = Field(default_factory=list, description="""a list of names of things this element has as parts (components)""") equivalent_to: Optional[str] = Field(None, description="""an OWL class expression with the necessary and sufficient conditions for this entity to be an instance of this class""") + class Category(OntologyElement): @@ -65,6 +68,7 @@ class Category(OntologyElement): parts: Optional[List[str]] = Field(default_factory=list, description="""a list of names of things this element has as parts (components)""") equivalent_to: Optional[str] = Field(None, description="""an OWL class expression with the necessary and sufficient conditions for this entity to be an instance of this class""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -78,17 +82,20 @@ class ExtractionResult(ConfiguredBaseModel): 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: Optional[str] = Field(None, description="""A unique identifier for the named entity""") + 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 Triple(CompoundExpression): """ @@ -101,18 +108,32 @@ class Triple(CompoundExpression): 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): @@ -122,6 +143,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -129,6 +151,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -141,7 +164,8 @@ class AnnotatorResult(ConfiguredBaseModel): CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/human_phenotype.py b/src/ontogpt/templates/human_phenotype.py index 2e392604c..3170dad2e 100644 --- a/src/ontogpt/templates/human_phenotype.py +++ b/src/ontogpt/templates/human_phenotype.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -45,12 +46,14 @@ class ExtractionResult(ConfiguredBaseModel): 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: Optional[str] = Field(None, description="""A unique identifier for the named entity""") + 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 HumanPhenotypeSet(NamedEntity): @@ -58,17 +61,20 @@ class HumanPhenotypeSet(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 HumanPhenotype(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 Triple(CompoundExpression): """ @@ -81,18 +87,32 @@ class Triple(CompoundExpression): 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): @@ -102,6 +122,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -109,6 +130,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -120,7 +142,8 @@ class AnnotatorResult(ConfiguredBaseModel): CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/ibd.py b/src/ontogpt/templates/ibd.py index 8f745c29d..c3f18f7d1 100644 --- a/src/ontogpt/templates/ibd.py +++ b/src/ontogpt/templates/ibd.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,28 +14,28 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +class ConfiguredBaseModel(BaseModel): + model_config = ConfigDict( + validate_assignment=True, + validate_default=True, + extra = 'forbid', + arbitrary_types_allowed=True, + use_enum_values = True) -class GeneLocationEnum(str, Enum): +class GeneLocationEnum(str): dummy = "dummy" -class GOCellComponentType(str, Enum): +class GOCellComponentType(str): dummy = "dummy" -class CellType(str, Enum): +class CellType(str): dummy = "dummy" @@ -63,6 +64,7 @@ class IBDAnnotations(ConfiguredBaseModel): gene_gene_interactions: Optional[List[GeneGeneInteraction]] = Field(default_factory=list, description="""semicolon-separated list of gene to gene interactions""") gene_localizations: Optional[List[GeneSubcellularLocalizationRelationship]] = Field(default_factory=list, description="""semicolon-separated list of genes plus their location in the cell; for example, \"gene1 / cytoplasm; gene2 / mitochondrion\"""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -76,71 +78,83 @@ class ExtractionResult(ConfiguredBaseModel): 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 Gene(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 Pathway(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 CellularProcess(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 MolecularActivity(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 GeneLocation(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 Organism(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 Molecule(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 GeneOrganismRelationship(CompoundExpression): gene: Optional[str] = Field(None) organism: Optional[str] = Field(None) + class GeneMolecularActivityRelationship(CompoundExpression): gene: Optional[str] = Field(None) molecular_activity: Optional[str] = Field(None) + class GeneMolecularActivityRelationship2(CompoundExpression): @@ -148,18 +162,21 @@ class GeneMolecularActivityRelationship2(CompoundExpression): molecular_activity: Optional[str] = Field(None) target: Optional[str] = Field(None) + class GeneSubcellularLocalizationRelationship(CompoundExpression): gene: Optional[str] = Field(None) location: Optional[str] = Field(None) + class GeneGeneInteraction(CompoundExpression): gene1: Optional[str] = Field(None) gene2: Optional[str] = Field(None) + class Triple(CompoundExpression): """ @@ -172,18 +189,32 @@ class Triple(CompoundExpression): 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): @@ -193,6 +224,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -200,6 +232,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -222,7 +255,8 @@ class AnnotatorResult(ConfiguredBaseModel): GeneGeneInteraction.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/ibd_literature.py b/src/ontogpt/templates/ibd_literature.py index 250915be3..2a54f0e32 100644 --- a/src/ontogpt/templates/ibd_literature.py +++ b/src/ontogpt/templates/ibd_literature.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -42,6 +43,7 @@ class IBDAnnotations(ConfiguredBaseModel): cellular_process: Optional[List[str]] = Field(default_factory=list, description="""semicolon-separated list of cellular processes""") disease_cellular_process_relationships: Optional[List[DiseaseCellularProcessRelationship]] = Field(default_factory=list, description="""semicolon-separated list of disease to cellular process relationships""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -55,53 +57,62 @@ class ExtractionResult(ConfiguredBaseModel): 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 Gene(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 ChemicalExposure(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 ChemicalExposureToGenePredicate(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 CellularProcess(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 DiseaseToCellularProcessPredicate(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 GeneExposureRelationship(CompoundExpression): @@ -111,6 +122,7 @@ class GeneExposureRelationship(CompoundExpression): subject_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the chemical exposure.""") object_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the gene.""") + class DiseaseCellularProcessRelationship(CompoundExpression): @@ -120,6 +132,7 @@ class DiseaseCellularProcessRelationship(CompoundExpression): subject_qualifier: Optional[str] = Field(None) object_qualifier: Optional[str] = Field(None) + class Triple(CompoundExpression): """ @@ -132,18 +145,32 @@ class Triple(CompoundExpression): 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): @@ -153,6 +180,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -160,6 +188,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -178,7 +207,8 @@ class AnnotatorResult(ConfiguredBaseModel): DiseaseCellularProcessRelationship.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/kidney.py b/src/ontogpt/templates/kidney.py index 1081867a8..d56fade94 100644 --- a/src/ontogpt/templates/kidney.py +++ b/src/ontogpt/templates/kidney.py @@ -1,29 +1,35 @@ from __future__ import annotations from datetime import datetime, date from enum import Enum -from typing import List, Dict, Optional, Any, Union, Literal -from pydantic import BaseModel as BaseModel, Field -from linkml_runtime.linkml_model import Decimal +from typing import List, Dict, Optional, Any, Union +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re +import sys +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + metamodel_version = "None" version = "None" -class WeakRefShimBaseModel(BaseModel): - __slots__ = '__weakref__' - -class ConfiguredBaseModel(WeakRefShimBaseModel, - validate_assignment = True, - validate_all = True, - underscore_attrs_are_private = True, - extra = 'forbid', - arbitrary_types_allowed = True): - pass +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" @@ -33,7 +39,7 @@ class KidneyAnnotations(ConfiguredBaseModel): cell_type: Optional[List[str]] = Field(default_factory=list) gene: Optional[List[str]] = Field(default_factory=list, description="""A gene""") - + class ExtractionResult(ConfiguredBaseModel): """ @@ -47,34 +53,34 @@ class ExtractionResult(ConfiguredBaseModel): 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: Optional[str] = Field(None, description="""A unique identifier for the named entity""") + 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 CellType(NamedEntity): - id: Optional[str] = Field(None, description="""A unique identifier for the named entity""") + 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 Gene(NamedEntity): - id: Optional[str] = Field(None, description="""A unique identifier for the named entity""") + 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 Triple(CompoundExpression): """ @@ -87,21 +93,32 @@ class Triple(CompoundExpression): 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: Optional[str] = Field(None, description="""A unique identifier for the named entity""") + 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): @@ -111,7 +128,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") - + class AnnotatorResult(ConfiguredBaseModel): @@ -119,20 +136,21 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) - - - -# Update forward refs -# see https://pydantic-docs.helpmanual.io/usage/postponed_annotations/ -KidneyAnnotations.update_forward_refs() -ExtractionResult.update_forward_refs() -NamedEntity.update_forward_refs() -CellType.update_forward_refs() -Gene.update_forward_refs() -CompoundExpression.update_forward_refs() -Triple.update_forward_refs() -TextWithTriples.update_forward_refs() -RelationshipType.update_forward_refs() -Publication.update_forward_refs() -AnnotatorResult.update_forward_refs() + + + +# Model rebuild +# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model +KidneyAnnotations.model_rebuild() +ExtractionResult.model_rebuild() +NamedEntity.model_rebuild() +CellType.model_rebuild() +Gene.model_rebuild() +CompoundExpression.model_rebuild() +Triple.model_rebuild() +TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() +RelationshipType.model_rebuild() +Publication.model_rebuild() +AnnotatorResult.model_rebuild() diff --git a/src/ontogpt/templates/maxo.py b/src/ontogpt/templates/maxo.py index e79d54fd7..f803d26c1 100644 --- a/src/ontogpt/templates/maxo.py +++ b/src/ontogpt/templates/maxo.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -45,12 +46,14 @@ class ExtractionResult(ConfiguredBaseModel): 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 Action(NamedEntity): """ @@ -59,6 +62,7 @@ class Action(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): """ @@ -67,6 +71,7 @@ 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 Symptom(NamedEntity): """ @@ -75,11 +80,13 @@ class Symptom(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 Triple(CompoundExpression): """ @@ -92,6 +99,7 @@ class Triple(CompoundExpression): 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 ActionToDiseaseRelationship(Triple): """ @@ -104,6 +112,7 @@ class ActionToDiseaseRelationship(Triple): subject_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the medical action.""") object_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the disease.""") + class ActionToSymptomRelationship(Triple): """ @@ -116,6 +125,7 @@ class ActionToSymptomRelationship(Triple): subject_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the medical action.""") object_qualifier: Optional[str] = Field(None, description="""An optional qualifier or modifier for the symptom.""") + class TextWithTriples(ConfiguredBaseModel): """ @@ -124,6 +134,7 @@ class TextWithTriples(ConfiguredBaseModel): publication: Optional[Publication] = Field(None) triples: Optional[List[Triple]] = Field(default_factory=list) + class MaxoAnnotations(TextWithTriples): @@ -135,6 +146,7 @@ class MaxoAnnotations(TextWithTriples): publication: Optional[Publication] = Field(None) triples: Optional[List[Triple]] = Field(default_factory=list) + class TextWithEntity(ConfiguredBaseModel): """ @@ -143,12 +155,14 @@ class TextWithEntity(ConfiguredBaseModel): 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): @@ -158,6 +172,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -165,6 +180,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -184,4 +200,4 @@ class AnnotatorResult(ConfiguredBaseModel): RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/mendelian_disease.py b/src/ontogpt/templates/mendelian_disease.py index 368adc838..da2ff02d3 100644 --- a/src/ontogpt/templates/mendelian_disease.py +++ b/src/ontogpt/templates/mendelian_disease.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -45,12 +46,14 @@ class ExtractionResult(ConfiguredBaseModel): 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: Optional[str] = Field(None, description="""A unique identifier for the named entity""") + 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 MendelianDisease(NamedEntity): @@ -66,18 +69,21 @@ class MendelianDisease(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 DiseaseCategory(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 Gene(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 Symptom(NamedEntity): @@ -88,6 +94,7 @@ class Symptom(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 Onset(NamedEntity): @@ -97,17 +104,20 @@ class Onset(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 Inheritance(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 Triple(CompoundExpression): """ @@ -120,18 +130,32 @@ class Triple(CompoundExpression): 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): @@ -141,6 +165,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -148,6 +173,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -163,7 +189,8 @@ class AnnotatorResult(ConfiguredBaseModel): CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/metabolic_process.py b/src/ontogpt/templates/metabolic_process.py index 62af3f51e..d6c39c015 100644 --- a/src/ontogpt/templates/metabolic_process.py +++ b/src/ontogpt/templates/metabolic_process.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -45,12 +46,14 @@ class ExtractionResult(ConfiguredBaseModel): 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: Optional[str] = Field(None, description="""A unique identifier for the named entity""") + 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 MetabolicProcess(NamedEntity): @@ -63,23 +66,27 @@ class MetabolicProcess(NamedEntity): outputs: Optional[List[str]] = Field(default_factory=list, description="""the outputs of the metabolic process""") id: str = Field(..., description="""A unique identifier for the named entity""") + class MetabolicProcessCategory(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 ChemicalEntity(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 Triple(CompoundExpression): """ @@ -92,18 +99,32 @@ class Triple(CompoundExpression): 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): @@ -113,6 +134,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -120,6 +142,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -132,7 +155,8 @@ class AnnotatorResult(ConfiguredBaseModel): CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/metagenome_study.py b/src/ontogpt/templates/metagenome_study.py index 522fc8133..e8a6d76dd 100644 --- a/src/ontogpt/templates/metagenome_study.py +++ b/src/ontogpt/templates/metagenome_study.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -45,6 +46,7 @@ class Study(ConfiguredBaseModel): sequencing_technologies: Optional[str] = Field(None) organisms: Optional[List[str]] = Field(default_factory=list, description="""semicolon-separated list of all studied organism taxons""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -58,77 +60,90 @@ class ExtractionResult(ConfiguredBaseModel): 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 Location(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 EnvironmentalMaterial(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 Environment(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 Variable(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 SequencingTechnology(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 Treatment(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 Organism(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 Measurement(CompoundExpression): value: Optional[str] = Field(None, description="""the value of the measurement""") unit: Optional[str] = Field(None, description="""the unit of the measurement""") + class CausalRelationship(CompoundExpression): cause: Optional[str] = Field(None, description="""the variable that is the cause of the effect""") effect: Optional[str] = Field(None, description="""the things that is affected""") + class Triple(CompoundExpression): """ @@ -141,18 +156,32 @@ class Triple(CompoundExpression): 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): @@ -162,6 +191,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -169,6 +199,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -189,7 +220,8 @@ class AnnotatorResult(ConfiguredBaseModel): CausalRelationship.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/mondo_simple.py b/src/ontogpt/templates/mondo_simple.py index 09027f9de..3e892a986 100644 --- a/src/ontogpt/templates/mondo_simple.py +++ b/src/ontogpt/templates/mondo_simple.py @@ -2,7 +2,8 @@ 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 +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -45,12 +46,14 @@ class ExtractionResult(ConfiguredBaseModel): 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 OntologyTermSet(NamedEntity): @@ -58,17 +61,20 @@ class OntologyTermSet(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 OntologyTerm(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 Triple(CompoundExpression): """ @@ -81,6 +87,7 @@ class Triple(CompoundExpression): 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): """ @@ -89,6 +96,7 @@ class TextWithTriples(ConfiguredBaseModel): publication: Optional[Publication] = Field(None) triples: Optional[List[Triple]] = Field(default_factory=list) + class TextWithEntity(ConfiguredBaseModel): """ @@ -97,12 +105,14 @@ class TextWithEntity(ConfiguredBaseModel): 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): @@ -112,6 +122,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -119,6 +130,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild diff --git a/src/ontogpt/templates/nmdc_schema_data.py b/src/ontogpt/templates/nmdc_schema_data.py index 220e68c00..42172a68a 100644 --- a/src/ontogpt/templates/nmdc_schema_data.py +++ b/src/ontogpt/templates/nmdc_schema_data.py @@ -1,29 +1,35 @@ from __future__ import annotations from datetime import datetime, date from enum import Enum -from typing import List, Dict, Optional, Any, Union, Literal -from pydantic import BaseModel as BaseModel, Field -from linkml_runtime.linkml_model import Decimal +from typing import List, Dict, Optional, Any, Union +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re +import sys +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + metamodel_version = "None" version = "None" -class WeakRefShimBaseModel(BaseModel): - __slots__ = '__weakref__' - -class ConfiguredBaseModel(WeakRefShimBaseModel, - validate_assignment = True, - validate_all = True, - underscore_attrs_are_private = True, - extra = 'forbid', - arbitrary_types_allowed = True): - pass +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" @@ -34,7 +40,7 @@ class Dataset(ConfiguredBaseModel): environmental_material: Optional[List[str]] = Field(default_factory=list, description="""the environmental material that was sampled""") environments: Optional[List[str]] = Field(default_factory=list, description="""the environmental context in which the study was conducted""") - + class ExtractionResult(ConfiguredBaseModel): """ @@ -48,34 +54,34 @@ class ExtractionResult(ConfiguredBaseModel): 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(None, description="""A unique identifier for the named entity""") + 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 EnvironmentalMaterial(NamedEntity): - id: str = Field(None, description="""A unique identifier for the named entity""") + 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 Environment(NamedEntity): - id: str = Field(None, description="""A unique identifier for the named entity""") + 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 Triple(CompoundExpression): """ @@ -88,21 +94,32 @@ class Triple(CompoundExpression): 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(None, description="""A unique identifier for the named entity""") + 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): @@ -112,7 +129,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") - + class AnnotatorResult(ConfiguredBaseModel): @@ -120,20 +137,21 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) - - - -# Update forward refs -# see https://pydantic-docs.helpmanual.io/usage/postponed_annotations/ -Dataset.update_forward_refs() -ExtractionResult.update_forward_refs() -NamedEntity.update_forward_refs() -EnvironmentalMaterial.update_forward_refs() -Environment.update_forward_refs() -CompoundExpression.update_forward_refs() -Triple.update_forward_refs() -TextWithTriples.update_forward_refs() -RelationshipType.update_forward_refs() -Publication.update_forward_refs() -AnnotatorResult.update_forward_refs() + + + +# Model rebuild +# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model +Dataset.model_rebuild() +ExtractionResult.model_rebuild() +NamedEntity.model_rebuild() +EnvironmentalMaterial.model_rebuild() +Environment.model_rebuild() +CompoundExpression.model_rebuild() +Triple.model_rebuild() +TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() +RelationshipType.model_rebuild() +Publication.model_rebuild() +AnnotatorResult.model_rebuild() diff --git a/src/ontogpt/templates/ontology_class.py b/src/ontogpt/templates/ontology_class.py index 0aeb70ea6..588529fcd 100644 --- a/src/ontogpt/templates/ontology_class.py +++ b/src/ontogpt/templates/ontology_class.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -39,6 +40,7 @@ class LogicalDefinition(ConfiguredBaseModel): differentiating_characteristic_relationship: Optional[str] = Field(None) differentiating_characteristic_parents: Optional[List[str]] = Field(default_factory=list) + class ExtractionResult(ConfiguredBaseModel): """ @@ -52,12 +54,14 @@ class ExtractionResult(ConfiguredBaseModel): 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 OntologyClass(NamedEntity): @@ -69,17 +73,20 @@ class OntologyClass(NamedEntity): logical_definition: Optional[LogicalDefinition] = Field(None, description="""the necessary and sufficient conditions for this entity to be an instance of this class""") id: str = Field(..., description="""A unique identifier for the named entity""") + class Relation(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 Triple(CompoundExpression): """ @@ -92,18 +99,32 @@ class Triple(CompoundExpression): 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): @@ -113,6 +134,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -120,6 +142,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -132,7 +155,8 @@ class AnnotatorResult(ConfiguredBaseModel): CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/ontology_issue.py b/src/ontogpt/templates/ontology_issue.py index 2c0401479..3f3319e2e 100644 --- a/src/ontogpt/templates/ontology_issue.py +++ b/src/ontogpt/templates/ontology_issue.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +class ConfiguredBaseModel(BaseModel): + model_config = ConfigDict( + validate_assignment=True, + validate_default=True, + extra = 'forbid', + arbitrary_types_allowed=True, + use_enum_values = True) class ProblemType(str, Enum): @@ -76,6 +77,7 @@ class OntologyIssue(ConfiguredBaseModel): problem_list: Optional[List[OntologyProblem]] = Field(default_factory=list, description="""A list of problems stated at a high level""") proposed_changes: Optional[List[OntologyChange]] = Field(default_factory=list, description="""What part of the ontology does this pertain to.""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -89,23 +91,27 @@ class ExtractionResult(ConfiguredBaseModel): 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 OntologyClass(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 OntologyProblem(CompoundExpression): @@ -114,6 +120,7 @@ class OntologyProblem(CompoundExpression): category: Optional[ProblemType] = Field(None, description="""What category does this problem fall into?""") about: Optional[List[str]] = Field(default_factory=list, description="""What terms in the ontology is this problem about?""") + class OntologyChange(CompoundExpression): @@ -121,6 +128,7 @@ class OntologyChange(CompoundExpression): category: Optional[ChangeType] = Field(None, description="""What kind of change?""") about: Optional[List[str]] = Field(default_factory=list, description="""What terms in the ontology will this change affect?""") + class Triple(CompoundExpression): """ @@ -133,18 +141,32 @@ class Triple(CompoundExpression): 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): @@ -154,6 +176,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -161,6 +184,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -174,7 +198,8 @@ class AnnotatorResult(ConfiguredBaseModel): OntologyChange.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/phenotype.py b/src/ontogpt/templates/phenotype.py index fb166b96a..45e8cb1bf 100644 --- a/src/ontogpt/templates/phenotype.py +++ b/src/ontogpt/templates/phenotype.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -39,6 +40,7 @@ class Trait(ConfiguredBaseModel): anatomical_entity: Optional[str] = Field(None, description="""The anatomical location that the chemical entity is measured in""") chemical_entity: Optional[str] = Field(None, description="""The chemical entity that is being measured""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -52,35 +54,41 @@ class ExtractionResult(ConfiguredBaseModel): 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 Quality(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 ChemicalEntity(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 AnatomicalEntity(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 Triple(CompoundExpression): """ @@ -93,18 +101,32 @@ class Triple(CompoundExpression): 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): @@ -114,6 +136,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -121,6 +144,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -134,7 +158,8 @@ class AnnotatorResult(ConfiguredBaseModel): CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/reaction.py b/src/ontogpt/templates/reaction.py index 92d8cb18f..f836ecc97 100644 --- a/src/ontogpt/templates/reaction.py +++ b/src/ontogpt/templates/reaction.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -39,6 +40,7 @@ class GeneToReaction(ConfiguredBaseModel): reactions: Optional[Dict[str, Reaction]] = Field(default_factory=dict, description="""semicolon separated list of reaction equations (e.g. A+B = C+D) catalyzed by the gene""") organism: Optional[str] = Field(None) + class ReactionDocument(ConfiguredBaseModel): @@ -48,6 +50,7 @@ class ReactionDocument(ConfiguredBaseModel): organism: Optional[str] = Field(None) has_evidence: Optional[List[str]] = Field(default_factory=list, description="""evidence for the reaction""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -61,12 +64,14 @@ class ExtractionResult(ConfiguredBaseModel): 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 Reaction(NamedEntity): @@ -78,47 +83,55 @@ class Reaction(NamedEntity): right_side: Optional[List[str]] = Field(default_factory=list, description="""semicolon separated list of chemical entities on the right side""") id: str = Field(..., description="""A unique identifier for the named entity""") + class ReactionGrouping(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 ChemicalEntity(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 Evidence(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 Gene(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 Organism(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 GeneReactionPairing(CompoundExpression): gene: Optional[str] = Field(None, description="""name of the gene that catalyzes the reaction""") reaction: Optional[str] = Field(None, description="""equation describing the reaction (e.g. A+B = C+D) catalyzed by the gene""") + class Triple(CompoundExpression): """ @@ -131,18 +144,32 @@ class Triple(CompoundExpression): 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): @@ -152,6 +179,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -159,6 +187,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -177,7 +206,8 @@ class AnnotatorResult(ConfiguredBaseModel): GeneReactionPairing.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/recipe.py b/src/ontogpt/templates/recipe.py index 6b98d9a93..394e17304 100644 --- a/src/ontogpt/templates/recipe.py +++ b/src/ontogpt/templates/recipe.py @@ -2,7 +2,8 @@ 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 +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -17,7 +18,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra='forbid', + extra = 'forbid', arbitrary_types_allowed=True, use_enum_values = True) @@ -42,6 +43,7 @@ class Recipe(ConfiguredBaseModel): ingredients: Optional[List[Ingredient]] = Field(default_factory=list, description="""a semicolon separated list of the ingredients plus quantities of the recipe""") steps: Optional[List[Step]] = Field(default_factory=list, description="""a semicolon separated list of the individual steps involved in this recipe""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -55,59 +57,69 @@ class ExtractionResult(ConfiguredBaseModel): 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 FoodType(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 RecipeCategory(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 Action(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 UtensilType(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 Ingredient(CompoundExpression): food_item: Optional[FoodItem] = Field(None, description="""the food item""") amount: Optional[Quantity] = Field(None, description="""the quantity of the ingredient, e.g. 2 lbs""") + class Quantity(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 Step(CompoundExpression): @@ -116,12 +128,14 @@ class Step(CompoundExpression): outputs: Optional[List[FoodItem]] = Field(default_factory=list, description="""a semicolon separated list of the outputs of this step""") utensils: Optional[List[str]] = Field(default_factory=list, description="""the kitchen utensil used in this step (e.g. pan, bowl)""") + class FoodItem(CompoundExpression): food: Optional[str] = Field(None, description="""the food item""") state: Optional[str] = Field(None, description="""the state of the food item (e.g. chopped, diced)""") + class Triple(CompoundExpression): """ @@ -134,6 +148,7 @@ class Triple(CompoundExpression): 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): """ @@ -142,6 +157,7 @@ class TextWithTriples(ConfiguredBaseModel): publication: Optional[Publication] = Field(None) triples: Optional[List[Triple]] = Field(default_factory=list) + class TextWithEntity(ConfiguredBaseModel): """ @@ -150,12 +166,14 @@ class TextWithEntity(ConfiguredBaseModel): 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): @@ -165,6 +183,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -172,6 +191,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild diff --git a/src/ontogpt/templates/traits.py b/src/ontogpt/templates/traits.py index ce42f834e..37fc7d712 100644 --- a/src/ontogpt/templates/traits.py +++ b/src/ontogpt/templates/traits.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,13 +14,13 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +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): @@ -45,6 +46,7 @@ class Taxon(ConfiguredBaseModel): phenotypic_plasticiticy_traits: Optional[List[str]] = Field(default_factory=list, description="""The phenotypic plasticiticy traits for the taxon.""") preferred_environments: Optional[List[str]] = Field(default_factory=list, description="""The preferred environments for the taxon.""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -58,23 +60,27 @@ class ExtractionResult(ConfiguredBaseModel): 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 Trait(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 Triple(CompoundExpression): """ @@ -87,18 +93,32 @@ class Triple(CompoundExpression): 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): @@ -108,6 +128,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -115,6 +136,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -126,7 +148,8 @@ class AnnotatorResult(ConfiguredBaseModel): CompoundExpression.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - + diff --git a/src/ontogpt/templates/treatment.py b/src/ontogpt/templates/treatment.py index 8b9ada930..6644eeac4 100644 --- a/src/ontogpt/templates/treatment.py +++ b/src/ontogpt/templates/treatment.py @@ -2,7 +2,8 @@ from datetime import datetime, date from enum import Enum from typing import List, Dict, Optional, Any, Union -from pydantic import BaseModel as BaseModel, Field +from pydantic import BaseModel as BaseModel, ConfigDict, Field, field_validator +import re import sys if sys.version_info >= (3, 8): from typing import Literal @@ -13,46 +14,46 @@ metamodel_version = "None" version = "None" -class ConfiguredBaseModel(BaseModel, - validate_assignment = True, - validate_default = True, - extra = 'forbid', - arbitrary_types_allowed = True, - use_enum_values = True): - pass +class ConfiguredBaseModel(BaseModel): + model_config = ConfigDict( + validate_assignment=True, + validate_default=True, + extra = 'forbid', + arbitrary_types_allowed=True, + use_enum_values = True) -class NCITDrugType(str, Enum): +class NCITDrugType(str): dummy = "dummy" -class NCITTreatmentType(str, Enum): +class NCITTreatmentType(str): dummy = "dummy" -class NCITTActivityType(str, Enum): +class NCITTActivityType(str): dummy = "dummy" -class MAXOActionType(str, Enum): +class MAXOActionType(str): dummy = "dummy" -class MESHTherapeuticType(str, Enum): +class MESHTherapeuticType(str): dummy = "dummy" -class CHEBIDrugType(str, Enum): +class CHEBIDrugType(str): dummy = "dummy" @@ -79,6 +80,7 @@ class DiseaseTreatmentSummary(ConfiguredBaseModel): treatment_efficacies: Optional[List[TreatmentEfficacy]] = Field(default_factory=list, description="""semicolon-separated list of treatment to efficacy associations, e.g. Imatinib*effective""") treatment_adverse_effects: Optional[List[TreatmentAdverseEffect]] = Field(default_factory=list, description="""semicolon-separated list of treatment to adverse effect associations, e.g. Imatinib*nausea""") + class ExtractionResult(ConfiguredBaseModel): """ @@ -92,77 +94,90 @@ class ExtractionResult(ConfiguredBaseModel): 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 Gene(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 Symptom(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 AdverseEffect(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 Treatment(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 Mechanism(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 Drug(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 TreatmentMechanism(CompoundExpression): treatment: Optional[str] = Field(None) mechanism: Optional[str] = Field(None) + class TreatmentAdverseEffect(CompoundExpression): treatment: Optional[str] = Field(None) adverse_effects: Optional[List[str]] = Field(default_factory=list) + class TreatmentEfficacy(CompoundExpression): treatment: Optional[str] = Field(None) efficacy: Optional[str] = Field(None) + class Triple(CompoundExpression): """ @@ -175,18 +190,32 @@ class Triple(CompoundExpression): 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): @@ -196,6 +225,7 @@ class Publication(ConfiguredBaseModel): combined_text: Optional[str] = Field(None) full_text: Optional[str] = Field(None, description="""The full text of the publication""") + class AnnotatorResult(ConfiguredBaseModel): @@ -203,6 +233,7 @@ class AnnotatorResult(ConfiguredBaseModel): object_id: Optional[str] = Field(None) object_text: Optional[str] = Field(None) + # Model rebuild @@ -223,7 +254,8 @@ class AnnotatorResult(ConfiguredBaseModel): TreatmentEfficacy.model_rebuild() Triple.model_rebuild() TextWithTriples.model_rebuild() +TextWithEntity.model_rebuild() RelationshipType.model_rebuild() Publication.model_rebuild() AnnotatorResult.model_rebuild() - +