added package loops.classifier for automatic classificaton of resources
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1792 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									a0838de6f1
								
							
						
					
					
						commit
						e0c9b96a10
					
				
					 8 changed files with 239 additions and 0 deletions
				
			
		
							
								
								
									
										36
									
								
								classifier/README.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								classifier/README.txt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,36 @@ | ||||||
|  | =============================================================== | ||||||
|  | loops - Linked Objects for Organization and Processing Services | ||||||
|  | =============================================================== | ||||||
|  | 
 | ||||||
|  | Automatic classification of resources. | ||||||
|  | 
 | ||||||
|  |   ($Id$) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | Setting up a loops Site and Utilities | ||||||
|  | ===================================== | ||||||
|  | 
 | ||||||
|  | Let's do some basic set up | ||||||
|  | 
 | ||||||
|  |   >>> from zope import component, interface | ||||||
|  |   >>> from zope.traversing.api import getName | ||||||
|  |   >>> from zope.app.testing.setup import placefulSetUp, placefulTearDown | ||||||
|  |   >>> site = placefulSetUp(True) | ||||||
|  | 
 | ||||||
|  | and build a simple loops site with a concept manager and some concepts | ||||||
|  | (with a relation registry, a catalog, and all the type machinery - what | ||||||
|  | in real life is done via standard ZCML setup or via local utility | ||||||
|  | configuration): | ||||||
|  | 
 | ||||||
|  |   >>> from loops.classifier.testsetup import TestSite | ||||||
|  |   >>> t = TestSite(site) | ||||||
|  |   >>> concepts, resources, views = t.setup() | ||||||
|  | 
 | ||||||
|  |   >>> len(concepts) + len(resources) | ||||||
|  |   16 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | Fin de partie | ||||||
|  | ============= | ||||||
|  | 
 | ||||||
|  |   >>> placefulTearDown() | ||||||
							
								
								
									
										4
									
								
								classifier/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								classifier/__init__.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,4 @@ | ||||||
|  | """ | ||||||
|  | $Id$ | ||||||
|  | """ | ||||||
|  | 
 | ||||||
							
								
								
									
										52
									
								
								classifier/base.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								classifier/base.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,52 @@ | ||||||
|  | # | ||||||
|  | #  Copyright (c) 2007 Helmut Merz helmutm@cy55.de | ||||||
|  | # | ||||||
|  | #  This program is free software; you can redistribute it and/or modify | ||||||
|  | #  it under the terms of the GNU General Public License as published by | ||||||
|  | #  the Free Software Foundation; either version 2 of the License, or | ||||||
|  | #  (at your option) any later version. | ||||||
|  | # | ||||||
|  | #  This program is distributed in the hope that it will be useful, | ||||||
|  | #  but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | #  GNU General Public License for more details. | ||||||
|  | # | ||||||
|  | #  You should have received a copy of the GNU General Public License | ||||||
|  | #  along with this program; if not, write to the Free Software | ||||||
|  | #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||||
|  | # | ||||||
|  | 
 | ||||||
|  | """ | ||||||
|  | Adapters and others classes for analyzing resources. | ||||||
|  | 
 | ||||||
|  | $Id$ | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | from zope.cachedescriptors.property import Lazy | ||||||
|  | from zope import component | ||||||
|  | from zope.component import adapts | ||||||
|  | from zope.event import notify | ||||||
|  | from zope.interface import implements | ||||||
|  | from zope.traversing.api import getName, getParent | ||||||
|  | 
 | ||||||
|  | from loops.classifier.interfaces import IClassifier | ||||||
|  | from loops.common import AdapterBase, adapted | ||||||
|  | from loops.interfaces import IResource, IConcept | ||||||
|  | from loops.resource import Resource | ||||||
|  | from loops.setup import addAndConfigureObject | ||||||
|  | from loops.type import TypeInterfaceSourceList | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | TypeInterfaceSourceList.typeInterfaces += (IClassifier,) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class Classifier(AdapterBase): | ||||||
|  |     """ A concept adapter for analyzing resources. | ||||||
|  |     """ | ||||||
|  | 
 | ||||||
|  |     implements(IClassifier) | ||||||
|  |     adapts(IConcept) | ||||||
|  | 
 | ||||||
|  |     _adapterAttributes = ('context', '__parent__',) | ||||||
|  |     _contextAttributes = list(IClassifier) + list(IConcept) | ||||||
|  | 
 | ||||||
							
								
								
									
										30
									
								
								classifier/browser.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								classifier/browser.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,30 @@ | ||||||
|  | # | ||||||
|  | #  Copyright (c) 2007 Helmut Merz helmutm@cy55.de | ||||||
|  | # | ||||||
|  | #  This program is free software; you can redistribute it and/or modify | ||||||
|  | #  it under the terms of the GNU General Public License as published by | ||||||
|  | #  the Free Software Foundation; either version 2 of the License, or | ||||||
|  | #  (at your option) any later version. | ||||||
|  | # | ||||||
|  | #  This program is distributed in the hope that it will be useful, | ||||||
|  | #  but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | #  GNU General Public License for more details. | ||||||
|  | # | ||||||
|  | #  You should have received a copy of the GNU General Public License | ||||||
|  | #  along with this program; if not, write to the Free Software | ||||||
|  | #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||||
|  | # | ||||||
|  | 
 | ||||||
|  | """ | ||||||
|  | View class(es) for resource classifiers. | ||||||
|  | 
 | ||||||
|  | $Id$ | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | from zope import interface, component | ||||||
|  | from zope.app.pagetemplate import ViewPageTemplateFile | ||||||
|  | from zope.cachedescriptors.property import Lazy | ||||||
|  | 
 | ||||||
|  | from loops.browser.concept import ConceptView | ||||||
|  | from loops.common import adapted | ||||||
							
								
								
									
										19
									
								
								classifier/configure.zcml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								classifier/configure.zcml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | ||||||
|  | <!-- $Id$ --> | ||||||
|  | 
 | ||||||
|  | <configure | ||||||
|  |    xmlns:zope="http://namespaces.zope.org/zope" | ||||||
|  |    xmlns:browser="http://namespaces.zope.org/browser" | ||||||
|  |    i18n_domain="zope" | ||||||
|  |    > | ||||||
|  | 
 | ||||||
|  |   <zope:adapter factory="loops.classifier.base.Classifier" | ||||||
|  |                 trusted="True" /> | ||||||
|  | 
 | ||||||
|  |   <zope:class class="loops.classifier.base.Classifier"> | ||||||
|  |     <require permission="zope.View" | ||||||
|  |              interface="loops.classifier.interfaces.IClassifier" /> | ||||||
|  |     <require permission="zope.ManageContent" | ||||||
|  |              set_schema="loops.classifier.interfaces.IClassifier" /> | ||||||
|  |   </zope:class> | ||||||
|  | 
 | ||||||
|  | </configure> | ||||||
							
								
								
									
										41
									
								
								classifier/interfaces.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								classifier/interfaces.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | ||||||
|  | # | ||||||
|  | #  Copyright (c) 2007 Helmut Merz helmutm@cy55.de | ||||||
|  | # | ||||||
|  | #  This program is free software; you can redistribute it and/or modify | ||||||
|  | #  it under the terms of the GNU General Public License as published by | ||||||
|  | #  the Free Software Foundation; either version 2 of the License, or | ||||||
|  | #  (at your option) any later version. | ||||||
|  | # | ||||||
|  | #  This program is distributed in the hope that it will be useful, | ||||||
|  | #  but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | #  GNU General Public License for more details. | ||||||
|  | # | ||||||
|  | #  You should have received a copy of the GNU General Public License | ||||||
|  | #  along with this program; if not, write to the Free Software | ||||||
|  | #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||||
|  | # | ||||||
|  | 
 | ||||||
|  | """ | ||||||
|  | Classifier interfaces. | ||||||
|  | 
 | ||||||
|  | $Id$ | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | from zope.interface import Interface, Attribute | ||||||
|  | from zope import interface, component, schema | ||||||
|  | 
 | ||||||
|  | from loops.util import _ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class IClassifier(Interface): | ||||||
|  |     """ | ||||||
|  |     """ | ||||||
|  | 
 | ||||||
|  |     providerName = schema.TextLine( | ||||||
|  |             title=_(u'Provider name'), | ||||||
|  |             description=_(u'The name of a utility that provides the ' | ||||||
|  |                            'external objects; default is a directory ' | ||||||
|  |                            'collection provider'), | ||||||
|  |             required=False) | ||||||
|  | 
 | ||||||
							
								
								
									
										23
									
								
								classifier/tests.py
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										23
									
								
								classifier/tests.py
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,23 @@ | ||||||
|  | # $Id$ | ||||||
|  | 
 | ||||||
|  | import unittest, doctest | ||||||
|  | from zope.testing.doctestunit import DocFileSuite | ||||||
|  | from zope.interface.verify import verifyClass | ||||||
|  | #from loops.versioning import versionable | ||||||
|  | 
 | ||||||
|  | class Test(unittest.TestCase): | ||||||
|  |     "Basic tests for the classifier sub-package." | ||||||
|  | 
 | ||||||
|  |     def testSomething(self): | ||||||
|  |         pass | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def test_suite(): | ||||||
|  |     flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS | ||||||
|  |     return unittest.TestSuite(( | ||||||
|  |                 unittest.makeSuite(Test), | ||||||
|  |                 DocFileSuite('README.txt', optionflags=flags), | ||||||
|  |             )) | ||||||
|  | 
 | ||||||
|  | if __name__ == '__main__': | ||||||
|  |     unittest.main(defaultTest='test_suite') | ||||||
							
								
								
									
										34
									
								
								classifier/testsetup.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								classifier/testsetup.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,34 @@ | ||||||
|  | """ | ||||||
|  | Set up a loops site for testing. | ||||||
|  | 
 | ||||||
|  | $Id$ | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | import os | ||||||
|  | from zope import component | ||||||
|  | 
 | ||||||
|  | from loops import util | ||||||
|  | from loops.interfaces import IFile, IExternalFile | ||||||
|  | from loops.concept import Concept | ||||||
|  | from loops.resource import Resource | ||||||
|  | from loops.knowledge.setup import SetupManager as KnowledgeSetupManager | ||||||
|  | from loops.setup import SetupManager, addAndConfigureObject | ||||||
|  | from loops.tests.setup import TestSite as BaseTestSite | ||||||
|  | 
 | ||||||
|  | dataDir = os.path.join(os.path.dirname(__file__), 'testdata') | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class TestSite(BaseTestSite): | ||||||
|  | 
 | ||||||
|  |     def __init__(self, site): | ||||||
|  |         self.site = site | ||||||
|  | 
 | ||||||
|  |     def setup(self): | ||||||
|  |         component.provideAdapter(KnowledgeSetupManager, name='knowledge') | ||||||
|  |         concepts, resources, views = self.baseSetup() | ||||||
|  | 
 | ||||||
|  |         tType = concepts.getTypeConcept() | ||||||
|  | 
 | ||||||
|  |         self.indexAll(concepts, resources) | ||||||
|  |         return concepts, resources, views | ||||||
|  | 
 | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm