diff --git a/loops/classifier/README.txt b/loops/classifier/README.txt index e5b7a1b..6ac1c54 100644 --- a/loops/classifier/README.txt +++ b/loops/classifier/README.txt @@ -4,8 +4,6 @@ loops - Linked Objects for Organization and Processing Services Automatic classification of resources. - ($Id$) - Setting up a loops Site and Utilities ===================================== @@ -39,7 +37,7 @@ from external files so we have something to work with. >>> tExternalCollection = concepts['extcollection'] >>> coll01 = addObject(concepts, Concept, 'coll01', - ... title=u'Collection One', conceptType=tExternalCollection) + ... title='Collection One', conceptType=tExternalCollection) >>> aColl01 = adapted(coll01) >>> aColl01.baseAddress = dataDir >>> aColl01.address = '' @@ -49,7 +47,7 @@ from external files so we have something to work with. 7 >>> rnames = list(sorted(resources.keys())) >>> rnames[0] - u'cust_im_contract_webbg_20071015.txt' + 'cust_im_contract_webbg_20071015.txt' Filename-based Classification @@ -76,7 +74,7 @@ and follow the classifier step by step. >>> from loops.classifier.interfaces import IExtractor, IAnalyzer >>> infoSet = InformationSet() >>> for name in classifier.extractors.split(): - ... print 'extractor:', name + ... print('extractor:', name) ... extractor = component.getAdapter(adapted(r1), IExtractor, name=name) ... infoSet.update(extractor.extractInformationSet()) extractor: filename @@ -96,32 +94,32 @@ So there seems to be something missing - we have to create concepts that may be identified as being candidates for classification. >>> tInstitution = addObject(concepts, Concept, 'institution', - ... title=u'Institution', conceptType=concepts['type']) + ... title='Institution', conceptType=concepts['type']) >>> cust_im = addObject(concepts, Concept, 'im_editors', - ... title=u'im Editors', conceptType=tInstitution) + ... title='im Editors', conceptType=tInstitution) >>> cust_mc = addObject(concepts, Concept, 'mc_consulting', - ... title=u'MC Management Consulting', conceptType=tInstitution) + ... title='MC Management Consulting', conceptType=tInstitution) >>> tDoctype = addObject(concepts, Concept, 'doctype', - ... title=u'Document Type', conceptType=concepts['type']) + ... title='Document Type', conceptType=concepts['type']) >>> dt_note = addObject(concepts, Concept, 'dt_note', - ... title=u'Note', conceptType=tDoctype) + ... title='Note', conceptType=tDoctype) >>> dt_contract = addObject(concepts, Concept, 'dt_contract', - ... title=u'Contract', conceptType=tDoctype) + ... title='Contract', conceptType=tDoctype) >>> tPerson = concepts['person'] >>> webbg = addObject(concepts, Concept, 'webbg', - ... title=u'Gerald Webb', conceptType=tPerson) + ... title='Gerald Webb', conceptType=tPerson) >>> smitha = addObject(concepts, Concept, 'smitha', - ... title=u'Angelina Smith', conceptType=tPerson) + ... title='Angelina Smith', conceptType=tPerson) >>> watersj = addObject(concepts, Concept, 'watersj', - ... title=u'Jerry Waters', conceptType=tPerson) + ... title='Jerry Waters', conceptType=tPerson) >>> millerj = addObject(concepts, Concept, 'millerj', - ... title=u'Jeannie Miller', conceptType=tPerson) + ... title='Jeannie Miller', conceptType=tPerson) >>> t.indexAll(concepts, resources) - >>> from zope.app.catalog.interfaces import ICatalog + >>> from zope.catalog.interfaces import ICatalog >>> cat = component.getUtility(ICatalog) >>> statements = analyzer.extractStatements(infoSet) @@ -135,7 +133,7 @@ So we are now ready to have the whole stuff run in one call. Classifier fileclassifier: Assigning: ... >>> list(sorted([c.title for c in r1.getConcepts()])) - [u'Collection One', u'Contract', u'External File', u'Gerald Webb', u'im Editors'] + ['Collection One', 'Contract', 'External File', 'Gerald Webb', 'im Editors'] >>> for name in rnames[1:]: ... classifier.process(resources[name]) diff --git a/loops/classifier/base.py b/loops/classifier/base.py index a71d12e..1370659 100644 --- a/loops/classifier/base.py +++ b/loops/classifier/base.py @@ -1,23 +1,6 @@ -# -# Copyright (c) 2015 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 -# +# looops.classifier.base -""" -Adapters and others classes for analyzing resources. +""" Adapters and others classes for analyzing resources. """ from itertools import tee @@ -26,7 +9,7 @@ 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.interface import implementer from zope.traversing.api import getName, getParent from cybertools.typology.interfaces import IType @@ -44,11 +27,11 @@ logger = getLogger('Classifier') TypeInterfaceSourceList.typeInterfaces += (IClassifier,) +@implementer(IClassifier) class Classifier(AdapterBase): """ A concept adapter for analyzing resources. """ - implements(IClassifier) adapts(IConcept) _contextAttributes = list(IClassifier) + list(IConcept) @@ -112,9 +95,9 @@ class Classifier(AdapterBase): logger.info(u'%s: %s' % (getName(self.context), message)) +@implementer(IExtractor) class Extractor(object): - implements(IExtractor) adapts(IResource) def __init__(self, context): @@ -124,9 +107,9 @@ class Extractor(object): return InformationSet() +@implementer(IAnalyzer) class Analyzer(object): - implements(IAnalyzer) adapts(IClassifier) def __init__(self, context): @@ -147,15 +130,15 @@ class Analyzer(object): return r1 +@implementer(IInformationSet) class InformationSet(dict): - implements(IInformationSet) + pass +@implementer(IStatement) class Statement(object): - implements(IStatement) - def __init__(self, object=None, predicate=None, subject=None, relevance=100): self.subject = subject self.predicate = predicate diff --git a/loops/classifier/sample.py b/loops/classifier/sample.py index 5e7c5f9..ad7a03f 100644 --- a/loops/classifier/sample.py +++ b/loops/classifier/sample.py @@ -1,30 +1,11 @@ -# -# 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 -# +# loops.classifier.sample -""" -Sample classifier implementation. - -$Id$ +""" Sample classifier implementation. """ from zope import component -from zope.app.catalog.interfaces import ICatalog from zope.cachedescriptors.property import Lazy +from zope.catalog.interfaces import ICatalog from zope.component import adapts from zope.traversing.api import getName