Skip to content

Commit

Permalink
Add docstrings to engines
Browse files Browse the repository at this point in the history
  • Loading branch information
caufieldjh committed Sep 24, 2024
1 parent 955dd87 commit 4a1a731
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 6 deletions.
22 changes: 20 additions & 2 deletions src/ontogpt/engines/embedding_similarity_engine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
"""Similarity engine."""
"""
Embedding similarity engine.
This module provides functionality for calculating the similarity between entities
using embeddings and cosine similarity. It includes classes and methods for
searching for similar entities and retrieving textual representations of entities.
Classes:
EmbeddingSimilarity: A dataclass representing the similarity between two entities.
SimilarityEngine: A class for calculating similarity between entities.
Methods:
SimilarityEngine.similarity(entity1: str, entity2: str) -> EmbeddingSimilarity:
Get similarity between two entities.
SimilarityEngine.search(entity1: str, entities: List[str]) -> Iterable[EmbeddingSimilarity]:
Search for similar entities.
SimilarityEngine.entity_text(entity: str) -> str:
Get text representation for an entity.
"""

import logging
from dataclasses import dataclass
Expand All @@ -25,7 +43,7 @@ class EmbeddingSimilarity:

@dataclass
class SimilarityEngine(KnowledgeEngine):
"""Engine for generating synonyms."""
"""Engine for finding embedding similarity."""

adapter: BasicOntologyInterface = None
autolabel: bool = True
Expand Down
26 changes: 25 additions & 1 deletion src/ontogpt/engines/mapping_engine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
"""Synonym engine."""
"""
Mapping engine.
This module provides the `MappingEngine` class, which is responsible for generating and resolving mappings between concepts in different ontologies. It utilizes various classes and enums to represent mapping tasks, categorized mappings, and confidence levels.
Classes:
MappingPredicate: Enum representing different types of mapping predicates.
Confidence: Enum representing different levels of confidence.
CategorizedMapping: Model representing a categorized mapping with various attributes.
MappingTask: Model representing a mapping task with various attributes.
MappingTaskCollection: Model representing a collection of mapping tasks.
Relationship: Model representing a relationship between concepts.
Concept: Model representing a concept with various attributes.
MappingEngine: Engine class for generating and resolving mappings.
Functions:
categorize_mapping: Categorizes a mapping between a subject and an object using a template.
_parse: Parses the payload from the categorization process into a `CategorizedMapping`.
categorize_mappings: Categorizes multiple mappings between subjects and object sources.
run_tasks: Runs a collection of mapping tasks and categorizes the results.
generate_tasks: Generates mapping tasks from a collection or specified subjects and object sources.
from_sssom: Generates tasks from an SSSOM file.
categorize_sssom_mapping: Categorizes a single SSSOM mapping.
_concept: Retrieves a concept from an ontology adapter.
"""

import logging
from copy import deepcopy
Expand Down
22 changes: 21 additions & 1 deletion src/ontogpt/engines/reasoner_engine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
"""Reasoner engine."""
"""
Reasoner engine.
This module provides the implementation of the ReasonerEngine class, which is used to perform reasoning tasks using a Language Model (LLM). The engine takes an ontology and a query task as input, translates it into an LLM prompt, and performs reasoning over the ontology.
Classes:
ReasonerResult: Represents the result of a reason query.
ReasonerResultSet: Represents a set of reasoner results.
ReasonerEngine: Engine for performing reasoning using an LLM.
Functions:
flatten_list(lst): Flattens a nested list into a single list.
reason(task, template_path=None, strict=False, evaluate=None): Performs reasoning over axioms and query entailments.
reason_multiple(task_collection, **kwargs): Performs reasoning over multiple tasks.
_parse_single_answer(payload, task): Parses a single answer from the payload.
evaluate(result, task): Evaluates the result against the task.
Usage:
The ReasonerEngine can be used to perform reasoning tasks such as finding superclasses of a given class.
It can also provide explanations for the reasoning process.
"""

import logging
import re
Expand Down
14 changes: 13 additions & 1 deletion src/ontogpt/engines/synonym_engine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
"""Synonym engine."""
"""
Synonym engine.
This module defines the SynonymEngine class, which is responsible for generating synonyms for given named entities within a specified domain.
Classes:
SynonymEngine: Inherits from KnowledgeEngine and provides a method to retrieve synonyms.
Methods:
synonyms(named_entity: str, domain: str) -> List[str]:
Retrieves synonyms for the given named entity within the specified domain.
"""

from dataclasses import dataclass
from typing import List

Expand Down
15 changes: 14 additions & 1 deletion src/ontogpt/engines/topic_classifier_engine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
"""Topic classifier engine."""
"""
Topic classifier engine.
This module contains the `TopicClassifierEngine` class, which inherits from `KnowledgeEngine`.
The engine is designed to classify input text based on a given topic.
Classes:
TopicClassifierEngine: Engine for classifying input text based on its topic.
Methods:
binary_classify(topic: str, text: str) -> bool:
Given a topic description, indicate whether it applies to the input text.
Returns True if the text matches the topic, otherwise returns False.
"""

import logging

Expand Down

0 comments on commit 4a1a731

Please sign in to comment.