💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Only add page breaks if requested via configuration
davidmezzetti5de34a667b85
diff --git a/src/python/txtai/pipeline/data/textractor.py b/src/python/txtai/pipeline/data/textractor.pyindex 1d6c9692..1d1f9eaf 100644--- a/src/python/txtai/pipeline/data/textractor.py+++ b/src/python/txtai/pipeline/data/textractor.py@@ -36,7 +36,7 @@ class Textractor(Segmentation):self.tika = self.checkjava() if tika else False# HTML to Text extractor- self.extract = Extract()+ self.extract = Extract(self.sections)def text(self, text):# Use Tika if available@@ -87,6 +87,16 @@ class Extract:Visual formatting is not included (bold, italic, styling etc)."""+ def __init__(self, sections):+ """+ Create a new Extract instance.++ Args:+ sections: True if section parsing enabled, False otherwise+ """++ self.sections = sections+def __call__(self, html):"""Transforms input HTML into formatted text.@@ -135,8 +145,8 @@ class Extract:# Join elements into texttext = "\n".join(self.process(node) for node in children) if self.iscontainer(node, children) else self.text(node)- # Detect page breaks. Otherwise add node text.- return f"{text}\f" if page else text+ # Add page breaks, if section parsing enabled. Otherwise add node text.+ return f"{text}\f" if page and self.sections else textdef text(self, node):"""diff --git a/test/python/testapi/testpipelines.py b/test/python/testapi/testpipelines.pyindex 7b1c9349..fb28a6a3 100644--- a/test/python/testapi/testpipelines.py+++ b/test/python/testapi/testpipelines.py@@ -277,7 +277,7 @@ class TestPipelines(unittest.TestCase):text = self.client.get(f"textract?file={Utils.PATH}/article.pdf").json()# Check length of text is as expected- self.assertEqual(len(text), 2334)+ self.assertEqual(len(text), 2333)def testTextractorBatch(self):"""@@ -287,7 +287,7 @@ class TestPipelines(unittest.TestCase):path = Utils.PATH + "/article.pdf"texts = self.client.post("batchtextract", json=[path, path]).json()- self.assertEqual((len(texts[0]), len(texts[1])), (2334, 2334))+ self.assertEqual((len(texts[0]), len(texts[1])), (2333, 2333))def testTranscribe(self):"""diff --git a/test/python/testpipeline/testtextractor.py b/test/python/testpipeline/testtextractor.pyindex 7f0efefd..f5d0707d 100644--- a/test/python/testpipeline/testtextractor.py+++ b/test/python/testpipeline/testtextractor.py@@ -95,7 +95,7 @@ class TestTextractor(unittest.TestCase):text = textractor(Utils.PATH + "/article.pdf")# Check length of text is as expected- self.assertEqual(len(text), 2334)+ self.assertEqual(len(text), 2333)def testTable(self):"""