deepdoc-lib 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- deepdoc/README.md +122 -0
- deepdoc/README_zh.md +116 -0
- deepdoc/__init__.py +43 -0
- deepdoc/_version.py +34 -0
- deepdoc/common/__init__.py +52 -0
- deepdoc/common/config_utils.py +63 -0
- deepdoc/common/connection_utils.py +73 -0
- deepdoc/common/file_utils.py +19 -0
- deepdoc/common/misc_utils.py +44 -0
- deepdoc/common/model_store.py +369 -0
- deepdoc/common/settings.py +42 -0
- deepdoc/common/tiktoken_cache.py +84 -0
- deepdoc/common/token_utils.py +96 -0
- deepdoc/config.py +149 -0
- deepdoc/depend/find_codec.py +42 -0
- deepdoc/depend/nltk_manager.py +114 -0
- deepdoc/depend/prompts/vision_llm_describe_prompt.md +23 -0
- deepdoc/depend/prompts/vision_llm_figure_describe_prompt.md +24 -0
- deepdoc/depend/prompts.py +35 -0
- deepdoc/depend/rag_tokenizer.py +578 -0
- deepdoc/depend/simple_cv_model.py +469 -0
- deepdoc/depend/surname.py +91 -0
- deepdoc/depend/timeout.py +73 -0
- deepdoc/depend/vision_llm_chunk.py +35 -0
- deepdoc/dict/README.md +19 -0
- deepdoc/dict/huqie.txt +555629 -0
- deepdoc/download_models.py +169 -0
- deepdoc/llm_adapter/__init__.py +15 -0
- deepdoc/llm_adapter/adapter.py +223 -0
- deepdoc/llm_adapter/utils.py +104 -0
- deepdoc/llm_adapter/vision.py +163 -0
- deepdoc/parser/__init__.py +42 -0
- deepdoc/parser/docling_parser.py +889 -0
- deepdoc/parser/docx_parser.py +150 -0
- deepdoc/parser/excel_parser.py +270 -0
- deepdoc/parser/figure_parser.py +182 -0
- deepdoc/parser/html_parser.py +221 -0
- deepdoc/parser/json_parser.py +179 -0
- deepdoc/parser/markdown_parser.py +321 -0
- deepdoc/parser/mineru_parser.py +646 -0
- deepdoc/parser/pdf_parser.py +1591 -0
- deepdoc/parser/ppt_parser.py +96 -0
- deepdoc/parser/resume/__init__.py +109 -0
- deepdoc/parser/resume/entities/__init__.py +15 -0
- deepdoc/parser/resume/entities/corporations.py +128 -0
- deepdoc/parser/resume/entities/degrees.py +44 -0
- deepdoc/parser/resume/entities/industries.py +712 -0
- deepdoc/parser/resume/entities/regions.py +789 -0
- deepdoc/parser/resume/entities/res/corp.tks.freq.json +65 -0
- deepdoc/parser/resume/entities/res/corp_baike_len.csv +31480 -0
- deepdoc/parser/resume/entities/res/corp_tag.json +14939 -0
- deepdoc/parser/resume/entities/res/good_corp.json +911 -0
- deepdoc/parser/resume/entities/res/good_sch.json +595 -0
- deepdoc/parser/resume/entities/res/school.rank.csv +1627 -0
- deepdoc/parser/resume/entities/res/schools.csv +5713 -0
- deepdoc/parser/resume/entities/schools.py +91 -0
- deepdoc/parser/resume/step_one.py +189 -0
- deepdoc/parser/resume/step_two.py +692 -0
- deepdoc/parser/tcadp_parser.py +538 -0
- deepdoc/parser/txt_parser.py +64 -0
- deepdoc/parser/utils.py +33 -0
- deepdoc/vision/__init__.py +90 -0
- deepdoc/vision/layout_recognizer.py +481 -0
- deepdoc/vision/ocr.py +757 -0
- deepdoc/vision/operators.py +733 -0
- deepdoc/vision/postprocess.py +370 -0
- deepdoc/vision/recognizer.py +451 -0
- deepdoc/vision/seeit.py +87 -0
- deepdoc/vision/t_ocr.py +101 -0
- deepdoc/vision/t_recognizer.py +186 -0
- deepdoc/vision/table_structure_recognizer.py +617 -0
- deepdoc_lib-0.2.0.dist-info/METADATA +246 -0
- deepdoc_lib-0.2.0.dist-info/RECORD +78 -0
- deepdoc_lib-0.2.0.dist-info/WHEEL +5 -0
- deepdoc_lib-0.2.0.dist-info/entry_points.txt +2 -0
- deepdoc_lib-0.2.0.dist-info/licenses/LICENSE +201 -0
- deepdoc_lib-0.2.0.dist-info/top_level.txt +2 -0
- scripts/download_models.py +10 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
import json
|
|
19
|
+
import re
|
|
20
|
+
import copy
|
|
21
|
+
import pandas as pd
|
|
22
|
+
|
|
23
|
+
current_file_path = os.path.dirname(os.path.abspath(__file__))
|
|
24
|
+
TBL = pd.read_csv(
|
|
25
|
+
os.path.join(current_file_path, "res/schools.csv"), sep="\t", header=0
|
|
26
|
+
).fillna("")
|
|
27
|
+
TBL["name_en"] = TBL["name_en"].map(lambda x: x.lower().strip())
|
|
28
|
+
GOOD_SCH = json.load(open(os.path.join(current_file_path, "res/good_sch.json"), "r",encoding="utf-8"))
|
|
29
|
+
GOOD_SCH = set([re.sub(r"[,. &()()]+", "", c) for c in GOOD_SCH])
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def loadRank(fnm):
|
|
33
|
+
global TBL
|
|
34
|
+
TBL["rank"] = 1000000
|
|
35
|
+
with open(fnm, "r", encoding="utf-8") as f:
|
|
36
|
+
while True:
|
|
37
|
+
line = f.readline()
|
|
38
|
+
if not line:
|
|
39
|
+
break
|
|
40
|
+
line = line.strip("\n").split(",")
|
|
41
|
+
try:
|
|
42
|
+
nm, rk = line[0].strip(), int(line[1])
|
|
43
|
+
# assert len(TBL[((TBL.name_cn == nm) | (TBL.name_en == nm))]),f"<{nm}>"
|
|
44
|
+
TBL.loc[((TBL.name_cn == nm) | (TBL.name_en == nm)), "rank"] = rk
|
|
45
|
+
except Exception:
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
loadRank(os.path.join(current_file_path, "res/school.rank.csv"))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def split(txt):
|
|
53
|
+
tks = []
|
|
54
|
+
for t in re.sub(r"[ \t]+", " ", txt).split():
|
|
55
|
+
if (
|
|
56
|
+
tks
|
|
57
|
+
and re.match(r".*[a-zA-Z]$", tks[-1])
|
|
58
|
+
and re.match(r"[a-zA-Z]", t)
|
|
59
|
+
and tks
|
|
60
|
+
):
|
|
61
|
+
tks[-1] = tks[-1] + " " + t
|
|
62
|
+
else:
|
|
63
|
+
tks.append(t)
|
|
64
|
+
return tks
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def select(nm):
|
|
68
|
+
global TBL
|
|
69
|
+
if not nm:
|
|
70
|
+
return
|
|
71
|
+
if isinstance(nm, list):
|
|
72
|
+
nm = str(nm[0])
|
|
73
|
+
nm = split(nm)[0]
|
|
74
|
+
nm = str(nm).lower().strip()
|
|
75
|
+
nm = re.sub(r"[((][^()()]+[))]", "", nm.lower())
|
|
76
|
+
nm = re.sub(r"(^the |[,.&()();;·]+|^(英国|美国|瑞士))", "", nm)
|
|
77
|
+
nm = re.sub(r"大学.*学院", "大学", nm)
|
|
78
|
+
tbl = copy.deepcopy(TBL)
|
|
79
|
+
tbl["hit_alias"] = tbl["alias"].map(lambda x: nm in set(x.split("+")))
|
|
80
|
+
res = tbl[((tbl.name_cn == nm) | (tbl.name_en == nm) | tbl.hit_alias)]
|
|
81
|
+
if res.empty:
|
|
82
|
+
return
|
|
83
|
+
|
|
84
|
+
return json.loads(res.to_json(orient="records"))[0]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def is_good(nm):
|
|
88
|
+
global GOOD_SCH
|
|
89
|
+
nm = re.sub(r"[((][^()()]+[))]", "", nm.lower())
|
|
90
|
+
nm = re.sub(r"[''`‘’“”,. &()();;]+", "", nm)
|
|
91
|
+
return nm in GOOD_SCH
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
from deepdoc.parser.resume.entities import degrees, regions, industries
|
|
19
|
+
|
|
20
|
+
FIELDS = [
|
|
21
|
+
"address STRING",
|
|
22
|
+
"annual_salary int",
|
|
23
|
+
"annual_salary_from int",
|
|
24
|
+
"annual_salary_to int",
|
|
25
|
+
"birth STRING",
|
|
26
|
+
"card STRING",
|
|
27
|
+
"certificate_obj string",
|
|
28
|
+
"city STRING",
|
|
29
|
+
"corporation_id int",
|
|
30
|
+
"corporation_name STRING",
|
|
31
|
+
"corporation_type STRING",
|
|
32
|
+
"degree STRING",
|
|
33
|
+
"discipline_name STRING",
|
|
34
|
+
"education_obj string",
|
|
35
|
+
"email STRING",
|
|
36
|
+
"expect_annual_salary int",
|
|
37
|
+
"expect_city_names string",
|
|
38
|
+
"expect_industry_name STRING",
|
|
39
|
+
"expect_position_name STRING",
|
|
40
|
+
"expect_salary_from int",
|
|
41
|
+
"expect_salary_to int",
|
|
42
|
+
"expect_type STRING",
|
|
43
|
+
"gender STRING",
|
|
44
|
+
"industry_name STRING",
|
|
45
|
+
"industry_names STRING",
|
|
46
|
+
"is_deleted STRING",
|
|
47
|
+
"is_fertility STRING",
|
|
48
|
+
"is_house STRING",
|
|
49
|
+
"is_management_experience STRING",
|
|
50
|
+
"is_marital STRING",
|
|
51
|
+
"is_oversea STRING",
|
|
52
|
+
"language_obj string",
|
|
53
|
+
"name STRING",
|
|
54
|
+
"nation STRING",
|
|
55
|
+
"phone STRING",
|
|
56
|
+
"political_status STRING",
|
|
57
|
+
"position_name STRING",
|
|
58
|
+
"project_obj string",
|
|
59
|
+
"responsibilities string",
|
|
60
|
+
"salary_month int",
|
|
61
|
+
"scale STRING",
|
|
62
|
+
"school_name STRING",
|
|
63
|
+
"self_remark string",
|
|
64
|
+
"skill_obj string",
|
|
65
|
+
"title_name STRING",
|
|
66
|
+
"tob_resume_id STRING",
|
|
67
|
+
"updated_at Timestamp",
|
|
68
|
+
"wechat STRING",
|
|
69
|
+
"work_obj string",
|
|
70
|
+
"work_experience int",
|
|
71
|
+
"work_start_time BIGINT"
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
def refactor(df):
|
|
75
|
+
def deal_obj(obj, k, kk):
|
|
76
|
+
if not isinstance(obj, type({})):
|
|
77
|
+
return ""
|
|
78
|
+
obj = obj.get(k, {})
|
|
79
|
+
if not isinstance(obj, type({})):
|
|
80
|
+
return ""
|
|
81
|
+
return obj.get(kk, "")
|
|
82
|
+
|
|
83
|
+
def loadjson(line):
|
|
84
|
+
try:
|
|
85
|
+
return json.loads(line)
|
|
86
|
+
except Exception:
|
|
87
|
+
pass
|
|
88
|
+
return {}
|
|
89
|
+
|
|
90
|
+
df["obj"] = df["resume_content"].map(lambda x: loadjson(x))
|
|
91
|
+
df.fillna("", inplace=True)
|
|
92
|
+
|
|
93
|
+
clms = ["tob_resume_id", "updated_at"]
|
|
94
|
+
|
|
95
|
+
def extract(nms, cc=None):
|
|
96
|
+
nonlocal clms
|
|
97
|
+
clms.extend(nms)
|
|
98
|
+
for c in nms:
|
|
99
|
+
if cc:
|
|
100
|
+
df[c] = df["obj"].map(lambda x: deal_obj(x, cc, c))
|
|
101
|
+
else:
|
|
102
|
+
df[c] = df["obj"].map(
|
|
103
|
+
lambda x: json.dumps(
|
|
104
|
+
x.get(
|
|
105
|
+
c,
|
|
106
|
+
{}),
|
|
107
|
+
ensure_ascii=False) if isinstance(
|
|
108
|
+
x,
|
|
109
|
+
type(
|
|
110
|
+
{})) and (
|
|
111
|
+
isinstance(
|
|
112
|
+
x.get(c),
|
|
113
|
+
type(
|
|
114
|
+
{})) or not x.get(c)) else str(x).replace(
|
|
115
|
+
"None",
|
|
116
|
+
""))
|
|
117
|
+
|
|
118
|
+
extract(["education", "work", "certificate", "project", "language",
|
|
119
|
+
"skill"])
|
|
120
|
+
extract(["wechat", "phone", "is_deleted",
|
|
121
|
+
"name", "tel", "email"], "contact")
|
|
122
|
+
extract(["nation", "expect_industry_name", "salary_month",
|
|
123
|
+
"industry_ids", "is_house", "birth", "annual_salary_from",
|
|
124
|
+
"annual_salary_to", "card",
|
|
125
|
+
"expect_salary_to", "expect_salary_from",
|
|
126
|
+
"expect_position_name", "gender", "city",
|
|
127
|
+
"is_fertility", "expect_city_names",
|
|
128
|
+
"political_status", "title_name", "expect_annual_salary",
|
|
129
|
+
"industry_name", "address", "position_name", "school_name",
|
|
130
|
+
"corporation_id",
|
|
131
|
+
"is_oversea", "responsibilities",
|
|
132
|
+
"work_start_time", "degree", "management_experience",
|
|
133
|
+
"expect_type", "corporation_type", "scale", "corporation_name",
|
|
134
|
+
"self_remark", "annual_salary", "work_experience",
|
|
135
|
+
"discipline_name", "marital", "updated_at"], "basic")
|
|
136
|
+
|
|
137
|
+
df["degree"] = df["degree"].map(lambda x: degrees.get_name(x))
|
|
138
|
+
df["address"] = df["address"].map(lambda x: " ".join(regions.get_names(x)))
|
|
139
|
+
df["industry_names"] = df["industry_ids"].map(lambda x: " ".join([" ".join(industries.get_names(i)) for i in
|
|
140
|
+
str(x).split(",")]))
|
|
141
|
+
clms.append("industry_names")
|
|
142
|
+
|
|
143
|
+
def arr2str(a):
|
|
144
|
+
if not a:
|
|
145
|
+
return ""
|
|
146
|
+
if isinstance(a, list):
|
|
147
|
+
a = " ".join([str(i) for i in a])
|
|
148
|
+
return str(a).replace(",", " ")
|
|
149
|
+
|
|
150
|
+
df["expect_industry_name"] = df["expect_industry_name"].map(
|
|
151
|
+
lambda x: arr2str(x))
|
|
152
|
+
df["gender"] = df["gender"].map(
|
|
153
|
+
lambda x: "男" if x == 'M' else (
|
|
154
|
+
"女" if x == 'F' else ""))
|
|
155
|
+
for c in ["is_fertility", "is_oversea", "is_house",
|
|
156
|
+
"management_experience", "marital"]:
|
|
157
|
+
df[c] = df[c].map(
|
|
158
|
+
lambda x: '是' if x == 'Y' else (
|
|
159
|
+
'否' if x == 'N' else ""))
|
|
160
|
+
df["is_management_experience"] = df["management_experience"]
|
|
161
|
+
df["is_marital"] = df["marital"]
|
|
162
|
+
clms.extend(["is_management_experience", "is_marital"])
|
|
163
|
+
|
|
164
|
+
df.fillna("", inplace=True)
|
|
165
|
+
for i in range(len(df)):
|
|
166
|
+
if not df.loc[i, "phone"].strip() and df.loc[i, "tel"].strip():
|
|
167
|
+
df.loc[i, "phone"] = df.loc[i, "tel"].strip()
|
|
168
|
+
|
|
169
|
+
for n in ["industry_ids", "management_experience", "marital", "tel"]:
|
|
170
|
+
for i in range(len(clms)):
|
|
171
|
+
if clms[i] == n:
|
|
172
|
+
del clms[i]
|
|
173
|
+
break
|
|
174
|
+
|
|
175
|
+
clms = list(set(clms))
|
|
176
|
+
|
|
177
|
+
df = df.reindex(sorted(clms), axis=1)
|
|
178
|
+
#print(json.dumps(list(df.columns.values)), "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL")
|
|
179
|
+
for c in clms:
|
|
180
|
+
df[c] = df[c].map(
|
|
181
|
+
lambda s: str(s).replace(
|
|
182
|
+
"\t",
|
|
183
|
+
" ").replace(
|
|
184
|
+
"\n",
|
|
185
|
+
"\\n").replace(
|
|
186
|
+
"\r",
|
|
187
|
+
"\\n"))
|
|
188
|
+
# print(df.values.tolist())
|
|
189
|
+
return dict(zip([n.split()[0] for n in FIELDS], df.values.tolist()[0]))
|