packages feed

corenlp-parser 0.1.0.1 → 0.2.0.0

raw patch · 2 files changed

+102/−6 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ NLP.CoreNLP: CAUSE_OF_DEATH :: NamedEntity
+ NLP.CoreNLP: CC :: PennPOS
+ NLP.CoreNLP: CD :: PennPOS
+ NLP.CoreNLP: CITY :: NamedEntity
+ NLP.CoreNLP: COUNTRY :: NamedEntity
+ NLP.CoreNLP: CRIMINAL_CHARGE :: NamedEntity
+ NLP.CoreNLP: DATE :: NamedEntity
+ NLP.CoreNLP: DT :: PennPOS
+ NLP.CoreNLP: DURATION :: NamedEntity
+ NLP.CoreNLP: EMAIL :: NamedEntity
+ NLP.CoreNLP: EX :: PennPOS
+ NLP.CoreNLP: FW :: PennPOS
+ NLP.CoreNLP: IDEOLOGY :: NamedEntity
+ NLP.CoreNLP: IN :: PennPOS
+ NLP.CoreNLP: JJ :: PennPOS
+ NLP.CoreNLP: JJR :: PennPOS
+ NLP.CoreNLP: JJS :: PennPOS
+ NLP.CoreNLP: LOCATION :: NamedEntity
+ NLP.CoreNLP: LRB :: PennPOS
+ NLP.CoreNLP: LS :: PennPOS
+ NLP.CoreNLP: MD :: PennPOS
+ NLP.CoreNLP: MISC :: NamedEntity
+ NLP.CoreNLP: MONEY :: NamedEntity
+ NLP.CoreNLP: NATIONALITY :: NamedEntity
+ NLP.CoreNLP: NN :: PennPOS
+ NLP.CoreNLP: NNP :: PennPOS
+ NLP.CoreNLP: NNPS :: PennPOS
+ NLP.CoreNLP: NNS :: PennPOS
+ NLP.CoreNLP: NUMBER :: NamedEntity
+ NLP.CoreNLP: O :: NamedEntity
+ NLP.CoreNLP: ORDINAL :: NamedEntity
+ NLP.CoreNLP: ORGANIZATION :: NamedEntity
+ NLP.CoreNLP: PDT :: PennPOS
+ NLP.CoreNLP: PERCENT :: NamedEntity
+ NLP.CoreNLP: PERSON :: NamedEntity
+ NLP.CoreNLP: POS :: PennPOS
+ NLP.CoreNLP: PRP :: PennPOS
+ NLP.CoreNLP: PRPDollar :: PennPOS
+ NLP.CoreNLP: PosPunctuation :: Text -> PennPOS
+ NLP.CoreNLP: RB :: PennPOS
+ NLP.CoreNLP: RBR :: PennPOS
+ NLP.CoreNLP: RBS :: PennPOS
+ NLP.CoreNLP: RELIGION :: NamedEntity
+ NLP.CoreNLP: RP :: PennPOS
+ NLP.CoreNLP: RRB :: PennPOS
+ NLP.CoreNLP: SET :: NamedEntity
+ NLP.CoreNLP: STATE_OR_PROVINCE :: NamedEntity
+ NLP.CoreNLP: SYM :: PennPOS
+ NLP.CoreNLP: TIME :: NamedEntity
+ NLP.CoreNLP: TITLE :: NamedEntity
+ NLP.CoreNLP: TO :: PennPOS
+ NLP.CoreNLP: UH :: PennPOS
+ NLP.CoreNLP: URL :: NamedEntity
+ NLP.CoreNLP: VB :: PennPOS
+ NLP.CoreNLP: VBD :: PennPOS
+ NLP.CoreNLP: VBG :: PennPOS
+ NLP.CoreNLP: VBN :: PennPOS
+ NLP.CoreNLP: VBP :: PennPOS
+ NLP.CoreNLP: VBZ :: PennPOS
+ NLP.CoreNLP: WDT :: PennPOS
+ NLP.CoreNLP: WP :: PennPOS
+ NLP.CoreNLP: WPDollar :: PennPOS
+ NLP.CoreNLP: WRB :: PennPOS
+ NLP.CoreNLP: data NamedEntity
+ NLP.CoreNLP: data PennPOS
+ NLP.CoreNLP: instance Data.Aeson.Types.FromJSON.FromJSON NLP.CoreNLP.NamedEntity
+ NLP.CoreNLP: instance Data.Aeson.Types.FromJSON.FromJSON NLP.CoreNLP.PennPOS
+ NLP.CoreNLP: instance Data.Aeson.Types.ToJSON.ToJSON NLP.CoreNLP.NamedEntity
+ NLP.CoreNLP: instance Data.Aeson.Types.ToJSON.ToJSON NLP.CoreNLP.PennPOS
+ NLP.CoreNLP: instance GHC.Classes.Eq NLP.CoreNLP.NamedEntity
+ NLP.CoreNLP: instance GHC.Classes.Eq NLP.CoreNLP.PennPOS
+ NLP.CoreNLP: instance GHC.Generics.Generic NLP.CoreNLP.NamedEntity
+ NLP.CoreNLP: instance GHC.Generics.Generic NLP.CoreNLP.PennPOS
+ NLP.CoreNLP: instance GHC.Show.Show NLP.CoreNLP.NamedEntity
+ NLP.CoreNLP: instance GHC.Show.Show NLP.CoreNLP.PennPOS
- NLP.CoreNLP: Token :: Int -> Text -> Text -> Text -> Int -> Int -> Text -> Text -> Text -> Text -> Text -> Token
+ NLP.CoreNLP: Token :: Int -> Text -> Text -> Text -> Int -> Int -> PennPOS -> NamedEntity -> Text -> Text -> Text -> Token
- NLP.CoreNLP: [$sel:ner:Token] :: Token -> Text
+ NLP.CoreNLP: [$sel:ner:Token] :: Token -> NamedEntity
- NLP.CoreNLP: [$sel:pos:Token] :: Token -> Text
+ NLP.CoreNLP: [$sel:pos:Token] :: Token -> PennPOS

Files

corenlp-parser.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 1c8c69412199cfc131a9616ffeb4fa1d6cc14c80f11a354954fb37fd463ab36e+-- hash: e8a7cb9abd37d5caa6e148ad4d63629e9f60c0f297c21244bf1fff026e90c24c  name:           corenlp-parser-version:        0.1.0.1+version:        0.2.0.0 synopsis:       Launches CoreNLP and parses the JSON output description:    Launches CoreNLP and parses the JSON output category:       Natural Language Processing
src/NLP/CoreNLP.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE OverloadedStrings #-}  -- | Module provides a handy wrapper around the CoreNLP project\'s -- command-line utility https://nlp.stanford.edu/software/corenlp.html@@ -13,14 +14,17 @@   , Entitymention(..)   , Token(..)   , Sentence(..)+  , PennPOS(..)   , Coref(..)   , CorefsId   , Corefs   , Document(..)+  , NamedEntity(..)   -- * Internal   , test   ) where +import Control.Applicative import Control.Monad (forM, when) import qualified Data.Aeson as J import Data.Aeson (FromJSON, ToJSON)@@ -78,6 +82,100 @@ instance ToJSON Entitymention where   toJSON = J.genericToJSON jsonOpts +data PennPOS+  = CC -- ^ Coordinating conjunction+  | CD -- ^ Cardinal number+  | DT -- ^ Determiner+  | EX -- ^ Existential *there*+  | FW -- ^ Foreign word+  | IN -- ^ Preposition or subordinating conjunction+  | JJ -- ^ Adjective+  | JJR -- ^ Adjective, comparative+  | JJS -- ^ Adjective, superlative+  | LS -- ^ List item marker+  | MD -- ^ Modal+  | NN -- ^ Noun, singular or mass+  | NNS -- ^ Noun, plural+  | NNP -- ^ Proper noun, singular+  | NNPS -- ^ Proper noun, plural+  | PDT -- ^ Predeterminer+  | POS -- ^ Possessive ending+  | PRP -- ^ Personal pronoun+  | PRPDollar -- ^ Possessive pronoun+  | RB -- ^ Adverb+  | RBR -- ^ Adverb, comparative+  | RBS -- ^ Adverb, superlative+  | RP -- ^ Particle+  | SYM -- ^ Symbol+  | TO -- ^ *to*+  | UH -- ^ Interjection+  | VB -- ^ Verb, base form+  | VBD -- ^ Verb, past tense+  | VBG -- ^ Verb, gerund or present participle+  | VBN -- ^ Verb, past participle+  | VBP -- ^ Verb, non-3rd person singular present+  | VBZ -- ^ Verb, 3rd person singular present+  | WDT -- ^ Wh-determiner+  | WP -- ^ Wh-pronoun+  | WPDollar -- ^ Possessive wh-pronoun+  | WRB -- ^ Wh-adverb+  | LRB -- ^ "-LRB-"? No idea what's this+  | RRB -- ^ "-RRB-"? No idea what's this+  | PosPunctuation Text -- ^ anyOf ".:,''$#$,", sometimes few together+  deriving (Show, Eq, Generic)++instance FromJSON PennPOS where+  parseJSON (J.String "WP$") = pure WPDollar+  parseJSON (J.String "PRP$") = pure PRPDollar+  parseJSON (J.String "-LRB-") = pure LRB+  parseJSON (J.String "-RRB-") = pure RRB+  parseJSON x = J.genericParseJSON jsonOpts x <|> parsePunctuation x+    where+      parsePunctuation (J.String y) = pure (PosPunctuation y)+      parsePunctuation _ = fail "Expecting POS to be a String"++instance ToJSON PennPOS where+  toJSON WPDollar = J.String "WP$"+  toJSON PRPDollar = J.String "PRP$"+  toJSON (PosPunctuation t) = J.String t+  toJSON LRB = J.String "-LRB-"+  toJSON RRB = J.String "-RRB-"+  toJSON x = J.genericToJSON jsonOpts x++-- | See https:\/\/stanfordnlp.github.io\/CoreNLP\/ner.html+data NamedEntity+  = PERSON+  | LOCATION+  | ORGANIZATION+  | MISC+  | MONEY+  | NUMBER+  | ORDINAL+  | PERCENT+  | DATE+  | TIME+  | DURATION+  | SET+  | EMAIL+  | URL+  | CITY+  | STATE_OR_PROVINCE+  | COUNTRY+  | NATIONALITY+  | RELIGION+  | TITLE -- ^ Job title+  | IDEOLOGY+  | CRIMINAL_CHARGE+  | CAUSE_OF_DEATH+  | O -- ^ Not a named entity? TODO: check somehow+  deriving (Show, Eq, Generic)++instance FromJSON NamedEntity where+  parseJSON = J.genericParseJSON jsonOpts++instance ToJSON NamedEntity where+  toJSON = J.genericToJSON jsonOpts+ data Token = Token   { index :: Int   , word :: Text@@ -85,8 +183,8 @@   , lemma :: Text   , characterOffsetBegin :: Int   , characterOffsetEnd :: Int-  , pos :: Text-  , ner :: Text+  , pos :: PennPOS+  , ner :: NamedEntity   , speaker :: Text   , before :: Text   , after :: Text@@ -186,13 +284,11 @@       code <- waitForProcess processHandle       when (code /= ExitSuccess) (error (show code))       let tmpFileNamesJson = map (<> ".json") tmpFileNames-      _ <- Prelude.getLine       results <- forM tmpFileNamesJson $ \fname -> T.readFile fname       return (map parseJsonDoc results)  headlines :: Text headlines =-  S.toText $   [r| {   "docId": "headlines.txt",