File size: 1,033 Bytes
8360ec7 |
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 |
import random
import string
from openfactcheck.core.solver import Solver
from openfactcheck.core.state import FactCheckerState
from openfactcheck.core.solver import StandardTaskSolver, Solver
@Solver.register("ignorant_search_engine_retriever", "claims", "claims_with_evidences")
class IgnorantSearchEngineRetriever(StandardTaskSolver):
def __init__(self, args):
super().__init__(args)
self.max_num_documents = args.get("max_num_documents",5)
def __call__(self, state: FactCheckerState, *args, **kwargs):
claims = state.get(self.input_name)
claims_with_evidences = {}
for idx, claim in enumerate(claims):
# Assume we call some search engine API here
documents = [string.ascii_letters[random.randint(0, 25)] for i in range(self.max_num_documents)]
key = f"{idx}-{claim}" # Convert the tuple to a string key
claims_with_evidences[key] = documents
state.set(self.output_name, claims_with_evidences)
return True, state
|