-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpos_feature.py
executable file
·37 lines (34 loc) · 1.13 KB
/
pos_feature.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
import nltk
from nltk import pos_tag, word_tokenize
from nltk.corpus import brown
brown_tagged = brown.tagged_sents()
unigram_tagger = nltk.UnigramTagger(brown_tagged)
def pos_tagger(context,position,dictionary):
list_tags = pos_tag(word_tokenize(context[position]))
x,y = list_tags[0]
dictionary["pos"] = y
return dictionary
def unigram_tagger(context,position):
list_tags = unigram_tagger.tag(word_tokenize(context[position]))
x,y = list_tags[0]
dictionary["unigram pos"] = y
return dictionary
def bigram_tagger(context, position):
if position == 0:
input = context[position]
else:
input = context[position] + " " + context[position-1]
list_tags = bigram_tagger.tag(word_tokenize(input))
x,y = list_tags[1]
dictionary["bigram pos"] = y
return dictionary
def tag_answers():
import read_questions
#We probably don't want the answers in their own list like this.
#It's really here so I remember how to access the answers.
answers=[]
for i in read_questions.read_questions_answers():
list_tags = pos_tag(word_tokenize(i[3]))
answers.append(list_tags)
return answers