harvesttext package¶
Submodules¶
harvesttext.harvesttext module¶
-
class
harvesttext.harvesttext.
HarvestText
(standard_name=False)[源代码]¶ 基类:
object
-
build_entity_ego_graph
(docs, word, min_freq=0, inv_index={}, used_types=[])[源代码]¶ Entity only version of build_word_ego_graph() :param docs: :param word: :param min_freq: :param inv_index: :param used_types: :return:
-
build_sent_dict
(sents, method='PMI', min_times=5, ft_size=100, ft_epochs=15, ft_window=5, pos_seeds=[], neg_seeds=[])[源代码]¶
-
build_word_ego_graph
(docs, word, standard_name=True, min_freq=0, other_min_freq=-1, stopwords=None)[源代码]¶ 根据文本和指定限定词,获得以限定词为中心的各词语的关系。 限定词可以是一个特定的方面(衣食住行这类文档),这样就可以从词语中心图中获得关于这个方面的简要信息 :param docs: 文本的列表 :param word: 限定词 :param standard_name: 把所有实体的指称化为标准实体名 :param stopwords: 需要过滤的停用词 :param min_freq: 作为边加入到图中的与中心词最小共现次数,用于筛掉可能过多的边 :param other_min_freq: 中心词以外词语关系的最小共现次数 :return: G(networxX中的Graph)
-
find_entity_with_rule
(text, rulesets=[], add_to_dict=True, type0='添加词')[源代码]¶ 利用规则从分词结果中的词语找到实体,并可以赋予相应的类型再加入实体库 :param text: string, 一段文本 :param rulesets: list of (tuple of rules or single rule) from match_patterns, list中包含多个规则,满足其中一种规则的词就认为属于这个type 而每种规则由tuple或单个条件(pattern)表示,一个词必须满足其中的一个或多个条件。 :param add_to_dict: 是否把找到的结果直接加入词典 :param type0: 赋予满足条件的词语的实体类型, 仅当add_to_dict时才有意义 :return: found_entities
-
set_linking_strategy
(strategy, lastest_mention=None, entity_freq=None, type_freq=None)[源代码]¶ 为实体链接设定一些简单策略,目前可选的有: ‘None’,’freq’,’latest’,’latest&freq’ ‘None’: 默认选择候选实体字典序第一个 ‘freq’: 对于单个字面值,选择其候选实体中之前出现最频繁的一个。
对于多个重叠字面值,选择其中候选实体出现最频繁的一个进行连接【每个字面值已经确定唯一映射】。‘latest’: 对于单个字面值,如果在最近有可以确定的映射,就使用最近的映射。 ‘latest’- 对于职称等作为代称的情况可能会比较有用。 比如”经理”可能代指很多人,但是第一次提到的时候应该会包括姓氏。 我们就可以记忆这次信息,在后面用来消歧。 ‘freq’ - 单字面值例:’市长’+{‘A市长’:5,’B市长’:3} -> ‘A市长’ 重叠字面值例,’xx市长江yy’+{‘xx市长’:5,’长江yy’:3}+{‘市长’:’xx市长’}+{‘长江’:’长江yy’} -> ‘xx市长’ :param strategy: 可选 ‘None’,’freq’,’latest’,’latest&freq’ 中的一个 :param lastest_mention: dict,用于’latest’,预设 :param entity_freq: dict,用于’freq’,预设某实体的优先级(词频) :param type_freq: dict,用于’freq’,预设类别所有实体的优先级(词频) :return None
-
harvesttext.match_patterns module¶
harvesttext.resources module¶
-
harvesttext.resources.
get_baidu_stopwords
()[源代码]¶ 获得百度停用词列表 来源,网上流传的版本:https://wenku.baidu.com/view/98c46383e53a580216fcfed9.html 包含了中英文常见词及部分标点符号 :return: stopwords: set of string
-
harvesttext.resources.
get_qh_sent_dict
()[源代码]¶ 获得参考褒贬义词典: 褒贬义词典 清华大学 李军
此资源被用于以下论文中: Jun Li and Maosong Sun, Experimental Study on Sentiment Classification of Chinese Review using Machine Learning Techniques, in Proceding of IEEE NLPKE 2007 李军 中文评论的褒贬义分类实验研究 硕士论文 清华大学 2008 :return: qh_sent_dict = {“pos”:[words],”neg”:[words]}
-
harvesttext.resources.
get_qh_typed_words
(used_types=['IT', '动物', '医药', '历史人名', '地名', '成语', '法律', '财经', '食物'])[源代码]¶ THUOCL:清华大学开放中文词库 http://thuocl.thunlp.org/ IT 财经 成语 地名 历史名人 诗词 医学 饮食 法律 汽车 动物 :param used_types: :return: typed_words: 字典,键为类型,值为该类的词语组成的set
harvesttext.sent_dict module¶
harvesttext.word_discoverer module¶
-
class
harvesttext.word_discoverer.
WordDiscoverer
(doc, max_word_len=5, min_freq=5e-05, min_entropy=2.0, min_aggregation=50, ent_threshold='both', mem_saving=0)[源代码]¶ 基类:
object
-
genWords
(doc)[源代码]¶ Generate all candidate words with their frequency/entropy/aggregation informations @param doc the document used for words generation
-
-
class
harvesttext.word_discoverer.
WordInfo
(text)[源代码]¶ 基类:
object
Store information of each word, including its freqency, left neighbors and right neighbors
-
compute
(length)[源代码]¶ Compute frequency and entropy of this word @param length length of the document for training to get words
-
-
harvesttext.word_discoverer.
genSubparts
(string)[源代码]¶ Partition a string into all possible two parts, e.g. given “abcd”, generate [(“a”, “bcd”), (“ab”, “cd”), (“abc”, “d”)] For string of length 1, return empty list