Commit b78b1d28 authored by Jim Fulton's avatar Jim Fulton

Rearranged and, or, and near.

Got rid of get/setstate.
Made result-list-specific methods use mapping prootcol to make it
easier to mix with other mapping types.
parent 22d67f92
...@@ -30,7 +30,7 @@ Example usage: ...@@ -30,7 +30,7 @@ Example usage:
print i['blah'] print i['blah']
$Id: InvertedIndex.py,v 1.20 1997/03/05 19:28:18 chris Exp $''' $Id: InvertedIndex.py,v 1.21 1997/03/20 21:51:01 jim Exp $'''
# Copyright # Copyright
# #
# Copyright 1996 Digital Creations, L.C., 910 Princess Anne # Copyright 1996 Digital Creations, L.C., 910 Princess Anne
...@@ -82,6 +82,12 @@ $Id: InvertedIndex.py,v 1.20 1997/03/05 19:28:18 chris Exp $''' ...@@ -82,6 +82,12 @@ $Id: InvertedIndex.py,v 1.20 1997/03/05 19:28:18 chris Exp $'''
# (540) 371-6909 # (540) 371-6909
# #
# $Log: InvertedIndex.py,v $ # $Log: InvertedIndex.py,v $
# Revision 1.21 1997/03/20 21:51:01 jim
# Rearranged and, or, and near.
# Got rid of get/setstate.
# Made result-list-specific methods use mapping prootcol to make it
# easier to mix with other mapping types.
#
# Revision 1.20 1997/03/05 19:28:18 chris # Revision 1.20 1997/03/05 19:28:18 chris
# fixed typo # fixed typo
# #
...@@ -147,7 +153,7 @@ $Id: InvertedIndex.py,v 1.20 1997/03/05 19:28:18 chris Exp $''' ...@@ -147,7 +153,7 @@ $Id: InvertedIndex.py,v 1.20 1997/03/05 19:28:18 chris Exp $'''
# #
# #
# #
__version__='$Revision: 1.20 $'[11:-2] __version__='$Revision: 1.21 $'[11:-2]
import regex, regsub, string, copy import regex, regsub, string, copy
...@@ -181,7 +187,7 @@ class ResultList: ...@@ -181,7 +187,7 @@ class ResultList:
'''\ '''\
addentry(document_key, *info) addentry(document_key, *info)
add a document and related information to this ResultList''' add a document and related information to this ResultList'''
self._dict[document_key] = info self[document_key] = info
def __str__(self): def __str__(self):
...@@ -195,6 +201,10 @@ class ResultList: ...@@ -195,6 +201,10 @@ class ResultList:
def __getitem__(self, key): def __getitem__(self, key):
return self._dict[key] return self._dict[key]
def __setitem__(self, key, v):
self._dict[key]=v
# Note self.__changed__(1) via the
def __delitem__(self, key): def __delitem__(self, key):
del self._dict[key] del self._dict[key]
...@@ -235,15 +245,27 @@ class ResultList: ...@@ -235,15 +245,27 @@ class ResultList:
by calculating the geometric mean of each pair of corresponding by calculating the geometric mean of each pair of corresponding
frequencies.''' frequencies.'''
result = {} result = self.__class__()
for key in x.keys(): for key,v in self.items():
try: try:
result[key] = ( pow(self[key][0] * x[key][0], 0.5), None ) xv=x[key]
except KeyError: v=pow(v[0]*xv[0],0.5), v[1]+xv[1]
pass result[key] = v
except KeyError: pass
return result
return self.__class__(result) def and_not(self, x):
'''Return items in the reciever that are not in the argument'''
result = self.__class__()
for key,v in self.items():
try: x[key]
except KeyError: result[key] = v
return result
def __or__(self, x): def __or__(self, x):
...@@ -252,18 +274,14 @@ class ResultList: ...@@ -252,18 +274,14 @@ class ResultList:
combined by calculating the sum of each pair of corresponding combined by calculating the sum of each pair of corresponding
frequencies.''' frequencies.'''
result = {} result = self.__class__()
for key in self.keys():
result[key] = ( self[key][0], None )
for key in x.keys(): for key,v in self.items():
try: try:
result[key] = (result[key][0] + x[key][0], None) xv=x[key]
except KeyError: v=v[0]+xv[0], v[1]+xv[1]
result[key] = ( x[key][0], None ) except: pass
result[key] = v
return self.__class__(result)
def Not(self, index): def Not(self, index):
...@@ -305,39 +323,30 @@ class ResultList: ...@@ -305,39 +323,30 @@ class ResultList:
Returns a ResultList containing documents which contain''' Returns a ResultList containing documents which contain'''
result = {} result = self.__class__()
for key in self.keys(): for key,v in self.items():
try: try: value = x[key]
value = x[key] except KeyError: value=None
except KeyError: if value is None: continue
continue
positions = v[1]+value[1]
positions1 = self[key][1] positions.sort()
positions2 = value[1] positionsr=[]
rel = pow(v[0] * value[0], 0.5)
for position1 in positions1:
for position2 in positions2: pl=positions[0]
rl=-1
if (position1 is None or position2 is None): for i in range(1,len(positions)):
break p=positions[i]
d=p-pl
prox = position2 - position1 if d > 0 and d <= distance:
if ((prox > 0) and (prox <= distance)): if pl != rl: positionsr.append(pl)
rel = pow(self[key][0] * value[0], 0.5) positionsr.append(p)
rl=p
try: pl=p
pos = result[key][1] + [ position2 ] result[key]=positionsr
except KeyError: return result
pos = [ position2 ]
result[key] = (rel, pos)
else:
continue
break
return self.__class__(result)
def __getstate__(self): def __getstate__(self):
...@@ -625,18 +634,6 @@ class Index: ...@@ -625,18 +634,6 @@ class Index:
return d.keys() return d.keys()
def __getstate__(self):
return None
def __setstate__(self, state):
pass
def __getinitargs__(self):
return (self._index_object, self.list_class)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment