<commit_before>#from lxml import etree as ET


class TransUnit(object):

    "Container for XLIFF trans-unit element"

    def __init__(self, argument):
        self.origin_unit = argument
        self.attributes = argument.attrib
        self.id = ''
        self.ns = ''
        self.state = ''

    @staticmethod
    def create(xml_tu):

        tunit = TransUnit(xml_tu)

        tunit.id = tunit.attributes['id']
        tunit.ns = tunit.__read_ns()
        tunit.state = tunit.__get_state_from_target()
        return tunit

    def __get_state_from_target(self):

        target = self.origin_unit.find('{}target'.format(self.ns))
        if "state" in target.attrib.keys():
            return target.attrib['state']
        else:
            return ''

    def __has_ns(self):
        return '{' in self.origin_unit.tag

    def __read_ns(self):
        if self.__has_ns():
            ns, tag = self.origin_unit.tag.split('}')
            ns = ns + '}'
            return ns
        else:
            return ''
<commit_msg>Restructure transUnit class for better readibility<commit_after>class TransUnit(object):

    "Container for XLIFF trans-unit element"

    def __init__(self, argument):
        self.origin_unit = argument
        self.attributes = argument.attrib
        self.id = ''
        self.ns = ''
        self.state = ''

    @staticmethod
    def create(xml_tu):

        tunit = TransUnit(xml_tu)

        tunit.id = tunit.attributes['id']
        tunit.ns = tunit._read_ns()
        tunit.state = tunit._get_state_from_target()
        return tunit

    def _read_ns(self):
        if self._has_ns():
            ns, tag = self.origin_unit.tag.split('}')
            ns = ns + '}'
            return ns
        else:
            return ''

    def _has_ns(self):
        return '{' in self.origin_unit.tag

    def _get_state_from_target(self):

        target = self.origin_unit.find('{}target'.format(self.ns))
        if "state" in target.attrib.keys():
            return target.attrib['state']
        else:
            return ''

{'fraction_non_alphanumeric': 0.11488124091129423, 'fraction_numerical': 0.0, 'mean_word_length': 1.9485714285714286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, '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': '2072825', 'n_tokens_mistral': 644, 'n_tokens_neox': 623, 'n_words': 131}