2023-12-21 17:38:20 +08:00
|
|
|
from typing import List
|
|
|
|
|
|
|
|
from knext.client.search import SearchClient
|
2023-12-22 14:11:31 +08:00
|
|
|
from knext.operator.op import PredictOp
|
2023-12-21 17:38:20 +08:00
|
|
|
from knext.operator.spg_record import SPGRecord
|
|
|
|
|
|
|
|
|
2023-12-22 14:11:31 +08:00
|
|
|
class IndicatorPredict(PredictOp):
|
2023-12-21 17:38:20 +08:00
|
|
|
|
|
|
|
bind_to = ("Financial.State", "derivedFrom", "Financial.Indicator")
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2023-12-22 19:49:39 +08:00
|
|
|
self.search_client = SearchClient("Financial.Indicator")
|
2023-12-21 17:38:20 +08:00
|
|
|
|
|
|
|
def invoke(self, subject_record: SPGRecord) -> List[SPGRecord]:
|
2023-12-22 14:11:31 +08:00
|
|
|
print("##########IndicatorPredict###########")
|
2023-12-22 19:49:39 +08:00
|
|
|
query = {"match": {"name": subject_record.get_property("name", "")}}
|
|
|
|
recall_records = self.search_client.search(query, start=0, size=10)
|
|
|
|
if recall_records is not None and len(recall_records) > 0:
|
|
|
|
rerank_record = SPGRecord("Financial.Indicator", {"id": recall_records[0].doc_id, "name": recall_records[0].properties.get("name", "")})
|
|
|
|
return [rerank_record]
|
|
|
|
return []
|