예제 #1
0
def _test_english_rules(verbose=False):
    """A suite of tests for each morphology rule.
    """

    print
    print "Testing rules:"

    if _POSITIVE_CASES.keys() != _NEGATIVE_CASES.keys():
        sys.exit("ERROR english_rules.py: either missing positive or negative cases example to test")

    positive_morpho_input = _test_generate_morpho_input(_POSITIVE_CASES)
    negative_morpho_input = _test_generate_morpho_input(_NEGATIVE_CASES)

    morphopro_input = "\n".join(positive_morpho_input + [""] + negative_morpho_input)

    morphopro_output = morpho_pro.process(morphopro_input, base_filename="english_rules_text", overwrite=True)

    if len(morphopro_output) != len(_POSITIVE_CASES.keys() + _NEGATIVE_CASES.keys()):
        sys.exit("ERROR _test_english_rules(): morphopro output did not processing input correctly")

    if verbose:
        print "\tPOSITIVE: "

    pos_cases = len(_POSITIVE_CASES.keys())

    positive_test_results = _test_cases(_POSITIVE_CASES, morphopro_output[0:pos_cases], verbose=verbose)

    if verbose:
        print "\tNEGATIVE: ",

    negative_test_results = _test_cases(_NEGATIVE_CASES, morphopro_output[pos_cases:], verbose=verbose)

    # summarize and output. indicate if everything passed!
    print
    print "SUMMARY: "

    did_not_match = [rule for rule in positive_test_results if positive_test_results[rule] is False]
    did_match = [rule for rule in negative_test_results if negative_test_results[rule] is True]

    print "\tPOSITIVE: Passed {}/ Total {}".format(len(positive_test_results) - len(did_not_match), len(positive_test_results))

    if len(did_not_match):
        for no_match in did_not_match:
            print "\t\tPOSITIVE TEST FAILED: ({})".format(no_match)

    print "\tNEGATIVE: Passed {}/ Total {}".format(len(negative_test_results) - len(did_match), len(negative_test_results))

    if len(did_match):
        for match in did_match:
            print "\t\tNEGATIVE TEST FAILED: ({})".format(match)
def _test_english_rules(verbose=False):
    """A suite of tests for each morphology rule.
    """

    print
    print "Testing rules:"

    if _POSITIVE_CASES.keys() != _NEGATIVE_CASES.keys():
        sys.exit("ERROR english_rules.py: either missing positive or negative cases example to test")

    positive_morpho_input = _test_generate_morpho_input(_POSITIVE_CASES)
    negative_morpho_input = _test_generate_morpho_input(_NEGATIVE_CASES)

    morphopro_input = "\n".join(positive_morpho_input + [""] + negative_morpho_input)

    morphopro_output = morpho_pro.process(morphopro_input, base_filename="english_rules_text", overwrite=True)

    if len(morphopro_output) != len(_POSITIVE_CASES.keys() + _NEGATIVE_CASES.keys()):
        sys.exit("ERROR _test_english_rules(): morphopro output did not processing input correctly")

    if verbose:
        print "\tPOSITIVE: "

    pos_cases = len(_POSITIVE_CASES.keys())

    positive_test_results = _test_cases(_POSITIVE_CASES, morphopro_output[0:pos_cases], verbose=verbose)

    if verbose:
        print "\tNEGATIVE: ",

    negative_test_results = _test_cases(_NEGATIVE_CASES, morphopro_output[pos_cases:], verbose=verbose)

    # summarize and output. indicate if everything passed!
    print
    print "SUMMARY: "

    did_not_match = [rule for rule in positive_test_results if positive_test_results[rule] is False]
    did_match = [rule for rule in negative_test_results if negative_test_results[rule] is True]

    print "\tPOSITIVE: Passed {}/ Total {}".format(len(positive_test_results) - len(did_not_match), len(positive_test_results))

    if len(did_not_match):
        for no_match in did_not_match:
            print "\t\tPOSITIVE TEST FAILED: ({})".format(no_match)

    print "\tNEGATIVE: Passed {}/ Total {}".format(len(negative_test_results) - len(did_match), len(negative_test_results))

    if len(did_match):
        for match in did_match:
            print "\t\tNEGATIVE TEST FAILED: ({})".format(match)
from code.learning import english_rules

from code.notes.utilities.pre_processing import morpho_pro

print morpho_pro.process("he\nhad\nsaid")

# print english_rules._tests_active_voice()

# print english_rules._tests_passive_voice()

#print english_rules._tests_auxiliar()

# print english_rules._do_did()

# print english_rules._infinitive()

# english_rules._single_word_VP_test()

# english_rules._two_piece_VP()

# english_rules._prepart()

# english_rules._adjectives()

# english_rules._test_english_rules(verbose=True)

#from code.notes.utilities.pre_processing import morpho_pro

#corpus = "\n".join(["he","is","teaching"])

#print  corpus