Skip to content

Commit

Permalink
Fixing constraint problem with next()/previous() (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Dec 12, 2016
1 parent 6bf1385 commit fb9df94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion formats/folia.py
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,7 @@ def next(self, Class=True, scope=True, reverse=False):
returnnext = False
for e in order(parent):
if e is child:
#we found the current item, next item will be the one to return
returnnext = True
elif returnnext and e.auth and not isinstance(e,AbstractAnnotationLayer) and (not structural or (structural and (not isinstance(e,(AbstractTokenAnnotation,TextContent)) ) )):
if structural and isinstance(e,Correction):
Expand All @@ -2159,7 +2160,7 @@ def next(self, Class=True, scope=True, reverse=False):

#generational iteration
child = parent
if scope is not None and child in scope:
if scope is not None and child.__class__ in scope:
#you shall not pass!
break
parent = parent.parent
Expand Down
6 changes: 6 additions & 0 deletions tests/folia.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ def test021b_previousword_noscope(self):
self.assertTrue( isinstance(prevw, folia.Word) )
self.assertEqual( prevw.text(), "." )

def test021c_previousword_constrained(self):
"""Sanity Check - Obtaining non-existing previous word with scope constraint"""
w = self.doc['WR-P-E-J-0000000001.p.1.s.4.w.1']
prevw = w.previous(folia.Word, [folia.Sentence])
self.assertEqual(prevw, None)

def test022_nextword(self):
"""Sanity Check - Obtaining next word"""
w = self.doc['WR-P-E-J-0000000001.p.1.s.2.w.7']
Expand Down

0 comments on commit fb9df94

Please sign in to comment.