-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Bindings to the C version of the PGF runtime -- -- GF, Grammatical Framework, is a programming language for multilingual -- grammar applications. GF grammars are compiled into Portable Grammar -- Format (PGF) which can be used with the PGF runtime, written in C. -- This package provides Haskell bindings to that runtime. @package pgf2 @version 1.2.0 -- | This module is an Application Programming Interface to load and -- interpret grammars compiled in the Portable Grammar Format (PGF). The -- PGF format is produced as the final output from the GF compiler. The -- API is meant to be used for embedding GF grammars in Haskell programs module PGF2 -- | An abstract data type representing multilingual grammar in Portable -- Grammar Format. data PGF -- | Reads file in Portable Grammar Format and produces PGF -- structure. The file is usually produced with: -- --
-- $ gf -make <grammar file name> --readPGF :: FilePath -> IO PGF showPGF :: PGF -> String -- | An data type that represents identifiers for functions and categories -- in PGF. type CId = String type AbsName = CId Name of abstract syntax -- | The abstract language name is the name of the top-level abstract -- module abstractName :: PGF -> AbsName type Cat = CId Name of syntactic category -- | List of all categories defined in the grammar. The categories are -- defined in the abstract syntax with the 'cat' keyword. categories :: PGF -> [Cat] categoryContext :: PGF -> Cat -> [Hypo] type Fun = CId Name of function -- | List of all functions defined in the abstract syntax functions :: PGF -> [Fun] -- | List of all functions defined for a category functionsByCat :: PGF -> Cat -> [Fun] -- | The type of a function functionType :: PGF -> Fun -> Maybe Type -- | The type of a function functionIsConstructor :: PGF -> Fun -> Bool -- | Returns True if there is a linearization defined for that function in -- that language hasLinearization :: Concr -> Fun -> Bool data Expr -- | renders an expression as a String. The list of identifiers is -- the list of all free variables in the expression in order reverse to -- the order of binding. showExpr :: [CId] -> Expr -> String -- | parses a String as an expression readExpr :: String -> Maybe Expr pExpr :: ReadS Expr -- | Constructs an expression by lambda abstraction mkAbs :: BindType -> CId -> Expr -> Expr -- | Decomposes an expression into an abstraction and a body unAbs :: Expr -> Maybe (BindType, CId, Expr) -- | Constructs an expression by applying a function to a list of -- expressions mkApp :: Fun -> [Expr] -> Expr -- | Decomposes an expression into an application of a function unApp :: Expr -> Maybe (Fun, [Expr]) -- | Constructs an expression from a string literal mkStr :: String -> Expr -- | Decomposes an expression into a string literal unStr :: Expr -> Maybe String -- | Constructs an expression from an integer literal mkInt :: Int -> Expr -- | Decomposes an expression into an integer literal unInt :: Expr -> Maybe Int -- | Constructs an expression from a real number mkFloat :: Double -> Expr -- | Decomposes an expression into a real number literal unFloat :: Expr -> Maybe Double -- | Constructs a meta variable as an expression mkMeta :: Int -> Expr -- | Decomposes an expression into a meta variable unMeta :: Expr -> Maybe Int -- | this functions is only for backward compatibility with the old Haskell -- runtime mkCId :: () => p -> p exprHash :: Int32 -> Expr -> Int32 exprSize :: Expr -> Int exprFunctions :: Expr -> [Fun] exprSubstitute :: Expr -> [Expr] -> Expr treeProbability :: PGF -> Expr -> Float data Type -- | Hypo represents a hypothesis in a type i.e. in the type A -> -- B, A is the hypothesis type Hypo = (BindType, CId, Type) data BindType Explicit :: BindType Implicit :: BindType -- | The start category is defined in the grammar with the 'startcat' flag. -- This is usually the sentence category but it is not necessary. Despite -- that there is a start category defined you can parse with any -- category. The start category definition is just for convenience. startCat :: PGF -> Type -- | parses a String as a type readType :: String -> Maybe Type -- | renders a type as a String. The list of identifiers is the list -- of all free variables in the type in order reverse to the order of -- binding. showType :: [CId] -> Type -> String -- | renders a type as a String. The list of identifiers is the list -- of all free variables in the type in order reverse to the order of -- binding. showContext :: [CId] -> [Hypo] -> String -- | creates a type from a list of hypothesises, a category and a list of -- arguments for the category. The operation mkType [h_1,...,h_n] C -- [e_1,...,e_m] will create h_1 -> ... -> h_n -> C e_1 -- ... e_m mkType :: [Hypo] -> CId -> [Expr] -> Type -- | Decomposes a type into a list of hypothesises, a category and a list -- of arguments for the category. unType :: Type -> ([Hypo], CId, [Expr]) -- | Checks an expression against a specified type. checkExpr :: PGF -> Expr -> Type -> Either String Expr -- | Tries to infer the type of an expression. Note that even if the -- expression is type correct it is not always possible to infer its type -- in the GF type system. In this case the function returns an error. inferExpr :: PGF -> Expr -> Either String (Expr, Type) -- | Check whether a type is consistent with the abstract syntax of the -- grammar. checkType :: PGF -> Type -> Either String Type compute :: PGF -> Expr -> Expr type ConcName = CId Name of concrete syntax data Concr -- | List of all languages available in the grammar. languages :: PGF -> Map ConcName Concr concreteName :: Concr -> ConcName languageCode :: Concr -> String -- | Linearizes an expression as a string in the language linearize :: Concr -> Expr -> String -- | Generates all possible linearizations of an expression linearizeAll :: Concr -> Expr -> [String] -- | Generates a table of linearizations for an expression tabularLinearize :: Concr -> Expr -> [(String, String)] -- | Generates a table of linearizations for an expression tabularLinearizeAll :: Concr -> Expr -> [[(String, String)]] bracketedLinearize :: Concr -> Expr -> [BracketedString] bracketedLinearizeAll :: Concr -> Expr -> [[BracketedString]] type FId = Int -- | BracketedString represents a sentence that is linearized as usual but -- we also want to retain the 'brackets' that mark the beginning -- and the end of each constituent. data BracketedString -- | this is the leaf i.e. a single token Leaf :: String -> BracketedString -- | the surrounding tokens must be bound together BIND :: BracketedString -- | this is a bracket. The CId is the category of the phrase. The -- FId is an unique identifier for every phrase in the sentence. -- For context-free grammars i.e. without discontinuous constituents this -- identifier is also unique for every bracket. When there are -- discontinuous phrases then the identifiers are unique for every phrase -- but not for every bracket since the bracket represents a constituent. -- The different constituents could still be distinguished by using the -- analysis string. If the grammar is reduplicating then the constituent -- indices will be the same for all brackets that represents the same -- constituent. The second CId is the name of the abstract -- function that generated this phrase. Bracket :: CId -> {-# UNPACK #-} !FId -> String -> CId -> [BracketedString] -> BracketedString -- | Renders the bracketed string as a string where the brackets are shown -- as (S ...) where S is the category. showBracketedString :: BracketedString -> String -- | Extracts the sequence of tokens from the bracketed string flattenBracketedString :: BracketedString -> [String] printName :: Concr -> Fun -> Maybe String categoryFields :: Concr -> Cat -> Maybe [String] alignWords :: Concr -> Expr -> [(String, [Int])] -- | This data type encodes the different outcomes which you could get from -- the parser. data ParseOutput a -- | The integer is the position in number of unicode characters where the -- parser failed. The string is the token where the parser have failed. ParseFailed :: Int -> String -> ParseOutput a -- | If the parsing and the type checking are successful we get the -- abstract syntax trees as either a list or a chart. ParseOk :: a -> ParseOutput a -- | The sentence is not complete. ParseIncomplete :: ParseOutput a parse :: Concr -> Type -> String -> ParseOutput [(Expr, Float)] parseWithHeuristics :: Concr -> Type -> String -> Double -> [(Cat, String -> Int -> Maybe (Expr, Float, Int))] -> ParseOutput [(Expr, Float)] parseToChart :: Concr -> Type -> String -> Double -> [(Cat, String -> Int -> Maybe (Expr, Float, Int))] -> Int -> ParseOutput ([FId], Map FId ([(Int, Int, String)], [(Expr, [PArg], Float)], Cat)) data PArg PArg :: [FId] -> {-# UNPACK #-} !FId -> PArg lookupSentence :: Concr -> Type -> String -> [(Expr, Float)] -- | Generates an exhaustive possibly infinite list of all abstract syntax -- expressions of the given type. The expressions are ordered by their -- probability. generateAll :: PGF -> Type -> [(Expr, Float)] -- | This triple is returned by all functions that deal with the grammar's -- lexicon. Its first element is the name of an abstract lexical function -- which can produce a given word or a multiword expression (i.e. this is -- the lemma). After that follows a string which describes the particular -- inflection form. -- -- The last element is a logarithm from the the probability of the -- function. The probability is not conditionalized on the category of -- the function. This makes it possible to compare the likelihood of two -- functions even if they have different types. type MorphoAnalysis = (Fun, String, Float) -- | lookupMorpho takes a string which must be a single word or a -- multiword expression. It then computes the list of all possible -- morphological analyses. lookupMorpho :: Concr -> String -> [MorphoAnalysis] -- | lookupCohorts takes an arbitrary string an produces a list of -- all places where lexical items from the grammar have been identified -- (i.e. cohorts). The list consists of triples of the format -- (start,ans,end), where start-end identifies the span -- in the text and ans is the list of possible morphological -- analyses similar to lookupMorpho. -- -- The list is sorted first by the start position and after than -- by the end position. This can be used for instance if you -- want to filter only the longest matches. lookupCohorts :: Concr -> String -> [(Int, String, [MorphoAnalysis], Int)] fullFormLexicon :: Concr -> [(String, [MorphoAnalysis])] filterBest :: [(Int, String, [MorphoAnalysis], Int)] -> [(Int, String, [MorphoAnalysis], Int)] filterLongest :: [(Int, String, [MorphoAnalysis], Int)] -> [(Int, String, [MorphoAnalysis], Int)] data GraphvizOptions GraphvizOptions :: Bool -> Bool -> Bool -> Bool -> String -> String -> String -> String -> String -> String -> GraphvizOptions [noLeaves] :: GraphvizOptions -> Bool [noFun] :: GraphvizOptions -> Bool [noCat] :: GraphvizOptions -> Bool [noDep] :: GraphvizOptions -> Bool [nodeFont] :: GraphvizOptions -> String [leafFont] :: GraphvizOptions -> String [nodeColor] :: GraphvizOptions -> String [leafColor] :: GraphvizOptions -> String [nodeEdgeStyle] :: GraphvizOptions -> String [leafEdgeStyle] :: GraphvizOptions -> String graphvizDefaults :: GraphvizOptions -- | Renders an abstract syntax tree in a Graphviz format. graphvizAbstractTree :: PGF -> GraphvizOptions -> Expr -> String graphvizParseTree :: Concr -> GraphvizOptions -> Expr -> String graphvizWordAlignment :: [Concr] -> GraphvizOptions -> Expr -> String newtype PGFError PGFError :: String -> PGFError type LiteralCallback = PGF -> (ConcName, Concr) -> String -> String -> Int -> Maybe (Expr, Float, Int) -- | Callbacks for the App grammar literalCallbacks :: [(AbsName, [(Cat, LiteralCallback)])] instance GHC.Show.Show PGF2.PGFError instance GHC.Exception.Exception PGF2.PGFError module PGF2.Internal type FId = Int isPredefFId :: FId -> Bool type FunId = Int type Token = String data Production PApply :: {-# UNPACK #-} !FunId -> [PArg] -> Production PCoerce :: {-# UNPACK #-} !FId -> Production data PArg PArg :: [FId] -> {-# UNPACK #-} !FId -> PArg data Symbol SymCat :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !LIndex -> Symbol SymLit :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !LIndex -> Symbol SymVar :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> Symbol SymKS :: Token -> Symbol SymKP :: [Symbol] -> [([Symbol], [String])] -> Symbol SymBIND :: Symbol SymNE :: Symbol SymSOFT_BIND :: Symbol SymSOFT_SPACE :: Symbol SymCAPIT :: Symbol SymALL_CAPIT :: Symbol data Literal -- | a string constant LStr :: String -> Literal -- | an integer constant LInt :: Int -> Literal -- | a floating point constant LFlt :: Double -> Literal globalFlags :: PGF -> [(String, Literal)] abstrFlags :: PGF -> [(String, Literal)] concrFlags :: Concr -> [(String, Literal)] concrTotalCats :: Concr -> FId concrCategories :: Concr -> [(Cat, FId, FId, [String])] concrProductions :: Concr -> FId -> [Production] concrTotalFuns :: Concr -> FunId concrFunction :: Concr -> FunId -> (Fun, [SeqId]) concrTotalSeqs :: Concr -> SeqId concrSequence :: Concr -> SeqId -> [Symbol] build :: (forall s. (?builder :: Builder s) => B s a) -> a eAbs :: (?builder :: Builder s) => BindType -> String -> B s Expr -> B s Expr eApp :: (?builder :: Builder s) => B s Expr -> B s Expr -> B s Expr eMeta :: (?builder :: Builder s) => Int -> B s Expr eFun :: (?builder :: Builder s) => Fun -> B s Expr eVar :: (?builder :: Builder s) => Int -> B s Expr eTyped :: (?builder :: Builder s) => B s Expr -> B s Type -> B s Expr eImplArg :: (?builder :: Builder s) => B s Expr -> B s Expr dTyp :: (?builder :: Builder s) => [B s Hypo] -> Cat -> [B s Expr] -> B s Type hypo :: BindType -> CId -> B s Type -> (B s Hypo) data AbstrInfo newAbstr :: (?builder :: Builder s) => [(String, Literal)] -> [(Cat, [B s Hypo], Float)] -> [(Fun, B s Type, Int, Float)] -> AbstrInfo data ConcrInfo newConcr :: (?builder :: Builder s) => AbstrInfo -> [(String, Literal)] -> [(String, String)] -> [(FId, [FunId])] -> [(FId, [FunId])] -> [(FId, [Production])] -> [(Fun, [SeqId])] -> [[Symbol]] -> [(Cat, FId, FId, [String])] -> FId -> ConcrInfo newPGF :: (?builder :: Builder s) => [(String, Literal)] -> AbsName -> AbstrInfo -> [(ConcName, ConcrInfo)] -> B s PGF -- | An abstract data type representing multilingual grammar in Portable -- Grammar Format. data PGF PGF :: Ptr PgfPGF -> Touch -> PGF [pgf] :: PGF -> Ptr PgfPGF [touchPGF] :: PGF -> Touch data Concr Concr :: Ptr PgfConcr -> Touch -> Concr [concr] :: Concr -> Ptr PgfConcr [touchConcr] :: Concr -> Touch writePGF :: FilePath -> PGF -> IO () instance GHC.Show.Show PGF2.Internal.Literal instance GHC.Classes.Ord PGF2.Internal.Literal instance GHC.Classes.Eq PGF2.Internal.Literal instance GHC.Show.Show PGF2.Internal.Production instance GHC.Classes.Ord PGF2.Internal.Production instance GHC.Classes.Eq PGF2.Internal.Production instance GHC.Show.Show PGF2.Internal.Symbol instance GHC.Classes.Ord PGF2.Internal.Symbol instance GHC.Classes.Eq PGF2.Internal.Symbol