OpenSPG/openspg

算子中的bind_schemas是什么?

Closed this issue · 1 comments

以下的LinkOp和FuseOp都包含了bind_schemas,请问是什么?有什么作用?能否举例说一下他的应用场景
`class LinkOp(BaseOp, ABC):
"""Base class for all entity link operators."""

bind_to: SPGTypeName

bind_schemas: Dict[SPGTypeName, str] = {}

def __init__(self):
    super().__init__()

def invoke(self, property: str, subject_record: SPGRecord) -> List[SPGRecord]:
    raise NotImplementedError(
        f"{self.__class__.__name__} need to implement `invoke` method."
    )

def _handle(self, *inputs) -> Dict[str, Any]:
    _property, subject_record = self._pre_process(*inputs)
    cache_key = str(self.bind_to) + _property
    cache_property = cache.get(cache_key)
    if cache_property:
        output = [
            SPGRecord(spg_type_name=self.bind_to).upsert_property(
                "id", cache_property
            )
        ]
    else:
        output = self.invoke(_property, subject_record)
    post_output = self._post_process(output)
    return post_output

@staticmethod
def _pre_process(*inputs):
    return inputs[0], SPGRecord.from_dict(inputs[1])

@staticmethod
def _post_process(output) -> Dict[str, Any]:
    if isinstance(output, InvokeResult):
        return output.to_dict()
    if isinstance(output, tuple):
        return InvokeResult[List[SPGRecord]](*output[:3]).to_dict()
    else:
        return InvokeResult[List[SPGRecord]](output).to_dict()

`

bind_schemas是通过扫描builder/operator目录下所有算子的bind_to参数来生成的,用来记录算子和SPGType之间绑定关系的类变量。在实现和使用LinkOp/FuseOp算子时无需设置该参数,只需要设置bind_to参数即可。