import logging
import progressbar
[docs]class Agent(object):
"""Base class for Graphbrain cognitive agents.
These agents perform some change to an hypergraph, either by processing
some external source of information of by inferring new knowledge from
what is already contained in the hypregraph.
"""
def __init__(self, name, progress_bar=True, logging_level=logging.INFO):
self.name = name
self.progress_bar = progress_bar
self.logger = logging.getLogger(self.name)
self.logger.setLevel(logging_level)
self.search_pattern = '*'
self.recursive = True
self.system = None
self.running = False
[docs] def languages(self):
"""Returns set of languages supported by the agent, or an empty set
if the agent is language-agnostic.
"""
return set()
[docs] def process_edge(self, edge, depth):
"""Feeds the agent an edge to process."""
# do nothing by default
return None
[docs] def on_start(self):
"""Called before a cycle of activity is started."""
[docs] def on_end(self):
"""Called at the end of a cycle of activity."""
return []
[docs] def report(self):
"""Produce a report of the agent's activities."""
return ''
[docs] def run(self):
"""High-level method to run an agent."""
for op in self.input():
yield op