MCPcopy Create free account
hub / github.com/cxcscmu/Craw4LLM / DocumentRater

Class DocumentRater

document_rater.py:16–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14
15
16class DocumentRater:
17 _name = None
18 _require_doc_text = None
19
20 def __init__(
21 self, rater_name: str | None = None, normalizer: ScoreNormalizer | None = None, **kwargs
22 ) -> None:
23 self._obj_name = rater_name if rater_name is not None else self._name
24 self.normalizer = normalizer
25 logger.info(
26 f"Initializing rater type: {self._name}, name: {self._obj_name}, normalizer: {self.normalizer}, args: {kwargs}"
27 )
28
29 def _annotate_doc(self, doc: Document, score: float | int) -> Document:
30 if self.normalizer is None:
31 return Document(
32 docid=doc.docid,
33 text=doc.text,
34 annotations=DocumentAnnotation({self.get_name(): score, **doc.annotations}),
35 )
36 logger.debug(f"Normalizing score: {self.get_name()}")
37 return Document(
38 docid=doc.docid,
39 text=doc.text,
40 annotations=DocumentAnnotation(
41 {
42 self.get_name(): score,
43 f"{self.get_name()}_{self.normalizer.get_name()}_normalized": self.normalizer(
44 score
45 ),
46 **doc.annotations,
47 }
48 ),
49 )
50
51 @abstractmethod
52 def __call__(self, docs: list[Document]) -> list[Document]: ...
53
54 def get_name(self) -> str | None:
55 return self._obj_name
56
57 @classmethod
58 def require_doc_text(cls) -> bool | None:
59 return cls._require_doc_text
60
61
62class RandomRater(DocumentRater):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected