From be3f43702b665af46e033e419659ba8a0ea0d5df Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 28 Jun 2016 15:01:02 -0400 Subject: [PATCH] Replace incomparable terms. --- src/Data/RandomWalkSimilarity.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Data/RandomWalkSimilarity.hs b/src/Data/RandomWalkSimilarity.hs index 03d9a37eb..ba45ff8b1 100644 --- a/src/Data/RandomWalkSimilarity.hs +++ b/src/Data/RandomWalkSimilarity.hs @@ -25,6 +25,7 @@ rws compare getLabel as bs | otherwise = uncurry deleteRemaining . (`runState` Set.empty) $ traverse findNearestNeighbourTo (featurize <$> bs) where insert = pure . Insert delete = pure . Delete + replace = (pure .) . Replace (p, q) = (2, 2) d = 15 fas = featurize <$> as @@ -35,11 +36,12 @@ rws compare getLabel as bs let (k, nearest) = KdTree.nearest kdas kv if k `Set.member` mapped then pure $! insert v - else case compare nearest v of - Just y -> do - put (Set.insert k mapped) - pure y - _ -> pure $! delete v + else do + put (Set.insert k mapped) + case compare nearest v of + Just y -> do + pure y + _ -> pure $! replace nearest v deleteRemaining diff mapped = diff <> (delete . snd <$> filter (not . (`Set.member` mapped) . fst) fas) data Gram label = Gram { stem :: [Maybe label], base :: [Maybe label] }