Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions pyConTextNLP/tagObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,33 @@ def limitScope(self, obj):
update the scope of self
returns True if a obj modified the scope of self"""
if not self.getRule() or self.getRule()== 'terminate' or \
(not self.isA(obj.getCategory()) and obj.getRule() != 'terminate'):
(not self.isA(obj.getCategory()) and obj.getRule() != 'terminate'):
return False

# Change scope of self
originalScope = copy.copy((self.getScope()))
if 'forward' in self.getRule().lower() or \
'bidirectional' in self.getRule().lower():
if obj > self:

# Case1: self is bidirectional:
if 'bidirectional' in self.getRule().lower():
# self is upstream of obj:
if self.getSpan()[1] <= obj.getSpan()[0]:
# Adjust self downstream scope if currently includes obj
self.__scope[1] = min(self.__scope[1],obj.getSpan()[0])
# obj is upstream of self:
elif obj.getSpan()[1] <= self.getSpan()[0]:
# Adjust self upstream scope if currently includes obj
self.__scope[0] = max(self.__scope[0],obj.getSpan()[1])

# Case2: self has forward scope and is upstream of obj
elif 'forward' in self.getRule().lower() and \
self.getSpan()[1] <= obj.getSpan()[0]:
self.__scope[1] = min(self.__scope[1],obj.getSpan()[0])
elif 'backward' in self.getRule().lower() or \
'bidirectional' in self.getRule().lower():
if obj < self:

# Case3: self has backward scope and is downstream of obj
elif 'backward' in self.getRule().lower() and \
obj.getSpan()[1] <= self.getSpan()[0]:
self.__scope[0] = max(self.__scope[0],obj.getSpan()[1])

if originalScope != self.__scope:
return True
else:
Expand All @@ -111,7 +127,7 @@ def applyRule(self, term):
if not self.getRule() or self.getRule() == 'terminate':
return False
if self.__scope[0] <= term.getSpan()[0] <= self.__scope[1]:
return True
return True


def getConTextCategory(self):
Expand Down Expand Up @@ -266,6 +282,3 @@ def __str__(self):
return self.__unicode__()
def __repr__(self):
return self.__unicode__()