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

Generalize featureVectorDecorator to accept any Hashable label.

This commit is contained in:
Rob Rix 2017-12-01 17:00:40 -05:00
parent 2c561be63f
commit 99f3633060

View File

@ -125,9 +125,9 @@ defaultFeatureVectorDecorator
defaultFeatureVectorDecorator getLabel = featureVectorDecorator . pqGramDecorator getLabel defaultP defaultQ
-- | Annotates a term with a feature vector at each node, parameterized by stem length, base width, and feature vector dimensions.
featureVectorDecorator :: (Foldable f, Functor f, Hashable label) => Term f (Record (Gram label ': fields)) -> Term f (Record (FeatureVector ': fields))
featureVectorDecorator = cata (\ (In (gram :. rest) functor) ->
termIn (foldl' addSubtermVector (unitVector (hash gram)) functor :. rest) functor)
featureVectorDecorator :: (Foldable f, Functor f, Hashable label) => Term f (Record (label ': fields)) -> Term f (Record (FeatureVector ': fields))
featureVectorDecorator = cata (\ (In (label :. rest) functor) ->
termIn (foldl' addSubtermVector (unitVector (hash label)) functor :. rest) functor)
where addSubtermVector v term = addVectors v (rhead (termAnnotation term))
-- | Annotates a term with the corresponding p,q-gram at each node.