Skip to content

Commit fa46fbc

Browse files
committed
#33: improve simplification of sequences with missing/redundant patterns
1 parent c51991c commit fa46fbc

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/Errors.hs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Stability : experimental
88
module Errors where
99

1010
import Data.List
11+
import Data.Maybe
1112
import Data.Bifunctor
1213
import RTree
1314
import UDConcepts
@@ -125,14 +126,26 @@ simplifyErrorPattern = bimap simplifyUDPattern simplifyUDPattern
125126
-- simplification of sequence patterns only works if there is only one
126127
-- error, like in DaLAJ sentences
127128
(SEQUENCE p1s,SEQUENCE p2s) -> (SEQUENCE p1s',SEQUENCE p2s')
128-
where (p1s',p2s') = unzip $ rmCommonPrePost $ p1s `zip` p2s
129+
where (p1s',p2s') = simplifySeqs p1s p2s
129130
(SEQUENCE_ p1s,SEQUENCE_ p2s) -> (SEQUENCE_ p1s',SEQUENCE_ p2s')
130-
where (p1s',p2s') = unzip $ rmCommonPrePost $ p1s `zip` p2s
131+
where (p1s',p2s') = simplifySeqs p1s p2s
131132
ep -> ep
132133
where
133134
filterSubpatterns p1s p2s = if length p1s == length p2s
134135
then unzip $ filter (\(p1,p2) -> p1 /= p2) (p1s `zip` p2s)
135136
else (p1s,p2s)
137+
simplifySeqs p1s p2s
138+
-- word order error
139+
| length p1s == length p2s = unzip $ rmCommonPrePost $ p1s `zip` p2s
140+
-- missing token (assuming only one token is missing for now)
141+
| length p1s < length p2s =
142+
let i = fromJust $ elemIndex (head (p2s \\ p1s)) p2s
143+
in (slice (i - 1) (i) p1s, slice (i - 1) (i + 1) p2s)
144+
| length p1s > length p2s =
145+
let i = fromJust $ elemIndex (head (p1s \\ p2s)) p1s
146+
in (slice (i - 1) (i + 1) p1s, slice (i - 1) (i) p2s)
147+
-- redundant token (assuming only one token is redundant for now)
148+
136149

137150
-- | Shorthand to convert into a Universal morphosyntactic pattern and
138151
-- simplify

src/Utils/Misc.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ rmCommonPost = reverse . rmCommonPre . reverse
2727

2828
-- | Apply oth rmCommonPre and rmCommonPost to a zipped list
2929
rmCommonPrePost :: Eq a => [(a,a)] -> [(a,a)]
30-
rmCommonPrePost = rmCommonPost . rmCommonPre
30+
rmCommonPrePost = rmCommonPost . rmCommonPre
31+
32+
-- | List slices
33+
slice :: Int -> Int -> [a] -> [a]
34+
slice from to xs = take (to - from + 1) (drop from xs)

0 commit comments

Comments
 (0)