<commit_before>from pysb import *
from pysb import ReactionPattern, ComplexPattern, ComponentDuplicateNameError
from collections import namedtuple
import textwrap

BoundCondition = namedtuple('BoundCondition', ['agent', 'is_bound'])

class Agent(object):

    def __init__(self, name, mods=None, mod_sites=None, active=None,
                 bound_conditions=None, db_refs=None):
        self.name = name

        if mods is None:
            self.mods = []
        else:
            self.mods = mods

        if mod_sites is None:
            self.mod_sites = []
        else:
            self.mod_sites = mod_sites

        if bound_conditions is None:
            self.bound_conditions = []
        else:
            self.bound_conditions = bound_conditions

        self.active = active

        if db_refs is None:
            self.db_refs = {}
        else:
            self.db_refs = db_refs

    def matches(self, other):
        # FIXME: Check db_refs!!!
        if not (self.name == other.name and \
                set(self.mods) == set(other.mods) and \
                set(self.mod_sites) == set(other.mod_sites) and \
                self.active == other.active and \
                len(self.bound_conditions) == len(other.bound_conditions)):
            return False

        # Check for corresponding bound_condition in the other Agent
        sorted_other_bcs = sorted(other.bound_conditions,
                                  key=lambda x: x.agent.name)
        # Check the state of all the Agents that the Agents are bound to
        for bc_ix, bc in enumerate(sorted(self.bound_conditions,
                                          key=lambda x: x.agent.name)):
            if not (bc.agent.matches(sorted_other_bcs[bc_ix].agent) and \
                    bc.is_bound == sorted_other_bcs[bc_ix].is_bound):
                # A mismatch!
                return False

        # Everything checks out, the two Agents match
        return True

    def matches_key(self):
        key = self.name
        key += str(set(self.mods))
        key += str(set(self.mod_sites))
        key += str(self.active)
        key += str(len(self.bound_conditions))
        key += ''.join(['%s%s' % (bc.agent.name, bc.is_bound)
                        for bc in sorted(self.bound_conditions,
                                         key=lambda x: x.agent.name)])
        return key

    def entity_matches_key(self):
        key = self.name
        return key

    def entity_matches(self, other):
        return self.entity_matches_key() == other.entity_matches_key()

    def __repr__(self):
        attr_strs = []
        if self.mods:
            attr_strs.append('mods: %s' % self.mods)
        if self.mod_sites:
            attr_strs.append('mod_sites: %s' % self.mod_sites)
        if self.active:
            attr_strs.append('active: %s' % self.active)
        if self.bound_conditions:
            attr_strs += ['bound: [%s, %s]' % (b.agent.name, b.is_bound)
                          for b in self.bound_conditions]
        if self.db_refs:
            attr_strs.append('db_refs: %s' % self.db_refs)
        attr_str = ', '.join(attr_strs)
        return '%s(%s)' % (self.name, attr_str)


class Evidence(object):
    """Container for evidence supporting a given statement.

    Attributes
    ----------
    source_api : string or None
        String identifying the INDRA API used to capture the statement,
        e.g., 'trips', 'biopax', 'bel'.
    source_id : string or None
        For statements drawn from databases, ID of the database entity
        corresponding to the statement.
    pmid : string or None
        String indicating the Pubmed ID of the source of the statement.
    text : string
        Natural language text supporting the statement.
    annotations : list
        List containing additional information on the context of the statement,
        e.g., species, cell line, tissue type, etc. The entries may vary
        depending on the source of the information.
    epistemics : string
        An identifier describing the epistemic certainty associated with the
        statement.
    """

    def __init__(self, source_api=None, source_id=None, pmid=None, text=None,
                 annotations=None, epistemics=None):
        self.source_api = source_api
        self.source_id = source_id
        self.pmid = pmid
        self.text = text
        if annotations:
            self.annotations = annotations
        else:
            self.annotations = []
        self.epistemics = epistemics

    def __str__(self):
        print_text = '' if self.text is None else self.text.encode('utf-8')
        ev_str = 'Evidence(%s, %s, %s, %s)' % \
                 (self.source_api, self.pmid, self.annotations,
                  print_text)
        return ev_str

    def __repr__(self):<commit_msg>Fix evidence printing with mixed unicode and non-unicode strings<commit_after>from pysb import *
from pysb import ReactionPattern, ComplexPattern, ComponentDuplicateNameError
from collections import namedtuple
import textwrap

BoundCondition = namedtuple('BoundCondition', ['agent', 'is_bound'])

class Agent(object):

    def __init__(self, name, mods=None, mod_sites=None, active=None,
                 bound_conditions=None, db_refs=None):
        self.name = name

        if mods is None:
            self.mods = []
        else:
            self.mods = mods

        if mod_sites is None:
            self.mod_sites = []
        else:
            self.mod_sites = mod_sites

        if bound_conditions is None:
            self.bound_conditions = []
        else:
            self.bound_conditions = bound_conditions

        self.active = active

        if db_refs is None:
            self.db_refs = {}
        else:
            self.db_refs = db_refs

    def matches(self, other):
        # FIXME: Check db_refs!!!
        if not (self.name == other.name and \
                set(self.mods) == set(other.mods) and \
                set(self.mod_sites) == set(other.mod_sites) and \
                self.active == other.active and \
                len(self.bound_conditions) == len(other.bound_conditions)):
            return False

        # Check for corresponding bound_condition in the other Agent
        sorted_other_bcs = sorted(other.bound_conditions,
                                  key=lambda x: x.agent.name)
        # Check the state of all the Agents that the Agents are bound to
        for bc_ix, bc in enumerate(sorted(self.bound_conditions,
                                          key=lambda x: x.agent.name)):
            if not (bc.agent.matches(sorted_other_bcs[bc_ix].agent) and \
                    bc.is_bound == sorted_other_bcs[bc_ix].is_bound):
                # A mismatch!
                return False

        # Everything checks out, the two Agents match
        return True

    def matches_key(self):
        key = self.name
        key += str(set(self.mods))
        key += str(set(self.mod_sites))
        key += str(self.active)
        key += str(len(self.bound_conditions))
        key += ''.join(['%s%s' % (bc.agent.name, bc.is_bound)
                        for bc in sorted(self.bound_conditions,
                                         key=lambda x: x.agent.name)])
        return key

    def entity_matches_key(self):
        key = self.name
        return key

    def entity_matches(self, other):
        return self.entity_matches_key() == other.entity_matches_key()

    def __repr__(self):
        attr_strs = []
        if self.mods:
            attr_strs.append('mods: %s' % self.mods)
        if self.mod_sites:
            attr_strs.append('mod_sites: %s' % self.mod_sites)
        if self.active:
            attr_strs.append('active: %s' % self.active)
        if self.bound_conditions:
            attr_strs += ['bound: [%s, %s]' % (b.agent.name, b.is_bound)
                          for b in self.bound_conditions]
        if self.db_refs:
            attr_strs.append('db_refs: %s' % self.db_refs)
        attr_str = ', '.join(attr_strs)
        return '%s(%s)' % (self.name, attr_str)


class Evidence(object):
    """Container for evidence supporting a given statement.

    Attributes
    ----------
    source_api : string or None
        String identifying the INDRA API used to capture the statement,
        e.g., 'trips', 'biopax', 'bel'.
    source_id : string or None
        For statements drawn from databases, ID of the database entity
        corresponding to the statement.
    pmid : string or None
        String indicating the Pubmed ID of the source of the statement.
    text : string
        Natural language text supporting the statement.
    annotations : list
        List containing additional information on the context of the statement,
        e.g., species, cell line, tissue type, etc. The entries may vary
        depending on the source of the information.
    epistemics : string
        An identifier describing the epistemic certainty associated with the
        statement.
    """

    def __init__(self, source_api=None, source_id=None, pmid=None, text=None,
                 annotations=None, epistemics=None):
        self.source_api = source_api
        self.source_id = source_id
        self.pmid = pmid
        self.text = text
        if annotations:
            self.annotations = annotations
        else:
            self.annotations = []
        self.epistemics = epistemics

    def __str__(self):
        ev_str = u'Evidence(%s, %s, %s, %s)' % \
                 (self.source_api, self.pmid, self.annotations,
                  self.text)
        return ev_str.encode('utf-8')

    def __repr__(self):
{'fraction_non_alphanumeric': 0.09382435088445226, 'fraction_numerical': 0.00020688941760628945, 'mean_word_length': 1.9085439229843562, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3783910', 'n_tokens_mistral': 2799, 'n_tokens_neox': 2664, 'n_words': 754}