当前位置: 首页>>代码示例>>Python>>正文


Python NERTagger.tag_sents方法代码示例

本文整理汇总了Python中nltk.tag.stanford.NERTagger.tag_sents方法的典型用法代码示例。如果您正苦于以下问题:Python NERTagger.tag_sents方法的具体用法?Python NERTagger.tag_sents怎么用?Python NERTagger.tag_sents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nltk.tag.stanford.NERTagger的用法示例。


在下文中一共展示了NERTagger.tag_sents方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ner_tag

# 需要导入模块: from nltk.tag.stanford import NERTagger [as 别名]
# 或者: from nltk.tag.stanford.NERTagger import tag_sents [as 别名]
def ner_tag(sents, silent=True) :
    """ Named Entety Recognition for sentences.

        Keyword arguments:
            sents -- Sentece, list of sentences or list of tokens.
        Returns :
            List of (word,neg-tag) pairs, that aims to preserve the structure of the sents input argument.
    """

    if len(sents) == 0 :
        return []

    # saves ner_tagger as global variable,
    # such that it is not recreated everytime ner_tag is executed
    if not 'ner_tagger' in globals():
        global ner_tagger
        ner_tagger = NERTagger(stanford_ner_classifier, stanford_ner)

    # if sentence not tokenized
    if type(sents) in [str,unicode] :
        sents = tokenize(sents,'sw')

    # bring input sents in right form
    elif type(sents[0]) in [str,unicode] :
        if ' ' in sents[0] :
            sents = [tokenize(s,'w') for s in sents]
        else :
            sents = [sents]

    tagged = ner_tagger.tag_sents(sents)

    if not silent :
        print('ner-tags:', tagged)

    return tagged
开发者ID:SherlockProject,项目名称:bluemix_benchmark,代码行数:37,代码来源:nlp_utils.py

示例2: add_ner

# 需要导入模块: from nltk.tag.stanford import NERTagger [as 别名]
# 或者: from nltk.tag.stanford.NERTagger import tag_sents [as 别名]
 def add_ner(self,target):
     all_token = self.get_token(target);
     st = \
     NERTagger('../stanford-ner-2015-04-20/classifiers/english.all.3class.distsim.crf.ser.gz','../stanford-ner-2015-04-20/stanford-ner.jar');
     ner_result = st.tag_sents(all_token);
     w = open('ner_%s'%target,'wb');
     for num,row in enumerate(ner_result):
         for item in row:
             w.write(item[0]+'\n');
         w.write('\n');
     #end for 
     print len(ner_result),len(all_token);
     return;
开发者ID:victormm88,项目名称:SemEval,代码行数:15,代码来源:Feature_Tool.py

示例3: run_tagger

# 需要导入模块: from nltk.tag.stanford import NERTagger [as 别名]
# 或者: from nltk.tag.stanford.NERTagger import tag_sents [as 别名]
    def run_tagger(self, payload):
        """
        Runs :py:meth:`nltk.tag.stanford.NERTagger.tag_sents` on the provided
        text (http://www.nltk.org/api/nltk.tag.html#nltk.tag.stanford.NERTagger.tag_sents)

        :param payload: Fulltext payload.
        :type payload: string
        :return: List of parsed sentences.
        """
        if NERTagger is None:
            return None
        tagger = NERTagger(self.classifier, self.jarfile)
        return tagger.tag_sents([payload.encode('ascii', 'ignore').split()])
开发者ID:hyperstudio,项目名称:parserbot,代码行数:15,代码来源:stanford.py

示例4: str

# 需要导入模块: from nltk.tag.stanford import NERTagger [as 别名]
# 或者: from nltk.tag.stanford.NERTagger import tag_sents [as 别名]
            list_of_sentences.extend(tkzd_sentences)

            i+=1

        except Exception as error:
            if "utf" in str(error):
                pass
            else:
                print "SOMETHING HAPPENED"
    
    print "\nxxxxxxxxxxx-------------xxxxxxxxxxx\n"
    print len(list_of_sentences)
    print i
    # raw_input("...continue?")

    IOB_sentences = tagger.tag_sents(list_of_sentences)
    print len(IOB_sentences)
    twitter_ners = {}
    for ne_tagged_sent in IOB_sentences:
        named_entities = get_continuous_chunks(ne_tagged_sent)
        named_entities_str = [" ".join([token for token, tag in ne]) for ne in named_entities]
        named_entities_str_tag = [(" ".join([token for token, tag in ne]), ne[0][1]) for ne in named_entities]

        if len(named_entities_str_tag)>0:
            for string, tag in named_entities_str_tag:
                try:
                    twitter_ners[tag.lower()].append(string.lower())
                except:
                    twitter_ners[tag.lower()] = [string.lower()]

    for k,v in twitter_ners.items():
开发者ID:priyamtejaswin,项目名称:twitNER,代码行数:33,代码来源:twitter_ner.py


注:本文中的nltk.tag.stanford.NERTagger.tag_sents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。