Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
b98b6471
Commit
b98b6471
authored
May 23, 2002
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Whitespace normalization.
parent
80cc084f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
51 additions
and
52 deletions
+51
-52
lib/python/Products/ZCTextIndex/HTMLSplitter.py
lib/python/Products/ZCTextIndex/HTMLSplitter.py
+2
-2
lib/python/Products/ZCTextIndex/IPipelineElementFactory.py
lib/python/Products/ZCTextIndex/IPipelineElementFactory.py
+6
-6
lib/python/Products/ZCTextIndex/Lexicon.py
lib/python/Products/ZCTextIndex/Lexicon.py
+12
-12
lib/python/Products/ZCTextIndex/PipelineFactory.py
lib/python/Products/ZCTextIndex/PipelineFactory.py
+9
-9
lib/python/Products/ZCTextIndex/ZCTextIndex.py
lib/python/Products/ZCTextIndex/ZCTextIndex.py
+9
-9
lib/python/Products/ZCTextIndex/__init__.py
lib/python/Products/ZCTextIndex/__init__.py
+4
-5
lib/python/Products/ZCTextIndex/tests/queryhtml.py
lib/python/Products/ZCTextIndex/tests/queryhtml.py
+1
-1
lib/python/Products/ZCTextIndex/tests/testPipelineFactory.py
lib/python/Products/ZCTextIndex/tests/testPipelineFactory.py
+8
-8
No files found.
lib/python/Products/ZCTextIndex/HTMLSplitter.py
View file @
b98b6471
...
...
@@ -37,8 +37,8 @@ class HTMLWordSplitter:
for pat in remove:
text = re.sub(pat, "
", text)
return re.findall(wordpat, text)
element_factory.registerFactory('Word Splitter',
element_factory.registerFactory('Word Splitter',
'HTML aware splitter',
HTMLWordSplitter)
...
...
lib/python/Products/ZCTextIndex/IPipelineElementFactory.py
View file @
b98b6471
...
...
@@ -19,21 +19,21 @@ class IPipelineElementFactory(Interface):
def
registerFactory
(
group
,
name
,
factory
):
"""Registers a pipeline factory by name and element group.
Each name can be registered only once for a given group. Duplicate
Each name can be registered only once for a given group. Duplicate
registrations will raise a ValueError
"""
def
getFactoryGroups
():
"""Returns a sorted list of element group names
"""
def
getFactoryNames
(
group
):
"""Returns a sorted list of registered pipeline factory names
in the specified element group
"""
def
instantiate
(
group
,
name
):
"""Instantiates a pipeline element by group and name. If name is not
"""Instantiates a pipeline element by group and name. If name is not
registered raise a KeyError.
"""
lib/python/Products/ZCTextIndex/Lexicon.py
View file @
b98b6471
...
...
@@ -170,22 +170,22 @@ class Splitter:
for s in lst:
result += self.rxGlob.findall(s)
return result
element_factory.registerFactory('Word Splitter',
'Whitespace splitter',
element_factory.registerFactory('Word Splitter',
'Whitespace splitter',
Splitter)
class CaseNormalizer:
def process(self, lst):
return [w.lower() for w in lst]
element_factory.registerFactory('Case Normalizer',
'Case Normalizer',
'Case Normalizer',
CaseNormalizer)
element_factory.registerFactory('Stop Words',
' Don
\
'
t remove stop words',
element_factory.registerFactory('Stop Words',
' Don
\
'
t remove stop words',
None)
class StopWordRemover:
...
...
@@ -202,8 +202,8 @@ class StopWordRemover:
def process(self, lst):
return self._process(self.dict, lst)
element_factory.registerFactory('Stop Words',
'Remove listed stop words only',
element_factory.registerFactory('Stop Words',
'Remove listed stop words only',
StopWordRemover)
class StopWordAndSingleCharRemover(StopWordRemover):
...
...
@@ -211,7 +211,7 @@ class StopWordAndSingleCharRemover(StopWordRemover):
dict = get_stopdict().copy()
for c in range(255):
dict[chr(c)] = None
element_factory.registerFactory('Stop Words',
'Remove listed and single char words',
element_factory.registerFactory('Stop Words',
'Remove listed and single char words',
StopWordAndSingleCharRemover)
lib/python/Products/ZCTextIndex/PipelineFactory.py
View file @
b98b6471
...
...
@@ -14,36 +14,36 @@
from
Products.ZCTextIndex.IPipelineElementFactory
\
import
IPipelineElementFactory
class
PipelineElementFactory
:
__implements__
=
IPipelineElementFactory
def
__init__
(
self
):
self
.
_groups
=
{}
def
registerFactory
(
self
,
group
,
name
,
factory
):
if
self
.
_groups
.
has_key
(
group
)
and
\
self
.
_groups
[
group
].
has_key
(
name
):
raise
ValueError
(
'ZCTextIndex lexicon element "%s" '
'already registered in group "%s"'
'already registered in group "%s"'
%
(
name
,
group
))
elements
=
self
.
_groups
.
get
(
group
)
if
elements
is
None
:
elements
=
self
.
_groups
[
group
]
=
{}
elements
[
name
]
=
factory
def
getFactoryGroups
(
self
):
groups
=
self
.
_groups
.
keys
()
groups
.
sort
()
return
groups
def
getFactoryNames
(
self
,
group
):
names
=
self
.
_groups
[
group
].
keys
()
names
.
sort
()
return
names
def
instantiate
(
self
,
group
,
name
):
factory
=
self
.
_groups
[
group
][
name
]
if
factory
is
not
None
:
...
...
lib/python/Products/ZCTextIndex/ZCTextIndex.py
View file @
b98b6471
...
...
@@ -35,7 +35,7 @@ from PipelineFactory import element_factory
from
Products.ZCTextIndex.CosineIndex
import
CosineIndex
from
Products.ZCTextIndex.OkapiIndex
import
OkapiIndex
index_types
=
{
'Okapi BM25 Rank'
:
OkapiIndex
,
index_types
=
{
'Okapi BM25 Rank'
:
OkapiIndex
,
'Cosine Measure'
:
CosineIndex
}
class
ZCTextIndex
(
Persistent
,
Acquisition
.
Implicit
,
SimpleItem
):
...
...
@@ -77,7 +77,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
self
.
_index_type
=
extra
.
index_type
else
:
self
.
_index_factory
=
index_factory
self
.
clear
()
## External methods not in the Pluggable Index API ##
...
...
@@ -157,7 +157,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
## User Interface Methods ##
manage_main
=
DTMLFile
(
'dtml/manageZCTextIndex'
,
globals
())
def
getIndexType
(
self
):
"""Return index type string"""
return
getattr
(
self
,
'_index_type'
,
self
.
_index_factory
.
__name__
)
...
...
@@ -176,10 +176,10 @@ manage_addLexiconForm = DTMLFile('dtml/addLexicon', globals())
def
manage_addLexicon
(
self
,
id
,
title
=
''
,
elements
=
[],
REQUEST
=
None
):
"""Add ZCTextIndex Lexicon"""
pipeline
=
[]
for
el_record
in
elements
:
if
not
hasattr
(
el_record
,
'name'
):
if
not
hasattr
(
el_record
,
'name'
):
continue
# Skip over records that only specify element group
element
=
element_factory
.
instantiate
(
el_record
.
group
,
el_record
.
name
)
if
element
is
not
None
:
...
...
@@ -199,7 +199,7 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
"""Lexicon for ZCTextIndex"""
meta_type
=
'ZCTextIndex Lexicon'
manage_options
=
({
'label'
:
'Overview'
,
'action'
:
'manage_main'
},)
+
\
SimpleItem
.
manage_options
...
...
@@ -207,13 +207,13 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
self
.
id
=
str
(
id
)
self
.
title
=
str
(
title
)
PLexicon
.
inheritedAttribute
(
'__init__'
)(
self
,
*
pipeline
)
## User Interface Methods ##
def
getPipelineNames
(
self
):
"""Return list of names of pipeline element classes"""
return
[
element
.
__class__
.
__name__
for
element
in
self
.
_pipeline
]
manage_main
=
DTMLFile
(
'dtml/manageLexicon'
,
globals
())
InitializeClass
(
PLexicon
)
lib/python/Products/ZCTextIndex/__init__.py
View file @
b98b6471
...
...
@@ -39,15 +39,14 @@ def initialize(context):
getElementGroups
,
getElementNames
),
icon
=
'www/lexicon.gif'
)
## Functions below are for use in the ZMI constructor forms ##
def
getElementGroups
(
self
):
return
element_factory
.
getFactoryGroups
()
def
getElementNames
(
self
,
group
):
return
element_factory
.
getFactoryNames
(
group
)
def
getIndexTypes
(
self
):
return
ZCTextIndex
.
index_types
.
keys
()
lib/python/Products/ZCTextIndex/tests/queryhtml.py
View file @
b98b6471
...
...
@@ -54,7 +54,7 @@ def main(rt):
chooser
=
NBest
(
10
)
chooser
.
addmany
(
b
.
items
())
results
=
chooser
.
getbest
()
else
:
try
:
for
_
in
ITERS
:
...
...
lib/python/Products/ZCTextIndex/tests/testPipelineFactory.py
View file @
b98b6471
...
...
@@ -17,32 +17,32 @@ from Products.ZCTextIndex.IPipelineElement import IPipelineElement
from
Products.ZCTextIndex.PipelineFactory
import
PipelineElementFactory
class
NullPipelineElement
:
__implements__
=
IPipelineElement
def
process
(
source
):
pass
pass
class
PipelineFactoryTest
(
TestCase
):
def
setUp
(
self
):
self
.
huey
=
NullPipelineElement
()
self
.
dooey
=
NullPipelineElement
()
self
.
louie
=
NullPipelineElement
()
self
.
daffy
=
NullPipelineElement
()
def
testPipeline
(
self
):
pf
=
PipelineElementFactory
()
pf
.
registerFactory
(
'donald'
,
'huey'
,
self
.
huey
)
pf
.
registerFactory
(
'donald'
,
'dooey'
,
self
.
dooey
)
pf
.
registerFactory
(
'donald'
,
'louie'
,
self
.
louie
)
pf
.
registerFactory
(
'looney'
,
'daffy'
,
self
.
daffy
)
self
.
assertRaises
(
ValueError
,
pf
.
registerFactory
,
'donald'
,
'huey'
,
self
.
assertRaises
(
ValueError
,
pf
.
registerFactory
,
'donald'
,
'huey'
,
self
.
huey
)
self
.
assertEqual
(
pf
.
getFactoryGroups
(),
[
'donald'
,
'looney'
])
self
.
assertEqual
(
pf
.
getFactoryNames
(
'donald'
),
self
.
assertEqual
(
pf
.
getFactoryNames
(
'donald'
),
[
'dooey'
,
'huey'
,
'louie'
])
def
test_suite
():
return
makeSuite
(
PipelineFactoryTest
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment