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

"""Extract date & time formatted using ISO 8601 format."""

import re
import datetime

from chronos.extractor.base import Extractor


class ISO8601Extractor(Extractor):
    """Extract date/time formatted in ISO 8601 standard."""

    def __init__(self, ref=None):
        super(ISO8601Extractor, self).__init__(ref)
        self.load_patterns()

    def load_patterns(self):
        """Load a list of possible patterns to check the text for.

        Patterns should be loaded in the longest first order
        so that text containing date & time are found before text containing
        just date.
        """
        # Using pattern from http://stackoverflow.com/a/8270148/1448
        self.pattern = re.compile(r"""(
                                        \d{4}\-\d\d\-\d\d  # date
                                        ([tT][\d:\.]*)?    # optional time
                                      )
                                   """, re.VERBOSE)

    def extract(self, text):
        """Extract ISO formatted dates and time."""
        result = []
        matches = self.pattern.findall(text)

        for match in matches:
            # Use the right strptime format to parse it
            if len(match[0]) == 10: # YYYY-MM-DD
                fmt = "%Y-%m-%d"
            elif len(match[0]) == 13: # YYYY-MM-DDThh<commit_msg>Move pattern into __init__method<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Extract date & time formatted using ISO 8601 format."""

import re
import datetime

from chronos.extractor.base import Extractor


class ISO8601Extractor(Extractor):
    """Extract date/time formatted in ISO 8601 standard."""

    def __init__(self, ref=None):
        super(ISO8601Extractor, self).__init__(ref)
        # Using pattern from http://stackoverflow.com/a/8270148/1448
        self.pattern = re.compile(r"""(
                                        \d{4}\-\d\d\-\d\d  # date
                                        ([tT][\d:\.]*)?    # optional time
                                      )
                                   """, re.VERBOSE)

    def extract(self, text):
        """Extract ISO formatted dates and time."""
        result = []
        matches = self.pattern.findall(text)

        for match in matches:
            # Use the right strptime format to parse it
            if len(match[0]) == 10: # YYYY-MM-DD
                fmt = "%Y-%m-%d"
            elif len(match[0]) == 13: # YYYY-MM-DDThh
{'fraction_non_alphanumeric': 0.12197059992054032, 'fraction_numerical': 0.027810885975367503, 'mean_word_length': 1.6421825813221407, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5696262', 'n_tokens_mistral': 755, 'n_tokens_neox': 694, 'n_words': 198}