-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ontology usage extraction template (#393)
- Loading branch information
Showing
2 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
from __future__ import annotations | ||
from datetime import ( | ||
datetime, | ||
date | ||
) | ||
from decimal import Decimal | ||
from enum import Enum | ||
import re | ||
import sys | ||
from typing import ( | ||
Any, | ||
List, | ||
Literal, | ||
Dict, | ||
Optional, | ||
Union | ||
) | ||
from pydantic.version import VERSION as PYDANTIC_VERSION | ||
if int(PYDANTIC_VERSION[0])>=2: | ||
from pydantic import ( | ||
BaseModel, | ||
ConfigDict, | ||
Field, | ||
field_validator | ||
) | ||
else: | ||
from pydantic import ( | ||
BaseModel, | ||
Field, | ||
validator | ||
) | ||
|
||
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, | ||
strict = False, | ||
) | ||
pass | ||
|
||
|
||
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 CompoundExpression(ConfiguredBaseModel): | ||
pass | ||
|
||
|
||
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) | ||
|
||
|
||
class Document(NamedEntity): | ||
ontologies: Optional[List[str]] = Field(default_factory=list) | ||
use_cases: Optional[List[UseCase]] = Field(default_factory=list) | ||
id: str = Field(..., description="""A unique identifier for the named entity""") | ||
label: Optional[str] = Field(None, description="""The label (name) of the named thing""") | ||
|
||
|
||
class Ontology(NamedEntity): | ||
""" | ||
a single ontology name or abbreviation. | ||
""" | ||
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 UseCase(CompoundExpression): | ||
ontology: Optional[str] = Field(None, description="""The ontology involved in a specific use case.""") | ||
usecase: Optional[str] = Field(None, description="""A short description of the use case, in one or two sentences.""") | ||
|
||
|
||
# Model rebuild | ||
# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model | ||
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() | ||
Document.model_rebuild() | ||
Ontology.model_rebuild() | ||
UseCase.model_rebuild() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
id: http://w3id.org/ontogpt/onto_usage | ||
name: onto_usage | ||
title: Ontology Usage Extraction Template | ||
description: >- | ||
A template for extracting statements about the usage of ontologies in | ||
scientific literature. | ||
license: https://creativecommons.org/publicdomain/zero/1.0/ | ||
prefixes: | ||
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# | ||
onto_usage: http://w3id.org/ontogpt/onto_usage | ||
linkml: https://w3id.org/linkml/ | ||
|
||
default_prefix: onto_usage | ||
default_range: string | ||
|
||
imports: | ||
- linkml:types | ||
- core | ||
|
||
classes: | ||
Document: | ||
tree_root: true | ||
is_a: NamedEntity | ||
attributes: | ||
ontologies: | ||
annotations: | ||
prompt: >- | ||
A semicolon-delimited list of all ontologies | ||
mentioned in the text, either in name or abbreviation. | ||
For example, "Gene Ontology", "GO", "Human Phenotype Ontology", | ||
"HPO". Include all ontologies, even if they are not the focus | ||
of a specific use case. | ||
range: Ontology | ||
multivalued: true | ||
use_cases: | ||
annotations: | ||
prompt: >- | ||
A semicolon-delimited list of all use cases | ||
mentioned in the text. A use case is a specific application | ||
or context in which an ontology is used. For example, | ||
"Gene Ontology USED FOR gene function prediction", | ||
"MONDO Disease Ontology USED FOR disease diagnosis" | ||
range: UseCase | ||
multivalued: true | ||
|
||
Ontology: | ||
is_a: NamedEntity | ||
description: a single ontology name or abbreviation. | ||
|
||
UseCase: | ||
is_a: CompoundExpression | ||
annotations: | ||
owl: IntersectionOf | ||
attributes: | ||
ontology: | ||
description: >- | ||
The ontology involved in a specific use case. | ||
range: Ontology | ||
usecase: | ||
description: >- | ||
A short description of the use case, in one or two | ||
sentences. | ||
range: string |