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

Idiomatic record construction.

This commit is contained in:
Rob Rix 2016-08-09 11:06:27 -04:00
parent 638d8eda23
commit 8d1fb84ed3

View File

@ -96,7 +96,7 @@ decorateTermWithPQGram q = cata algebra
-- | Replaces bags of p,q-grams in a terms annotations with corresponding feature vectors. -- | Replaces bags of p,q-grams in a terms annotations with corresponding feature vectors.
decorateTermWithFeatureVector :: (Hashable label, Prologue.Foldable f, Functor f) => Int -> Cofree f (Record (Gram label ': fields)) -> Cofree f (Record (Vector.Vector Double ': fields)) decorateTermWithFeatureVector :: (Hashable label, Prologue.Foldable f, Functor f) => Int -> Cofree f (Record (Gram label ': fields)) -> Cofree f (Record (Vector.Vector Double ': fields))
decorateTermWithFeatureVector d = cata $ \ (RCons gram rest :< functor) -> decorateTermWithFeatureVector d = cata $ \ (RCons gram rest :< functor) ->
cofree (RCons (foldr (Vector.zipWith (+) . getField . extract) (unitVector d (hash gram)) functor) rest :< functor) cofree ((foldr (Vector.zipWith (+) . getField . extract) (unitVector d (hash gram)) functor .: rest) :< functor)
-- | Computes a unit vector of the specified dimension from a hash. -- | Computes a unit vector of the specified dimension from a hash.
unitVector :: Int -> Int -> Vector.Vector Double unitVector :: Int -> Int -> Vector.Vector Double