75 lines
1.5 KiB
Python
Raw Normal View History

2023-12-08 11:25:26 +08:00
from abc import ABC
2023-12-11 10:44:37 +08:00
from enum import Enum
2023-12-08 11:25:26 +08:00
from typing import Union
2023-12-11 23:13:19 +08:00
from knext.component.base import Component
2023-12-08 11:25:26 +08:00
2023-12-11 23:13:19 +08:00
class ComponentTypeEnum(str, Enum):
CsvSourceReader = "CSV_SOURCE"
LLMBasedExtractor = "LLM_BASED_EXTRACT"
UserDefinedExtractor = "USER_DEFINED_EXTRACT"
SPGTypeMapping = "SPG_TYPE_MAPPING"
RelationMapping = "RELATION_MAPPING"
SubGraphMapping = "SUBGRAPH_MAPPING"
KGSinkWriter = "GRAPH_SINK"
2023-12-11 10:44:37 +08:00
class BuilderComponent(Component, ABC):
@property
def type(self):
2023-12-11 23:13:19 +08:00
return ComponentTypeEnum.__members__[self.__class__.__name__].value
2023-12-11 10:44:37 +08:00
@property
def input_keys(self):
return
@property
def output_keys(self):
return
class SourceReader(BuilderComponent, ABC):
2023-12-08 11:25:26 +08:00
@property
def upstream_types(self):
2023-12-11 10:44:37 +08:00
return None
2023-12-08 11:25:26 +08:00
@property
def downstream_types(self):
return Union[SPGExtractor, Mapping]
2023-12-11 10:44:37 +08:00
class SPGExtractor(BuilderComponent, ABC):
2023-12-08 11:25:26 +08:00
@property
def upstream_types(self):
return Union[SourceReader, SPGExtractor]
@property
def downstream_types(self):
2023-12-11 10:44:37 +08:00
return Union[SPGExtractor, Mapping]
2023-12-08 11:25:26 +08:00
2023-12-11 10:44:37 +08:00
class Mapping(BuilderComponent, ABC):
2023-12-08 11:25:26 +08:00
@property
def upstream_types(self):
2023-12-11 10:44:37 +08:00
return Union[SourceReader, SPGExtractor]
2023-12-08 11:25:26 +08:00
@property
def downstream_types(self):
2023-12-11 10:44:37 +08:00
return Union[SinkWriter]
2023-12-08 11:25:26 +08:00
2023-12-11 10:44:37 +08:00
class SinkWriter(BuilderComponent, ABC):
2023-12-08 11:25:26 +08:00
@property
def upstream_types(self):
2023-12-11 10:44:37 +08:00
return Union[Mapping]
2023-12-08 11:25:26 +08:00
@property
def downstream_types(self):
2023-12-11 10:44:37 +08:00
return None