2016-04-17 18 views
1

からTreeTagger's website私はディレクトリを作成し、指定されたファイルをダウンロードしました。その後treetaggerwrapperは、これdocumentationから私がテストし、次のようにいくつかのテキストをタグ付けする方法をしようとしてみました:TreeTaggerでタグ付けしながら、* unicode *文字列をタグとしてテキストとして使用する必要がありますか?

In [40]: 

import treetaggerwrapper 

tagger = treetaggerwrapper.TreeTagger(TAGLANG='en') 

tags = tagger.TagText("This is a very short text to tag.") 

print tags 

は、それから私は、次の警告を得た:

私は略語ファイルをダウンロードします
WARNING:TreeTagger:Abbreviation file not found: english-abbreviations 
WARNING:TreeTagger:Processing without abbreviations file. 
ERROR:TreeTagger:Must use *unicode* string as text to tag, not <type 'str'>. 

--------------------------------------------------------------------------- 
TreeTaggerError       Traceback (most recent call last) 
<ipython-input-40-37b912126580> in <module>() 
     1 import treetaggerwrapper 
     2 tagger = treetaggerwrapper.TreeTagger(TAGLANG='en') 
----> 3 tags = tagger.TagText("This is a very short text to tag.") 
     4 print tags 

/usr/local/lib/python2.7/site-packages/treetaggerwrapper.pyc in TagText(self, text, numlines, tagonly, prepronly, tagblanks, notagurl, notagemail, notagip, notagdns, encoding, errors) 
    1236   return self.tag_text(text, numlines=numlines, tagonly=tagonly, 
    1237     prepronly=prepronly, tagblanks=tagblanks, notagurl=notagurl, 
-> 1238     notagemail=notagemail, notagip=notagip, notagdns=notagdns) 
    1239 
    1240  # -------------------------------------------------------------------------- 

/usr/local/lib/python2.7/site-packages/treetaggerwrapper.pyc in tag_text(self, text, numlines, tagonly, prepronly, tagblanks, notagurl, notagemail, notagip, notagdns, nosgmlsplit) 
    1302    # Raise exception now, with an explicit message. 
    1303    logger.error("Must use *unicode* string as text to tag, not %s.", type(text)) 
-> 1304    raise TreeTaggerError("Must use *unicode* string as text to tag.") 
    1305 
    1306   if isinstance(text, six.text_type): 

TreeTaggerError: Must use *unicode* string as text to tag. 

英語とスペイン語の言語は?、どうすれば正しくtreetaggerwrapperをインストールできますか?

答えて

3

方法が唯一のUnicode文字列がunicode文字列作るためにあなたの文字列にuを追加しとります

tags = tagger.TagText(u"This is a very short text to tag.") 

"This is a very short text to tag."あなたはuを追加したら、それはユニコードで、STRタイプです:

In [12]: type("This is a very short text to tag.") 
Out[12]: str 

In [13]: type(u"This is a very short text to tag.") 
Out[13]: unicode 

strを別のソースから取得する場合は、デコードする必要があります。

見つからない略称ファイル:: `WARNING:TreeTagger英語略語 WARNING:TreeTagger
In [15]: s = "This is a very short text to tag." 

In [16]: type(s) 
Out[16]: str 

In [17]: type(s.decode("utf-8")) 
Out[17]: unicode 

タギングスクリプトは一方で、私はまだ同じ警告を受ける、助けのためhere

+0

感謝をダウンロードすることができます。略語ファイルなしの処理。 'どのようにパスを指定するか、またはscuhファイルをダウンロードする方法の任意のアイデア? – tumbleweed

+1

あなたはどのOSを使用していますか? –

+0

OSX ...助けてくれてありがとう! – tumbleweed

関連する問題