mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
Manage to get completion working in PGF2
This commit is contained in:
@@ -972,13 +972,13 @@ parseWithOracle lang cat sent (predict,complete,literal) =
|
|||||||
return ep
|
return ep
|
||||||
Nothing -> do return nullPtr
|
Nothing -> do return nullPtr
|
||||||
|
|
||||||
|
-- | Returns possible completions of the current partial input.
|
||||||
complete :: Concr -- ^ the language with which we parse
|
complete :: Concr -- ^ the language with which we parse
|
||||||
-> Type -- ^ the start category
|
-> Type -- ^ the start category
|
||||||
-> String -- ^ the input sentence
|
-> String -- ^ the input sentence (excluding token being completed)
|
||||||
-> String -- ^ prefix (?)
|
-> String -- ^ prefix (partial token being completed)
|
||||||
-> Maybe Int -- ^ maximum number of results
|
-> ParseOutput [(String, CId, CId, Float)] -- ^ (token, category, function, probability)
|
||||||
-> ParseOutput [String]
|
complete lang (Type ctype _) sent pfx =
|
||||||
complete lang (Type ctype _) sent pfx mn =
|
|
||||||
unsafePerformIO $ do
|
unsafePerformIO $ do
|
||||||
parsePl <- gu_new_pool
|
parsePl <- gu_new_pool
|
||||||
exn <- gu_new_exn parsePl
|
exn <- gu_new_exn parsePl
|
||||||
@@ -1013,7 +1013,7 @@ complete lang (Type ctype _) sent pfx mn =
|
|||||||
fpl <- newForeignPtr gu_pool_finalizer parsePl
|
fpl <- newForeignPtr gu_pool_finalizer parsePl
|
||||||
ParseOk <$> fromCompletions enum fpl
|
ParseOk <$> fromCompletions enum fpl
|
||||||
where
|
where
|
||||||
fromCompletions :: Ptr GuEnum -> ForeignPtr GuPool -> IO [String]
|
fromCompletions :: Ptr GuEnum -> ForeignPtr GuPool -> IO [(String, CId, CId, Float)]
|
||||||
fromCompletions enum fpl =
|
fromCompletions enum fpl =
|
||||||
withGuPool $ \tmpPl -> do
|
withGuPool $ \tmpPl -> do
|
||||||
cmpEntry <- alloca $ \ptr ->
|
cmpEntry <- alloca $ \ptr ->
|
||||||
@@ -1026,11 +1026,12 @@ complete lang (Type ctype _) sent pfx mn =
|
|||||||
touchConcr lang
|
touchConcr lang
|
||||||
return []
|
return []
|
||||||
else do
|
else do
|
||||||
(sb,out) <- newOut tmpPl
|
tok <- peekUtf8CString =<< (#peek PgfTokenProb, tok) cmpEntry
|
||||||
cstr <- gu_string_buf_freeze sb tmpPl
|
cat <- peekUtf8CString =<< (#peek PgfTokenProb, cat) cmpEntry
|
||||||
tok <- peekUtf8CString cstr
|
fun <- peekUtf8CString =<< (#peek PgfTokenProb, fun) cmpEntry
|
||||||
|
prob <- (#peek PgfTokenProb, prob) cmpEntry
|
||||||
toks <- unsafeInterleaveIO (fromCompletions enum fpl)
|
toks <- unsafeInterleaveIO (fromCompletions enum fpl)
|
||||||
return (tok : toks)
|
return ((tok, cat, fun, prob) : toks)
|
||||||
|
|
||||||
-- | 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
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ data PgfApplication
|
|||||||
data PgfConcr
|
data PgfConcr
|
||||||
type PgfExpr = Ptr ()
|
type PgfExpr = Ptr ()
|
||||||
data PgfExprProb
|
data PgfExprProb
|
||||||
|
data PgfTokenProb
|
||||||
data PgfExprParser
|
data PgfExprParser
|
||||||
data PgfFullFormEntry
|
data PgfFullFormEntry
|
||||||
data PgfMorphoCallback
|
data PgfMorphoCallback
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
import PGF2
|
|
||||||
import qualified Data.Char as C
|
|
||||||
import qualified Data.List as L
|
|
||||||
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)
|
|
||||||
loop = do
|
|
||||||
putStr "> "
|
|
||||||
input <- getLine
|
|
||||||
let
|
|
||||||
(sent,pfx) =
|
|
||||||
if C.isSpace (last input)
|
|
||||||
then (input, "")
|
|
||||||
else let toks = words input in (unwords (init toks), last toks)
|
|
||||||
let pr = complete concr (startCat pgf) sent pfx Nothing
|
|
||||||
case pr of
|
|
||||||
ParseOk x -> print x
|
|
||||||
ParseFailed x s -> putStrLn $ "parse failed at " ++ show x ++ " " ++ s
|
|
||||||
ParseIncomplete -> putStrLn "input incomplete"
|
|
||||||
loop
|
|
||||||
loop
|
|
||||||
Reference in New Issue
Block a user