partition() re-classifies a .txt file as CSV or JSON from its content

オープン 初心者向け
#4,876 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend, data

調査の方向性

unstructured/file_utils/filetype.py、特に _TextFileDifferentiator.file_type を読み、.txt ファイルに対して partition() が detect_filetype() をどのように使うかを追ってください。.txt ファイル内のカンマ区切りコンテンツと JSON コンテンツに関するテストを追加または確認し、そのうえで、名前のあるテキストファイルは引き続きプレーンテキストとして処理され、拡張子のないファイルは引き続きコンテンツに基づいて判定されることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

Describe the bug

partition() and detect_filetype() re-classify a file named *.txt from its content. A plain text file whose lines all contain the same number of commas is detected as CSV, so the commas are dropped and the lines are fused into a single Table.

notes.txt:  "Dear Ann,\nThank you for the gift,\nSee you soon,\n"
names.txt:  "Smith, John\nDoe, Jane\nRoe, Richard\n"
from unstructured.partition.auto import partition
partition("names.txt")
# [('Table', 'Smith John Doe Jane Roe Richard')]   metadata.filetype == "text/csv"
partition("notes.txt")
# [('Table', 'Dear Ann Thank you for the gift See you soon')]

partition_text("names.txt") gives three Title elements, so only the type detection is affected. A .txt file that contains a JSON object is likewise routed to the JSON partitioner and its text is rewritten.

Cause

In _TextFileDifferentiator.file_type (unstructured/file_utils/filetype.py), .csv, .json, .md, .eml, ... are trusted by extension first, but the .txt/.text check comes after _is_json, _is_csv and _is_eml.

Expected

A file the user named .txt is plain text. The content sniffs stay for files without an extension.

Proposed fix

Return FileType.TXT for .txt/.text before the content sniffs. I have a small PR with tests ready; happy to adjust if you want to keep the sniffing for some case I missed.

Version: main at d9c80bdb, Python 3.12, Windows 11.

主要言語
HTML
スター
15.8k
フォーク
1.4k
平均マージ
8日 4時間
マージ済み PR(30日)
40

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Unstructured-IO/unstructured のほかの issue

Unstructured-IO/unstructured の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。