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

Pad the base at the root.

This commit is contained in:
Rob Rix 2016-08-04 20:03:44 -04:00
parent ea950d1953
commit 46f4ca93c3

View File

@ -99,7 +99,7 @@ decorateTermWithPGram p = futu coalgebra . (,) []
RCons label rest -> (Gram (padToSize p parentLabels) (pure (Just label)) .: rest) :< fmap (pure . (,) (take p (Just label : parentLabels))) (unwrap c)
decorateTermWithBagOfPQGrams :: (Typeable label, Prologue.Foldable f, Functor f) => Int -> Cofree f (Record (Gram label ': fields)) -> Cofree f (Record (DList.DList (Gram label) ': fields))
decorateTermWithBagOfPQGrams q = fmap (\ (RCons (first, rest) t) -> DList.cons first rest .: t) . cata algebra
decorateTermWithBagOfPQGrams q = fmap (\ (RCons (first, rest) t) -> DList.cons (first { base = padToSize q (base first) }) rest .: t) . cata algebra
where algebra :: (Prologue.Foldable f, Functor f) => CofreeF f (Record (Gram label ': fields)) (Cofree f (Record ((Gram label, DList.DList (Gram label)) ': fields))) -> Cofree f (Record ((Gram label, DList.DList (Gram label)) ': fields))
algebra (RCons gram rest :< functor) = cofree (((gram, DList.fromList (windowed q setBases [] (fst . getGrams . extract <$> toList functor)) <> foldMap (snd . getGrams . extract) functor) .: rest) :< functor)
setBases :: Gram label -> [Gram label] -> [Gram label] -> [Gram label]