From fedf85e823b25e57b00d91be48e9e478767f5b6e Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 23 Oct 2017 23:41:00 -0400 Subject: [PATCH] Featurize the unmapped terms early. --- src/RWS.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RWS.hs b/src/RWS.hs index 9af6e2275..8d144307b 100644 --- a/src/RWS.hs +++ b/src/RWS.hs @@ -63,7 +63,7 @@ rws _ _ as [] = This <$> as rws _ _ [] bs = That <$> bs rws canCompare _ [a] [b] = if canCompareTerms canCompare a b then [These a b] else [That b, This a] rws canCompare equivalent as bs - = ses (\ a b -> equivalent (snd a) (snd b)) (zip [0..] as) (zip [0..] bs) + = ses (\ a b -> equivalent (term a) (term b)) (zipWith featurize [0..] as) (zipWith featurize [0..] bs) & mapContiguous canCompare & fmap (bimap snd snd) @@ -125,14 +125,14 @@ defaultMoveBound = 0 mapContiguous :: (Foldable syntax, Functor syntax, GAlign syntax) => ComparabilityRelation syntax (Record (FeatureVector ': fields1)) (Record (FeatureVector ': fields2)) - -> [These (Int, Term syntax (Record (FeatureVector ': fields1))) (Int, Term syntax (Record (FeatureVector ': fields2)))] + -> [These (UnmappedTerm syntax (Record (FeatureVector ': fields1))) (UnmappedTerm syntax (Record (FeatureVector ': fields2)))] -> [MappedDiff syntax (Record (FeatureVector ': fields1)) (Record (FeatureVector ': fields2))] mapContiguous canCompare = go [] [] where go as bs [] = mapChunk as bs go as bs (first : rest) = case first of - This (i, a) -> go (featurize i a : as) bs rest - That (j, b) -> go as (featurize j b : bs) rest - These _ _ -> mapChunk as bs <> (first : go [] [] rest) + This a -> go (a : as) bs rest + That b -> go as (b : bs) rest + These _ _ -> mapChunk as bs <> (bimap (termIndex &&& term) (termIndex &&& term) first : go [] [] rest) mapChunk as [] = This . (termIndex &&& term) <$> reverse as mapChunk [] bs = That . (termIndex &&& term) <$> reverse bs mapChunk as bs = findNearestNeighbourTo canCompare (reverse as) (reverse bs)