Changeset 459
- Timestamp:
- 08/24/07 00:44:47 (11 months ago)
- Files:
-
- pyndexter/branches/simplification/pyndexter/__init__.py (modified) (5 diffs)
- pyndexter/branches/simplification/pyndexter/stemmers (added)
- pyndexter/branches/simplification/pyndexter/stemmers/__init__.py (added)
- pyndexter/branches/simplification/pyndexter/stemmers/porter.py (added)
- pyndexter/branches/simplification/pyndexter/stemmers/snowball.py (added)
- pyndexter/branches/simplification/setup.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pyndexter/branches/simplification/pyndexter/__init__.py
r458 r459 33 33 34 34 35 __all__ = ['Document', 'Query', 'Hit', 'Indexer', 'ResultSet', 35 __all__ = ['Document', 'Query', 'Hit', 'Indexer', 'ResultSet', 'Stemmer', 36 36 'Error', 'DocumentNotFound', 'InvalidURI', 'InvalidIndexer', 37 37 'connect'] 38 39 40 def _debug(message): 41 """Print a debug message.""" 42 if _debug.enabled: 43 print >> sys.stderr, message 44 # Set this to true to enable debug tracing 45 _debug.enabled = False 38 46 39 47 … … 45 53 methods.""" 46 54 47 class InvalidURI(Error): 48 """The URI provided was invalid in that context.""" 49 50 class InvalidIndexer(Error): 51 """The provided indexer URI was invalid.""" 55 class PluginError(Error): 56 """An error occurred in the plugin system.""" 57 58 59 class Stemmer(object): 60 """Abstraction for a stemming algorithm.""" 61 def __call__(self, words): 62 """Return an iterable of the words in stemmed form.""" 63 raise NotImplementedError 52 64 53 65 … … 297 309 298 310 299 def connect(uri, plugin_paths=None): 300 """Connect to the indexer defined by URI.""" 311 def load_plugin(name, entry_point, plugin_paths=None): 301 312 import pkg_resources 302 uri = URI(uri)303 313 304 314 if plugin_paths is None: … … 310 320 311 321 for dist in distributions: 322 _debug('Adding distribution %s' % dist) 312 323 pkg_resources.working_set.add(dist) 313 324 … … 328 339 _debug(_format_error(dist, e)) 329 340 330 for entry in pkg_resources.working_set.iter_entry_points( 'pyndexter.indexers'):331 if entry.name == uri.scheme:341 for entry in pkg_resources.working_set.iter_entry_points(entry_point): 342 if entry.name == name: 332 343 try: 333 344 _debug('Loading %s' % entry) 334 connect= entry.load(require=True)335 return IndexerWrapper(connect(uri))345 factory = entry.load(require=True) 346 return factory 336 347 except (ImportError, pkg_resources.DistributionNotFound, 337 348 pkg_resources.VersionConflict, pkg_resources.UnknownExtra), e: 338 _debug('Failed to load %s: %s' % (uri.scheme, _format_error(entry, e))) 339 raise InvalidIndexer('%s (%s)' % (str(uri), _format_error(entry, e))) 340 341 342 def _debug(message): 343 """Print a debug message.""" 344 if _debug.enabled: 345 print >> sys.stderr, message 346 # Set this to true to enable debug tracing 347 _debug.enabled = False 348 349 349 _debug('Failed to load %s: %s' % (name, _format_error(entry, e))) 350 raise PluginError('%s (%s)' % (name, _format_error(entry, e))) 351 raise PluginError('No suitable plugins found for %s' % name) 352 353 354 def connect(uri, plugin_paths=None): 355 """Connect to the indexer defined by uri.""" 356 uri = URI(uri) 357 indexer_factory = load_plugin(uri.scheme, 'pyndexter.indexers', 358 plugin_paths) 359 return IndexerWrapper(indexer_factory(uri)) pyndexter/branches/simplification/setup.py
r458 r459 24 24 'Topic :: Software Development :: Libraries'], 25 25 packages=find_packages(exclude=['*.tests']), 26 dependency_links=[ 27 'http://snowball.tartarus.org/download.php', 28 ], 26 29 extras_require={ 27 30 'hyperestraier': ['hyperestraier>=0.9.3'], 31 'snowball': ['PyStemmer>=1.0.1'], 28 32 # TODO put more indexer requirements in here 29 33 }, … … 33 37 34 38 [pyndexter.stemmers] 35 builtin = pyndexter.stemmers.builtin 39 porter = pyndexter.stemmers.porter:factory 40 snowball = pyndexter.stemmers.snowball:factory[snowball] 36 41 """ 37 42 )
