packages feed

bighugethesaurus (empty) → 0.1.0.0

raw patch · 4 files changed

+75/−0 lines, 4 filesdep +HTTPdep +basedep +splitsetup-changed

Dependencies added: HTTP, base, split

Files

+ LICENSE view
@@ -0,0 +1,12 @@+This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 2 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ bighugethesaurus.cabal view
@@ -0,0 +1,23 @@+name:                bighugethesaurus+version:             0.1.0.0+synopsis:            API wrapper for Big Huge Thesaurus+description:         Get synonyms, antonyms, and other kinds of related words from words.bighugelabs.com+license:             GPL+license-file:        LICENSE+author:              Christopher King+maintainer:          G.nius.ck@gmail.com+copyright:           2015 Christopher King+category:            API, Language+build-type:          Simple+-- extra-source-files:+cabal-version:       >=1.10++library+  hs-source-dirs:      src+  exposed-modules:     Text.Thesaurus+  build-depends:       base >= 4.7 && < 5, split, HTTP+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/TheKing42/Big-Huge-Thesaurus-Haskell
+ src/Text/Thesaurus.hs view
@@ -0,0 +1,38 @@+-- | This module provides synonyms, antonyms, and other kinds of related words from https://words.bighugelabs.com/api.php.+--   See 'getWords'.++module Text.Thesaurus (POS(..), Relation(..), API(..), getWords)+    where++import Control.Applicative+import Data.Maybe (fromJust)+import Data.List.Split (splitOn)+import Network.HTTP (getRequest, simpleHTTP, getResponseBody)++-- | 'POS' is the part of speech a word.+data POS = Noun | Verb | Adj | Adv deriving (Show, Read, Eq, Ord, Enum, Bounded)+-- | 'Relation' is how a word is related to another.+data Relation = Synonym | Antonym | Related | Similar | Suggestion deriving (Show, Read, Eq, Ord, Enum, Bounded)+-- | 'API' is the api key. You can get one at https://words.bighugelabs.com/api.php.+newtype API = API String++parse word = do+    [pos',relation',related] <- return $ splitOn "|" word+    pos <- case pos' of+        "noun" -> Just Noun+        "verb" -> Just Verb+        "adjective" -> Just Adj+        "adverb" -> Just Adv+        _ -> Nothing+    relation <- case relation' of+        "syn" -> Just Synonym+        "ant" -> Just Antonym+        "rel" -> Just Related+        "sim" -> Just Similar+        "usr" -> Just Suggestion+        _ -> Nothing+    return (related,pos,relation)++-- | 'getWords' @key@ @word@ returns a list of words related @word@+getWords :: API -> String -> IO [ (String, POS, Relation) ]+getWords (API key) word = simpleHTTP (getRequest $ "http://words.bighugelabs.com/api/2/"++key++"/"++word++"/") >>= getResponseBody >>= (return . fmap (fromJust . parse) . lines)