cleaned up and documented PGF API

This commit is contained in:
krasimir
2008-05-30 13:07:11 +00:00
parent 56c34b5dd8
commit 3f3188a430
9 changed files with 153 additions and 71 deletions

View File

@@ -2,13 +2,17 @@ module PGF.CId (CId(..), wildCId, mkCId, prCId) where
import Data.ByteString.Char8 as BS
-- | An abstract data type that represents
-- function identifier in PGF.
newtype CId = CId BS.ByteString deriving (Eq,Ord,Show)
wildCId :: CId
wildCId = CId (BS.singleton '_')
-- | Creates a new identifier from 'String'
mkCId :: String -> CId
mkCId s = CId (BS.pack s)
-- | Renders the identifier as 'String'
prCId :: CId -> String
prCId (CId x) = BS.unpack x

View File

@@ -10,6 +10,8 @@ import Data.Array
-- internal datatypes for PGF
-- | An abstract data type representing multilingual grammar
-- in Portable Grammar Format.
data PGF = PGF {
absname :: CId ,
cncnames :: [CId] ,

View File

@@ -28,16 +28,17 @@ import qualified Data.Map as Map
-- main parsing function
parseFCF ::
String -> -- ^ parsing strategy
ParserInfo -> -- ^ compiled grammar (fcfg)
CId -> -- ^ starting category
[String] -> -- ^ input tokens
Err [Exp] -- ^ resulting GF terms
parseFCF :: String -- ^ parsing strategy
-> ParserInfo -- ^ compiled grammar (fcfg)
-> CId -- ^ starting category
-> [String] -- ^ input tokens
-> Err [Exp] -- ^ resulting GF terms
parseFCF strategy pinfo startCat inString =
do let inTokens = input inString
startCats <- Map.lookup startCat (startupCats pinfo)
fcfParser <- {- trace lctree $ -} parseFCF strategy
startCats <- case Map.lookup startCat (startupCats pinfo) of
Just cats -> return cats
Nothing -> fail $ "Unknown startup category: " ++ prCId startCat
fcfParser <- parseFCF strategy
let chart = fcfParser pinfo startCats inTokens
(i,j) = inputBounds inTokens
finalEdges = [makeFinalEdge cat i j | cat <- startCats]
@@ -46,6 +47,6 @@ parseFCF strategy pinfo startCat inString =
return $ nubsort $ filteredForests >>= forest2exps
where
parseFCF :: String -> Err (FCFParser)
parseFCF "bottomup" = Ok $ parse "b"
parseFCF "topdown" = Ok $ parse "t"
parseFCF strat = Bad $ "FCFG parsing strategy not defined: " ++ strat
parseFCF "bottomup" = return $ parse "b"
parseFCF "topdown" = return $ parse "t"
parseFCF strat = fail $ "FCFG parsing strategy not defined: " ++ strat

View File

@@ -181,7 +181,6 @@ fromExp e = case e of
EMeta _ -> AMet ----
EEq eqs ->
App "Eq" [App "E" (map fromExp (v:ps)) | Equ ps v <- eqs]
_ -> error $ "exp " ++ show e
fromTerm :: Term -> RExp
fromTerm e = case e of