如何在nltk中用hunpos标记文本文件? [英] How do I tag textfiles with hunpos in nltk?

查看:117
本文介绍了如何在nltk中用hunpos标记文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我用hunpos标记nltk中的语料库的语法吗?

Can someone help me with the syntax for hunpos tagging a corpus in nltk?

  1. 对于我如何HunPosTag语料库?请参见下面的代码.

    How do I HunPosTag the corpus? See the code below.


    import nltk 
    from nltk.corpus import PlaintextCorpusReader  
    from nltk.corpus.util import LazyCorpusLoader  
    
    corpus_root = './'  
    reader = PlaintextCorpusReader (corpus_root, '.*')  
    
    ntuen = LazyCorpusLoader ('ntumultien', PlaintextCorpusReader, reader)  
    ntuen.fileids()  
    isinstance (ntuen, PlaintextCorpusReader)  
    
    
    # So how do I hunpos tag `ntuen`? I can't get the following code to work.
    # please help me to correct my python syntax errors, I'm new to python 
    # but i really need this to work. sorry
    ##from nltk.tag import hunpos.HunPosTagger
    ht = HunPosTagger('english.model')
    for sentence in ntu.sent() ##looping through the no. of sentence
         ht.tag(ntusent()[i])
    

    推荐答案

    import nltk 
    from nltk.tag.hunpos import HunposTagger
    from nltk.tokenize import word_tokenize
    
    corpus = "so how do i hunpos tag my ntuen ? i can't get the following code to work."
    #please help me to correct my python syntax errors, i'm new to python 
    #but i really need this to work. sorry
    ##from nltk.tag import hunpos.HunPosTagger
    ht = HunposTagger('en_wsj.model')
    print ht.tag(word_tokenize(corpus))
    

    我觉得问题在于您没有对单词进行标记,但是还有其他原因可能导致代码无法正常工作(它是HunposTagger,而不是HunPosTagger).我根据您的问题做了一个简化的示例.如果您还有其他问题,请发表评论.

    I feel like the problem is you're not tokenizing the words, but there are other reasons the code may not work (it's HunposTagger, not HunPosTagger). I made this simplified example from your question. If you have any more questions please post a comment.

    我从这里获得了所有内容: http://code.google.com/p/hunpos/

    I got everything from here: http://code.google.com/p/hunpos/

    python hunpos.py

    python hunpos.py

    [('so','RB'),('how','WRB'),('do','VBP'),('i','FW'),('hunpos',' NN'),('tag','NN'),('my','PRP $'),('ntuen','NN'),('?','.'),('i', 'FW'),('ca','MD'),('n't','RB'),('get','VB'),('the','DT'),(' ','JJ'),('code','NN'),('to','TO'),('work','VB'),('.','.')]

    [('so', 'RB'), ('how', 'WRB'), ('do', 'VBP'), ('i', 'FW'), ('hunpos', 'NN'), ('tag', 'NN'), ('my', 'PRP$'), ('ntuen', 'NN'), ('?', '.'), ('i', 'FW'), ('ca', 'MD'), ("n't", 'RB'), ('get', 'VB'), ('the', 'DT'), ('following', 'JJ'), ('code', 'NN'), ('to', 'TO'), ('work', 'VB'), ('.', '.')]

    这篇关于如何在nltk中用hunpos标记文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆