<commit_before>from synergine.core.config.ConfigurationManager import ConfigurationManager
from synergine.synergy.object.SynergyObject import SynergyObject
from synergine.core.exception.NotFoundError import NotFoundError


class ObjectVisualizer():

    def __init__(self, config: dict, context):
        config_manager = ConfigurationManager(config)
        self._visualisation_configuration = config_manager.get('objects', {})
        self._objects_class_mapped = {}
        self._context = context
        self._callback_position = config_manager.get('callbacks.position', 0)

    def get_visual(self, obj: SynergyObject):
        visualisation_definition = self._get_visual_definition(obj)
        if 'callbacks' in visualisation_definition:
            for callback in visualisation_definition['callbacks']:
                callback_return = callback(obj, self._context)
                if callback_return is not False:
                    return callback_return
        return visualisation_definition['default']

    def get_for_position(self, position, objects):
        if self._callback_position:
            return self._callback_position(position, objects, self._context)

    # TODO: fix bug: on doit mettre en cache dans self._objects_class_mapped le dict {default... et non pas le resultat<commit_msg>fix bug: ObjectVizualizer::get_for_position must return something<commit_after>from synergine.core.config.ConfigurationManager import ConfigurationManager
from synergine.synergy.object.SynergyObject import SynergyObject
from synergine.core.exception.NotFoundError import NotFoundError


class ObjectVisualizer():

    def __init__(self, config: dict, context):
        config_manager = ConfigurationManager(config)
        self._visualisation_configuration = config_manager.get('objects', {})
        self._objects_class_mapped = {}
        self._context = context
        self._callback_position = config_manager.get('callbacks.position', 0)

    def get_visual(self, obj: SynergyObject):
        visualisation_definition = self._get_visual_definition(obj)
        if 'callbacks' in visualisation_definition:
            for callback in visualisation_definition['callbacks']:
                callback_return = callback(obj, self._context)
                if callback_return is not False:
                    return callback_return
        return visualisation_definition['default']

    def get_for_position(self, position, objects):
        if self._callback_position:
            return self._callback_position(position, objects, self._context)
        return (None, [])

    # TODO: fix bug: on doit mettre en cache dans self._objects_class_mapped le dict {default... et non pas le resultat
{'fraction_non_alphanumeric': 0.07453874538745388, 'fraction_numerical': 0.0007380073800738007, 'mean_word_length': 3.587140439932318, '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': '516575', 'n_tokens_mistral': 699, 'n_tokens_neox': 660, 'n_words': 172}