GenI-0.20.1: A natural language generator (specifically, an FB-LTAG surface realiser)Source codeContentsIndex
NLP.GenI.General
Contents
IO
Strict readFile
Timeouts
Strings
Triples
Lists
Trees
Intervals
Bit vectors
Bugs
Description
This module provides some very generic, non-GenI specific functions on strings, trees and other miscellaneous odds and ends. Whenever possible, one should try to replace these functions with versions that are available in the standard libraries, or the Haskell platform ones, or on hackage.
Synopsis
ePutStr :: String -> IO ()
ePutStrLn :: String -> IO ()
eFlush :: IO ()
readFile' :: FilePath -> IO String
lazySlurp :: ForeignPtr Word8 -> Int -> Int -> IO String
withTimeout :: Integer -> IO a -> IO a -> IO a
exitTimeout :: IO ()
dropTillIncluding :: Char -> String -> String
trim :: String -> String
toUpperHead :: String -> String
toLowerHead :: String -> String
toAlphaNum :: String -> [AlphaNum]
fst3 :: (a, b, c) -> a
snd3 :: (a, b, c) -> b
thd3 :: (a, b, c) -> c
map' :: (a -> b) -> [a] -> [b]
boundsCheck :: Int -> [a] -> Bool
isEmptyIntersect :: Eq a => [a] -> [a] -> Bool
groupByFM :: Ord b => (a -> b) -> [a] -> Map b [a]
multiGroupByFM :: Ord b => (a -> [b]) -> [a] -> Map b [a]
insertToListMap :: Ord b => b -> a -> Map b [a] -> Map b [a]
groupAndCount :: (Eq a, Ord a) => [a] -> [(a, Int)]
combinations :: [[a]] -> [[a]]
mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]
repList :: (a -> Bool) -> (a -> a) -> [a] -> [a]
mapTree' :: (a -> b) -> Tree a -> Tree b
filterTree :: (a -> Bool) -> Tree a -> [a]
treeLeaves :: Tree a -> [a]
preTerminals :: Tree a -> [(a, a)]
repNode :: (Tree a -> Tree a) -> (Tree a -> Bool) -> Tree a -> Maybe (Tree a)
repAllNode :: (Tree a -> Tree a) -> (Tree a -> Bool) -> Tree a -> Tree a
listRepNode :: (Tree a -> Tree a) -> (Tree a -> Bool) -> [Tree a] -> ([Tree a], Bool)
repNodeByNode :: (a -> Bool) -> a -> Tree a -> Tree a
type Interval = (Int, Int)
(!+!) :: Interval -> Interval -> Interval
ival :: Int -> Interval
showInterval :: Interval -> String
type BitVector = Integer
showBitVector :: Int -> BitVector -> String
geniBug :: String -> a
IO
ePutStr :: String -> IO ()Source
putStr on stderr
ePutStrLn :: String -> IO ()Source
eFlush :: IO ()Source
Strict readFile
readFile' :: FilePath -> IO StringSource
Using readFile' can be a good idea if you're dealing with not-so-huge files (i.e. where you don't want lazy evaluation), because it ensures that the handles are closed. No more ``too many open files''
lazySlurp :: ForeignPtr Word8 -> Int -> Int -> IO StringSource
Timeouts
withTimeoutSource
::
=> Integeraction to run upon timing out
-> IO amain action to run
-> IO a
-> IO a
exitTimeout :: IO ()Source
Like exitFailure, except that we return with a code that we reserve for timing out
Strings
dropTillIncluding :: Char -> String -> StringSource
Drop all characters up to and including the one in question
trim :: String -> StringSource
toUpperHead :: String -> StringSource
Make the first character of a string upper case
toLowerHead :: String -> StringSource
Make the first character of a string lower case
toAlphaNum :: String -> [AlphaNum]Source
An alphanumeric sort is one where you treat the numbers in the string as actual numbers. An alphanumeric sort would put x2 before x100, because 2 < 10, wheraeas a naive sort would put it the other way around because the characters 1 < 2. To sort alphanumerically, just 'sortBy (comparing toAlphaNum)'
Triples
fst3 :: (a, b, c) -> aSource
snd3 :: (a, b, c) -> bSource
thd3 :: (a, b, c) -> cSource
Lists
map' :: (a -> b) -> [a] -> [b]Source
A strict version of map
boundsCheck :: Int -> [a] -> BoolSource
Makes sure that index s is in the bounds of list l. Surely there must be some more intelligent way to deal with this.
isEmptyIntersect :: Eq a => [a] -> [a] -> BoolSource
True if the intersection of two lists is empty.
groupByFM :: Ord b => (a -> b) -> [a] -> Map b [a]Source
Serves the same function as groupBy. It groups together items by some property they have in common. The difference is that the property is used as a key to a Map that you can lookup.
multiGroupByFM :: Ord b => (a -> [b]) -> [a] -> Map b [a]Source
Same as groupByFM, except that we let an item appear in multiple groups. The fn extracts the property from the item, and returns multiple results in the form of a list
insertToListMap :: Ord b => b -> a -> Map b [a] -> Map b [a]Source
groupAndCount :: (Eq a, Ord a) => [a] -> [(a, Int)]Source
Convert a list of items into a list of tuples (a,b) where a is an item in the list and b is the number of times a in occurs in the list.
combinations :: [[a]] -> [[a]]Source
mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]Source
repList :: (a -> Bool) -> (a -> a) -> [a] -> [a]Source
Return the list, modifying only the first matching item.
Trees
mapTree' :: (a -> b) -> Tree a -> Tree bSource
Strict version of mapTree (for non-strict, just use fmap)
filterTree :: (a -> Bool) -> Tree a -> [a]Source
Like filter, except on Trees. Filter might not be a good name, though, because we return a list of nodes, not a tree.
treeLeaves :: Tree a -> [a]Source
The leaf nodes of a Tree
preTerminals :: Tree a -> [(a, a)]Source
Return pairs of (parent, terminal)
repNodeSource
::
=> Tree a -> Tree afiltering function
-> Tree a -> Bool
-> Tree a
-> Maybe (Tree a)
repNode fn filt t returns a version of t in which the first node which filt matches is transformed using fn.
repAllNode :: (Tree a -> Tree a) -> (Tree a -> Bool) -> Tree a -> Tree aSource
Like repNode except that it performs the operations on all nodes that match and doesn't care if any nodes match or not
listRepNodeSource
::
=> Tree a -> Tree afiltering function
-> Tree a -> Boolnodes
-> [Tree a]
-> ([Tree a], Bool)
Like repNode but on a list of tree nodes
repNodeByNodeSource
::
=> a -> Bool
-> a
-> Tree a
-> Tree a
Replace a node in the tree in-place with another node; keep the children the same. If the node is not found in the tree, or if there are multiple instances of the node, this is treated as an error.
Intervals
type Interval = (Int, Int)Source
(!+!) :: Interval -> Interval -> IntervalSource
Add two intervals
ival :: Int -> IntervalSource
ival x builds a trivial interval from x to x
showInterval :: Interval -> StringSource
Bit vectors
type BitVector = IntegerSource
showBitVector :: Int -> BitVector -> StringSource
displays a bit vector, using a minimum number of bits
Bugs
geniBug :: String -> aSource
errors specifically in GenI, which is very likely NOT the user's fault.
Produced by Haddock version 2.6.0