Search code examples
pythonattributeerror

AttributeError: 'module' object has no attribute 'TreeTagger'


I am trying to use the Python wrapper for TreeTagger, a Part-of-Speech Tagger. The code I use for importing and invoking the wrapper is:

import TreeTaggerWrapper
tagger = TreeTaggerWrapper.TreeTagger(TAGLANG='en',TAGDIR='D:/Programme/TreeTagger')
tags = tagger.TagText("This is a very short text to tag.")
print tags

the error is: 'AttributeError: 'module' object has no attribute 'TreeTagger''

The init.py exists in the TreeTaggerWrapper directory and is empty.

How would I go about systematically resolving the issue?


Solution

  • Try this wrapper:

    http://cental.fltr.ucl.ac.be/team/~panchenko/def/treetaggerwrapper.py

    There is documentation inside the file.

    Update

    Copy the file treetaggerwrapper.py to python/Lib.

    Try this:

    import treetaggerwrapper
    tagger = treetaggerwrapper.TreeTagger(TAGLANG='en',TAGDIR='D:/Programme/TreeTagger')
    tags = tagger.TagText("This is a very short text to tag.")
    print tags
    

    Update 2

    If you have Lib/site-packages/TreeTaggerWrapper/treetaggerwrapper.py, then you should do this:

    from TreeTaggerWrapper import treetaggerwrapper
    tagger = treetaggerwrapper.TreeTagger(TAGLANG='en',TAGDIR='D:/Programme/TreeTagger')
    tags = tagger.TagText("This is a very short text to tag.")
    print tags