Browse Source

clean rag word_extractor. (#19397)

Signed-off-by: zhanluxianshen <zhanluxianshen@163.com>
tags/1.4.0
湛露先生 5 months ago
parent
commit
1119790b02
No account linked to committer's email address
1 changed files with 3 additions and 4 deletions
  1. 3
    4
      api/core/rag/extractor/word_extractor.py

+ 3
- 4
api/core/rag/extractor/word_extractor.py View File

parsed = urlparse(url) parsed = urlparse(url)
return bool(parsed.netloc) and bool(parsed.scheme) return bool(parsed.netloc) and bool(parsed.scheme)


def _extract_images_from_docx(self, doc, image_folder):
os.makedirs(image_folder, exist_ok=True)
def _extract_images_from_docx(self, doc):
image_count = 0 image_count = 0
image_map = {} image_map = {}




content = [] content = []


image_map = self._extract_images_from_docx(doc, image_folder)
image_map = self._extract_images_from_docx(doc)


hyperlinks_url = None hyperlinks_url = None
url_pattern = re.compile(r"http://[^\s+]+//|https://[^\s+]+") url_pattern = re.compile(r"http://[^\s+]+//|https://[^\s+]+")
xml = ElementTree.XML(run.element.xml) xml = ElementTree.XML(run.element.xml)
x_child = [c for c in xml.iter() if c is not None] x_child = [c for c in xml.iter() if c is not None]
for x in x_child: for x in x_child:
if x_child is None:
if x is None:
continue continue
if x.tag.endswith("instrText"): if x.tag.endswith("instrText"):
if x.text is None: if x.text is None:

Loading…
Cancel
Save