mirror of
https://github.com/Unstructured-IO/unstructured.git
synced 2025-07-03 23:20:35 +00:00

### Description * If the contents of a doc were updated by the process of reading/downloading it, this was not being persisted. To fix this, the data being passed around was updated to use a multiprocessing safe dict rather than the json string. Now that dict is updated after the `get_file` method is called. * Wikipedia connector was updated to use a static filename rather than one requiring a call to fetch data. * The read config param `re_download` was not being leveraged by the source node, this was fixed. * Added fix: chunking and embedding order reversed so chunking runs before embeddings --------- Co-authored-by: ryannikolaidis <1208590+ryannikolaidis@users.noreply.github.com> Co-authored-by: rbiseck3 <rbiseck3@users.noreply.github.com>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
from unstructured.ingest.connector.local import LocalIngestDoc, SimpleLocalConfig
|
|
from unstructured.ingest.connector.registry import (
|
|
create_ingest_doc_from_dict,
|
|
create_ingest_doc_from_json,
|
|
)
|
|
from unstructured.ingest.interfaces import ProcessorConfig, ReadConfig
|
|
|
|
doc = LocalIngestDoc(
|
|
path="test_unstructured_ingest/example-docs/layout-parser-paper.pdf",
|
|
connector_config=SimpleLocalConfig(input_path="test_unstructured_ingest/example-docs/"),
|
|
processor_config=ProcessorConfig(),
|
|
read_config=ReadConfig(),
|
|
)
|
|
doc.update_source_metadata()
|
|
serialized_json = doc.to_json()
|
|
serialized_dict = doc.to_dict()
|
|
|
|
|
|
def test_manual_deserialization():
|
|
deserialized_doc = LocalIngestDoc.from_json(serialized_json)
|
|
assert doc == deserialized_doc
|
|
|
|
|
|
def test_registry_from_json():
|
|
deserialized_doc = create_ingest_doc_from_json(serialized_json)
|
|
assert doc == deserialized_doc
|
|
|
|
|
|
def test_registry_from_dict():
|
|
deserialized_doc = create_ingest_doc_from_dict(serialized_dict)
|
|
assert doc == deserialized_doc
|
|
|
|
|
|
def test_source_metadata_serialization():
|
|
doc = LocalIngestDoc(
|
|
path="test_unstructured_ingest/example-docs/layout-parser-paper.pdf",
|
|
connector_config=SimpleLocalConfig(input_path="test_unstructured_ingest/example-docs/"),
|
|
processor_config=ProcessorConfig(),
|
|
read_config=ReadConfig(),
|
|
)
|
|
serialized_json = doc.to_dict()
|
|
assert not serialized_json["_source_metadata"]
|
|
|
|
doc.update_source_metadata()
|
|
serialized_json_w_meta = doc.to_dict()
|
|
assert serialized_json_w_meta["_source_metadata"]
|