forked from GitHub/gf-core
an API to access the names of all fields withing a category
This commit is contained in:
@@ -163,6 +163,20 @@ pgf_category_prob(PgfPGF* pgf, PgfCId catname)
|
|||||||
return abscat->prob;
|
return abscat->prob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGF_API GuString*
|
||||||
|
pgf_category_fields(PgfConcr* concr, PgfCId catname, size_t *n_lins)
|
||||||
|
{
|
||||||
|
PgfCncCat* cnccat =
|
||||||
|
gu_map_get(concr->cnccats, catname, PgfCncCat*);
|
||||||
|
if (!cnccat) {
|
||||||
|
*n_lins = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*n_lins = cnccat->n_lins;
|
||||||
|
return &cnccat->labels;
|
||||||
|
}
|
||||||
|
|
||||||
PGF_API GuString
|
PGF_API GuString
|
||||||
pgf_language_code(PgfConcr* concr)
|
pgf_language_code(PgfConcr* concr)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -95,6 +95,9 @@ pgf_category_context(PgfPGF *gr, PgfCId catname);
|
|||||||
PGF_API_DECL prob_t
|
PGF_API_DECL prob_t
|
||||||
pgf_category_prob(PgfPGF* pgf, PgfCId catname);
|
pgf_category_prob(PgfPGF* pgf, PgfCId catname);
|
||||||
|
|
||||||
|
PGF_API GuString*
|
||||||
|
pgf_category_fields(PgfConcr* concr, PgfCId catname, size_t *n_lins);
|
||||||
|
|
||||||
PGF_API_DECL void
|
PGF_API_DECL void
|
||||||
pgf_iter_functions(PgfPGF* pgf, GuMapItor* itor, GuExn* err);
|
pgf_iter_functions(PgfPGF* pgf, GuMapItor* itor, GuExn* err);
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ module PGF2 (-- * PGF
|
|||||||
-- ** Linearization
|
-- ** Linearization
|
||||||
linearize,linearizeAll,tabularLinearize,tabularLinearizeAll,bracketedLinearize,bracketedLinearizeAll,
|
linearize,linearizeAll,tabularLinearize,tabularLinearizeAll,bracketedLinearize,bracketedLinearizeAll,
|
||||||
FId, BracketedString(..), showBracketedString, flattenBracketedString,
|
FId, BracketedString(..), showBracketedString, flattenBracketedString,
|
||||||
printName,
|
printName, categoryFields,
|
||||||
|
|
||||||
alignWords,
|
alignWords,
|
||||||
-- ** Parsing
|
-- ** Parsing
|
||||||
@@ -988,6 +988,7 @@ tabularLinearizeAll lang e = unsafePerformIO $
|
|||||||
exn <- gu_new_exn tmpPl
|
exn <- gu_new_exn tmpPl
|
||||||
cts <- pgf_lzr_concretize (concr lang) (expr e) exn tmpPl
|
cts <- pgf_lzr_concretize (concr lang) (expr e) exn tmpPl
|
||||||
failed <- gu_exn_is_raised exn
|
failed <- gu_exn_is_raised exn
|
||||||
|
touchConcr lang
|
||||||
if failed
|
if failed
|
||||||
then throwExn exn
|
then throwExn exn
|
||||||
else collect cts exn tmpPl
|
else collect cts exn tmpPl
|
||||||
@@ -1033,6 +1034,28 @@ tabularLinearizeAll lang e = unsafePerformIO $
|
|||||||
throwIO (PGFError msg)
|
throwIO (PGFError msg)
|
||||||
else do throwIO (PGFError "The abstract tree cannot be linearized")
|
else do throwIO (PGFError "The abstract tree cannot be linearized")
|
||||||
|
|
||||||
|
categoryFields :: Concr -> Cat -> Maybe [String]
|
||||||
|
categoryFields lang cat =
|
||||||
|
unsafePerformIO $ do
|
||||||
|
withGuPool $ \tmpPl -> do
|
||||||
|
p_n_lins <- gu_malloc tmpPl (#size size_t)
|
||||||
|
c_cat <- newUtf8CString cat tmpPl
|
||||||
|
c_fields <- pgf_category_fields (concr lang) c_cat p_n_lins
|
||||||
|
if c_fields == nullPtr
|
||||||
|
then do touchConcr lang
|
||||||
|
return Nothing
|
||||||
|
else do len <- peek p_n_lins
|
||||||
|
fs <- peekFields len c_fields
|
||||||
|
touchConcr lang
|
||||||
|
return (Just fs)
|
||||||
|
where
|
||||||
|
peekFields 0 ptr = return []
|
||||||
|
peekFields len ptr = do
|
||||||
|
f <- peek ptr >>= peekUtf8CString
|
||||||
|
fs <- peekFields (len-1) (ptr `plusPtr` (#size GuString))
|
||||||
|
return (f:fs)
|
||||||
|
|
||||||
|
|
||||||
-- | BracketedString represents a sentence that is linearized
|
-- | BracketedString represents a sentence that is linearized
|
||||||
-- as usual but we also want to retain the ''brackets'' that
|
-- as usual but we also want to retain the ''brackets'' that
|
||||||
-- mark the beginning and the end of each constituent.
|
-- mark the beginning and the end of each constituent.
|
||||||
|
|||||||
@@ -313,6 +313,9 @@ foreign import ccall "pgf/pgf.h pgf_category_context"
|
|||||||
foreign import ccall "pgf/pgf.h pgf_category_prob"
|
foreign import ccall "pgf/pgf.h pgf_category_prob"
|
||||||
pgf_category_prob :: Ptr PgfPGF -> CString -> IO (#type prob_t)
|
pgf_category_prob :: Ptr PgfPGF -> CString -> IO (#type prob_t)
|
||||||
|
|
||||||
|
foreign import ccall "pgf/pgf.h pgf_category_fields"
|
||||||
|
pgf_category_fields :: Ptr PgfConcr -> CString -> Ptr CSize -> IO (Ptr CString)
|
||||||
|
|
||||||
foreign import ccall "pgf/pgf.h pgf_iter_functions"
|
foreign import ccall "pgf/pgf.h pgf_iter_functions"
|
||||||
pgf_iter_functions :: Ptr PgfPGF -> Ptr GuMapItor -> Ptr GuExn -> IO ()
|
pgf_iter_functions :: Ptr PgfPGF -> Ptr GuMapItor -> Ptr GuExn -> IO ()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user