mirror of
https://github.com/github/semantic.git
synced 2024-12-20 13:21:59 +03:00
Revert "Carry indices along through the computation."
This reverts commit 2cc2d4d78688266a4a6791de47bfd27bfa3cca43.
This commit is contained in:
parent
a5cce717c8
commit
11a2ab907a
@ -22,25 +22,24 @@ rws compare getLabel as bs
|
|||||||
| null as, null bs = []
|
| null as, null bs = []
|
||||||
| null as = insert <$> bs
|
| null as = insert <$> bs
|
||||||
| null bs = delete <$> as
|
| null bs = delete <$> as
|
||||||
| otherwise = uncurry deleteRemaining . (`runState` Set.empty) $ traverse findNearestNeighbourTo fbs
|
| 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
|
replace = (pure .) . Replace
|
||||||
(p, q) = (2, 2)
|
(p, q) = (2, 2)
|
||||||
d = 15
|
d = 15
|
||||||
fas = zip (featurize <$> as) [0..]
|
fas = featurize <$> as
|
||||||
fbs = zip (featurize <$> bs) [0..]
|
kdas = KdTree.build (Vector.toList . fst) fas
|
||||||
kdas = KdTree.build (Vector.toList . fst . fst) fas
|
|
||||||
featurize = featureVector d . pqGrams p q getLabel &&& identity
|
featurize = featureVector d . pqGrams p q getLabel &&& identity
|
||||||
findNearestNeighbourTo kv@((_, v), i) = do
|
findNearestNeighbourTo kv@(_, v) = do
|
||||||
mapped <- get
|
mapped <- get
|
||||||
let ((k, nearest), j) = 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 do
|
else do
|
||||||
put (Set.insert k mapped)
|
put (Set.insert k mapped)
|
||||||
pure $! fromMaybe (replace nearest v) (compare nearest v)
|
pure $! fromMaybe (replace nearest v) (compare nearest v)
|
||||||
deleteRemaining diff mapped = diff <> (delete . snd . fst <$> filter (not . (`Set.member` mapped) . fst . 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] }
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
Loading…
Reference in New Issue
Block a user