<commit_before>"""
Knowledge provider that will respond to requests made by the rdf publisher or another bot.
"""
from sleekxmpp.plugins.base import base_plugin
from rhobot.components.storage.client import StoragePayload
from rdflib.namespace import FOAF
from rhobot.namespace import RHO
import logging

logger = logging.getLogger(__name__)


class KnowledgeProvider(base_plugin):
    name = 'knowledge_provider'
    description = 'Knowledge Provider'
    dependencies = {'rho_bot_storage_client', 'rho_bot_rdf_publish', }

    type_requirements = {str(FOAF.Person), str(RHO.Owner), }

    def plugin_init(self):
        pass

    def post_init(self):
        base_plugin.post_init(self)
        self.xmpp['rho_bot_rdf_publish'].add_message_handler(self._rdf_request_message)

    def _rdf_request_message(self, rdf_payload):
        logger.info('Looking up knowledge')

        form = rdf_payload['form']

        payload = StoragePayload(form)

        intersection = self.type_requirements.intersection(set(payload.types()))
<commit_msg>Update knowledge provider to work with API changes.<commit_after>"""
Knowledge provider that will respond to requests made by the rdf publisher or another bot.
"""
from sleekxmpp.plugins.base import base_plugin
from rhobot.components.storage.client import StoragePayload
from rdflib.namespace import FOAF
from rhobot.namespace import RHO
import logging

logger = logging.getLogger(__name__)


class KnowledgeProvider(base_plugin):
    name = 'knowledge_provider'
    description = 'Knowledge Provider'
    dependencies = {'rho_bot_storage_client', 'rho_bot_rdf_publish', }

    type_requirements = {str(FOAF.Person), str(RHO.Owner), }

    def plugin_init(self):
        pass

    def post_init(self):
        base_plugin.post_init(self)
        self.xmpp['rho_bot_rdf_publish'].add_request_handler(self._rdf_request_message)

    def _rdf_request_message(self, rdf_payload):
        logger.info('Looking up knowledge')

        form = rdf_payload['form']

        payload = StoragePayload(form)

        intersection = self.type_requirements.intersection(set(payload.types()))

{'fraction_non_alphanumeric': 0.09017941454202077, 'fraction_numerical': 0.0, 'mean_word_length': 4.391857506361323, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3419842', 'n_tokens_mistral': 642, 'n_tokens_neox': 611, 'n_words': 143}