當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。