Skip to content

Commit cc597ee

Browse files
committed
[fql] Added extra tests for restoring original after deletion of structural correction (proycon/flat#120)
1 parent 22e3dbc commit cc597ee

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

pynlpl/formats/fql.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,6 @@ def parse(q,i=0):
14261426
action.span, i = Span.parse(q,i+1)
14271427
if action.action == "DELETE" and q.kw(i,("RESTORE")):
14281428
action.restore = q[i+1].upper()
1429-
print("DEBUG RESTORE=", action.restore,file=sys.stderr)
14301429
i += 2
14311430
else:
14321431
action.restore = None
@@ -1609,14 +1608,14 @@ def __call__(self, query, contextselector, debug=False):
16091608
if debug: print("[FQL EVALUATION DEBUG] Action - Applying DELETE to focus ", repr(focus),file=sys.stderr)
16101609
p = focus.parent
16111610
if action.restore == "ORIGINAL":
1611+
index = p.getindex(focus, False, False)
16121612
if not isinstance(focus, folia.Correction):
16131613
raise QueryError("RESTORE ORIGINAL can only be performed when the focus is a correction")
16141614
#restore original
1615-
originals = list(focus.original())
1616-
for original in originals:
1615+
for original in reversed(focus.original()):
16171616
if debug: print("[FQL EVALUATION DEBUG] Action - Restoring original: ", repr(original),file=sys.stderr)
16181617
original.parent = p
1619-
p.append(original)
1618+
p.insert(index, original)
16201619
p.remove(focus)
16211620
#we set the parent back on the element we return, so return types like ancestor-focus work
16221621
focus.parent = p

pynlpl/tests/fql.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@
158158
Qfeat4 = "EDIT feat WHERE subset = \"strength\" AND class = \"strong\" WITH class \"verystrong\" FOR ID \"WR-P-E-J-0000000001.text.sentiment.1\""
159159

160160
Qdelete_correction = "DELETE correction ID \"correctionexample.s.1.w.2.correction.1\" RESTORE ORIGINAL RETURN ancestor-focus"
161+
Qdelete_structural_correction = "DELETE correction ID \"correctionexample.s.3.correction.1\" RESTORE ORIGINAL RETURN ancestor-focus"
162+
Qdelete_structural_correction2 = "DELETE correction ID \"correctionexample.s.3.correction.2\" RESTORE ORIGINAL RETURN ancestor-focus"
161163

162164

163165
class Test1UnparsedQuery(unittest.TestCase):
@@ -973,6 +975,24 @@ def test4_delete_correction(self):
973975
self.assertIsInstance(results[0], folia.Word)
974976
self.assertEqual(results[0].text(), "word")
975977

978+
def test4b_delete_structural_correction(self):
979+
"""Deleting a structural correction and restoring the original (runon error)"""
980+
q = fql.Query(Qdelete_structural_correction)
981+
results = q(self.doc)
982+
self.assertIsInstance(results[0], folia.Sentence)
983+
self.assertIsInstance(results[0][0], folia.Word)
984+
self.assertEqual(results[0][0].text(), "Ikhoor")
985+
986+
def test4c_delete_structural_correction(self):
987+
"""Deleting a structural correction and restoring the original (split error)"""
988+
q = fql.Query(Qdelete_structural_correction2)
989+
results = q(self.doc)
990+
self.assertIsInstance(results[0], folia.Sentence)
991+
self.assertIsInstance(results[0][1], folia.Word)
992+
self.assertIsInstance(results[0][2], folia.Word)
993+
self.assertEqual(results[0][1].text(), "on")
994+
self.assertEqual(results[0][2].text(), "weer")
995+
976996
if os.path.exists('../../FoLiA'):
977997
FOLIAPATH = '../../FoLiA/'
978998
elif os.path.exists('../FoLiA'):

0 commit comments

Comments
 (0)