mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-18 17:29:32 -06:00
Fix createCategory. Add functionProbability.
This commit is contained in:
@@ -287,6 +287,28 @@ PGF_functionIsConstructor(PGFObject *self, PyObject *args)
|
||||
return PyBool_FromLong(isCon);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PGF_functionProbability(PGFObject *self, PyObject *args)
|
||||
{
|
||||
const char *s;
|
||||
Py_ssize_t size;
|
||||
if (!PyArg_ParseTuple(args, "s#", &s, &size))
|
||||
return NULL;
|
||||
|
||||
PgfText *funname = (PgfText *)PyMem_Malloc(sizeof(PgfText)+size+1);
|
||||
memcpy(funname->text, s, size+1);
|
||||
funname->size = size;
|
||||
|
||||
PgfExn err;
|
||||
prob_t prob = pgf_function_prob(self->db, self->revision, funname, &err);
|
||||
PyMem_Free(funname);
|
||||
if (handleError(err) != PGF_EXN_NONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyFloat_FromDouble((double)prob);
|
||||
}
|
||||
|
||||
static PyGetSetDef PGF_getseters[] = {
|
||||
{"abstractName",
|
||||
(getter)PGF_getAbstractName, NULL,
|
||||
@@ -324,6 +346,9 @@ static PyMethodDef PGF_methods[] = {
|
||||
{"functionIsConstructor", (PyCFunction)PGF_functionIsConstructor, METH_VARARGS,
|
||||
"Checks whether a function is a constructor"
|
||||
},
|
||||
{"functionProbability", (PyCFunction)PGF_functionProbability, METH_VARARGS,
|
||||
"Returns the probability of a function"
|
||||
},
|
||||
|
||||
{"newTransaction", (PyCFunction)PGF_newTransaction, METH_VARARGS,
|
||||
"Create new transaction"
|
||||
|
||||
Reference in New Issue
Block a user