mirror of
https://github.com/microsoft/graphrag.git
synced 2026-02-04 18:22:44 +08:00
Some checks are pending
Python Build and Type Check / python-ci (ubuntu-latest, 3.11) (push) Waiting to run
Python Build and Type Check / python-ci (ubuntu-latest, 3.12) (push) Waiting to run
Python Build and Type Check / python-ci (windows-latest, 3.11) (push) Waiting to run
Python Build and Type Check / python-ci (windows-latest, 3.12) (push) Waiting to run
Python Integration Tests / python-ci (ubuntu-latest, 3.12) (push) Waiting to run
Python Integration Tests / python-ci (windows-latest, 3.12) (push) Waiting to run
Python Notebook Tests / python-ci (ubuntu-latest, 3.12) (push) Waiting to run
Python Notebook Tests / python-ci (windows-latest, 3.12) (push) Waiting to run
Python Smoke Tests / python-ci (ubuntu-latest, 3.12) (push) Waiting to run
Python Smoke Tests / python-ci (windows-latest, 3.12) (push) Waiting to run
Python Unit Tests / python-ci (ubuntu-latest, 3.12) (push) Waiting to run
Python Unit Tests / python-ci (windows-latest, 3.12) (push) Waiting to run
* Add graphrag-storage.
101 lines
3.1 KiB
Python
101 lines
3.1 KiB
Python
# Copyright (c) 2024 Microsoft Corporation.
|
|
# Licensed under the MIT License
|
|
|
|
from graphrag.config.enums import InputFileType
|
|
from graphrag.config.models.input_config import InputConfig
|
|
from graphrag.index.input.factory import InputReaderFactory
|
|
from graphrag_storage import StorageConfig, create_storage
|
|
|
|
|
|
async def test_json_loader_one_file_one_object():
|
|
config = InputConfig(
|
|
storage=StorageConfig(
|
|
base_dir="tests/unit/indexing/input/data/one-json-one-object",
|
|
),
|
|
file_type=InputFileType.json,
|
|
file_pattern=".*\\.json$",
|
|
)
|
|
storage = create_storage(config.storage)
|
|
documents = (
|
|
await InputReaderFactory()
|
|
.create(config.file_type, {"storage": storage, "config": config})
|
|
.read_files()
|
|
)
|
|
assert documents.shape == (1, 4)
|
|
assert documents["title"].iloc[0] == "input.json"
|
|
|
|
|
|
async def test_json_loader_one_file_multiple_objects():
|
|
config = InputConfig(
|
|
storage=StorageConfig(
|
|
base_dir="tests/unit/indexing/input/data/one-json-multiple-objects",
|
|
),
|
|
file_type=InputFileType.json,
|
|
file_pattern=".*\\.json$",
|
|
)
|
|
storage = create_storage(config.storage)
|
|
documents = (
|
|
await InputReaderFactory()
|
|
.create(config.file_type, {"storage": storage, "config": config})
|
|
.read_files()
|
|
)
|
|
print(documents)
|
|
assert documents.shape == (3, 4)
|
|
assert documents["title"].iloc[0] == "input.json"
|
|
|
|
|
|
async def test_json_loader_one_file_with_title():
|
|
config = InputConfig(
|
|
storage=StorageConfig(
|
|
base_dir="tests/unit/indexing/input/data/one-json-one-object",
|
|
),
|
|
file_type=InputFileType.json,
|
|
file_pattern=".*\\.json$",
|
|
title_column="title",
|
|
)
|
|
storage = create_storage(config.storage)
|
|
documents = (
|
|
await InputReaderFactory()
|
|
.create(config.file_type, {"storage": storage, "config": config})
|
|
.read_files()
|
|
)
|
|
assert documents.shape == (1, 4)
|
|
assert documents["title"].iloc[0] == "Hello"
|
|
|
|
|
|
async def test_json_loader_one_file_with_metadata():
|
|
config = InputConfig(
|
|
storage=StorageConfig(
|
|
base_dir="tests/unit/indexing/input/data/one-json-one-object",
|
|
),
|
|
file_type=InputFileType.json,
|
|
file_pattern=".*\\.json$",
|
|
title_column="title",
|
|
metadata=["title"],
|
|
)
|
|
storage = create_storage(config.storage)
|
|
documents = (
|
|
await InputReaderFactory()
|
|
.create(config.file_type, {"storage": storage, "config": config})
|
|
.read_files()
|
|
)
|
|
assert documents.shape == (1, 5)
|
|
assert documents["metadata"][0] == {"title": "Hello"}
|
|
|
|
|
|
async def test_json_loader_multiple_files():
|
|
config = InputConfig(
|
|
storage=StorageConfig(
|
|
base_dir="tests/unit/indexing/input/data/multiple-jsons",
|
|
),
|
|
file_type=InputFileType.json,
|
|
file_pattern=".*\\.json$",
|
|
)
|
|
storage = create_storage(config.storage)
|
|
documents = (
|
|
await InputReaderFactory()
|
|
.create(config.file_type, {"storage": storage, "config": config})
|
|
.read_files()
|
|
)
|
|
assert documents.shape == (4, 4)
|