1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 21:16:12 +03:00

Define run in terms of runAlgorithm.

This commit is contained in:
Rob Rix 2016-08-03 20:14:41 -04:00
parent f9969601e8
commit b3d09f538e

View File

@ -55,21 +55,10 @@ algorithmWithTerms t1 t2 = case (unwrap t1, unwrap t2) of
-- | Runs the diff algorithm -- | Runs the diff algorithm
run :: (Eq leaf, Hashable leaf, Eq (Record fields), HasField fields Category) => DiffConstructor leaf (Record fields) -> Comparable leaf (Record fields) -> SES.Cost (Diff leaf (Record fields)) -> Algorithm (Term leaf (Record fields)) (Diff leaf (Record fields)) (Diff leaf (Record fields)) -> Maybe (Diff leaf (Record fields)) run :: (Eq leaf, Hashable leaf, Eq (Record fields), HasField fields Category) => DiffConstructor leaf (Record fields) -> Comparable leaf (Record fields) -> SES.Cost (Diff leaf (Record fields)) -> Algorithm (Term leaf (Record fields)) (Diff leaf (Record fields)) (Diff leaf (Record fields)) -> Maybe (Diff leaf (Record fields))
run construct comparable cost algorithm = (`F.iter` fmap Just algorithm) $ \case run construct comparable cost = runAlgorithm construct (constructAndRun construct comparable cost) cost getLabel . fmap Just
Recursive t1 t2 f -> f $ recur a b where where getLabel (h :< t) = (category h, case t of
(annotation1 :< a, annotation2 :< b) = (runCofree t1, runCofree t2) Leaf s -> Just s
annotate = construct . (both annotation1 annotation2 :<) _ -> Nothing)
recur a b = maybe (pure (Replace t1 t2)) (annotate . fmap diffThese) (galign a b)
diffThese = these (pure . Delete) (pure . Insert) (diffTerms construct comparable cost)
ByIndex a b f -> f $ ses (constructAndRun construct comparable cost) cost a b
ByRandomWalkSimilarity a b f -> f $ rws (constructAndRun construct comparable cost) getLabel a b
where getLabel (h :< t) = (category h, case t of
Leaf s -> Just s
_ -> Nothing)
runAlgorithm :: (Functor f, GAlign f, Eq a, Eq annotation, Eq (f (Cofree f annotation)), Prologue.Foldable f, Hashable label) => 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))) -> (CofreeF f (Both annotation) (Free (CofreeF f (Both annotation)) (Patch (Cofree f annotation))) -> Free (CofreeF f (Both annotation)) (Patch (Cofree f annotation))) ->