forked from GitHub/gf-core
First attempt at adding support for complete in PGF2 (gives segmentation faults)
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
|
## 1.3.0
|
||||||
|
|
||||||
|
- Add completion support.
|
||||||
|
|
||||||
## 1.2.1
|
## 1.2.1
|
||||||
|
|
||||||
- Remove deprecated pgf_print_expr_tuple
|
- Remove deprecated `pgf_print_expr_tuple`.
|
||||||
- Added an API for cloning expressions/types/literals
|
- Added an API for cloning expressions/types/literals.
|
||||||
|
|
||||||
## 1.2.0
|
## 1.2.0
|
||||||
|
|
||||||
|
|||||||
@@ -43,32 +43,28 @@ module PGF2 (-- * PGF
|
|||||||
mkCId,
|
mkCId,
|
||||||
exprHash, exprSize, exprFunctions, exprSubstitute,
|
exprHash, exprSize, exprFunctions, exprSubstitute,
|
||||||
treeProbability,
|
treeProbability,
|
||||||
|
|
||||||
-- ** Types
|
-- ** Types
|
||||||
Type, Hypo, BindType(..), startCat,
|
Type, Hypo, BindType(..), startCat,
|
||||||
readType, showType, showContext,
|
readType, showType, showContext,
|
||||||
mkType, unType,
|
mkType, unType,
|
||||||
|
|
||||||
-- ** Type checking
|
-- ** Type checking
|
||||||
-- | Dynamically-built expressions should always be type-checked before using in other functions,
|
-- | Dynamically-built expressions should always be type-checked before using in other functions,
|
||||||
-- as the exceptions thrown by using invalid expressions may not catchable.
|
-- as the exceptions thrown by using invalid expressions may not catchable.
|
||||||
checkExpr, inferExpr, checkType,
|
checkExpr, inferExpr, checkType,
|
||||||
|
|
||||||
-- ** Computing
|
-- ** Computing
|
||||||
compute,
|
compute,
|
||||||
|
|
||||||
-- * Concrete syntax
|
-- * Concrete syntax
|
||||||
ConcName,Concr,languages,concreteName,languageCode,
|
ConcName,Concr,languages,concreteName,languageCode,
|
||||||
|
|
||||||
-- ** Linearization
|
-- ** Linearization
|
||||||
linearize,linearizeAll,tabularLinearize,tabularLinearizeAll,bracketedLinearize,bracketedLinearizeAll,
|
linearize,linearizeAll,tabularLinearize,tabularLinearizeAll,bracketedLinearize,bracketedLinearizeAll,
|
||||||
FId, BracketedString(..), showBracketedString, flattenBracketedString,
|
FId, BracketedString(..), showBracketedString, flattenBracketedString,
|
||||||
printName, categoryFields,
|
printName, categoryFields,
|
||||||
|
|
||||||
alignWords,
|
alignWords,
|
||||||
-- ** Parsing
|
-- ** Parsing
|
||||||
ParseOutput(..), parse, parseWithHeuristics,
|
ParseOutput(..), parse, parseWithHeuristics,
|
||||||
parseToChart, PArg(..),
|
parseToChart, PArg(..),
|
||||||
|
complete,
|
||||||
-- ** Sentence Lookup
|
-- ** Sentence Lookup
|
||||||
lookupSentence,
|
lookupSentence,
|
||||||
-- ** Generation
|
-- ** Generation
|
||||||
@@ -976,6 +972,36 @@ parseWithOracle lang cat sent (predict,complete,literal) =
|
|||||||
return ep
|
return ep
|
||||||
Nothing -> do return nullPtr
|
Nothing -> do return nullPtr
|
||||||
|
|
||||||
|
complete :: Concr -- ^ the language with which we parse
|
||||||
|
-> Type -- ^ the start category
|
||||||
|
-> String -- ^ the input sentence
|
||||||
|
-> String -- ^ prefix (?)
|
||||||
|
-> Maybe Int -- ^ maximum number of results
|
||||||
|
-> ParseOutput [(Expr,Float)]
|
||||||
|
complete lang (Type ctype _) sent pfx mn =
|
||||||
|
unsafePerformIO $ do
|
||||||
|
parsePl <- gu_new_pool
|
||||||
|
exprPl <- gu_new_pool
|
||||||
|
exn <- gu_new_exn parsePl
|
||||||
|
|
||||||
|
sent <- newUtf8CString sent parsePl
|
||||||
|
pfx <- newUtf8CString pfx parsePl
|
||||||
|
|
||||||
|
enum <- pgf_complete (concr lang) ctype sent pfx exn parsePl
|
||||||
|
failed <- gu_exn_is_raised exn
|
||||||
|
if failed
|
||||||
|
then do
|
||||||
|
is_parse_error <- gu_exn_caught exn gu_exn_type_PgfParseError
|
||||||
|
if is_parse_error
|
||||||
|
then return (ParseFailed 0 "")
|
||||||
|
else throwIO (PGFError "Some other error")
|
||||||
|
-- TODO cleanup!!!
|
||||||
|
else do
|
||||||
|
parseFPl <- newForeignPtr gu_pool_finalizer parsePl
|
||||||
|
exprFPl <- newForeignPtr gu_pool_finalizer exprPl
|
||||||
|
exprs <- fromPgfExprEnum enum parseFPl (touchConcr lang >> touchForeignPtr exprFPl)
|
||||||
|
return (ParseOk exprs)
|
||||||
|
|
||||||
-- | Returns True if there is a linearization defined for that function in that language
|
-- | Returns True if there is a linearization defined for that function in that language
|
||||||
hasLinearization :: Concr -> Fun -> Bool
|
hasLinearization :: Concr -> Fun -> Bool
|
||||||
hasLinearization lang id = unsafePerformIO $
|
hasLinearization lang id = unsafePerformIO $
|
||||||
|
|||||||
@@ -422,6 +422,9 @@ foreign import ccall
|
|||||||
foreign import ccall "pgf/pgf.h pgf_parse_with_oracle"
|
foreign import ccall "pgf/pgf.h pgf_parse_with_oracle"
|
||||||
pgf_parse_with_oracle :: Ptr PgfConcr -> CString -> CString -> Ptr PgfOracleCallback -> Ptr GuExn -> Ptr GuPool -> Ptr GuPool -> IO (Ptr GuEnum)
|
pgf_parse_with_oracle :: Ptr PgfConcr -> CString -> CString -> Ptr PgfOracleCallback -> Ptr GuExn -> Ptr GuPool -> Ptr GuPool -> IO (Ptr GuEnum)
|
||||||
|
|
||||||
|
foreign import ccall "pgf/pgf.h pgf_complete"
|
||||||
|
pgf_complete :: Ptr PgfConcr -> PgfType -> CString -> CString -> Ptr GuExn -> Ptr GuPool -> IO (Ptr GuEnum)
|
||||||
|
|
||||||
foreign import ccall "pgf/pgf.h pgf_lookup_morpho"
|
foreign import ccall "pgf/pgf.h pgf_lookup_morpho"
|
||||||
pgf_lookup_morpho :: Ptr PgfConcr -> CString -> Ptr PgfMorphoCallback -> Ptr GuExn -> IO ()
|
pgf_lookup_morpho :: Ptr PgfConcr -> CString -> Ptr PgfMorphoCallback -> Ptr GuExn -> IO ()
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: pgf2
|
name: pgf2
|
||||||
version: 1.2.1
|
version: 1.3.0
|
||||||
synopsis: Bindings to the C version of the PGF runtime
|
synopsis: Bindings to the C version of the PGF runtime
|
||||||
description:
|
description:
|
||||||
GF, Grammatical Framework, is a programming language for multilingual grammar applications.
|
GF, Grammatical Framework, is a programming language for multilingual grammar applications.
|
||||||
|
|||||||
12
src/runtime/haskell-bind/test.hs
Normal file
12
src/runtime/haskell-bind/test.hs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import PGF2
|
||||||
|
import qualified Data.Map as M
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
pgf <- readPGF "/Users/john/repositories/GF/contrib/foods/Foods.pgf"
|
||||||
|
let Just concr = M.lookup "FoodsEng" (languages pgf)
|
||||||
|
let pr = complete concr (startCat pgf) "this" "wi" Nothing
|
||||||
|
case pr of
|
||||||
|
ParseOk x -> print (head x)
|
||||||
|
ParseFailed _ _ -> putStrLn "parse failed"
|
||||||
|
ParseIncomplete -> putStrLn "input incomplete"
|
||||||
Reference in New Issue
Block a user