packages feed

sloane 0.1.5 → 1.1

raw patch · 3 files changed

+92/−74 lines, 3 filesdep +bytestring

Dependencies added: bytestring

Files

README.md view
@@ -1,72 +1,84 @@-sloane-======+---+title: SLOANE(1) Sloane User Manual | Version 1.0+date: October 28, 2013+--- -A command line interface to Sloane's [On-Line Encyclopedia of Integer Sequences (OEIS)](http://oeis.org)+# NAME -Install--------+sloane - a command line interface to Sloane's+On-Line Encyclopedia of Integer Sequences (OEIS) <http://oeis.org> -    $ cabal install sloane+# SYNOPSIS -Usage------+sloane [*options*] *search-terms* -    $ sloane --help-    Search Sloane's On-Line Encyclopedia of Integer Sequences+# DESCRIPTION -    sloane [OPTIONS] SEARCH-TERMS+The sloane command searches Sloane's On-Line Encyclopedia of Integer+Sequences (OEIS). The search terms are typically the leading term of a+sequence, but can be a sequence id (its A-number) or even arbitrary words. -    Common flags:-      -k --keys=KEYS  Keys of fields to print (default: SN)-      -a --all        Print all fields-      -u --url        Only print urls of found entries-      -n --limit=INT  Limit the number of entries retrieved (default: 5)-      -? --help       Display help message-      -V --version    Print version information+# OPTIONS -Examples---------+-k --keys=KEYS+:   Keys of fields to print (default: SN) -Search for entries matching a sequence:+-a --all+:   Print all fields -    $ sloane 1,3,19,183,2371,38703+-u --url+:   Only print urls of found entries -    S A006531 1,1,3,19,183,2371,38703,763099,17648823,468603091,14050842303,-    N A006531 Semiorders on n elements.+-n --limit=INT+:   Limit the number of entries retrieved (default: 5) -Show the sequence, name, comments, and formula fields of the sequence whose A-number is A006531:+-? --help+:   Display a short help message -    $ sloane -kSNCF id:A006531+-V --version+:   Print version information -    S A006531 1,1,3,19,183,2371,38703,763099,17648823,468603091,14050842303,-    N A006531 Semiorders on n elements.-    C A006531 Labeled semiorders on n elements: (1+3) and (2+2)-free posets. - Detlef Pauly (dettodet(AT)yahoo.de), Dec 27 2002-    F A006531 O.g.f.: Sum_{n>=1} (2*n)!/(n+1)! * x^n / Product_{k=0..n} (1+k*x). [From Paul D. Hanna, Jul 20 2011]-    F A006531 E.g.f.: C(1-exp(-x)), where C(x) = (1 - sqrt(1 - 4*x)) / (2*x) is the ordinary g.f. for the Catalan numbers A000108.-    F A006531 a(n) = sum( S(n, k) * k! * M(k-1), k=1..n), S(n, k): Stirling number of the second kind, M(n): Motzkin number, A001006. - Detlef Pauly, Jun 06 2002+# EXAMPLES -Return at most 3 results of a free text search:+The most common search is for entries matching a sequence of consecutive terms: -    $ sloane -n3 "(2+2)-free posets"+~~~~~+sloane 1,3,19,183,2371,38703+~~~~~ -    S A079144 1,1,3,19,207,3451,81663,2602699,107477247,5581680571,356046745023,-    N A079144 Number of labeled interval orders on n elements: (2+2)-free posets.+At the time of writing this particular query would return -    S A022493 1,1,2,5,15,53,217,1014,5335,31240,201608,1422074,10886503,89903100,-    N A022493 Number of linearized chord diagrams of degree n; also number of nonisomorphic interval orders on n unlabeled points.+~~~~~+S A006531 1,1,3,19,183,2371,38703,763099,17648823,468603091,14050842303,+N A006531 Semiorders on n elements.+~~~~~ -    S A006531 1,1,3,19,183,2371,38703,763099,17648823,468603091,14050842303,-    N A006531 Semiorders on n elements.+As this illustrates, the default is to return just the sequence (S) and+the name (N) fields. To override the default one can use the keys+option. For instance, the following search shows the sequence, name,+comments, and formula fields of the sequence whose A-number is A006531: -Look at those 3 results in firefox:+~~~~~+sloane -kSNCF id:A006531+~~~~~ -    $ firefox `sloane --url -n3 "(2+2)-free posets"`+The next example returns at most 3 results of a free text search: -Keys-----+~~~~~+sloane -n3 "(2+2)-free posets"+~~~~~ -These are the [keys used by OEIS](http://oeis.org/eishelp2.html).+To view the full entries of these 3 results in a browser (e.g., firefox)+one can use the url option: +~~~~~+firefox `sloane --url -n3 "(2+2)-free posets"`+~~~~~++# KEYS++These are the keys used by OEIS <http://oeis.org/eishelp2.html>.+     I  ID number      S  1st line of unsigned sequence@@ -94,8 +106,17 @@     A  Author     E  Extensions and errors -Caveat-------+# NOTES -Please use this program with moderation as not to overburden the OEIS-server; see-[OEIS' policy on searching the database](http://oeis.org/wiki/Welcome#Policy_on_Searching_the_Database).+Please use this program with moderation as not to overburden the+OEIS-server; see OEIS' policy on searching the database:+<http://oeis.org/wiki/Welcome#Policy_on_Searching_the_Database>.++# SEE ALSO++The sloane source code may be downloaded from+<http://src.akc.is/sloane>.++# AUTHOR++Anders Claesson
sloane.cabal view
@@ -1,5 +1,5 @@ Name:                sloane-Version:             0.1.5+Version:             1.1 Synopsis:            A command line interface to Sloane's On-Line Encyclopedia of Integer Sequences Description:         A command line interface to Sloane's On-Line Encyclopedia of Integer Sequences.                      For usage see <http://github.com/akc/sloane>.@@ -20,4 +20,4 @@  Executable sloane   Main-is:             sloane.hs-  Build-depends:       base >= 3 && < 5, cmdargs, HTTP, url >=2+  Build-depends:       base >= 3 && < 5, cmdargs, HTTP, url >=2, bytestring >=0.9
sloane.hs view
@@ -1,14 +1,15 @@ {-# LANGUAGE DeriveDataTypeable #-}  -- |--- Copyright   : Anders Claesson 2012, 2013+-- Copyright   : Anders Claesson 2012, 2013, 2014 -- Maintainer  : Anders Claesson <anders.claesson@gmail.com>+-- License     : BSD-3 ----import Prelude hiding (all)+import Prelude hiding (all, putStrLn)+import Data.ByteString.Char8 (putStrLn, pack) import System.Console.CmdArgs import Data.Maybe (fromJust)-import Control.Monad (when, guard)+import Control.Monad (unless, guard) import Network.HTTP (simpleHTTP, getRequest, getResponseBody) import Network.URL (importURL, exportURL, add_param) @@ -28,15 +29,15 @@                      }               deriving (Data, Typeable) -sloane = cmdArgsMode $ Sloane -         { keys  = "SN"  &= typ "KEYS" &= help "Keys of fields to print (default: SN)"-         , all   = False &= name "a"   &= help "Print all fields"-         , url   = False &= name "u"   &= help "Print urls of found entries"-         , limit = 5     &= name "n"   &= help "Limit the number of entries retrieved (default: 5)"-         , terms = def   &= argPos 0   &= typ "SEARCH-TERMS"-         }-         &= versionArg [summary "sloane 0.1.5"]-         &= summary "Search Sloane's On-Line Encyclopedia of Integer Sequences"+sloane = cmdArgsMode $ Sloane+  { keys  = "SN"  &= typ "KEYS" &= help "Keys of fields to print (default: SN)"+  , all   = False &= name "a"   &= help "Print all fields"+  , url   = False &= name "u"   &= help "Print urls of found entries"+  , limit = 5     &= name "n"   &= help "Limit the number of entries retrieved (default: 5)"+  , terms = def   &= argPos 0   &= typ "SEARCH-TERMS"+  }+  &= versionArg [summary "sloane 1.1"]+  &= summary "Search Sloane's On-Line Encyclopedia of Integer Sequences"  select :: [Key] -> OEISEntries -> OEISEntries select ks = unlines . filter (\xs -> null xs || head xs `elem` ks) . lines@@ -45,11 +46,11 @@ urls es = unlines $ do             ids <- lines $ select "I" es             guard $ not (null ids)-            let aNum = (words ids) !! 1+            let aNum = words ids !! 1             return $ oeisHost ++ "/" ++ aNum  searchOEIS :: Int -> Query -> IO OEISEntries-searchOEIS n s = do+searchOEIS n s =   trim `fmap` (simpleHTTP (getRequest url) >>= getResponseBody)     where       trim = unlines . map (drop 1) . reverse . drop 2 . reverse . drop 5 . lines@@ -57,11 +58,7 @@  main = do   args <- cmdArgsRun sloane-  result <- searchOEIS (limit args) . filter (`notElem` "[]") $ terms args-  when (not $ null result) $ do-    putStrLn ""-    if (url args)-      then-        putStrLn $ urls result-      else-        putStrLn $ if all args then result else select (keys args) result+  entries <- searchOEIS (limit args) . filter (`notElem` "[]") $ terms args+  let pick = if all args then id else select (keys args)+  unless (null entries) $+         putStrLn . pack $ '\n' : (if url args then urls else pick) entries