mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
fixes in the C and Python API to make them closer to the Haskell API
This commit is contained in:
@@ -220,7 +220,7 @@ static PgfLinFuncs pgf_bracket_lin_funcs = {
|
||||
.end_phrase = pgf_bracket_lzn_end_phrase
|
||||
};
|
||||
|
||||
void
|
||||
static void
|
||||
pgf_graphviz_parse_level(GuBuf* level, GuWriter* wtr, GuExn* err)
|
||||
{
|
||||
gu_puts("\n subgraph {rank=same;\n", wtr, err);
|
||||
|
||||
@@ -130,7 +130,7 @@ pgf_jit_predicate(PgfJitState* state, PgfCIdMap* abscats,
|
||||
jit_pusharg_p(JIT_V0);
|
||||
jit_pusharg_p(JIT_V2);
|
||||
jit_pusharg_p(JIT_V1);
|
||||
jit_finish(pgf_try_first);
|
||||
jit_finish(pgf_reasoner_try_first);
|
||||
}
|
||||
|
||||
#ifdef PGF_JIT_DEBUG
|
||||
@@ -182,7 +182,7 @@ pgf_jit_predicate(PgfJitState* state, PgfCIdMap* abscats,
|
||||
jit_pusharg_p(JIT_V0);
|
||||
jit_pusharg_p(JIT_V2);
|
||||
jit_pusharg_p(JIT_V1);
|
||||
jit_finish(pgf_try_else);
|
||||
jit_finish(pgf_reasoner_try_else);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < n_hypos; i++) {
|
||||
@@ -240,7 +240,7 @@ pgf_jit_predicate(PgfJitState* state, PgfCIdMap* abscats,
|
||||
jit_getarg_p(JIT_V1, rs_arg);
|
||||
jit_getarg_p(JIT_V2, st_arg);
|
||||
} else {
|
||||
jit_patch_movi(ref,pgf_complete);
|
||||
jit_patch_movi(ref,pgf_reasoner_complete);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -260,7 +260,7 @@ pgf_jit_predicate(PgfJitState* state, PgfCIdMap* abscats,
|
||||
jit_pusharg_p(JIT_V0);
|
||||
jit_pusharg_p(JIT_V2);
|
||||
jit_pusharg_p(JIT_V1);
|
||||
jit_finish(pgf_try_constant);
|
||||
jit_finish(pgf_reasoner_try_constant);
|
||||
} else {
|
||||
#ifdef PGF_JIT_DEBUG
|
||||
gu_puts(" COMPLETE\n", wtr, err);
|
||||
@@ -270,7 +270,7 @@ pgf_jit_predicate(PgfJitState* state, PgfCIdMap* abscats,
|
||||
jit_prepare(2);
|
||||
jit_pusharg_p(JIT_V2);
|
||||
jit_pusharg_p(JIT_V1);
|
||||
jit_finish(pgf_complete);
|
||||
jit_finish(pgf_reasoner_complete);
|
||||
}
|
||||
|
||||
#ifdef PGF_JIT_DEBUG
|
||||
|
||||
@@ -254,8 +254,8 @@ pgf_parse_with_heuristics(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
||||
}
|
||||
|
||||
GuEnum*
|
||||
pgf_get_completions(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
||||
GuString prefix, GuPool* pool)
|
||||
pgf_complete(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
||||
GuString prefix, GuPool* pool)
|
||||
{
|
||||
// Begin parsing a sentence of the specified category
|
||||
PgfParseState* state =
|
||||
|
||||
@@ -51,6 +51,7 @@ typedef struct PgfConcr PgfConcr;
|
||||
|
||||
#include <pgf/expr.h>
|
||||
#include <pgf/lexer.h>
|
||||
#include <pgf/graphviz.h>
|
||||
|
||||
/// An enumeration of #PgfExpr elements.
|
||||
typedef GuEnum PgfExprEnum;
|
||||
@@ -126,15 +127,15 @@ pgf_parse_with_heuristics(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
||||
GuPool* pool, GuPool* out_pool);
|
||||
|
||||
GuEnum*
|
||||
pgf_get_completions(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
||||
GuString prefix, GuPool* pool);
|
||||
pgf_complete(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
||||
GuString prefix, GuPool* pool);
|
||||
|
||||
bool
|
||||
pgf_parseval(PgfConcr* concr, PgfExpr expr, PgfCId cat,
|
||||
double *precision, double *recall, double *exact);
|
||||
|
||||
PgfExprEnum*
|
||||
pgf_generate(PgfPGF* pgf, PgfCId cat, GuPool* pool);
|
||||
pgf_generate_all(PgfPGF* pgf, PgfCId cat, GuPool* pool);
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ pgf_combine1(PgfReasoner* rs, PgfCombine1State* st)
|
||||
}
|
||||
|
||||
void
|
||||
pgf_try_first(PgfReasoner* rs, PgfExprState* parent, PgfAbsFun* absfun)
|
||||
pgf_reasoner_try_first(PgfReasoner* rs, PgfExprState* parent, PgfAbsFun* absfun)
|
||||
{
|
||||
PgfCId cat = absfun->type->cid;
|
||||
|
||||
@@ -276,7 +276,7 @@ pgf_try_first(PgfReasoner* rs, PgfExprState* parent, PgfAbsFun* absfun)
|
||||
}
|
||||
|
||||
void
|
||||
pgf_try_else(PgfReasoner* rs, PgfExprState* prev, PgfAbsFun* absfun)
|
||||
pgf_reasoner_try_else(PgfReasoner* rs, PgfExprState* prev, PgfAbsFun* absfun)
|
||||
{
|
||||
PgfExprState *st = gu_new(PgfExprState, rs->tmp_pool);
|
||||
st->base.continuation = (PgfPredicate) absfun->predicate;
|
||||
@@ -311,7 +311,7 @@ pgf_combine2(PgfReasoner* rs, PgfCombine2State* st)
|
||||
}
|
||||
|
||||
void
|
||||
pgf_complete(PgfReasoner* rs, PgfExprState* st)
|
||||
pgf_reasoner_complete(PgfReasoner* rs, PgfExprState* st)
|
||||
{
|
||||
PgfExprProb* ep = gu_new(PgfExprProb, rs->pool);
|
||||
ep->prob = st->base.prob - st->answers->outside_prob;
|
||||
@@ -332,10 +332,10 @@ pgf_complete(PgfReasoner* rs, PgfExprState* st)
|
||||
}
|
||||
|
||||
void
|
||||
pgf_try_constant(PgfReasoner* rs, PgfExprState* prev, PgfAbsFun* absfun)
|
||||
pgf_reasoner_try_constant(PgfReasoner* rs, PgfExprState* prev, PgfAbsFun* absfun)
|
||||
{
|
||||
pgf_try_else(rs, prev, absfun);
|
||||
pgf_complete(rs, prev);
|
||||
pgf_reasoner_try_else(rs, prev, absfun);
|
||||
pgf_reasoner_complete(rs, prev);
|
||||
}
|
||||
|
||||
static PgfExprProb*
|
||||
@@ -382,7 +382,7 @@ pgf_reasoner_enum_next(GuEnum* self, void* to, GuPool* pool)
|
||||
}
|
||||
|
||||
PgfExprEnum*
|
||||
pgf_generate(PgfPGF* pgf, PgfCId cat, GuPool* pool)
|
||||
pgf_generate_all(PgfPGF* pgf, PgfCId cat, GuPool* pool)
|
||||
{
|
||||
PgfReasoner* rs = gu_new(PgfReasoner, pool);
|
||||
rs->pool = pool;
|
||||
|
||||
@@ -8,15 +8,15 @@ typedef struct PgfExprState PgfExprState;
|
||||
typedef void (*PgfPredicate)(PgfReasoner* rs, PgfReasonerState* st);
|
||||
|
||||
void
|
||||
pgf_try_first(PgfReasoner* rs, PgfExprState* parent, PgfAbsFun* absfun);
|
||||
pgf_reasoner_try_first(PgfReasoner* rs, PgfExprState* parent, PgfAbsFun* absfun);
|
||||
|
||||
void
|
||||
pgf_try_else(PgfReasoner* rs, PgfExprState* prev, PgfAbsFun* absfun);
|
||||
pgf_reasoner_try_else(PgfReasoner* rs, PgfExprState* prev, PgfAbsFun* absfun);
|
||||
|
||||
void
|
||||
pgf_complete(PgfReasoner* rs, PgfExprState* st);
|
||||
pgf_reasoner_complete(PgfReasoner* rs, PgfExprState* st);
|
||||
|
||||
void
|
||||
pgf_try_constant(PgfReasoner* rs, PgfExprState* prev, PgfAbsFun* absfun);
|
||||
pgf_reasoner_try_constant(PgfReasoner* rs, PgfExprState* prev, PgfAbsFun* absfun);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1228,7 +1228,7 @@ Concr_parse(ConcrObject* self, PyObject *args, PyObject *keywds)
|
||||
}
|
||||
|
||||
static IterObject*
|
||||
Concr_getCompletions(ConcrObject* self, PyObject *args, PyObject *keywds)
|
||||
Concr_complete(ConcrObject* self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
static char *kwlist[] = {"sentence", "tokens", "cat",
|
||||
"prefix", "n", NULL};
|
||||
@@ -1295,7 +1295,7 @@ Concr_getCompletions(ConcrObject* self, PyObject *args, PyObject *keywds)
|
||||
}
|
||||
|
||||
pyres->res =
|
||||
pgf_get_completions(self->concr, catname, lexer, prefix, pyres->pool);
|
||||
pgf_complete(self->concr, catname, lexer, prefix, pyres->pool);
|
||||
|
||||
if (pyres->res == NULL) {
|
||||
Py_DECREF(pyres);
|
||||
@@ -1698,7 +1698,7 @@ static PyMethodDef Concr_methods[] = {
|
||||
"- n (int), max. trees; OPTIONAL, default: extract all trees\n"
|
||||
"- heuristics (double >= 0.0); OPTIONAL, default: taken from the flags in the grammar"
|
||||
},
|
||||
{"getCompletions", (PyCFunction)Concr_getCompletions, METH_VARARGS | METH_KEYWORDS,
|
||||
{"complete", (PyCFunction)Concr_complete, METH_VARARGS | METH_KEYWORDS,
|
||||
"Parses a partial string and returns a list with the top n possible next tokens"
|
||||
},
|
||||
{"parseval", (PyCFunction)Concr_parseval, METH_VARARGS,
|
||||
@@ -2011,7 +2011,7 @@ PGF_functionType(PGFObject* self, PyObject *args)
|
||||
}
|
||||
|
||||
static IterObject*
|
||||
PGF_generate(PGFObject* self, PyObject *args, PyObject *keywds)
|
||||
PGF_generateAll(PGFObject* self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
static char *kwlist[] = {"cat", "n", NULL};
|
||||
|
||||
@@ -2040,7 +2040,7 @@ PGF_generate(PGFObject* self, PyObject *args, PyObject *keywds)
|
||||
GuString catname = gu_str_string(catname_s, tmp_pool);
|
||||
|
||||
pyres->res =
|
||||
pgf_generate(self->pgf, catname, pyres->pool);
|
||||
pgf_generate_all(self->pgf, catname, pyres->pool);
|
||||
if (pyres->res == NULL) {
|
||||
Py_DECREF(pyres);
|
||||
gu_pool_free(tmp_pool);
|
||||
@@ -2122,7 +2122,7 @@ static PyMethodDef PGF_methods[] = {
|
||||
{"functionType", (PyCFunction)PGF_functionType, METH_VARARGS,
|
||||
"Returns the type of a function"
|
||||
},
|
||||
{"generate", (PyCFunction)PGF_generate, METH_VARARGS | METH_KEYWORDS,
|
||||
{"generateAll", (PyCFunction)PGF_generateAll, METH_VARARGS | METH_KEYWORDS,
|
||||
"Generates abstract syntax trees of given category in decreasing probability order"
|
||||
},
|
||||
{"compute", (PyCFunction)PGF_compute, METH_VARARGS,
|
||||
|
||||
Reference in New Issue
Block a user