<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import Reactor
from Events import Event
from Policy import PolicyRuleset



class Agent:
    """This class represents something that generates Events.
    
    When receiving an event with an Agent associated,
    call acquire to show your interest. If you are an 
    application, you may call complete directly.
    
    If you are a recognizer call complete when you have
    fully recognized a gesture. For symbolic gestures 
    this means at the end of the recognition. For continuous
    gestures, you may call complete directly instead of
    acquire, as you know that anything is ypur gesture.
    
    Whenever you feel that you don't need this agent
    anymore, call discard AS EARLY AS POSSIBLE.
    
    Recognizers must call these through their own helpers
    in the class Recognizer.
    """
    #Policy on whenever a confirmed recognizer can be failed by a new recognizer confirming
    completion_policy = PolicyRuleset()
    #Policy on whenever one gesture can be confirmed while another can be aquired (for instance when a continuous gesture can
    #finish another gesture to complete.
    compatibility_policy = PolicyRuleset()
    
    def __init__(self,eventnames,creator):
        """eventnames is a list of names that will become member events.
        creator is a class or instance with newAgent event to be called when recycling this agent."""
        self.recognizers_acquired = []
        self.recognizer_complete = None
        self.events = {}
        self.owners = []
        self.newAgent = creator.newAgent
        #is this agent having a confirmed recognizer?
        self.completed = False
        #is this agent recycled?
        self.recycled = False
        self.finished = False
        for ename in list(eventnames)+["finishAgent"]:
            self.events[ename]=Event()
            setattr(self,ename,self.events[ename])
        
    def acquire(self,Recognizer):
        "The recognizer is interested on this agent"
        #can we acquire even if there is someone confirmed?
        if self.completed and self.compatibility_policy.result(self.recognizer_complete,Recognizer) != True:
            return False
        else:
            self.recognizers_acquired.append(Recognizer)
            return True
    
    def finish(self):
        "The owner of the event will not generate more events"<commit_msg>self.finished was never set<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import Reactor
from Events import Event
from Policy import PolicyRuleset



class Agent:
    """This class represents something that generates Events.
    
    When receiving an event with an Agent associated,
    call acquire to show your interest. If you are an 
    application, you may call complete directly.
    
    If you are a recognizer call complete when you have
    fully recognized a gesture. For symbolic gestures 
    this means at the end of the recognition. For continuous
    gestures, you may call complete directly instead of
    acquire, as you know that anything is ypur gesture.
    
    Whenever you feel that you don't need this agent
    anymore, call discard AS EARLY AS POSSIBLE.
    
    Recognizers must call these through their own helpers
    in the class Recognizer.
    """
    #Policy on whenever a confirmed recognizer can be failed by a new recognizer confirming
    completion_policy = PolicyRuleset()
    #Policy on whenever one gesture can be confirmed while another can be aquired (for instance when a continuous gesture can
    #finish another gesture to complete.
    compatibility_policy = PolicyRuleset()
    
    def __init__(self,eventnames,creator):
        """eventnames is a list of names that will become member events.
        creator is a class or instance with newAgent event to be called when recycling this agent."""
        self.recognizers_acquired = []
        self.recognizer_complete = None
        self.events = {}
        self.owners = []
        self.newAgent = creator.newAgent
        #is this agent having a confirmed recognizer?
        self.completed = False
        #is this agent recycled?
        self.recycled = False
        self.finished = False
        for ename in list(eventnames)+["finishAgent"]:
            self.events[ename]=Event()
            setattr(self,ename,self.events[ename])
        
    def acquire(self,Recognizer):
        "The recognizer is interested on this agent"
        #can we acquire even if there is someone confirmed?
        if self.completed and self.compatibility_policy.result(self.recognizer_complete,Recognizer) != True:
            return False
        else:
            self.recognizers_acquired.append(Recognizer)
            return True
    
    def finish(self):
        "The owner of the event will not generate more events"
        self.finished = True
{'fraction_non_alphanumeric': 0.05725425815719269, 'fraction_numerical': 0.0004104247896572953, 'mean_word_length': 2.6896290688872067, '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': '732132', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1188, 'n_words': 528}