mirror of
https://github.com/github/semantic.git
synced 2025-01-03 04:51:57 +03:00
🔥 decorateTermWithPGram.
This commit is contained in:
parent
3cbba53c18
commit
bf3b8fdc3f
@ -75,13 +75,6 @@ featureVector d bag = sumVectors $ unitVector d . hash <$> bag
|
|||||||
decorateTermWithLabel :: Functor f => (forall b. CofreeF f (Record fields) b -> label) -> Cofree f (Record fields) -> Cofree f (Record (label ': fields))
|
decorateTermWithLabel :: Functor f => (forall b. CofreeF f (Record fields) b -> label) -> Cofree f (Record fields) -> Cofree f (Record (label ': fields))
|
||||||
decorateTermWithLabel getLabel = cata $ \ c -> cofree ((getLabel c .: headF c) :< tailF c)
|
decorateTermWithLabel getLabel = cata $ \ c -> cofree ((getLabel c .: headF c) :< tailF c)
|
||||||
|
|
||||||
-- | Replaces labels in a term’s annotations with corresponding p,1-grams.
|
|
||||||
decorateTermWithPGram :: Functor f => Int -> Cofree f (Record (label ': fields)) -> Cofree f (Record (Gram label ': fields))
|
|
||||||
decorateTermWithPGram p = ana coalgebra . (,) []
|
|
||||||
where coalgebra :: Functor f => ([Maybe label], Cofree f (Record (label ': fields))) -> CofreeF f (Record (Gram label ': fields)) ([Maybe label], Cofree f (Record (label ': fields)))
|
|
||||||
coalgebra (parentLabels, c) = case extract c of
|
|
||||||
RCons label rest -> (Gram (padToSize p parentLabels) (pure (Just label)) .: rest) :< fmap ((,) (padToSize p (Just label : parentLabels))) (unwrap c)
|
|
||||||
|
|
||||||
-- | Replaces labels in a term’s annotations with corresponding p,q-grams.
|
-- | Replaces labels in a term’s annotations with corresponding p,q-grams.
|
||||||
decorateTermWithPQGram :: Traversable f => Int -> Int -> Cofree f (Record (label ': fields)) -> Cofree f (Record (Gram label ': fields))
|
decorateTermWithPQGram :: Traversable f => Int -> Int -> Cofree f (Record (label ': fields)) -> Cofree f (Record (Gram label ': fields))
|
||||||
decorateTermWithPQGram p q = cata algebra
|
decorateTermWithPQGram p q = cata algebra
|
||||||
|
Loading…
Reference in New Issue
Block a user