nlpir package

nlpir.clean_logs(data_path: Optional[str] = None, include_current: bool = False)[source]

Clean logs

Parameters:
  • data_path – the cusi
  • include_current – include current directory or not
nlpir.get_instance(func: __F__) → __F__[source]

A wrapper to init instance when call the function

直接使用单层装饰器时,此装饰器会在import module的时候直接被调用, 生成对应的函数,导致对应的类实例过早初始化. 为了让类实例真正在函数调用时才初始化,使用下面的 functions.warps(), 此方法在直接import的时候不会被调用(因为初始化时仅仅为函数没有函数参数),故使用 这种方式.

让函数在真正执行时才进行类实例初始化的原因是为了使 init_setting() 可以被使用, 类似于 :func:logging.basicConfig 方法,可以在import对应module后可以有一次修改初始化 参数的可能.

nlpir.init_setting(init_module, encode: Optional[int] = None, lib_path: Optional[int] = None, data_path: Optional[str] = None, license_code: str = '')[source]

Init the NLPIR module for custom usage.

Only can init it , before call any process function in that module

Parameters:
Raise:

NLPIRException

Returns:

init module

nlpir.import_dict(word_list: list, instance) → list[source]

Temporary add word as dictionary, will loss it when restart the Program. Can use save_user_dict() to make persistence, clean_temp_user_dict() to delete all temporary words in memory or clean_user_dict() to clean all user words stored in memory and persistent in disk , but this function will not delete the persistent user dictionary in disk, the user persistent dictionary will be reloaded when restart the Program. delete_user_word() can delete part of the user dictionary.

The persistent dict cannot be clean by using method above. clean_saved_user_dict() will be used in this situation. But it will delete all user dict include saved dict in the past.

Every word in word_list can be a single word and the POS will be n. The custom POS can be added as word pos in word_list.

Parameters:
  • instance – instance to execute the function
  • word_list – list of words want to add to NLPIR
Returns:

the word fail to add to the NLPIR

nlpir.clean_temp_user_dict(instance) → bool[source]

Clean all temporary words in memory.

Parameters:instance – instance to execute the function
Returns:success or not
nlpir.clean_user_dict(instance) → bool[source]

Clean all user words stored in memory and persistent in disk, but this function will not delete the persistent user dictionary in disk, the user persistent dictionary will be reloaded when restart the Program.

More information shows in import_dict()

Parameters:instance – instance to execute the function
Returns:success or not
nlpir.delete_user_word(word_list: list, instance)[source]

Delete words in temporary dictionary, more information shows in import_dict()

Parameters:
  • instance – instance to execute the function
  • word_list – list of words want to delete
nlpir.save_user_dict(instance) → bool[source]

Save temporary dictionary to Data, more information shows in import_dict()

Parameters:instance – instance to execute the function
Returns:Success or not
nlpir.clean_saved_user_dict()[source]

Delete user dict from disk, which is :

  1. Data/FieldDict.pdat
  2. Data/FieldDict.pos
  3. Data/FieldDict.wordlist
  4. Data/UserDefinedDict.lst
Returns:Delete success or not
nlpir.import_blacklist(instance, filename: str, pos_blacklist=typing.List[str]) → bool[source]

Import Blacklist to system

This function will permanently import blacklist words to system not to the memory . If you want to delete the blacklist words, you should run clean_blacklist() to delete blacklist form system .

此函数将会把词永久性保存在NLPIR中,和保存用户词典类似.这里删除使用的是 clean_blacklist() .

停用词表,Format of stop word::
word1 n1 word2 n2 word3 n3

pos_blacklist 为: ['n1', 'n2']word1, word2 将会进入屏蔽列表

If pos_blacklist : ['n1', 'n2'] Then word1, word2 will be in the blacklist

Parameters:
  • instance – instance to execute the function
  • filename – A word list that the words want to import to the blacklist (stop word list), 一个停用词词表,里面为想进行屏蔽的词,也可以包括别的词,是否不进行抽取是按照词表中的词性来确定的.
  • pos_blacklist – A list of pos that want to block in the system, 想要屏蔽的词的词性
Returns:

是否成功导入

nlpir.clean_blacklist() → bool[source]

清除黑名单词表, 会将对应的文件进行重命名, 之后可以通过 recover_blacklist() 进行恢复,但仅可以进行一次,若重复调用本函数则恢复函数不起作用

Returns:clean success or not
nlpir.recover_blacklist() → bool[source]

恢复黑名单词表,仅在被重命名的词表存在时才起作用

Returns:

Submodules

nlpir.ictclas module

high-level toolbox for Chinese Word Segmentation

nlpir.ictclas.get_native_instance() → nlpir.native.ictclas.ICTCLAS[source]

返回原生NLPIR接口,使用更多函数

Returns:The singleton instance
nlpir.ictclas.process_to_list(txt: str, pos_tag: bool) → list[source]

Default function for post_process arg in nlpir.ictclas.segment(), which get list of tuple if it has POS tag, or get list of words

函数 nlpir.ictclas.segment()post_process 的默认参数, 使得分词函数 的输出为一个列表, 列表中的内容在进行词性标注时为 tuple, 内容为词和词性. 不进行词性标注时 直接为分词后的词.

本函数不可直接调用,仅作为 :func:`nlpir.ictclas.segment` 的参数才有意义

Parameters:
  • txt – Segmented string
  • pos_tag – The segmented string has POS tag or not
Returns:

list of tuple of list of word

Without POS tag:

[
    '法国', '启蒙', '思想家', '孟德斯', '鸠', '曾', '说', '过', ':', '“', '一切', '有', '权力',
    '的', '人', '都', '容易', '滥用', '权力', ',', '这', '是', '一', '条', '千古', '不', '变',
    '的', '经验', '。'
]

With POS tag:

[
    ('法国', 'nsf'), ('启蒙', 'vn'), ('思想家', 'n'), ('孟德斯', 'nrf'), ('鸠', 'n'), ('曾', 'd'),
    ('说', 'v'), ('过', 'uguo'), (':', 'wm'), ('“', 'wyz'), ('一切', 'rz'), ('有', 'vyou'),
    ('权力', 'n'), ('的', 'ude1'), ('人', 'n'), ('都', 'd'), ('容易', 'ad'), ('滥用', 'v'),
    ('权力', 'n'), (',', 'wd'), ('这', 'rzv'), ('是', 'vshi'), ('一', 'm'), ('条', 'q'), ('千古', 'n'),
    ('不', 'd'), ('变', 'v'), ('的', 'ude1'), ('经验', 'n'), ('。', 'wj'), ('有', 'vyou'), ('权力', 'n'),
    ('的', 'ude1'), ('人', 'n'), ('直到', 'v'), ('把', 'pba'), ('权力', 'n'), ('用到', 'v'),
    ('极限', 'n'), ('方可', 'd'), ('休止', 'vi'), ('。', 'wj')
]
nlpir.ictclas.process_to_generator(text: str, pos_tag: bool) → Generator[T_co, T_contra, V_co][source]

Same as process_to_list() ,return an iterator, save memory if the string is very large

nlpir.ictclas.segment() 的内置的处理函数, 非默认值. 本函数可以替换 process_to_list(), 输出的结果 为迭代器,用于获取较大长度的文本

Parameters:
  • text
  • pos_tag
Returns:

nlpir.ictclas.import_dict(word_list: list) → list[source]

See nlpir.import_dict()

Parameters:word_list – list of words want to add to NLPIR
Returns:the word fail to add to the NLPIR
nlpir.ictclas.clean_user_dict() → bool[source]

See nlpir.clean_user_dict()

Returns:success or not
nlpir.ictclas.clean_temp_user_dict() → bool[source]

See nlpir.clean_temp_user_dict()

Returns:success or not
nlpir.ictclas.delete_user_word(word_list: list)[source]

See nlpir.delete_user_word()

Parameters:word_list – list of words want to delete
nlpir.ictclas.save_user_dict() → bool[source]

See nlpir.save_user_dict()

Returns:Success or not
nlpir.ictclas.clean_saved_user_dict()[source]

See nlpir.clean_saved_user_dict()

Returns:Delete success or not
nlpir.ictclas.segment(txt: str, pos_tagged: bool = False, post_process: callable = <function process_to_list>) → Any[source]

中文分词函数,将字符串进行分词,支持多线程和多进程分词:

Example:

from multiprocessing import Pool
test_str = "法国启蒙思想家孟德斯鸠曾说过:“一切有权力的人都容易滥用权力,这是一条千古不变的经验。有权力的人直到把权力用到"                "极限方可休止。”另一法国启蒙思想家卢梭从社会契约论的观点出发,认为国家权力是公民让渡其全部“自然权利”而获得的,"                "他在其名著《社会契约论》中写道:“任何国家权力无不是以民众的权力(权利)让渡与公众认可作为前提的”。"
with Pool(16) as pool:
    result = pool.map(ictclas.segment, [data]*100)

默认只进行分词不进行分词标注,返回为list,可使用其他或者自行创建需要的post_process函数改变最终输出, post_process的输入为字符串,格式如下,分别为进行词性标注和不进行词性标注的:

test_str_seg_pos = '法国/nsf 启蒙/vn 思想家/n 孟德斯/nrf 鸠/n 曾/d 说/v 过/uguo :/wm “/wyz 一切/rz 有/vyou 权力/n '                            '的/ude1 人/n 都/d 容易/ad 滥用/v 权力/n ,/wd 这/rzv 是/vshi 一/m 条/q 千古/n 不/d 变/v 的/ude1 经'                            '验/n 。/wj 有/vyou 权力/n 的/ude1 人/n 直到/v 把/pba 权力/n 用到/v 极限/n 方可/d 休止/vi 。/wj ”/wyy'                            ' 另/rz 一/m 法国/nsf 启蒙/vn 思想家/n 卢/nr1 梭/ng 从/p 社会/n 契约/n 论/k 的/ude1 观点/n 出发/vi '                            ',/wd 认为/v 国家/n 权力/n 是/vshi 公民/n 让/v 渡/v 其/rz 全部/m “/wyz 自然/n 权利/n ”/wyy 而/cc '                            '获得/v 的/ude1 ,/wd 他/rr 在/p 其/rz 名著/n 《/wkz 社会/n 契约/n 论/v 》/wky 中/f 写道/v :/wm '                            '“/wyz 任何/rz 国家/n 权力/n 无不/d 是/vshi 以/p 民众/n 的/ude1 权力/n (/wkz 权利/n )/wky 让/v '                            '渡/v 与/p 公众/n 认可/vi 作为/p 前提/n 的/ude1 ”/wyy 。/wj '
test_str_seg = '法国 启蒙 思想家 孟德斯 鸠 曾 说 过 : “ 一切 有 权力 的 人 都 容易 滥用 权力 , 这 是 一 条 千古 不 变 的'                        ' 经验 。 有 权力 的 人 直到 把 权力 用到 极限 方可 休止 。 ” 另 一 法国 启蒙 思想家 卢 梭 从 社会 契约'                        ' 论 的 观点 出发 , 认为 国家 权力 是 公民 让 渡 其 全部 “ 自然 权利 ” 而 获得 的 , 他 在 其 名'                        '著 《 社会 契约 论 》 中 写道 : “ 任何 国家 权力 无不 是 以 民众 的 权力 ( 权利 ) 让 渡 与 公众'                        ' 认可 作为 前提 的 ” 。 '

默认的post_process是直接将上述结果变成列表形式,若想获得字符串形式,可以使用简单的lambda表达式使post_process直接返回:

segment(txt, pas_tagged, post_process=lambda t, _ : t)

默认使用的标注集为 nlpir.native.ictclas.ICTCLAS.ICT_POS_MAP_SECOND 计算所二级标注集

若需要进行标注集修改,使用 nlpir.native.ictclas.ICTCLAS.set_pos_map() 进行修改

Parameters:
  • txt – The string want to be segmented
  • pos_tagged – POS tagging or not
  • post_process – The post process function, in order to get different result
nlpir.ictclas.file_segment(src_path: str, tgt_path: str, pos_tagged: bool = False) → float[source]
Parameters:
  • src_path – path of txt file
  • tgt_path – path of result
  • pos_tagged – POS tagging or not
Returns:

time to process

nlpir.new_word_finder module

high-level toolbox for Chinese New Word Finder

nlpir.new_word_finder.get_native_instance() → nlpir.native.new_word_finder.NewWordFinder[source]

返回原生NLPIR接口,使用更多函数

Returns:The singleton instance
nlpir.new_word_finder.find_new_words(text: str, max_key: int) → Optional[List[dict]][source]

获取新词,返回新词和对应权重词性,此函数适合较少数量的文本的新词发现功能(不超过20M), 若数量较大可以使用 find_new_words_batch() 进行处理

Parameters:
  • text – 文本内容
  • max_key – 新词发现返回的新词数量最大值
Returns:

格式如下

[
    {
        "freq" : 225,
        "pos" : "n_new",
        "weight" : 126.28066602434734,
        "word" : "主权者"
    }, {
        "freq" : 100,
        "pos" : "n_new",
        "weight" : 60.782738270597314,
        "word" : "行政官"
    }, {
        "freq" : 103,
        "pos" : "n_new",
        "weight" : 45.549023266744136,
        "word" : "卢梭"
    }, { ... }
    ...
]
nlpir.new_word_finder.find_new_words_batch(text_iter: Iterable[str]) → Optional[List[dict]][source]
Parameters:text_iter – 文本迭代器, 迭代器内容为文本
Returns:find_new_words()
nlpir.new_word_finder.export_dict(words_result: List[dict], save_path: str) → bool[source]

find_new_words_batch()find_new_words() 获得的结果保存为词典

Parameters:
  • words_result – 新词发现返回结果
  • save_path – 保存词典位置
Returns:

是否保存成功

nlpir.key_extract module

high-level toolbox for Chinese Key-word Extraction

nlpir.key_extract.get_native_instance() → nlpir.native.key_extract.KeyExtract[source]

返回原生NLPIR接口,使用更多函数

Returns:The singleton instance
nlpir.key_extract.import_dict(word_list: list) → list[source]

See nlpir.import_dict()

Parameters:word_list – list of words want to add to NLPIR
Returns:the word fail to add to the NLPIR
nlpir.key_extract.clean_user_dict() → bool[source]

See nlpir.clean_user_dict()

Returns:success or not
nlpir.key_extract.clean_temp_user_dict() → bool[source]

See nlpir.clean_temp_user_dict()

Returns:success or not
nlpir.key_extract.delete_user_word(word_list: list)[source]

See nlpir.delete_user_word()

Parameters:word_list – list of words want to delete
nlpir.key_extract.save_user_dict() → bool[source]

See nlpir.save_user_dict()

Returns:Success or not
nlpir.key_extract.clean_saved_user_dict()[source]

See nlpir.clean_saved_user_dict()

Returns:Delete success or not
nlpir.key_extract.import_blacklist(filename: str, pos_blacklist=typing.List[str]) → bool[source]

Import Blacklist to system, see nlpir.import_blacklist()

nlpir.key_extract.clean_blacklist() → bool[source]

清除黑名单词表, see nlpir.clean_blacklist()

Returns:clean success or not
nlpir.key_extract.recover_blacklist() → bool[source]

恢复黑名单词表,仅在被重命名的词表存在时才起作用, see nlpir.recover_blacklist()

Returns:
nlpir.key_extract.get_key_words(text: str, max_key: int = 50) → List[dict][source]

获取文本对应的关键词,以及对应的权值,词性,词频等信息 Get keyword from text with weight, frequent and pos

Parameters:
  • text
  • max_key – max number keyword want to get
Returns:

a list of keywords with weight, example:

[
    {
        'freq': 2,
        'pos': 'n_new',
        'weight': 7.771335980376418,
        'word': '国家权力'
    },{
        'freq': 7,
        'pos': 'n',
        'weight': 7.438759706600493,
        'word': '权力'
    },{
        'freq': 1,
        'pos': 'nrf',
        'weight': 5.280000338096665,
        'word': '孟德斯鸠'
    },{ ...
    }, ...
]

nlpir.key_scanner module

high-level toolbox for Chinese Key-word Extraction

nlpir.key_scanner.get_native_instance() → nlpir.native.key_scanner.KeyScanner[source]

返回原生NLPIR接口,使用更多函数

Returns:The singleton instance
class nlpir.key_scanner.KeyScanProcessor(filter_type_index: int = 0)[source]

Bases: object

关键词过滤处理单元, 需要指定使用的过滤器, 若要新建 一过滤器, 选择没有被使用的编号实例化本类, 并使用 import_user_dict() 导入词典后便可使用,下次使用时仅需 实例化对应编号的本类即可.

导入词典后的过滤器会保存在Data文件夹下,若不删除则会一直存在,和导入 用户词典相似,不会消失.

Parameters:filter_type_index – 需要使用的过滤器
scan(text: str)[source]

Scan text

Parameters:text
Returns:
[
    {
        "class": class_name,
        "freq": frequent_of_class_hit
    },{
        ...
    },
    ...
]
scan_detail(text: str)[source]

Scan text get detail

{
    'Rules': ['傻逼'],
    'illegal':{
        'classes': [
            {'freq': 1, 'word': '粗言秽语'},
            {'freq': 1, 'word': '污言秽语'},
            {'freq': 1, 'word': '新华社禁用'}
        ],
        'hit_count': 3,
        'keys': ['傻逼'],
        'scan_val': 3.333333333333333
    },
    'line_id': 0,
    'org_file': '',
    'score': 3.333333333333333
}
Parameters:text
Returns:
nlpir.key_scanner.import_user_dict(user_dict: str, filter_index: int = 0, pinyin_abbrev_needed: bool = True, over_write: bool = False) → bool[source]

导入词典, 对应参数参考 nlpir.native.key_scanner.KeyScanner.import_user_dict()

Parameters:
  • user_dict
  • filter_index
  • pinyin_abbrev_needed
  • over_write
Returns:

nlpir.key_scanner.delete_user_dict(user_dict: str, filter_index: int = 0) → bool[source]

删除词典中的某些单词, 对应参数参考 nlpir.native.key_scanner.KeyScanner.delete_user_dict()

Parameters:
  • user_dict
  • filter_index
Returns:

nlpir.summary module

high-level toolbox for Summarization

nlpir.summary.get_native_instance() → nlpir.native.summary.Summary[source]

返回原生NLPIR接口,使用更多函数

Returns:The singleton instance
nlpir.summary.summarization(content: str, sum_rate: float = 0.0, sum_len: int = 250, html_tag_remove: bool = True, sentence_count: int = 0) → str[source]

摘要生成, 摘要长度受 sum_rate , sum_len 影响

Parameters:
  • content – 文档内容 text content
  • sum_rate – 文档摘要占原文百分比(为0.00则不限制) the percentage of summarization length comparing to original text (0.00 represent no limit):
  • sum_len – 用户限定的摘要长度(为0则不限制)The max len of summarization(0 will no limit)
  • html_tag_remove – 是否需要对原文进行Html标签的去除 remove the html tag or not
  • sentence_count (int) – 用户限定的句子数量 (为0则不限制)limit number of sentence, set 0 to no limit
Returns:

摘要字符串;出错返回空串 the summarization content, get null string if occurs error.

nlpir.doc_extractor module

high-level toolbox for Document Extractor

class nlpir.doc_extractor.ExtractResult(handle: int, user_retrieve_type: List[str])[source]

Bases: object

A class for retrieve result from Document Extractor’s handle

retrieve_type_map = {'abstract': 8, 'author': 4, 'country': 6, 'keyword': 3, 'location': 1, 'media': 5, 'negative': 10, 'organization': 2, 'person': 0, 'positive': 9, 'province': 7, 'text': 11, 'time': 12, 'user': 13}

Types map can be retrieved from DocExtractor

get_available_retrieve_types() → Dict[str, int][source]

Get a set of types_name and types available for current extraction result

Returns:
set_retrieve_types(retrieve_type_list: List[int]) → bool[source]

Set what type of data want to get from get_result() , can be set multi-times

Parameters:retrieve_type_list – list of retrieve types
Returns:
get_result(retrieve_types: Optional[List[int]] = None) → Dict[str, List[Dict[str, Union[str, int, float]]]][source]

Get result from current result, can be retrieved multi-times.

Parameters:retrieve_types – option, a list of retrieve types want to get, default is all types can be retrieved or certain types set by set_retrieve_types()
Returns:a dict of result : {type_name: [result}]} , example
{
"person": [
        {
            "word": "卢梭",
            "pos": "n",
            "weight": 1.5,
            "freq": 100
        }
    ]
}
get_sentiment_result() → int[source]

Get sentiment point from current extraction result

Returns:
nlpir.doc_extractor.get_native_instance() → nlpir.native.doc_extractor.DocExtractor[source]

返回原生NLPIR接口,使用更多函数

Returns:The singleton instance
nlpir.doc_extractor.extract(text: str, user_define_pos: List[str]) → nlpir.doc_extractor.ExtractResult[source]
Parameters:
  • text
  • user_define_pos
Returns:

nlpir.doc_extractor.import_dict(word_list: list) → list[source]

See nlpir.import_dict()

Parameters:word_list – list of words want to add to NLPIR
Returns:the word fail to add to the NLPIR
nlpir.doc_extractor.clean_user_dict() → bool[source]

See nlpir.clean_user_dict()

Returns:success or not
nlpir.doc_extractor.delete_user_word(word_list: list)[source]

See nlpir.delete_user_word()

Parameters:word_list – list of words want to delete
nlpir.doc_extractor.save_user_dict() → bool[source]

See nlpir.save_user_dict()

Returns:Success or not
nlpir.doc_extractor.clean_saved_user_dict()[source]

See nlpir.clean_saved_user_dict()

Returns:Delete success or not
nlpir.doc_extractor.import_blacklist(filename: str, pos_blacklist=typing.List[str]) → bool[source]

Import Blacklist to system, see nlpir.import_blacklist()

nlpir.doc_extractor.clean_blacklist() → bool[source]

清除黑名单词表, see nlpir.clean_blacklist()

Returns:clean success or not
nlpir.doc_extractor.recover_blacklist() → bool[source]

恢复黑名单词表,仅在被重命名的词表存在时才起作用, see nlpir.recover_blacklist()

Returns:

nlpir.cluster module

high-level toolbox for Text Cluster

nlpir.cluster.get_native_instance() → nlpir.native.cluster.Cluster[source]

返回原生NLPIR接口,使用更多函数

Returns:The singleton instance
nlpir.cluster.hash_text(text: str) → str[source]
nlpir.cluster.cluster(iter_text, max_doc: int, max_cls: int) → Tuple[List[Dict[KT, VT]], Dict[str, str]][source]

Make a cluster with a set of text, get the result as below

对文本进行聚类,获得结果的结构如下

[
    {
        "cluster_id": 1,
        "feature": ["aa", "bb", "cc"],
        "doc_num": 3,
        "doc_ids": ["abc", "cfg", "cca"]
    },
    ...
]

其中, doc_ids 使用 hash_text() 生成, 其结果会返回为 text_dict,

doc_ids is generated by hash_text() using document text, all the doc_id and doc_text will store to text_dict as KV

{
    doc_ids: text
}
Parameters:
  • iter_text – a iterator to get a set of text
  • max_doc – the maximum count for text
  • max_cls – the maximum count of class for clustering
Returns:

result, text_dict

nlpir.cluster.searchable_result(cluster_result: List[Dict[KT, VT]]) → Tuple[Dict[str, List[str]], Dict[str, List[str]], Dict[str, Set[str]]][source]

The cluster() ‘s result is not easily to search the result. This function will transform the result to a set of result dict to make search result easier.

cluster() 的结果并不容易使用, 本函数将其结果处理成多个容易搜索获取 结果的数据结构.

There are three dict data will return,

cluster_cls, can get every class’s features

{
    class_id: [class_feature]
}

feature_dict, can reverse the search above, get which classes have this feature

{
    word: [class_id]
}

result_dict, can get any doc’s class from doc’s hash from hash_text()

{
    doc_id: {class_id_1, class_id_2}
}
Parameters:cluster_result
Returns:cluster_cls, feature_dict, result_dict

nlpir.text_similarity module

high-level toolbox for Summarization

nlpir.text_similarity.get_native_instance() → nlpir.native.text_similarity.TextSimilarity[source]

返回原生NLPIR接口,使用更多函数

Returns:The singleton instance
nlpir.text_similarity.similarity(text_1: str, text_2: str, model=2) → float[source]

compute text similarity, there are three models:

  • SIM_MODEL_WORD 词模型,速度适中,常规适用于正常规范的长文档
  • IM_MODEL_CHAR 字模型,速度最快,适用于相对规范的短文本
  • SIM_MODEL_KEY 主题词模型,速度最慢,考虑语义最多,适合于复杂文本
Parameters:
  • text_1
  • text_2
  • model
Returns:

nlpir.sentiment_analysis module

high-level toolbox for Sentiment Analysis

class nlpir.sentiment_analysis.EmotionType[source]

Bases: str, enum.Enum

An enumeration.

EMOTION_HAPPY = 'EMOTION_HAPPY'
EMOTION_GOOD = 'EMOTION_GOOD'
EMOTION_ANGER = 'EMOTION_ANGER'
EMOTION_SORROW = 'EMOTION_SORROW'
EMOTION_FEAR = 'EMOTION_FEAR'
EMOTION_EVIL = 'EMOTION_EVIL'
EMOTION_SURPRISE = 'EMOTION_SURPRISE'
nlpir.sentiment_analysis.get_native_instance() → nlpir.native.sentiment.SentimentAnalysis[source]

返回原生NLPIR接口,使用更多函数

Returns:The singleton instance
nlpir.sentiment_analysis.get_emotion(content: str) → Dict[nlpir.sentiment_analysis.EmotionType, int][source]

获取 Sentiment Analysis 结果

Parameters:content – 文档内容 text content
Returns:

nlpir.eye_checker module

KGB

class nlpir.eye_checker.KGBItem(**data)[source]

Bases: pydantic.main.BaseModel

model_config = {}
model_fields = {'attribute': FieldInfo(annotation=str, required=True), 'id': FieldInfo(annotation=int, required=True), 'key_value': FieldInfo(annotation=str, required=True), 'name': FieldInfo(annotation=str, required=True), 'offset': FieldInfo(annotation=int, required=True), 'org_para_text': FieldInfo(annotation=str, required=True), 'para_id': FieldInfo(annotation=str, required=True), 'rule_used': FieldInfo(annotation=str, required=True)}
class nlpir.eye_checker.KGBSingleKeyResult(**data)[source]

Bases: pydantic.main.BaseModel

model_config = {}
model_fields = {'key_value': FieldInfo(annotation=List[nlpir.eye_checker.KGBItem], required=True)}
class nlpir.eye_checker.KGBTableResult(**data)[source]

Bases: pydantic.main.BaseModel

model_config = {}
model_fields = {}
class nlpir.eye_checker.KGBTupleResult(**data)[source]

Bases: pydantic.main.BaseModel

model_config = {}
model_fields = {'index': FieldInfo(annotation=int, required=True), 'tuple': FieldInfo(annotation=List[nlpir.eye_checker.KGBItem], required=True)}
class nlpir.eye_checker.KGBResult(**data)[source]

Bases: pydantic.main.BaseModel

model_config = {}
model_fields = {'single_key_result': FieldInfo(annotation=KGBSingleKeyResult, required=False), 'tables': FieldInfo(annotation=List[nlpir.eye_checker.KGBTableResult], required=False), 'tuples': FieldInfo(annotation=List[nlpir.eye_checker.KGBTupleResult], required=False)}
nlpir.eye_checker.get_native_instance() → nlpir.native.eye_checker.EyeChecker[source]

返回原生NLPIR接口,使用更多函数

Returns:The singleton instance
nlpir.eye_checker.import_kgb_rules(rule_text: str, overwrite: bool, report_type: int) → int[source]
nlpir.eye_checker.extract_knowledge(report_text: str, report_type: int) → nlpir.eye_checker.KGBResult[source]
nlpir.eye_checker.list_rules() → Set[int][source]
nlpir.eye_checker.delete_rules(rule: int)[source]

nlpir.deep_classifier module

high-level toolbox for text classify

nlpir.deep_classifier.get_native_instance() → nlpir.native.deep_classifier.DeepClassifier[source]

返回原生NLPIR接口,使用更多函数

Returns:The singleton instance
nlpir.deep_classifier.classify(txt: str) → str[source]

Text classify

Parameters:txt – text
Returns:class

nlpir.tools module

nlpir.tools.download(url, des)[source]

Download a file from url and save to des, use to download license from github

Parameters:
  • url – url to download
  • des – a path to save the data from url
Returns:

None

nlpir.tools.update_license(data_path=None) → None[source]

update license from NLPIR github repo

Parameters:data_path – the path to save the license, save in Data if None provide

nlpir.exception module

exception nlpir.exception.NLPIRException[source]

Bases: Exception