[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndex - GlobbingLexicon.py:1.16 Lexicon.py:1.9 TextIndex.py:1.34 Vocabulary.py:1.10
Martijn Pieters
mj@zope.com
Wed, 14 Aug 2002 18:20:03 -0400
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndex
In directory cvs.zope.org:/tmp/cvs-serv24540/TextIndex
Modified Files:
GlobbingLexicon.py Lexicon.py TextIndex.py Vocabulary.py
Log Message:
Clean up indentation and trailing whitespace.
=== Zope/lib/python/Products/PluginIndexes/TextIndex/GlobbingLexicon.py 1.15 => 1.16 ===
--- Zope/lib/python/Products/PluginIndexes/TextIndex/GlobbingLexicon.py:1.15 Thu Apr 25 13:45:47 2002
+++ Zope/lib/python/Products/PluginIndexes/TextIndex/GlobbingLexicon.py Wed Aug 14 18:19:32 2002
@@ -1,5 +1,5 @@
##############################################################################
-#
+#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -8,7 +8,7 @@
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
-#
+#
#############################################################################
from Lexicon import Lexicon
@@ -25,7 +25,7 @@
from Products.PluginIndexes.TextIndex.TextIndex import Or,Op
from Products.PluginIndexes.common.randid import randid
-from types import UnicodeType
+from types import UnicodeType
class GlobbingLexicon(Lexicon):
"""Lexicon which supports basic globbing function ('*' and '?').
@@ -80,11 +80,11 @@
def createDigrams(self, word):
"""Returns a list with the set of digrams in the word."""
-
+
word = '$'+word+'$'
return [ word[i:i+2] for i in range(len(word)-1)]
-
+
def getWordId(self, word):
"""Provided 'word', return the matching integer word id."""
@@ -112,7 +112,7 @@
try: insert=inverse.insert
except AttributeError:
# we have an "old" BTree object
- if inverse:
+ if inverse:
wid=inverse.keys()[-1]+1
else:
self._inverseLex=IOBTree()
@@ -135,7 +135,7 @@
return wid
-
+
def get(self, pattern):
""" Query the lexicon for words matching a pattern."""
@@ -170,7 +170,7 @@
if result is None:
return ()
return (result, )
-
+
## now get all of the intsets that contain the result digrams
result = None
for digram in digrams:
@@ -194,7 +194,7 @@
hits.insert(x)
return hits
-
+
def __getitem__(self, word):
""" """
return self.get(word)
@@ -235,8 +235,8 @@
try:
return self.SplitterFunc(
- astring,
- words,
+ astring,
+ words,
encoding=encoding,
singlechar=self.splitterParams.splitterSingleChars,
indexnumbers=self.splitterParams.splitterIndexNumbers,
@@ -269,5 +269,4 @@
# Next, we need to deal with single-character globbing
result = result.replace( '?', '.')
- return "%s$" % result
-
+ return "%s$" % result
=== Zope/lib/python/Products/PluginIndexes/TextIndex/Lexicon.py 1.8 => 1.9 ===
--- Zope/lib/python/Products/PluginIndexes/TextIndex/Lexicon.py:1.8 Thu Apr 25 13:45:47 2002
+++ Zope/lib/python/Products/PluginIndexes/TextIndex/Lexicon.py Wed Aug 14 18:19:32 2002
@@ -1,14 +1,14 @@
##############################################################################
#
# 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
-#
+#
##############################################################################
__doc__=""" Module breaks out Zope specific methods and behavior. In
@@ -48,7 +48,7 @@
self.stop_syn = {}
else:
self.stop_syn = stop_syn
-
+
self.useSplitter = Splitter.splitterNames[0]
if useSplitter: self.useSplitter=useSplitter
self.splitterParams = extra
@@ -58,7 +58,7 @@
def clear(self):
self._lexicon = OIBTree()
self._inverseLex = IOBTree()
-
+
def _convertBTrees(self, threshold=200):
if (type(self._lexicon) is OIBTree and
type(getattr(self, '_inverseLex', None)) is IOBTree):
@@ -81,7 +81,7 @@
self._inverseLex._p_jar=self._p_jar
convert(inverseLex, self._inverseLex, threshold)
-
+
def set_stop_syn(self, stop_syn):
""" pass in a mapping of stopwords and synonyms. Format is:
@@ -92,22 +92,22 @@
"""
self.stop_syn = stop_syn
-
+
def getWordId(self, word):
""" return the word id of 'word' """
wid=self._lexicon.get(word, None)
- if wid is None:
+ if wid is None:
wid=self.assignWordId(word)
return wid
-
+
set = getWordId
def getWord(self, wid):
""" post-2.3.1b2 method, will not work with unconverted lexicons """
return self._inverseLex.get(wid, None)
-
+
def assignWordId(self, word):
"""Assigns a new word id to the provided word and returns it."""
# First make sure it's not already in there
@@ -126,11 +126,11 @@
while not inverse.insert(wid, word):
wid=randid()
- if isinstance(word,StringType):
+ if isinstance(word,StringType):
self._lexicon[intern(word)] = wid
else:
self._lexicon[word] = wid
-
+
return wid
@@ -156,8 +156,8 @@
try:
return self.SplitterFunc(
- astring,
- words,
+ astring,
+ words,
encoding=encoding,
singlechar=self.splitterParams.splitterSingleChars,
indexnumbers=self.splitterParams.splitterIndexNumbers,
@@ -218,4 +218,3 @@
)
stop_word_dict={}
for word in stop_words: stop_word_dict[word]=None
-
=== Zope/lib/python/Products/PluginIndexes/TextIndex/TextIndex.py 1.33 => 1.34 ===
--- Zope/lib/python/Products/PluginIndexes/TextIndex/TextIndex.py:1.33 Thu Aug 1 12:00:40 2002
+++ Zope/lib/python/Products/PluginIndexes/TextIndex/TextIndex.py Wed Aug 14 18:19:32 2002
@@ -1,14 +1,14 @@
##############################################################################
#
# 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
-#
+#
##############################################################################
"""Text Index
@@ -23,7 +23,7 @@
from zLOG import LOG, ERROR
from Acquisition import Implicit
from Products.PluginIndexes.common.ResultList import ResultList
-from Products.PluginIndexes import PluggableIndex
+from Products.PluginIndexes import PluggableIndex
from Products.PluginIndexes.common.util import parseIndexRequest
from OFS.SimpleItem import SimpleItem
@@ -77,13 +77,13 @@
meta_type='TextIndex'
manage_options= (
- {'label': 'Settings',
+ {'label': 'Settings',
'action': 'manage_main',
'help': ('TextIndex','TextIndex_Settings.stx')},
)
query_options = ["query","operator"]
-
+
def __init__(self, id, ignore_ex=None, call_methods=None, lexicon=None,
caller=None, extra=None):
"""Create an index
@@ -143,9 +143,9 @@
if self.catalog is None:
self.catalog = self.aq_inner.aq_parent.aq_base
-
+
self._lexicon = getattr(self.catalog,self.vocabulary_id).getLexicon()
- except:
+ except:
self._lexicon = Lexicon()
self.vocabulary_id = '__intern__'
@@ -155,7 +155,7 @@
def __nonzero__(self):
return not not self._unindex
-
+
def clear(self):
"""Reinitialize the text index."""
@@ -168,7 +168,7 @@
def _convertBTrees(self, threshold=200):
if type(self._lexicon) is type(''):
- # Turn the name reference into a hard reference.
+ # Turn the name reference into a hard reference.
self._lexicon=self.getLexicon()
if type(self._index) is IOBTree: return
@@ -184,7 +184,7 @@
if type(scores) is not TupleType and type(scores) is not IIBTree():
scores=IIBTree(scores)
return scores
-
+
convert(_index, self._index, threshold, convertScores)
@@ -217,8 +217,8 @@
else:
return tuple(map(self.getLexicon().getWord,
results))
-
-
+
+
def insertForwardIndexEntry(self, entry, documentId, score=1):
"""Uses the information provided to update the indexes.
@@ -254,12 +254,12 @@
else:
if indexRow.get(documentId, -1) != score:
# score changed (or new entry)
-
+
if type(indexRow) is DictType:
indexRow[documentId] = score
if len(indexRow) > 3:
# Big enough to give it's own database record
- indexRow=IIBTree(indexRow)
+ indexRow=IIBTree(indexRow)
index[entry] = indexRow
else:
indexRow[documentId] = score
@@ -271,7 +271,7 @@
def index_object(self, documentId, obj, threshold=None):
""" Index an object:
'documentId' is the integer id of the document
-
+
'obj' is the object to be indexed
'threshold' is the number of words to process between
@@ -292,7 +292,7 @@
return 0
# sniff the object for 'id'+'_encoding'
-
+
try:
encoding = getattr(obj, self.id+'_encoding')
if callable(encoding ):
@@ -302,14 +302,14 @@
except (AttributeError, TypeError):
encoding = 'latin1'
-
+
lexicon = self.getLexicon()
splitter = lexicon.Splitter
wordScores = OIBTree()
last = None
-
+
# Run through the words and score them
for word in list(splitter(source,encoding=encoding)):
@@ -332,7 +332,7 @@
# Get rid of document words that are no longer indexed
self.unindex_objectWids(documentId, difference(currentWids, widScores))
-
+
# Now index the words. Note that the new xIBTrees are clever
# enough to do nothing when there isn't a change. Woo hoo.
insert=self.insertForwardIndexEntry
@@ -358,10 +358,10 @@
return last
- def unindex_object(self, i):
+ def unindex_object(self, i):
""" carefully unindex document with integer id 'i' from the text
index and do not fail if it does not exist """
-
+
index = self._index
unindex = self._unindex
wids = unindex.get(i, None)
@@ -369,7 +369,7 @@
self.unindex_objectWids(i, wids)
del unindex[i]
- def unindex_objectWids(self, i, wids):
+ def unindex_objectWids(self, i, wids):
""" carefully unindex document with integer id 'i' from the text
index and do not fail if it does not exist """
@@ -406,7 +406,7 @@
Note that this differentiates between being passed an Integer
and a String. Strings are looked up in the lexicon, whereas
Integers are assumed to be resolved word ids. """
-
+
if type(word) is IntType:
# We have a word ID
result = self._index.get(word, {})
@@ -417,7 +417,7 @@
if not splitSource:
return ResultList({}, (word,), self)
-
+
if len(splitSource) == 1:
splitSource = splitSource[0]
if splitSource[:1] == '"' and splitSource[-1:] == '"':
@@ -444,7 +444,7 @@
return r
- def _apply_index(self, request, cid=''):
+ def _apply_index(self, request, cid=''):
""" Apply the index to query parameters given in the argument,
request
@@ -452,11 +452,11 @@
If the request does not contain the needed parameters, then
None is returned.
-
+
Otherwise two objects are returned. The first object is a
ResultSet containing the record numbers of the matching
records. The second object is a tuple containing the names of
- all data fields used.
+ all data fields used.
"""
record = parseIndexRequest(request,self.id,self.query_options)
@@ -496,7 +496,7 @@
if r is not None:
return r, (self.id,)
-
+
return (IIBucket(), (self.id,))
@@ -534,7 +534,7 @@
def query(self, s, default_operator=Or):
""" Evaluate a query string.
-
+
Convert the query string into a data structure of nested lists
and strings, based on the grouping of whitespace-separated
strings by parentheses and quotes. The 'Near' operator is
@@ -578,7 +578,7 @@
if operandType is IntType:
left = self[left]
elif isinstance(left,StringType) or isinstance(left,UnicodeType):
- left = self[left]
+ left = self[left]
elif operandType is ListType:
left = self.evaluate(left)
@@ -586,7 +586,7 @@
if operandType is IntType:
right = self[right]
elif isinstance(right,StringType) or isinstance(right,UnicodeType):
- right = self[right]
+ right = self[right]
elif operandType is ListType:
right = self.evaluate(right)
@@ -713,12 +713,12 @@
mo = parens_re(s)
if mo is None:
return
-
+
open_index = mo.start(0) + 1
paren_count = 0
while mo is not None:
index = mo.start(0)
-
+
if s[index] == '(':
paren_count = paren_count + 1
else:
@@ -730,23 +730,23 @@
break
mo = parens_re(s, index + 1)
- raise QueryError, "Mismatched parentheses"
+ raise QueryError, "Mismatched parentheses"
def quotes(s):
if '"' not in s:
return s.split()
-
+
# split up quoted regions
splitted = re.split('\s*\"\s*', s)
if (len(splitted) % 2) == 0: raise QueryError, "Mismatched quotes"
-
+
for i in range(1,len(splitted),2):
# split the quoted region into words
words = splitted[i] = splitted[i].split()
-
+
# put the Proxmity operator in between quoted words
j = len(words) - 1
while j > 0:
@@ -767,4 +767,3 @@
def manage_addTextIndex(self, id, extra=None, REQUEST=None, RESPONSE=None, URL3=None):
"""Add a text index"""
return self.manage_addIndex(id, 'TextIndex', extra, REQUEST, RESPONSE, URL3)
-
=== Zope/lib/python/Products/PluginIndexes/TextIndex/Vocabulary.py 1.9 => 1.10 ===
--- Zope/lib/python/Products/PluginIndexes/TextIndex/Vocabulary.py:1.9 Tue Mar 12 10:30:49 2002
+++ Zope/lib/python/Products/PluginIndexes/TextIndex/Vocabulary.py Wed Aug 14 18:19:32 2002
@@ -1,14 +1,14 @@
##############################################################################
#
# 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
-#
+#
##############################################################################
"""ZCatalog product"""
@@ -50,7 +50,7 @@
meta_type = "Vocabulary"
_isAVocabulary = 1
-
+
manage_options=(
(
{'label': 'Vocabulary', 'action': 'manage_main',
@@ -65,15 +65,15 @@
__ac_permissions__=(
('Manage Vocabulary',
- ['manage_main', 'manage_vocab', 'manage_query'],
+ ['manage_main', 'manage_vocab', 'manage_query'],
['Manager']),
('Query Vocabulary',
['query',],
- ['Anonymous', 'Manager']),
+ ['Anonymous', 'Manager']),
)
-
+
manage_main = DTMLFile('dtml/manage_vocab', globals())
manage_query = DTMLFile('dtml/vocab_query', globals())
@@ -84,7 +84,7 @@
self.title = title
self.globbing = not not globbing
- self.useSplitter = Splitter.splitterNames[0]
+ self.useSplitter = Splitter.splitterNames[0]
if splitter:
self.useSplitter = splitter
@@ -114,7 +114,7 @@
result.append(pattern)
return str(result)
-
+
def manage_insert(self, word='', URL1=None, RESPONSE=None):
""" doc string """
@@ -131,4 +131,3 @@
def words(self):
return self.lexicon._lexicon.items()
-