diff --git a/classifier/README.txt b/classifier/README.txt index 70a656b..f48ab40 100644 --- a/classifier/README.txt +++ b/classifier/README.txt @@ -27,7 +27,7 @@ configuration): >>> concepts, resources, views = t.setup() >>> len(concepts) + len(resources) - 16 + 18 Fin de partie diff --git a/classifier/base.py b/classifier/base.py index caddcc2..55a95f8 100644 --- a/classifier/base.py +++ b/classifier/base.py @@ -29,7 +29,8 @@ 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.classifier.interfaces import IClassifier, IExtractor, IAnalyzer +from loops.classifier.interfaces import IInformationSet, IStatement from loops.common import AdapterBase, adapted from loops.interfaces import IResource, IConcept from loops.resource import Resource @@ -47,6 +48,45 @@ class Classifier(AdapterBase): implements(IClassifier) adapts(IConcept) - _adapterAttributes = ('context', '__parent__',) _contextAttributes = list(IClassifier) + list(IConcept) + def process(self, resource): + pass + + def assignConcept(self, statement): + pass + + +class Extractor(object): + + implements(IExtractor) + adapts(IResource) + + def __init__(self, context): + self.context = context + + def extractInformationSet(self): + return InformationSet() + + +class Analyzer(object): + + implements(IAnalyzer) + + def extractStatements(self,informationSet): + return [] + + +class InformationSet(dict): + + implements(IInformationSet) + + +class Statement(object): + + implements(IStatement) + + subject = None + predicate = None + object = None + relevance = 100 diff --git a/classifier/configure.zcml b/classifier/configure.zcml index 0e10ce6..7d96f8b 100644 --- a/classifier/configure.zcml +++ b/classifier/configure.zcml @@ -16,4 +16,16 @@ set_schema="loops.classifier.interfaces.IClassifier" /> + + + + + + + + + diff --git a/classifier/interfaces.py b/classifier/interfaces.py index 49769d8..8a0d513 100644 --- a/classifier/interfaces.py +++ b/classifier/interfaces.py @@ -29,13 +29,72 @@ from loops.util import _ class IClassifier(Interface): - """ + """ An object that is able to analyze a resource and identify the + concepts to assign. """ - 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) + analyzer = schema.TextLine( + title=_(u'Analyzer'), + description=_(u'Name of a utility that is able to analyze ' + 'the resources assigned to this classifier.'), + default=u'', + required=False) + + options = schema.List( + title=_(u'Options'), + description=_(u'Additional settings...'), + value_type=schema.TextLine(), + default=[], + required=False) + + def process(resource): + """ Do all that is needed to classify the resource given. + """ + + def assignConcept(statement): + """ Assign a concept representing the object of the statement + given to the statement's subject, using the statement's + predicate. + """ + + +class IExtractor(Interface): + """ Adapter for extracting an information set from a resource. + """ + + def extractInformationSet(): + """ Return an information set based on the resource given. + """ + + +class IAnalyzer(Interface): + """ Utility that is able to analyze an information set and + provide a collection of statements about it. + """ + + def extractStatements(informationSet): + """ Return a collection of statements derived from the + information set given. + """ + + +class IInformationSet(Interface): + """ A mapping or collection of key/value pairs; the keys are usually the + names of information elements, the values may be simple strings, + structured resources (e.g. XML documents), files providing such strings + or documents, or another kind of objects. The analyzer that is + fed with this information set must know what to do with it. + """ + + +class IStatement(Interface): + """ Represents a subject-predicate-object triple. These attributes + may be strings denoting the real + """ + + subject = Attribute('Subject of the Statement') + predicate = Attribute('Predicate of the Statement') + object = Attribute('Object of the Statement') + relevance = Attribute('A number denoting the relevance or correctness ' + 'of the statement') diff --git a/classifier/testsetup.py b/classifier/testsetup.py index f34f6f7..a20af82 100644 --- a/classifier/testsetup.py +++ b/classifier/testsetup.py @@ -8,7 +8,8 @@ import os from zope import component from loops import util -from loops.interfaces import IFile, IExternalFile +from loops.classifier.base import Classifier, Extractor, Analyzer +from loops.classifier.interfaces import IClassifier, IAnalyzer from loops.concept import Concept from loops.resource import Resource from loops.knowledge.setup import SetupManager as KnowledgeSetupManager @@ -28,6 +29,17 @@ class TestSite(BaseTestSite): concepts, resources, views = self.baseSetup() tType = concepts.getTypeConcept() + tClassifier = addAndConfigureObject(concepts, Concept, 'classifier', + title=u'Classifier', conceptType=tType, + typeInterface=IClassifier) + + component.provideAdapter(Classifier) + fileClassifier = addAndConfigureObject(concepts, Concept, + 'fileclassifier', title=u'File Classifier', + conceptType=tClassifier) + + component.provideAdapter(Extractor) + component.provideUtility(Analyzer, IAnalyzer) self.indexAll(concepts, resources) return concepts, resources, views diff --git a/common.py b/common.py index 48698a7..fc8a564 100644 --- a/common.py +++ b/common.py @@ -56,7 +56,7 @@ class AdapterBase(object): adapts(IConcept) - _adapterAttributes = ('context', '__parent__', ) + _adapterAttributes = ('context', '__parent__',) _contextAttributes = list(IConcept) def __init__(self, context):