<commit_before>import logging
import os
from typing import Any, List, Text

from rasa_core.actions.action import ACTION_LISTEN_NAME

from rasa_core import utils
from rasa_core.domain import Domain
from rasa_core.policies.policy import Policy
from rasa_core.trackers import DialogueStateTracker
from rasa_core.constants import MAPPING_SCORE

logger = logging.getLogger(__name__)


class MappingPolicy(Policy):
    """Policy which maps intents directly to actions.

    Intents can be assigned actioins in the domain file which are to be
    executed whenever the intent is detected. This policy takes precedence over
    any other policy."""

    def __init__(self) -> None:
        """Create a new Mapping policy."""

        super(MappingPolicy, self).__init__()
        self.last_msg_id = None

    def train(self, *args, **kwargs) -> None:
        """Does nothing. This policy is deterministic."""

        pass

    def predict_action_probabilities(self,
                                     tracker: DialogueStateTracker,
                                     domain: Domain) -> List[float]:
        """Predicts the assigned action.

        If the current intent is assigned to an action that action will be
        predicted with the highest probability of all policies. If it is not
        the policy will predict zero for every action."""

        intent = tracker.latest_message.intent.get('name')
        msg_id = tracker.latest_message.message_id
        action_name = domain.intent_properties.get(intent, {}).get('triggers')

        prediction = [0.0] * domain.num_actions
        if msg_id != self.last_msg_id and action_name is not None:
            idx = domain.index_for_action(action_name)
            if idx is None:
                logger.warning("MappingPolicy tried to predict unkown action "
                               "'{}'".format(action_name))
            else:
                prediction[idx] = MAPPING_SCORE
            self.last_msg_id = msg_id
        return prediction

    def persist(self, *args) -> None:
        """Does nothing since there is no data to be saved."""

        pass

    @classmethod
    def load(cls, *args) -> 'MappingPolicy':
        """Just returns the class since there is no data to be loaded."""

        return cls()
<commit_msg>prediction now only based on state of tracker<commit_after>import logging
import os
from typing import Any, List, Text

from rasa_core.actions.action import ACTION_LISTEN_NAME, ACTION_RESTART_NAME

from rasa_core import utils
from rasa_core.domain import Domain
from rasa_core.policies.policy import Policy
from rasa_core.trackers import DialogueStateTracker
from rasa_core.constants import MAPPING_SCORE

logger = logging.getLogger(__name__)


class MappingPolicy(Policy):
    """Policy which maps intents directly to actions.

    Intents can be assigned actioins in the domain file which are to be
    executed whenever the intent is detected. This policy takes precedence over
    any other policy."""

    def __init__(self) -> None:
        """Create a new Mapping policy."""

        super(MappingPolicy, self).__init__()

    def train(self, *args, **kwargs) -> None:
        """Does nothing. This policy is deterministic."""

        pass

    def predict_action_probabilities(self, tracker: DialogueStateTracker,
                                     domain: Domain) -> List[float]:
        """Predicts the assigned action.

        If the current intent is assigned to an action that action will be
        predicted with the highest probability of all policies. If it is not
        the policy will predict zero for every action."""

        prediction = [0.0] * domain.num_actions
        if tracker.latest_action_name == ACTION_LISTEN_NAME:
            intent = tracker.latest_message.intent.get('name')
            action = domain.intent_properties.get(intent, {}).get('triggers')
            if action:
                idx = domain.index_for_action(action)
                if idx is None:
                    logger.warning("MappingPolicy tried to predict unkown "
                                   "action '{}'.".format(action))
                else:
                    prediction[idx] = MAPPING_SCORE
        return prediction

    def persist(self, *args) -> None:
        """Does nothing since there is no data to be saved."""

        pass

    @classmethod
    def load(cls, *args) -> 'MappingPolicy':
        """Just returns the class since there is no data to be loaded."""

        return cls()

{'fraction_non_alphanumeric': 0.07799689785065367, 'fraction_numerical': 0.0008863283846665189, 'mean_word_length': 2.466973886328725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3851971', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1142, 'n_words': 423}