1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 22:31:36 +03:00

runAlgorithm receives a constructing function.

This commit is contained in:
Rob Rix 2016-08-03 20:14:33 -04:00
parent 78701ddd90
commit f9969601e8

View File

@ -72,12 +72,13 @@ run construct comparable cost algorithm = (`F.iter` fmap Just algorithm) $ \case
_ -> Nothing)
runAlgorithm :: (Functor f, GAlign f, Eq a, Eq annotation, Eq (f (Cofree f annotation)), Prologue.Foldable f, Hashable label) =>
(CofreeF f (Both annotation) (Free (CofreeF f (Both annotation)) (Patch (Cofree f annotation))) -> Free (CofreeF f (Both annotation)) (Patch (Cofree f annotation))) ->
(Cofree f annotation -> Cofree f annotation -> Maybe (Free (CofreeF f (Both annotation)) (Patch (Cofree f annotation)))) ->
SES.Cost (Free (CofreeF f (Both annotation)) (Patch (Cofree f annotation))) ->
(forall b. CofreeF f annotation b -> label) ->
Algorithm (Cofree f annotation) (Free (CofreeF f (Both annotation)) (Patch (Cofree f annotation))) a ->
a
runAlgorithm recur cost getLabel = F.iter $ \case
Recursive a b f -> f (maybe (pure (Replace a b)) (wrap . (both (extract a) (extract b) :<) . fmap (these (pure . Delete) (pure . Insert) ((fromMaybe (pure (Replace a b)) .) . recur))) (galign (unwrap a) (unwrap b)))
runAlgorithm construct recur cost getLabel = F.iter $ \case
Recursive a b f -> f (maybe (pure (Replace a b)) (construct . (both (extract a) (extract b) :<) . fmap (these (pure . Delete) (pure . Insert) ((fromMaybe (pure (Replace a b)) .) . recur))) (galign (unwrap a) (unwrap b)))
ByIndex as bs f -> f (ses recur cost as bs)
ByRandomWalkSimilarity as bs f -> f (rws recur getLabel as bs)