sentiwordnet-parser 0.1.0.0 → 0.1.1.0
raw patch · 2 files changed
+32/−3 lines, 2 filesdep +hashabledep +unordered-containersPVP ok
version bump matches the API change (PVP)
Dependencies added: hashable, unordered-containers
API changes (from Hackage documentation)
+ NLP.SentiwordnetParser: SentiWordNetLookupItem :: Int -> Decimal -> Decimal -> SentiWordNetLookupItem
+ NLP.SentiwordnetParser: [lookNegScore] :: SentiWordNetLookupItem -> Decimal
+ NLP.SentiwordnetParser: [lookPosScore] :: SentiWordNetLookupItem -> Decimal
+ NLP.SentiwordnetParser: [lookPos] :: SentiWordNetLookupItem -> Int
+ NLP.SentiwordnetParser: data SentiWordNetLookupItem
+ NLP.SentiwordnetParser: instance Data.Hashable.Class.Hashable NLP.SentiwordnetParser.POS
+ NLP.SentiwordnetParser: instance GHC.Generics.Generic NLP.SentiwordnetParser.POS
+ NLP.SentiwordnetParser: toSentiWordNetLookup :: SentiWordNet -> SentiWordNetLookup
+ NLP.SentiwordnetParser: type SentiWordNetLookup = HashMap (POS, Text) [SentiWordNetLookupItem]
Files
sentiwordnet-parser.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: e874425ac4cd0dc77602bc63619c082712827ce8371eec6e0646730a66c3bcd2+-- hash: 63064a8cda681a9767f685c20005f0e6b1064bb63bcb35c21169b4a0eb432ddf name: sentiwordnet-parser-version: 0.1.0.0+version: 0.1.1.0 synopsis: Parser for the SentiWordNet tab-separated file description: Parser for the SentiWordNet tab-separated file category: Natural Language Processing@@ -28,11 +28,13 @@ build-depends: Decimal , base >=4.7 && <5+ , hashable , parsers , safe , string-class , text , trifecta+ , unordered-containers , vector exposed-modules: NLP.SentiwordnetParser
src/NLP/SentiwordnetParser.hs view
@@ -1,5 +1,7 @@ {-# LANGUAGE ApplicativeDo #-} {-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE DeriveGeneric #-} module NLP.SentiwordnetParser ( parse@@ -7,6 +9,9 @@ , Entry(..) , SynsetTerm(..) , POS(..)+ , SentiWordNetLookup+ , SentiWordNetLookupItem(..)+ , toSentiWordNetLookup -- * internal stuff , parseSentiWordNet , parsePOS@@ -20,9 +25,13 @@ import Control.Applicative import Data.Decimal (Decimal)+import qualified Data.HashMap.Strict as H+import Data.Hashable (Hashable)+import Data.Semigroup import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.IO as T+import GHC.Generics (Generic) import Safe import Text.Trifecta @@ -37,7 +46,7 @@ | Adjective | AdjectiveSatellite | Adverb- deriving (Show, Eq)+ deriving (Show, Eq, Generic, Hashable) data Entry = Entry { pos :: POS@@ -105,6 +114,24 @@ parse :: Text -> Result SentiWordNet parse = parseString parseSentiWordNet mempty . T.unpack++data SentiWordNetLookupItem = SentiWordNetLookupItem+ { lookPos :: Int+ , lookPosScore :: Decimal+ , lookNegScore :: Decimal+ }++-- | Datastructure for efficient 'lookupScoreByPosAndName' lookups+type SentiWordNetLookup = H.HashMap (POS, Text) [SentiWordNetLookupItem]++-- | Convert function+toSentiWordNetLookup :: SentiWordNet -> SentiWordNetLookup+toSentiWordNetLookup SentiWordNet {..} =+ H.fromListWith (<>) (concatMap convEntry items)+ where+ convEntry Entry {..} = map (convTerm pos posScore negScore) synsetTerms+ convTerm pos posScore negScore SynsetTerm {..} =+ ((pos, name), [SentiWordNetLookupItem num posScore negScore]) test :: IO () test = do