1
1
mirror of https://github.com/github/semantic.git synced 2024-12-20 13:21:59 +03:00

Replace incomparable terms.

This commit is contained in:
Rob Rix 2016-06-28 15:01:02 -04:00
parent 2dde2a5775
commit be3f43702b

View File

@ -25,6 +25,7 @@ rws compare getLabel as bs
| otherwise = uncurry deleteRemaining . (`runState` Set.empty) $ traverse findNearestNeighbourTo (featurize <$> bs) | otherwise = uncurry deleteRemaining . (`runState` Set.empty) $ traverse findNearestNeighbourTo (featurize <$> bs)
where insert = pure . Insert where insert = pure . Insert
delete = pure . Delete delete = pure . Delete
replace = (pure .) . Replace
(p, q) = (2, 2) (p, q) = (2, 2)
d = 15 d = 15
fas = featurize <$> as fas = featurize <$> as
@ -35,11 +36,12 @@ rws compare getLabel as bs
let (k, nearest) = KdTree.nearest kdas kv let (k, nearest) = KdTree.nearest kdas kv
if k `Set.member` mapped if k `Set.member` mapped
then pure $! insert v then pure $! insert v
else case compare nearest v of else do
Just y -> do put (Set.insert k mapped)
put (Set.insert k mapped) case compare nearest v of
pure y Just y -> do
_ -> pure $! delete v pure y
_ -> pure $! replace nearest v
deleteRemaining diff mapped = diff <> (delete . snd <$> filter (not . (`Set.member` mapped) . fst) fas) deleteRemaining diff mapped = diff <> (delete . snd <$> filter (not . (`Set.member` mapped) . fst) fas)
data Gram label = Gram { stem :: [Maybe label], base :: [Maybe label] } data Gram label = Gram { stem :: [Maybe label], base :: [Maybe label] }