|
@@ -172,7 +172,10 @@ Graph_get_uri (GraphObject *self, void *closure)
|
|
static int
|
|
static int
|
|
Graph_set_uri (GraphObject *self, PyObject *value, void *closure)
|
|
Graph_set_uri (GraphObject *self, PyObject *value, void *closure)
|
|
{
|
|
{
|
|
- if (!PyObject_TypeCheck (value, &TermType)) return -1;
|
|
|
|
|
|
+ if (!PyObject_TypeCheck (value, &TermType)) {
|
|
|
|
+ PyErr_SetString (PyExc_TypeError, "URI is not a Term type.");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
|
|
LSUP_rc rc = LSUP_graph_set_uri (
|
|
LSUP_rc rc = LSUP_graph_set_uri (
|
|
self->ob_struct, ((TermObject*)value)->ob_struct->data);
|
|
self->ob_struct, ((TermObject*)value)->ob_struct->data);
|
|
@@ -208,13 +211,6 @@ Graph_copy (PyTypeObject *cls, PyObject *src)
|
|
static PyObject *
|
|
static PyObject *
|
|
Graph_store (PyObject *self)
|
|
Graph_store (PyObject *self)
|
|
{
|
|
{
|
|
- /*
|
|
|
|
- PyObject *dest_obj = PyObject_CallFunction (self, "b", LSUP_STORE_MDB);
|
|
|
|
- if (UNLIKELY (!dest_obj)) {
|
|
|
|
- PyErr_SetString (PyExc_SystemError, "Error Creating stored graph.");
|
|
|
|
- return NULL;
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
GraphObject *dest_obj = (GraphObject *) Py_TYPE (self)->tp_alloc(
|
|
GraphObject *dest_obj = (GraphObject *) Py_TYPE (self)->tp_alloc(
|
|
Py_TYPE (self), 0);
|
|
Py_TYPE (self), 0);
|
|
if (!dest_obj) return PyErr_NoMemory();
|
|
if (!dest_obj) return PyErr_NoMemory();
|
|
@@ -292,6 +288,68 @@ Graph_new_from_rdf (PyTypeObject *cls, PyObject *args)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+/** @brief Build a triple pattern for lookup purposes.
|
|
|
|
+ */
|
|
|
|
+inline static int build_trp_pattern (PyObject *args, LSUP_Term *spo[])
|
|
|
|
+{
|
|
|
|
+ PyObject *s_obj, *p_obj, *o_obj;
|
|
|
|
+
|
|
|
|
+ if (! (PyArg_ParseTuple (args, "OOO", &s_obj, &p_obj, &o_obj)))
|
|
|
|
+ return -1;
|
|
|
|
+
|
|
|
|
+ if (s_obj != Py_None && !PyObject_TypeCheck (s_obj, &TermType)) {
|
|
|
|
+ PyErr_SetString (PyExc_TypeError, "Subject must be a term or None.");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ if (p_obj != Py_None && !PyObject_TypeCheck (p_obj, &TermType)) {
|
|
|
|
+ PyErr_SetString (PyExc_TypeError, "Predicate must be a term or None.");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ if (o_obj != Py_None && !PyObject_TypeCheck (o_obj, &TermType)) {
|
|
|
|
+ PyErr_SetString (PyExc_TypeError, "Object must be a term or None.");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ spo[0] = s_obj != Py_None ? ((TermObject *)s_obj)->ob_struct : NULL;
|
|
|
|
+ spo[1] = s_obj != Py_None ? ((TermObject *)p_obj)->ob_struct : NULL;
|
|
|
|
+ spo[2] = s_obj != Py_None ? ((TermObject *)o_obj)->ob_struct : NULL;
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+static PyObject *
|
|
|
|
+Graph_new_set_from_store_lookup (PyTypeObject *cls, PyObject *args)
|
|
|
|
+{
|
|
|
|
+ LSUP_Term *spo[3];
|
|
|
|
+
|
|
|
|
+ if (UNLIKELY ((build_trp_pattern (args, spo)) < 0)) return NULL;
|
|
|
|
+
|
|
|
|
+ LSUP_Graph **gr_a = LSUP_graph_new_lookup (spo[0], spo[1], spo[2]);
|
|
|
|
+ if (UNLIKELY (!gr_a)) {
|
|
|
|
+ // TODO implement LSUP_strerror for more details.
|
|
|
|
+ PyErr_SetString (PyExc_SystemError, "Error looking up triples.");
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ PyObject *ret = PySet_New (NULL);
|
|
|
|
+
|
|
|
|
+ size_t i;
|
|
|
|
+ for (i = 0; gr_a[i] != NULL; i++) {
|
|
|
|
+ PyObject *gr_obj = cls->tp_alloc(cls, 0);
|
|
|
|
+ if (!gr_obj) return NULL;
|
|
|
|
+ ((GraphObject *) gr_obj)->ob_struct = gr_a[i];
|
|
|
|
+
|
|
|
|
+ Py_INCREF (gr_obj);
|
|
|
|
+ PySet_Add (ret, gr_obj);
|
|
|
|
+ }
|
|
|
|
+ log_debug ("Found %lu graphs for pattern.", i + 1);
|
|
|
|
+
|
|
|
|
+ Py_INCREF (ret);
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
static PyObject *
|
|
static PyObject *
|
|
Graph_richcmp (PyObject *self, PyObject *other, int op)
|
|
Graph_richcmp (PyObject *self, PyObject *other, int op)
|
|
{
|
|
{
|
|
@@ -377,34 +435,6 @@ finalize:
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-inline static int build_trp_pattern (PyObject *args, LSUP_Term *spo[])
|
|
|
|
-{
|
|
|
|
- PyObject *s_obj, *p_obj, *o_obj;
|
|
|
|
-
|
|
|
|
- if (! (PyArg_ParseTuple (args, "OOO", &s_obj, &p_obj, &o_obj)))
|
|
|
|
- return -1;
|
|
|
|
-
|
|
|
|
- if (s_obj != Py_None && !PyObject_TypeCheck (s_obj, &TermType)) {
|
|
|
|
- PyErr_SetString (PyExc_TypeError, "Subject must be a term or None.");
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
- if (p_obj != Py_None && !PyObject_TypeCheck (p_obj, &TermType)) {
|
|
|
|
- PyErr_SetString (PyExc_TypeError, "Predicate must be a term or None.");
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
- if (o_obj != Py_None && !PyObject_TypeCheck (o_obj, &TermType)) {
|
|
|
|
- PyErr_SetString (PyExc_TypeError, "Object must be a term or None.");
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- spo[0] = s_obj != Py_None ? ((TermObject *)s_obj)->ob_struct : NULL;
|
|
|
|
- spo[1] = s_obj != Py_None ? ((TermObject *)p_obj)->ob_struct : NULL;
|
|
|
|
- spo[2] = s_obj != Py_None ? ((TermObject *)o_obj)->ob_struct : NULL;
|
|
|
|
-
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
static PyObject *Graph_remove (PyObject *self, PyObject *args)
|
|
static PyObject *Graph_remove (PyObject *self, PyObject *args)
|
|
{
|
|
{
|
|
LSUP_rc rc;
|
|
LSUP_rc rc;
|
|
@@ -499,12 +529,18 @@ Graph_encode (PyObject *self, PyObject *args)
|
|
|
|
|
|
static PyMethodDef Graph_methods[] = {
|
|
static PyMethodDef Graph_methods[] = {
|
|
{
|
|
{
|
|
- "copy", (PyCFunction) Graph_copy,
|
|
|
|
- METH_CLASS | METH_VARARGS, "Copy a graph."
|
|
|
|
|
|
+ "copy", (PyCFunction) Graph_copy, METH_CLASS | METH_VARARGS,
|
|
|
|
+ "Copy a graph."
|
|
},
|
|
},
|
|
{
|
|
{
|
|
"from_rdf", (PyCFunction) Graph_new_from_rdf,
|
|
"from_rdf", (PyCFunction) Graph_new_from_rdf,
|
|
- METH_CLASS | METH_VARARGS, "Create a graph from a RDF file."
|
|
|
|
|
|
+ METH_CLASS | METH_VARARGS,
|
|
|
|
+ "Create a graph from a RDF file."
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "from_lookup", (PyCFunction) Graph_new_set_from_store_lookup,
|
|
|
|
+ METH_CLASS | METH_VARARGS,
|
|
|
|
+ "Create a set of graphs from a store SPO lookup."
|
|
},
|
|
},
|
|
{
|
|
{
|
|
"store", (PyCFunction) Graph_store, METH_NOARGS,
|
|
"store", (PyCFunction) Graph_store, METH_NOARGS,
|