knowledge: base functionality OK

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1227 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-05-26 07:01:53 +00:00
parent dc0993ecc5
commit cc1b0e4585
3 changed files with 28 additions and 8 deletions

View file

@ -49,7 +49,11 @@ programming with Python:
Now we can ask what knowledge john is lacking if he would like to take
the position offered:
>>> john.getMissingKnowledge(pos01) == (ooProg, pyOo,)
>>> missing = john.getMissingKnowledge(pos01)
>>> missing
(<...KnowledgeElement...>, <...KnowledgeElement...>)
>>> missing == (ooProg, pyOo,)
True
Luckily there are a few elearning content objects out there that
@ -65,6 +69,10 @@ provide some of the knowledge needed:
So that we are now able to find out what john has to study in order to
fulfill the position offered:
>>> list(john.getProvidersNeeded(pos01))
>>> prov = list(john.getProvidersNeeded(pos01))
>>> len(prov)
2
>>> [d[0] for k, d in prov] == [doc01, doc02]
True

View file

@ -90,10 +90,10 @@ class IKnowing(Interface):
"""
def getProvidersNeeded(position):
""" Return two tuples: first a tuple of knowledge providers that
provide knowledge needed for fulfilling the position given,
second a tuple with the requirements that could not
be met by the available knowledge providers.
""" Return a tuple of tuples: Each tuple has as its first element
a requirement of the position, the second element is a tuple
of the knowledge providers providing this knowledge
((requirement, (provider, ...,)), ...).
"""

View file

@ -45,8 +45,20 @@ class Knowing(object):
del obj._knowers[self]
def getMissingKnowledge(self, position):
# to be done
return tuple(position.getRequirements())
knowledge = self.getKnowledge()
missing = []
toCheck = [k for k in position.getRequirements() if k not in knowledge]
while toCheck:
k = toCheck.pop()
missing.insert(0, k)
for d in k.getDependencies():
if d in knowledge or k in toCheck:
continue
if d in missing:
# TODO: rearrange missing, but care for cycles...
continue
toCheck.append(d)
return tuple(missing)
def getProvidersNeeded(self, position):
return ((k, k.getProviders())