|
@@ -155,7 +155,25 @@ Graph_init (GraphObject *self, PyObject *args, PyObject *kwargs)
|
|
|
|
|
|
} else uri = LSUP_iriref_new (NULL, NULL);
|
|
} else uri = LSUP_iriref_new (NULL, NULL);
|
|
|
|
|
|
- self->ob_struct = LSUP_graph_new (uri, (LSUP_store_type) store_type);
|
|
+ // Set up the store if a function for that is defined.
|
|
|
|
+ const LSUP_StoreInt *sif = LSUP_store_int (store_type);
|
|
|
|
+ if (UNLIKELY (!sif)) {
|
|
|
|
+ PyErr_SetString (
|
|
|
|
+ PyExc_TypeError,
|
|
|
|
+ "No interface defined for given store type.");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ if (sif->setup_fn) {
|
|
|
|
+ if (sif->setup_fn(NULL, false) < LSUP_OK) {
|
|
|
|
+ PyErr_SetString (
|
|
|
|
+ PyExc_IOError, "Error initializing back end store.");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // TODO Make store ID, nsm and initial size accessible.
|
|
|
|
+ self->ob_struct = LSUP_graph_new (
|
|
|
|
+ uri, (LSUP_StoreType) store_type, NULL, NULL, 0);
|
|
if (!self->ob_struct) {
|
|
if (!self->ob_struct) {
|
|
PyErr_SetString (PyExc_ValueError, "Could not create graph.");
|
|
PyErr_SetString (PyExc_ValueError, "Could not create graph.");
|
|
return -1;
|
|
return -1;
|
|
@@ -210,21 +228,20 @@ static PyGetSetDef Graph_getsetters[] = {
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
-static PyObject *
|
|
+static int
|
|
-Graph_copy (PyTypeObject *cls, PyObject *src)
|
|
+Graph_copy_contents (GraphObject *self, GraphObject *dest)
|
|
{
|
|
{
|
|
- if (! PyObject_TypeCheck (src, cls)) return NULL;
|
|
+ if (LSUP_graph_copy_contents (self->ob_struct, dest->ob_struct) < LSUP_OK)
|
|
-
|
|
+ {
|
|
- GraphObject *res = (GraphObject *) cls->tp_alloc(cls, 0);
|
|
+ PyErr_SetString (PyExc_ValueError, "Error copying graph contents.");
|
|
- if (!res) return NULL;
|
|
+ return -1;
|
|
-
|
|
+ }
|
|
- res->ob_struct = LSUP_graph_copy (((GraphObject *) src)->ob_struct);
|
|
|
|
|
|
|
|
- Py_INCREF(res);
|
|
+ return 0;
|
|
- return (PyObject *) res;
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
+#if 0
|
|
static PyObject *
|
|
static PyObject *
|
|
Graph_store (PyObject *self)
|
|
Graph_store (PyObject *self)
|
|
{
|
|
{
|
|
@@ -232,7 +249,15 @@ Graph_store (PyObject *self)
|
|
Py_TYPE (self), 0);
|
|
Py_TYPE (self), 0);
|
|
if (!dest_obj) return PyErr_NoMemory();
|
|
if (!dest_obj) return PyErr_NoMemory();
|
|
|
|
|
|
- LSUP_rc rc = LSUP_graph_store (
|
|
+ // TODO Make store ID, nsm and initial size accessible.
|
|
|
|
+ LSUP_Graph *dest = LSUP_graph_new (
|
|
|
|
+ uri, LSUP_STORE_HTABLE, NULL, NULL, 0);
|
|
|
|
+ if (!dest) {
|
|
|
|
+ PyErr_SetString (PyExc_ValueError, "Could not create graph.");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ LSUP_rc rc = LSUP_GraphStore (
|
|
((GraphObject *) self)->ob_struct, &((dest_obj)->ob_struct), NULL);
|
|
((GraphObject *) self)->ob_struct, &((dest_obj)->ob_struct), NULL);
|
|
if (rc != LSUP_OK) {
|
|
if (rc != LSUP_OK) {
|
|
log_error (LSUP_strerror (rc));
|
|
log_error (LSUP_strerror (rc));
|
|
@@ -243,6 +268,7 @@ Graph_store (PyObject *self)
|
|
Py_INCREF (dest_obj);
|
|
Py_INCREF (dest_obj);
|
|
return (PyObject *)dest_obj;
|
|
return (PyObject *)dest_obj;
|
|
}
|
|
}
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
static PyObject *
|
|
@@ -394,9 +420,20 @@ Graph_bool_op (
|
|
GraphObject *res = (GraphObject *) cls->tp_alloc (cls, 0);
|
|
GraphObject *res = (GraphObject *) cls->tp_alloc (cls, 0);
|
|
if (!res) return NULL;
|
|
if (!res) return NULL;
|
|
|
|
|
|
- res->ob_struct = LSUP_graph_bool_op (
|
|
+ LSUP_Graph *dest = LSUP_graph_new (
|
|
|
|
+ NULL, LSUP_STORE_HTABLE, NULL, NULL, 0);
|
|
|
|
+ if (!dest) {
|
|
|
|
+ PyErr_SetString (PyExc_Exception, "Could not create destination graph.");
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ LSUP_rc rc = LSUP_graph_bool_op (
|
|
op, ((GraphObject *) gr1)->ob_struct,
|
|
op, ((GraphObject *) gr1)->ob_struct,
|
|
- ((GraphObject *) gr2)->ob_struct);
|
|
+ ((GraphObject *) gr2)->ob_struct, res->ob_struct);
|
|
|
|
+ if (rc < LSUP_OK) {
|
|
|
|
+ PyErr_SetString (PyExc_Exception, "Error performing boolean operation.");
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
|
|
Py_INCREF(res);
|
|
Py_INCREF(res);
|
|
return (PyObject *) res;
|
|
return (PyObject *) res;
|
|
@@ -546,8 +583,8 @@ Graph_encode (PyObject *self, PyObject *args)
|
|
|
|
|
|
static PyMethodDef Graph_methods[] = {
|
|
static PyMethodDef Graph_methods[] = {
|
|
{
|
|
{
|
|
- "copy", (PyCFunction) Graph_copy, METH_CLASS | METH_VARARGS,
|
|
+ "copy", (PyCFunction) Graph_copy_contents, METH_CLASS | METH_VARARGS,
|
|
- "Copy a graph."
|
|
+ "Copy the contents of a graph into another."
|
|
},
|
|
},
|
|
{
|
|
{
|
|
"from_rdf", (PyCFunction) Graph_new_from_rdf,
|
|
"from_rdf", (PyCFunction) Graph_new_from_rdf,
|
|
@@ -561,10 +598,12 @@ static PyMethodDef Graph_methods[] = {
|
|
"Create a set of graphs from a store SPO lookup."
|
|
"Create a set of graphs from a store SPO lookup."
|
|
},
|
|
},
|
|
*/
|
|
*/
|
|
|
|
+ /*
|
|
{
|
|
{
|
|
"store", (PyCFunction) Graph_store, METH_NOARGS,
|
|
"store", (PyCFunction) Graph_store, METH_NOARGS,
|
|
"Store a graph into the permanent back end."
|
|
"Store a graph into the permanent back end."
|
|
},
|
|
},
|
|
|
|
+ */
|
|
{"add", (PyCFunction) Graph_add, METH_O, "Add triples to a graph."},
|
|
{"add", (PyCFunction) Graph_add, METH_O, "Add triples to a graph."},
|
|
{
|
|
{
|
|
"remove", (PyCFunction) Graph_remove, METH_VARARGS,
|
|
"remove", (PyCFunction) Graph_remove, METH_VARARGS,
|