mirror of
https://github.com/github/semantic.git
synced 2024-12-22 22:31:36 +03:00
Define a function mapping p,q-gram bag–decorated terms into feature vector–decorated terms.
This commit is contained in:
parent
d573ca7940
commit
b079bf1b5a
@ -123,6 +123,9 @@ decorateTermWithPQGram p q = futu coalgebra . (,) []
|
||||
decorateTermWithBagsOfPQGrams :: (Prologue.Foldable f, Functor f) => Cofree f (Record (Gram label ': fields)) -> Cofree f (Record (DList.DList (Gram label) ': fields))
|
||||
decorateTermWithBagsOfPQGrams = cata $ \ (RCons gram rest :< functor) -> cofree ((DList.cons gram (foldMap (getField . extract) functor) .: rest) :< functor)
|
||||
|
||||
decorateTermWithFeatureVector :: (Hashable label, Functor f) => Int -> Cofree f (Record (DList.DList (Gram label) ': fields)) -> Cofree f (Record (Vector.Vector Double ': fields))
|
||||
decorateTermWithFeatureVector d = fmap $ \ (RCons grams rest) -> featureVector d grams .: rest
|
||||
|
||||
-- | The magnitude of a Euclidean vector, i.e. its distance from the origin.
|
||||
vmagnitude :: Vector.Vector Double -> Double
|
||||
vmagnitude = sqrtDouble . Vector.sum . fmap (** 2)
|
||||
|
Loading…
Reference in New Issue
Block a user