nerf 0.2.0 → 0.2.1
raw patch · 2 files changed
+56/−2 lines, 2 files
Files
- NLP/Nerf/Dict/PNET.hs +53/−0
- nerf.cabal +3/−2
+ NLP/Nerf/Dict/PNET.hs view
@@ -0,0 +1,53 @@+{-# LANGUAGE OverloadedStrings #-}++-- | Polish Named Entity Triggers <http://zil.ipipan.waw.pl/PNET> dictionary.++module NLP.Nerf.Dict.PNET+( parsePNET+, readPNET+, Typ (..)+, hasTyp+, Entry (..)+) where++import qualified Data.Text as T+import qualified Data.Text.Lazy as L+import qualified Data.Text.Lazy.IO as L++-- | Trigger type.+data Typ+ = Internal+ | External+ deriving (Show, Eq, Ord)++readTyp :: T.Text -> Typ+readTyp "int" = Internal+readTyp "ext" = External+readTyp x = error $ "readTyp: typ " ++ T.unpack x ++ " unknown"++-- | PNET entry.+data Entry = Entry+ { orth :: T.Text+ , base :: T.Text+ , tag :: T.Text+ , typ :: Typ+ , neTyp :: T.Text+ , example :: T.Text }++-- | Does entry represents a trigger of the given type?+hasTyp :: Typ -> Entry -> Bool+hasTyp x = (==x) . typ++parseLine :: L.Text -> Entry+parseLine line = case map L.toStrict (L.split (=='\t') line) of+ [_orth, _base, _tag, _typ, _neTyp, _example] ->+ Entry _orth _base _tag (readTyp _typ) _neTyp _example+ _ -> error $ "parseLine: invalid row \"" ++ L.unpack line ++ "\""++-- | Parse dictionary into a list of entries.+parsePNET :: L.Text -> [Entry]+parsePNET = map parseLine . L.lines++-- | Read dictionary from the file.+readPNET :: FilePath -> IO [Entry]+readPNET = fmap parsePNET . L.readFile
nerf.cabal view
@@ -1,5 +1,5 @@ name: nerf-version: 0.2.0+version: 0.2.1 synopsis: Nerf, the named entity recognition tool based on linear-chain CRFs description: The package provides the named entity recognition (NER) tool divided into a@@ -49,6 +49,7 @@ , NLP.Nerf.Dict , NLP.Nerf.Dict.Base , NLP.Nerf.Dict.PNEG+ , NLP.Nerf.Dict.PNET , NLP.Nerf.Dict.NELexicon , NLP.Nerf.Dict.Prolexbase @@ -56,7 +57,7 @@ source-repository head type: git- location: git://github.com/kawu/nerf.git+ location: https://github.com/kawu/nerf.git executable nerf hs-source-dirs: ., tools