Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Handle file urls more consistently, closes #151

davidmezzetti59f6abe492bb
diff --git a/src/python/txtai/pipeline/segment/textractor.py b/src/python/txtai/pipeline/segment/textractor.py
index 8af4a0f2..c666cb06 100644
--- a/src/python/txtai/pipeline/segment/textractor.py
+++ b/src/python/txtai/pipeline/segment/textractor.py
@@ -38,6 +38,9 @@ class Textractor(Segmentation):
def text(self, text):
# Use Tika if available
if self.tika:
+ # Format file urls as local file paths
+ text = text.replace("file://", "")
+
# text is a path to a file
parsed = parser.from_file(text)
return parsed["content"]
diff --git a/src/python/txtai/workflow/task/file.py b/src/python/txtai/workflow/task/file.py
index 895b064e..cdd56cde 100644
--- a/src/python/txtai/workflow/task/file.py
+++ b/src/python/txtai/workflow/task/file.py
@@ -2,16 +2,16 @@
FileTask module
"""
-import re
+import os
-from .url import UrlTask
+from .base import Task
-class FileTask(UrlTask):
+class FileTask(Task):
"""
- Task that processes file urls
+ Task that processes file paths
"""
def accept(self, element):
- # Only accept file URLs
- return super().accept(element) and re.match(UrlTask.FILE, element.lower())
+ # Only accept file paths that exist
+ return super().accept(element) and isinstance(element, str) and os.path.exists(element)
diff --git a/src/python/txtai/workflow/task/url.py b/src/python/txtai/workflow/task/url.py
index 9eba7fab..355e06b7 100644
--- a/src/python/txtai/workflow/task/url.py
+++ b/src/python/txtai/workflow/task/url.py
@@ -15,12 +15,6 @@ class UrlTask(Task):
# URL prefix
PREFIX = r"\w+:\/\/"
- # File prefix
- FILE = r"file:\/\/"
-
def accept(self, element):
# Only accept file URLs
return super().accept(element) and re.match(UrlTask.PREFIX, element.lower())
-
- def prepare(self, element):
- return re.sub(UrlTask.FILE, "", element)