Skip to content

Commit

Permalink
Fix convention for src/melt/tools/metrics/base.py
Browse files Browse the repository at this point in the history
  • Loading branch information
minhtrung23 committed Sep 8, 2024
1 parent 981e446 commit dc7f6b5
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions src/melt/tools/metrics/base.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,59 @@
from .post_process import get_answer_auto_from_text
"""
This module contains base classes for metrics processing.
"""

from .post_process import get_answer_auto_from_text

class BaseMetric:
# def __init__(self):
# return
"""
A base class for metrics that process text and extract answers.
"""

def __init__(self, data, args):
return
def __init__(self, data=None, args=None):
"""
Initializes the BaseMetric with optional data and arguments.
Args:
data (optional): Data related to the metric. Defaults to None.
args (optional): Arguments for processing. Defaults to None.
"""
self.data = data
self.args = args

def _get_answer(self, text: str, args) -> str:
"""Process a text and extract an answer based on certain arguments
"""
Process a text and extract an answer based on certain arguments.
Args:
text (str): A string containing the text from which the answer is \
to be extracted.
args: Arguments containing 'key_answer', 'class_names', and other \
parameters required for extraction.
Returns:
str: The extracted answer.
"""
return get_answer_auto_from_text(
text=text,
key_answer=args.key_answer,
class_names=args.class_names,
args=args,
)

def set_data(self, data):
"""
Sets the data for the metric.
Args:
data: The data to be set.
"""
self.data = data

def get_data(self):
"""
Gets the data for the metric.
Returns:
The current data.
"""
return self.data

0 comments on commit dc7f6b5

Please sign in to comment.