This same script can be easily modified to tag a file located in the file system: Note the for-loop in lines 17-18 that converts the tagged output (a list of tuples) into the two-column format: word_tag. # print the word and the pos_tag with the underscore as a delimiter ![]() # for loop to extract the elements of the tuples in the pos_tagged list # print the list of tuples: (word,word_class) Text_tok = nltk.word_tokenize("Just a small snippet of text.") # running the Stanford POS Tagger from NLTK The script below gives an example of a script using the Stanford PoS Tagger module of NLTK to tag an example sentence: This is, however, a good way of getting started using the tagger. It has, however, a disadvantage in that users have no choice between the models used for tagging. This is the simplest way of running the Stanford PoS Tagger from Python. NLTK integrates a version of the Stanford PoS tagger as a module that can be run without a separate local installation of the tagger. ![]() In this tutorial, we will be looking at two principal ways of driving the Stanford PoS Tagger from Python and show how this can be done with single files and with multiple files in a directory. ![]() And while the Stanford PoS Tagger is not written in Python, it can nevertheless be more or less seamlessly integrated into Python programs. However, many linguists will rather want to stick with Python as their preferred programming language, especially when they are using other Python packages such as NLTK as part of their workflow. The Stanford PoS Tagger is itself written in Java, so can be easily integrated in and called from Java programs. In this tutorial, we will be running the Stanford PoS Tagger from a Python script. While we will often be running an annotation tool in a stand-alone fashion directly from the command line, there are many scenarios in which we would like to integrate an automatic annotation tool in a larger workflow, for example with the aim of running pre-processing and annotation steps as well as analyses in one go.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |