From ca891c912b9f4ce2ddec28219f2f8e44d08f82bd Mon Sep 17 00:00:00 2001 From: krasimir Date: Fri, 12 May 2017 09:32:25 +0000 Subject: a binding to the sentence lookup from Haskell --- src/runtime/haskell-bind/PGF2.hsc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/runtime/haskell-bind/PGF2.hsc') diff --git a/src/runtime/haskell-bind/PGF2.hsc b/src/runtime/haskell-bind/PGF2.hsc index b022d06fe..e50fdd4b1 100644 --- a/src/runtime/haskell-bind/PGF2.hsc +++ b/src/runtime/haskell-bind/PGF2.hsc @@ -57,11 +57,13 @@ module PGF2 (-- * PGF alignWords, -- ** Parsing parse, parseWithHeuristics, - -- ** Generation + -- ** Sentence Lookup + lookupSentence, + -- ** Generation generateAll, -- ** Morphological Analysis MorphoAnalysis, lookupMorpho, fullFormLexicon, - -- ** Visualizations + -- ** Visualizations graphvizAbstractTree,graphvizParseTree, -- * Exceptions @@ -470,6 +472,22 @@ mkCallbacksMap concr callbacks pool = do predict_callback _ _ _ = return nullPtr +lookupSentence :: Concr -- ^ the language with which we parse + -> Type -- ^ the start category + -> String -- ^ the input sentence + -> [(Expr,Float)] +lookupSentence lang (Type ctype _) sent = + unsafePerformIO $ + do exprPl <- gu_new_pool + parsePl <- gu_new_pool + sent <- newUtf8CString sent parsePl + enum <- pgf_lookup_sentence (concr lang) ctype sent parsePl exprPl + parseFPl <- newForeignPtr gu_pool_finalizer parsePl + exprFPl <- newForeignPtr gu_pool_finalizer exprPl + exprs <- fromPgfExprEnum enum parseFPl (touchConcr lang >> touchForeignPtr exprFPl) + return exprs + + -- | The oracle is a triple of functions. -- The first two take a category name and a linearization field name -- and they should return True/False when the corresponding -- cgit v1.2.3