diff --git a/classifier/README.txt b/classifier/README.txt new file mode 100644 index 0000000..70a656b --- /dev/null +++ b/classifier/README.txt @@ -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() diff --git a/classifier/__init__.py b/classifier/__init__.py new file mode 100644 index 0000000..4bc90fb --- /dev/null +++ b/classifier/__init__.py @@ -0,0 +1,4 @@ +""" +$Id$ +""" + diff --git a/classifier/base.py b/classifier/base.py new file mode 100644 index 0000000..caddcc2 --- /dev/null +++ b/classifier/base.py @@ -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) + diff --git a/classifier/browser.py b/classifier/browser.py new file mode 100644 index 0000000..23d3cae --- /dev/null +++ b/classifier/browser.py @@ -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 diff --git a/classifier/configure.zcml b/classifier/configure.zcml new file mode 100644 index 0000000..0e10ce6 --- /dev/null +++ b/classifier/configure.zcml @@ -0,0 +1,19 @@ + + + + + + + + + + + + diff --git a/classifier/interfaces.py b/classifier/interfaces.py new file mode 100644 index 0000000..49769d8 --- /dev/null +++ b/classifier/interfaces.py @@ -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) + diff --git a/classifier/tests.py b/classifier/tests.py new file mode 100755 index 0000000..4e0a913 --- /dev/null +++ b/classifier/tests.py @@ -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') diff --git a/classifier/testsetup.py b/classifier/testsetup.py new file mode 100644 index 0000000..f34f6f7 --- /dev/null +++ b/classifier/testsetup.py @@ -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 +