-
Notifications
You must be signed in to change notification settings - Fork 1
/
thresholdfinder.py
executable file
·68 lines (56 loc) · 2.22 KB
/
thresholdfinder.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
# author: Rodney Summerscales
from rulebasedfinder import RuleBasedFinder
######################################################################
# Threshold finder
######################################################################
class ThresholdFinder(RuleBasedFinder):
""" Find and label tokens in phrase describing a threshold
e.g. 'less than 5', 'greater than 24'
"""
timeWords = set(['s', 'sec', 'second', 'min', 'minute', 'hr', 'hrs', \
'hour', 'day', 'wk', 'wks', 'week', 'month', 'yr', 'yrs', \
'year', 'baseline'])
label = 'threshold'
def __init__(self):
""" Create a finder that identifies threshold phrases. All tokens in
time phrases are labeled 'threshold'.
"""
RuleBasedFinder.__init__(self, [self.label])
def applyRules(self, token):
""" Label the given token as a 'threshold'. Also label all of the neighboring
tokens in the same phrase.
"""
pass # do not recognize thresholds at this point.
# we do not do anything productive with them right now
# if token.hasLabel(self.label) == True:
# # token has already been labeled
# return
#
# if token.text != 'greater' and token.text != 'less':
# return
#
# nextToken = token.nextToken()
# if nextToken == None or nextToken.text != 'than':
# return
#
# prevToken = token.previousToken()
# if prevToken == None or prevToken.text.lower() == 'p':
# return
#
# nextNextToken = nextToken.nextToken()
# if nextNextToken == None or nextNextToken.isNumber() == False:
# return
#
# token.addLabel(self.label)
# nextToken.addLabel(self.label)
# nextNextToken.addLabel(self.label)
#
# # so far we have 'greater/less' 'than', check if parent phrase
# # is a quantifier phrase
# if token.parseTreeNode != None and token.parseTreeNode.parent != None \
# and token.parseTreeNode.parent.parent != None \
# and token.parseTreeNode.parent.parent.parent != None:
# for ptNode in token.parseTreeNode.parent.parent.parent.tokenNodes():
# ptNode.token.addLabel(self.label)
#