mirror of
https://github.com/github/semantic.git
synced 2025-01-03 21:16:12 +03:00
Remove hashDecorator
This commit is contained in:
parent
6947c8cf9f
commit
f2ccad84c5
@ -3,7 +3,6 @@ module Data.RandomWalkSimilarity
|
||||
( rws
|
||||
, pqGramDecorator
|
||||
, defaultFeatureVectorDecorator
|
||||
, hashDecorator
|
||||
, featureVectorDecorator
|
||||
, editDistanceUpTo
|
||||
, defaultD
|
||||
@ -31,7 +30,7 @@ import Prologue
|
||||
import Term (termSize, zipTerms)
|
||||
import Test.QuickCheck hiding (Fixed)
|
||||
import Test.QuickCheck.Random
|
||||
import qualified SES as SES
|
||||
import qualified SES
|
||||
import Info
|
||||
import Data.Align.Generic
|
||||
|
||||
@ -143,12 +142,6 @@ data UnmappedTerm a = UnmappedTerm { termIndex :: {-# UNPACK #-} !Int, feature :
|
||||
data Gram label = Gram { stem :: [Maybe label], base :: [Maybe label] }
|
||||
deriving (Eq, Show)
|
||||
|
||||
-- -- | Annotates a term with it's hash at each node.
|
||||
hashDecorator :: forall hash f fields. (Hashable (f Int), Hashable hash, Traversable f) => (forall b. CofreeF f (Record fields) b -> hash) -> Cofree f (Record fields) -> Cofree f (Record (Int ': fields))
|
||||
hashDecorator getLabel = cata $ \case
|
||||
term@(record :< functor) ->
|
||||
cofree ((hash (getLabel term, fmap (getField . extract) functor :: f Int) .: record) :< functor)
|
||||
|
||||
-- | Annotates a term with a feature vector at each node, using the default values for the p, q, and d parameters.
|
||||
defaultFeatureVectorDecorator :: (Hashable label, Traversable f) => (forall b. CofreeF f (Record fields) b -> label) -> Cofree f (Record fields) -> Cofree f (Record (Vector.Vector Double ': fields))
|
||||
defaultFeatureVectorDecorator getLabel = featureVectorDecorator getLabel defaultP defaultQ defaultD
|
||||
|
@ -38,15 +38,18 @@ import qualified Data.Text as T
|
||||
import Category
|
||||
import Data.Aeson (toJSON, toEncoding)
|
||||
import Data.Aeson.Encoding (encodingToLazyByteString)
|
||||
import Data.Hashable
|
||||
|
||||
-- | Given a parser and renderer, diff two sources and return the rendered
|
||||
-- | result.
|
||||
-- | Returns the rendered result strictly, so it's always fully evaluated
|
||||
-- | with respect to other IO actions.
|
||||
diffFiles :: (HasField fields Category, HasField fields Cost, HasField fields Range, Eq (Record fields)) => Parser (Syntax Text) (Record fields) -> Renderer (Record (Vector.Vector Double ': Int ': fields)) -> Both SourceBlob -> IO Output
|
||||
diffFiles :: (HasField fields Category, HasField fields Cost, HasField fields Range, Eq (Record fields))
|
||||
=> Parser (Syntax Text) (Record fields)
|
||||
-> Renderer (Record (Vector.Vector Double ': fields))
|
||||
-> Both SourceBlob
|
||||
-> IO Output
|
||||
diffFiles parser renderer sourceBlobs = do
|
||||
terms <- traverse (fmap (defaultFeatureVectorDecorator getLabel . hashDecorator getLabel) . parser) sourceBlobs
|
||||
terms <- traverse (fmap (defaultFeatureVectorDecorator getLabel) . parser) sourceBlobs
|
||||
|
||||
let areNullOids = runBothWith (\a b -> (oid a == nullOid || null (source a), oid b == nullOid || null (source b))) sourceBlobs
|
||||
let textDiff = case areNullOids of
|
||||
@ -81,8 +84,8 @@ lineByLineParser blob = pure . cofree . root $ case foldl' annotateLeaves ([], 0
|
||||
where
|
||||
input = source blob
|
||||
lines = actualLines input
|
||||
root children = ((Range 0 $ length input) .: Program .: RNil) :< Indexed children
|
||||
leaf charIndex line = ((Range charIndex $ charIndex + T.length line) .: Program .: RNil) :< Leaf line
|
||||
root children = (Range 0 (length input) .: Program .: RNil) :< Indexed children
|
||||
leaf charIndex line = (Range charIndex (charIndex + T.length line) .: Program .: RNil) :< Leaf line
|
||||
annotateLeaves (accum, charIndex) line =
|
||||
(accum <> [ leaf charIndex (toText line) ] , charIndex + length line)
|
||||
toText = T.pack . Source.toString
|
||||
|
Loading…
Reference in New Issue
Block a user