unstructured bug(json): partition()将整个JSON文件放入具有.html扩展名的单个元素文本中时,当metadata_filename为.html时,

vdgimpew  于 2个月前  发布在  其他
关注(0)|答案(1)|浏览(112)

描述bug

当使用 partition() 对一个JSON文件进行分区,并提供一个具有 .html 扩展名的 metadata_filename 参数时,结果是一个只有一个元素的文件,其中包含整个JSON文件的内容作为文本。

重现

file_path = example_doc_path("simple.json")

with open(file_path, "rb") as f:
    elements = partition(file=f, metadata_filename="simple.html")

print(f"{elements}")
print(f"{elements[0].text}")

产生的输出:

[<unstructured.documents.elements.NarrativeText object at 0x371953bb0>]
[
    {
        "element_id": "a06d2d9e65212d4aa955c3ab32950ffa",
        "metadata": {
            "category_depth": 0,
            "file_directory": "unstructured/example-docs",
            "filename": "simple.docx",
            "filetype": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
            "languages": [
                "eng"
            ],
            "last_modified": "2024-07-06T16:44:51"
        },
        "text": "These are a few of my favorite things:",
        "type": "Title"
    },
    {
        "element_id": "b334c93e9b1cbca3b6f6d78ce8bc2484",
        "metadata": {
...

预期行为

elements_from_json("simple.json") 相同。metadata_filename 参数应被忽略。

附加上下文

  • 由于在使用 partition_json() 时不会出现这种行为,我认为这是由于 detect_filetype() 以某种方式使用 metadata_filename 进行消歧义的结果。因为序列化元素的原始文件名肯定不是 something.json ,所以这对于JSON文件来说是行不通的。
fnvucqvd

fnvucqvd1#

metadata_filename具有不同的扩展名,如simple.docx时,其他奇怪的情况也会发生。因此,文件类型似乎被错误地识别,文件被发送到错误的分区器。

相关问题