mirror of
https://github.com/github/semantic.git
synced 2024-12-22 14:21:31 +03:00
Reformat the algebra.
This commit is contained in:
parent
50c52af354
commit
0facfdbb7f
@ -74,7 +74,8 @@ featureVector d bag = sumVectors $ unitVector d . hash <$> bag
|
||||
-- | Annotates a term with the corresponding p,q-gram at each node.
|
||||
pqGramDecorator :: Traversable f => (forall b. CofreeF f (Record fields) b -> label) -> Int -> Int -> Cofree f (Record fields) -> Cofree f (Record (Gram label ': fields))
|
||||
pqGramDecorator getLabel p q = cata algebra
|
||||
where algebra (rest :< functor) = let label = getLabel (rest :< functor) in cofree ((Gram (padToSize p []) (padToSize q (pure (Just label))) .: rest) :< (`evalState` (siblingLabels functor)) (for functor (assignLabels label)))
|
||||
where algebra term = let label = getLabel term in
|
||||
cofree ((Gram (padToSize p []) (padToSize q (pure (Just label))) .: headF term) :< (`evalState` (siblingLabels (tailF term))) (for (tailF term) (assignLabels label)))
|
||||
assignLabels :: label -> Cofree f (Record (Gram label ': fields)) -> State [Maybe label] (Cofree f (Record (Gram label ': fields)))
|
||||
assignLabels label a = case runCofree a of
|
||||
RCons gram rest :< functor -> do
|
||||
|
Loading…
Reference in New Issue
Block a user