work in progress: loops.classifier: interfaces, basic utility and adapter classes

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1794 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2007-06-17 21:12:51 +00:00
parent 331e1894b1
commit 20b2bf4e5d
6 changed files with 135 additions and 12 deletions

View file

@ -27,7 +27,7 @@ configuration):
>>> concepts, resources, views = t.setup()
>>> len(concepts) + len(resources)
16
18
Fin de partie

View file

@ -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

View file

@ -16,4 +16,16 @@
set_schema="loops.classifier.interfaces.IClassifier" />
</zope:class>
<zope:adapter factory="loops.classifier.base.Extractor"
trusted="True" />
<zope:class class="loops.classifier.base.Extractor">
<require permission="zope.View"
interface="loops.classifier.interfaces.IExtractor" />
<require permission="zope.ManageContent"
set_schema="loops.classifier.interfaces.IExtractor" />
</zope:class>
<zope:utility factory="loops.classifier.base.Analyzer" />
</configure>

View file

@ -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')

View file

@ -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

View file

@ -56,7 +56,7 @@ class AdapterBase(object):
adapts(IConcept)
_adapterAttributes = ('context', '__parent__', )
_adapterAttributes = ('context', '__parent__',)
_contextAttributes = list(IConcept)
def __init__(self, context):