<commit_before>import sys
sys.path.append('../..')

from functions import functions
import reparse

patterns_path = "patterns.yaml"
expressions_path = "expressions.yaml"
patterns = reparse.build_from_yaml(functions, expressions_path, patterns_path)


def parse(line):
    output = None
    highest_order = 0
    for pattern in patterns:
        results = pattern.findall(line)
        if results and any(results):
            if pattern.order > highest_order:
                output = results
                highest_order = pattern.order
    return output

print parse(' +974-584-5656 ')
print parse(' Fax: +974-584-5656 ')<commit_msg>Fix phone example<commit_after>import sys
sys.path.append('../..')

from functions import functions
import reparse

# If file was imported, include that path
path = ""
if '__file__' in globals():
    import os
    path = str(os.path.dirname(__file__)) + "/"

patterns_path = path + "patterns.yaml"
expressions_path = path + "expressions.yaml"
patterns = reparse.build_from_yaml(functions, expressions_path, patterns_path)


def parse(line):
    """
    >>> parse('+974-584-5656')
    [phone(area_code='974', prefix='584', body='5656', fax=False)]
    >>> parse('Fax: +974-584-5656')
    [phone(area_code='974', prefix='584', body='5656', fax=True)]
    """
    output = None
    highest_order = 0
    for pattern in patterns:
        results = pattern.findall(line)
        if results and any(results):
            if pattern.order > highest_order:
                output = results
                highest_order = pattern.order
    return output

if __name__ == "__main__":
    print parse(' +974-584-5656 ')
    print parse(' Fax: +974-584-5656 ')
{'fraction_non_alphanumeric': 0.12648456057007126, 'fraction_numerical': 0.048693586698337295, 'mean_word_length': 3.1097560975609757, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 11, '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': '7451138', 'n_tokens_mistral': 570, 'n_tokens_neox': 528, 'n_words': 132}