Tanggal :September 27, 2020

nlp27. Creating tagged corpus in Python NLTK

Spread the love

We can tag each word in the corpus, putting the tag after the /.

Here a 6-word corpus is created with 6 tags.


# nlp27.py
from __future__ import print_function
import os
from nltk.data import path
name = 'MyTest2Corpus'
name1 = 'Test2'
word1 = ['Bush/R Clinton/D',
'Rubio/R Clinton/D',
'Paul/R Sanders/D']
os.chdir(path[0])
os.mkdir(name)
os.chdir(name)
word1 = [w+'n' for w in word1]
fout1 = open(name1,'w')
fout1.writelines(word1)
fout1.close()
print('word1 = n',word1)

# word1 =
# ['Bush/R Clinton/Dn', 'Rubio/R Clinton/Dn',
# 'Paul/R Sanders/Dn']

Share

Leave a Reply

Your email address will not be published. Required fields are marked *