[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG/src - indexsupport.c:1.1.2.1

Andreas Jung andreas@digicool.com
Thu, 14 Feb 2002 17:54:29 -0500


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG/src
In directory cvs.zope.org:/tmp/cvs-serv10427/src

Added Files:
      Tag: ajung-textindexng-branch
	indexsupport.c 
Log Message:
added new indexsupport module

- reimplementent StopWords loop to check for stopwords for a given list
  of words in C making the functionality about 10times faster


=== Added File Zope/lib/python/Products/PluginIndexes/TextIndexNG/src/indexsupport.c ===
/*****************************************************************************
 
  Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
  
  This software is subject to the provisions of the Zope Public License,
  Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
  WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
  FOR A PARTICULAR PURPOSE
  
 ****************************************************************************/

#include "Python.h"


static PyObject *
stopwordfilter(PyObject *modinfo, PyObject *args)
{
    PyObject *ref, *words, *list;
    int i;

    list = PyList_New(0);

    if (! (PyArg_ParseTuple(args,"OO",&words,&ref)))
        return NULL;

    for (i=PyList_Size(words)-1; i>=0; i--) {
        PyObject *item, *w;

        item = PyList_GetItem(words,i);

        w = PyDict_GetItem(ref,item);
        if (! w) PyList_Append(list,item);

    }

    Py_DECREF(words);

    return list;
}

static struct PyMethodDef indexsupport_module_methods[] =
    {
        { "stopwordfilter", (PyCFunction) stopwordfilter, METH_VARARGS,
            "stopwordfilter(wordslist,stopword dict') " "-- filters words from wordslist that are stopwords"
        },
        { NULL, NULL }
    };

static char indexsupport_module_documentation[] =
    "indexsupport module .\n"
    "\n"
    "$Id: indexsupport.c,v 1.1.2.1 2002/02/14 22:54:28 andreasjung Exp $\n"
    ;

void
initindexsupport(void)
{
    PyObject *m, *d;
    char *rev="$Revision: 1.1.2.1 $";

    /* Create the module and add the functions */
    m = Py_InitModule4("indexsupport", indexsupport_module_methods,
                       indexsupport_module_documentation,
                       (PyObject*)NULL,PYTHON_API_VERSION);

    /* Add some symbolic constants to the module */
    d = PyModule_GetDict(m);
    PyDict_SetItemString(d, "__version__",
                         PyString_FromStringAndSize(rev+11,strlen(rev+11)-2));

    if (PyErr_Occurred())
        Py_FatalError("can't initialize module indexsupport");
}