openspg/python/tests/disease_builder_job.py
2023-12-13 15:29:48 +08:00

39 lines
923 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from knext.client.model.builder_job import BuilderJob
from knext.component.builder import (
CsvSourceReader,
SPGTypeMapping,
LLMBasedExtractor,
KGSinkWriter,
)
class Disease(BuilderJob):
@property
def build(self):
"""
1. 定义输入源CSV文件其中CSV文件每一行为一段文本
"""
source = CsvSourceReader(
local_path="Disease.csv",
columns=["content"],
start_row=2,
)
"""
2. 指定SPG知识映射组件设置抽取算子从长文本中抽取多种实体类型
"""
mapping = SPGTypeMapping(spg_type_name=Medical.Disease).set_operator(
"DiseaseExtractor"
)
"""
3. 定义输出到图谱
"""
sink = SinkToKgComponent()
"""
4. 完整Pipeline定义
"""
return source >> mapping >> sink