2024-09-17 10:32:25 -07:00
|
|
|
# Copyright (c) 2024 Microsoft Corporation.
|
|
|
|
# Licensed under the MIT License
|
|
|
|
|
2024-10-24 10:20:03 -07:00
|
|
|
from graphrag.index.run.utils import create_run_context
|
2024-09-17 10:32:25 -07:00
|
|
|
from graphrag.index.workflows.v1.create_final_text_units import (
|
|
|
|
build_steps,
|
|
|
|
workflow_name,
|
|
|
|
)
|
|
|
|
|
|
|
|
from .util import (
|
|
|
|
compare_outputs,
|
|
|
|
get_config_for_workflow,
|
|
|
|
get_workflow_output,
|
|
|
|
load_input_tables,
|
2024-12-05 09:57:26 -08:00
|
|
|
load_test_table,
|
2024-09-17 10:32:25 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_create_final_text_units():
|
|
|
|
input_tables = load_input_tables([
|
|
|
|
"workflow:create_base_text_units",
|
|
|
|
"workflow:create_final_entities",
|
|
|
|
"workflow:create_final_relationships",
|
|
|
|
"workflow:create_final_covariates",
|
|
|
|
])
|
2024-12-05 09:57:26 -08:00
|
|
|
expected = load_test_table(workflow_name)
|
2024-09-17 10:32:25 -07:00
|
|
|
|
2024-10-24 10:20:03 -07:00
|
|
|
context = create_run_context(None, None, None)
|
|
|
|
await context.runtime_storage.set(
|
|
|
|
"base_text_units", input_tables["workflow:create_base_text_units"]
|
|
|
|
)
|
|
|
|
|
2024-09-17 10:32:25 -07:00
|
|
|
config = get_config_for_workflow(workflow_name)
|
|
|
|
|
|
|
|
config["covariates_enabled"] = True
|
|
|
|
|
2024-10-02 08:57:08 -07:00
|
|
|
steps = build_steps(config)
|
2024-09-17 10:32:25 -07:00
|
|
|
|
|
|
|
actual = await get_workflow_output(
|
|
|
|
input_tables,
|
|
|
|
{
|
|
|
|
"steps": steps,
|
|
|
|
},
|
2024-10-24 10:20:03 -07:00
|
|
|
context=context,
|
2024-09-17 10:32:25 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
compare_outputs(actual, expected)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_create_final_text_units_no_covariates():
|
|
|
|
input_tables = load_input_tables([
|
|
|
|
"workflow:create_base_text_units",
|
|
|
|
"workflow:create_final_entities",
|
|
|
|
"workflow:create_final_relationships",
|
|
|
|
"workflow:create_final_covariates",
|
|
|
|
])
|
2024-12-05 09:57:26 -08:00
|
|
|
expected = load_test_table(workflow_name)
|
2024-09-17 10:32:25 -07:00
|
|
|
|
2024-10-24 10:20:03 -07:00
|
|
|
context = create_run_context(None, None, None)
|
|
|
|
await context.runtime_storage.set(
|
|
|
|
"base_text_units", input_tables["workflow:create_base_text_units"]
|
|
|
|
)
|
|
|
|
|
2024-09-17 10:32:25 -07:00
|
|
|
config = get_config_for_workflow(workflow_name)
|
|
|
|
|
|
|
|
config["covariates_enabled"] = False
|
|
|
|
|
2024-10-02 08:57:08 -07:00
|
|
|
steps = build_steps(config)
|
2024-09-17 10:32:25 -07:00
|
|
|
|
|
|
|
actual = await get_workflow_output(
|
|
|
|
input_tables,
|
|
|
|
{
|
|
|
|
"steps": steps,
|
|
|
|
},
|
2024-10-24 10:20:03 -07:00
|
|
|
context=context,
|
2024-09-17 10:32:25 -07:00
|
|
|
)
|
|
|
|
|
2024-09-17 17:04:42 -07:00
|
|
|
# we're short a covariate_ids column
|
2024-11-13 15:11:19 -08:00
|
|
|
columns = list(expected.columns.values)
|
|
|
|
columns.remove("covariate_ids")
|
2024-09-17 17:04:42 -07:00
|
|
|
compare_outputs(
|
|
|
|
actual,
|
|
|
|
expected,
|
2024-11-13 15:11:19 -08:00
|
|
|
columns=columns,
|
2024-09-17 17:04:42 -07:00
|
|
|
)
|