소스 검색

add sql to naive parser (#1908)

### What problem does this PR solve?


### Type of change

- [ ] Bug Fix (non-breaking change which fixes an issue)
- [x] New Feature (non-breaking change which adds functionality)
tags/v0.10.0
Kevin Hu 1 년 전
부모
커밋
cafdee536f
No account linked to committer's email address
3개의 변경된 파일14개의 추가작업 그리고 8개의 파일을 삭제
  1. 1
    1
      api/utils/file_utils.py
  2. 9
    5
      deepdoc/parser/txt_parser.py
  3. 4
    2
      rag/app/naive.py

+ 1
- 1
api/utils/file_utils.py 파일 보기

@@ -156,7 +156,7 @@ def filename_type(filename):
return FileType.PDF.value
if re.match(
r".*\.(eml|doc|docx|ppt|pptx|yml|xml|htm|json|csv|txt|ini|xls|xlsx|wps|rtf|hlp|pages|numbers|key|md|py|js|java|c|cpp|h|php|go|ts|sh|cs|kt|html)$", filename):
r".*\.(eml|doc|docx|ppt|pptx|yml|xml|htm|json|csv|txt|ini|xls|xlsx|wps|rtf|hlp|pages|numbers|key|md|py|js|java|c|cpp|h|php|go|ts|sh|cs|kt|html|sql)$", filename):
return FileType.DOC.value
if re.match(

+ 9
- 5
deepdoc/parser/txt_parser.py 파일 보기

@@ -12,6 +12,7 @@
#

from rag.nlp import find_codec,num_tokens_from_string
import re

class RAGFlowTxtParser:
def __call__(self, fnm, binary=None, chunk_token_num=128):
@@ -29,14 +30,17 @@ class RAGFlowTxtParser:
return self.parser_txt(txt, chunk_token_num)

@classmethod
def parser_txt(cls, txt, chunk_token_num=128):
def parser_txt(cls, txt, chunk_token_num=128, delimiter="\n!?;。;!?"):
if type(txt) != str:
raise TypeError("txt type should be str!")
sections = []
for sec in txt.split("\n"):
for sec in re.split(r"[%s]+"%delimiter, txt):
if sections and sec in delimiter:
sections[-1][0] += sec
continue
if num_tokens_from_string(sec) > 10 * int(chunk_token_num):
sections.append((sec[: int(len(sec) / 2)], ""))
sections.append((sec[int(len(sec) / 2) :], ""))
sections.append([sec[: int(len(sec) / 2)], ""])
sections.append([sec[int(len(sec) / 2) :], ""])
else:
sections.append((sec, ""))
sections.append([sec, ""])
return sections

+ 4
- 2
rag/app/naive.py 파일 보기

@@ -224,9 +224,11 @@ def chunk(filename, binary=None, from_page=0, to_page=100000,
excel_parser = ExcelParser()
sections = [(l, "") for l in excel_parser.html(binary) if l]
elif re.search(r"\.(txt|py|js|java|c|cpp|h|php|go|ts|sh|cs|kt)$", filename, re.IGNORECASE):
elif re.search(r"\.(txt|py|js|java|c|cpp|h|php|go|ts|sh|cs|kt|sql)$", filename, re.IGNORECASE):
callback(0.1, "Start to parse.")
sections = TxtParser()(filename,binary,parser_config.get("chunk_token_num", 128))
sections = TxtParser()(filename,binary,
parser_config.get("chunk_token_num", 128),
parser_config.get("delimiter", "\n!?;。;!?"))
callback(0.8, "Finish parsing.")
elif re.search(r"\.(md|markdown)$", filename, re.IGNORECASE):

Loading…
취소
저장