Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pdf-miner
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Qin Kaijie
pdf-miner
Commits
57380cbe
Commit
57380cbe
authored
Jul 23, 2024
by
myhloli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(language): add FT LANG cache directory setup
parent
a396b8f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
0 deletions
+12
-0
language.py
magic_pdf/libs/language.py
+12
-0
lid.176.ftz
magic_pdf/resources/fasttext-langdetect/lid.176.ftz
+0
-0
No files found.
magic_pdf/libs/language.py
View file @
57380cbe
import
os
import
unicodedata
import
unicodedata
if
not
os
.
getenv
(
"FTLANG_CACHE"
):
current_file_path
=
os
.
path
.
abspath
(
__file__
)
current_dir
=
os
.
path
.
dirname
(
current_file_path
)
root_dir
=
os
.
path
.
dirname
(
current_dir
)
ftlang_cache_dir
=
os
.
path
.
join
(
root_dir
,
'resources'
,
'fasttext-langdetect'
)
os
.
environ
[
"FTLANG_CACHE"
]
=
str
(
ftlang_cache_dir
)
# print(os.getenv("FTLANG_CACHE"))
from
fast_langdetect
import
detect_language
from
fast_langdetect
import
detect_language
def
detect_lang
(
text
:
str
)
->
str
:
def
detect_lang
(
text
:
str
)
->
str
:
if
len
(
text
)
==
0
:
if
len
(
text
)
==
0
:
return
""
return
""
try
:
try
:
...
@@ -18,6 +29,7 @@ def detect_lang(text: str) -> str:
...
@@ -18,6 +29,7 @@ def detect_lang(text: str) -> str:
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
print
(
os
.
getenv
(
"FTLANG_CACHE"
))
print
(
detect_lang
(
"This is a test."
))
print
(
detect_lang
(
"This is a test."
))
print
(
detect_lang
(
"<html>This is a test</html>"
))
print
(
detect_lang
(
"<html>This is a test</html>"
))
print
(
detect_lang
(
"这个是中文测试。"
))
print
(
detect_lang
(
"这个是中文测试。"
))
...
...
magic_pdf/resources/fasttext-langdetect/lid.176.ftz
0 → 100644
View file @
57380cbe
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment