[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG/src - indexsupport.c:1.1.2.6
Andreas Jung
andreas@digicool.com
Mon, 18 Mar 2002 18:57:30 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG/src
In directory cvs.zope.org:/tmp/cvs-serv8218/src
Modified Files:
Tag: ajung-textindexng-branch
indexsupport.c
Log Message:
added factories for IISet and IIBucket
=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/src/indexsupport.c 1.1.2.5 => 1.1.2.6 ===
#include <stdlib.h>
+PyObject *IIBTreeModule, *IISet, *IIBucket;
static PyObject *
stopwordfilter(PyObject *modinfo, PyObject *args)
@@ -32,7 +33,8 @@
item = PyList_GetItem(words,i);
w = PyDict_GetItem(stopwords, item);
- if (! w) PyList_Append(list,item);
+ if (! w)
+ PyList_Append(list,item);
}
Py_DECREF(words);
@@ -58,7 +60,7 @@
item = PyList_GetItem(wordlist,i);
if (! PyObject_Compare(item, word))
- PyList_Append(list,PyInt_FromLong(i));
+ PyList_Append(list,PyInt_FromLong(i));
}
return list;
@@ -66,27 +68,31 @@
/*
Arguments:
-
+
- fwdIdx -- forward index (OIBTree)
- reverseIdx -- reverse index (IOBtree)
- words -- sequence of words to be inserted
*/
-PyObject *vocabularyBatchInsert(PyObject *modinfo,PyObject *args) {
+PyObject *vocabularyBatchInsert(PyObject *modinfo,PyObject *args)
+{
PyObject *fwdIdx,*revIdx, *lst, *word, *wid;
PyObject *wids;
int i;
- if (! PyArg_ParseTuple(args, "OOO", &fwdIdx,&revIdx,&lst)) return NULL;
+ if (! PyArg_ParseTuple(args, "OOO", &fwdIdx,&revIdx,&lst))
+ return NULL;
if (! PyMapping_Check(fwdIdx)) {
- PyErr_SetString(PyExc_TypeError, "1st argument must be OIBTree instance"); \
+ PyErr_SetString(PyExc_TypeError, "1st argument must be OIBTree instance");
+ \
return NULL;
}
if (! PyMapping_Check(revIdx)) {
- PyErr_SetString(PyExc_TypeError, "2nd argument must be IOTree instance"); \
+ PyErr_SetString(PyExc_TypeError, "2nd argument must be IOTree instance");
+ \
return NULL;
}
@@ -102,9 +108,8 @@
if (PyMapping_HasKey(fwdIdx,word)) {
wid = PyObject_GetItem(fwdIdx,word);
- }
- else {
-
+ } else {
+
do {
wid = PyInt_FromLong( rand() );
} while(PyMapping_HasKey(revIdx, wid));
@@ -114,21 +119,55 @@
}
PyList_Append(wids, wid);
- }
-
+ }
+
return wids;
}
+int importIIBTreeModule(void)
+{
+ PyObject *mod_dict;
+
+ IIBTreeModule = PyImport_ImportModule("BTrees.IIBTree");
+ if (! IIBTreeModule)
+ return 0;
+
+ mod_dict = PyModule_GetDict(IIBTreeModule);
+
+ IISet = PyDict_GetItemString(mod_dict, "IISet");
+ if (! IISet) return 0;
+
+ IIBucket = PyDict_GetItemString(mod_dict, "IIBucket");
+ if (! IIBucket) return 0;
+
+ return 1;
+}
+
+PyObject *IISetFactory()
+{
+ PyObject *iiset;
+ iiset = PyObject_CallFunction(IISet,NULL);
+ return iiset;
+}
+
+PyObject *IIBucketFactory()
+{
+ PyObject *iibucket;
+ iibucket = PyObject_CallFunction(IIBucket,NULL);
+ return iibucket;
+}
+
+
static struct PyMethodDef indexsupport_module_methods[] =
{
{ "stopwordfilter", (PyCFunction) stopwordfilter, METH_VARARGS,
- "stopwordfilter(wordslist,stopword dict') " "-- filters words from wordslist that are stopwords"
+ "stopwordfilter(wordslist,stopword dict') " "-- filters words from wordslist that are stopwords"
},
{ "vocabBatchInsert", (PyCFunction) vocabularyBatchInsert, METH_VARARGS,
- "vocabBatchInsert(fwdIdx,revIdx,wordLst)" "-- inserts forward and backward entries for vocabularies"
+ "vocabBatchInsert(fwdIdx,revIdx,wordLst)" "-- inserts forward and backward entries for vocabularies"
},
{ "listIndexes", (PyCFunction) listIndexes, METH_VARARGS,
- "listIndexes(list of words',word) " "-- find all positions of word in a list of words"
+ "listIndexes(list of words',word) " "-- find all positions of word in a list of words"
},
{ NULL, NULL }
};
@@ -154,7 +193,10 @@
d = PyModule_GetDict(m);
PyDict_SetItemString(d, "__version__",
PyString_FromStringAndSize(rev+11,strlen(rev+11)-2));
-
+ if (! importIIBTreeModule()) {
+ Py_FatalError("can't initialize module indexsupport");
+ }
if (PyErr_Occurred())
Py_FatalError("can't initialize module indexsupport");
}
+