File size: 1,899 Bytes
009d93e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from typing import Literal
from models import *
from .process import *
# predefined processing logic for routine extraction tasks
TaskType = Literal["NER", "RE", "EE", "Base"]

class DataPoint:
    def __init__(self,
                 task: TaskType = "Base",
                 instruction: str = "",
                 text: str = "",
                 output_schema: str = "",
                 constraint: str = "",
                 use_file: bool = False,
                 file_path: str = "",
                 truth: str = ""):
        """
        Initialize a DataPoint instance.
        """
        # task information
        self.task = task
        self.instruction = instruction
        self.text = text
        self.output_schema = output_schema
        self.constraint = constraint
        self.use_file = use_file
        self.file_path = file_path
        self.truth = extract_json_dict(truth)
        # temp storage
        self.print_schema = ""
        self.distilled_text = ""
        self.chunk_text_list = []
        # result feedback
        self.result_list = []
        self.result_trajectory = {}
        self.pred = ""

    def set_constraint(self, constraint):
        self.constraint = constraint

    def set_schema(self, output_schema):
        self.output_schema = output_schema

    def set_pred(self, pred):
        self.pred = pred

    def set_result_list(self, result_list):
        self.result_list = result_list

    def set_distilled_text(self, distilled_text):
        self.distilled_text = distilled_text

    def update_trajectory(self, function, result):
        if function not in self.result_trajectory:
            self.result_trajectory.update({function: result})

    def get_result_trajectory(self):
        return {"instruction": self.instruction, "text": self.text, "constraint": self.constraint,  "trajectory": self.result_trajectory, "pred": self.pred}