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

Combine the gram at each node in.

This commit is contained in:
Rob Rix 2016-08-02 13:56:48 -04:00
parent 192366d5ad
commit 1b02940e26

View File

@ -129,9 +129,12 @@ termCostDecorator :: (Prologue.Foldable f, Functor f) => TermDecorator f a Cost
termCostDecorator c = 1 + sum (cost <$> tailF c)
pqGramDecorator :: (Prologue.Foldable f, Functor f) => (forall b. CofreeF f (Record a) b -> label) -> Int -> Int -> TermDecorator f a (Gram label, DList.DList (Gram label))
pqGramDecorator getLabel p q c@(a :< s) = (Gram [] [ Just (getLabel c) ], foldMap (Prologue.snd . childGrams) s)
where childGrams :: HasField fields (Gram label, DList.DList (Gram label)) => Record fields -> (Gram label, DList.DList (Gram label))
childGrams = getField
pqGramDecorator getLabel p q c@(a :< s) = (Gram [] [ Just label ], foldMap (childGrams label) s)
where childGrams :: HasField fields (Gram label, DList.DList (Gram label)) => label -> Record fields -> DList.DList (Gram label)
childGrams label record = let (child, grandchildren) = getField record in
DList.singleton (prependParent label child) <> grandchildren
prependParent label gram = gram { stem = Just label : stem gram }
label = getLabel c
-- | The sum of the node count of the diffs patches.
diffCostWithCachedTermCosts :: HasField fields Cost => Diff leaf (Record fields) -> Integer