-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
c2b4448
commit 54f59cf
Showing
6 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#! coding=utf-8 | ||
""" | ||
high-level toolbox for text classify | ||
""" | ||
import re | ||
import typing | ||
import nlpir | ||
from nlpir import get_instance as __get_instance__ | ||
from nlpir import native | ||
|
||
# class and class instance | ||
__cls__ = native.deep_classifier.DeepClassifier | ||
__instance__: typing.Optional[native.deep_classifier.DeepClassifier] = None | ||
# Location of DLL | ||
__lib__ = None | ||
# Data directory | ||
__data__ = None | ||
# license_code | ||
__license_code__ = None | ||
# encode | ||
__nlpir_encode__ = native.UTF8_CODE | ||
|
||
__handler__ = None | ||
|
||
|
||
@__get_instance__ | ||
def get_native_instance() -> native.deep_classifier.DeepClassifier: | ||
""" | ||
返回原生NLPIR接口,使用更多函数 | ||
:return: The singleton instance | ||
""" | ||
return __instance__ | ||
|
||
|
||
@__get_instance__ | ||
def classify(txt: str) -> str: | ||
""" | ||
Text classify | ||
:param txt: text | ||
:return: class | ||
""" | ||
global __handler__ | ||
if __handler__ is None: | ||
# default model | ||
__handler__ = __instance__.new_instance(800) | ||
__instance__.load_train_result(__handler__) | ||
return __instance__.classify(txt, handler=__handler__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# coding=utf-8 | ||
""" | ||
Tested function: | ||
- :func:`nlpir.deep_classifier.classify` | ||
""" | ||
from nlpir import deep_classifier | ||
|
||
|
||
def test_classify(): | ||
from tests.strings import test_str | ||
assert deep_classifier.classify(txt=test_str) == "教育" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters