Fix createCategory. Add functionProbability.

This commit is contained in:
John J. Camilleri
2021-09-21 23:34:03 +02:00
parent b4b8572af3
commit 4af807c982
4 changed files with 58 additions and 18 deletions

View File

@@ -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"