Exemplo n.º 1
0
    file = f.read()
    test_sentences = file.split('\n')

# Build the parser with corpus_train
print('Building the parser...')
cyk_parser = CYK(corpus_train)
print('Done')

# Parsing of Evaluation sentences
print('Parsing...')

test_sentences_bis = []

with open('data/evaluation_data.parser.txt', 'w') as f:
    for sentence in test_sentences:
        parsed_sentence = cyk_parser.parse(sentence)
        if parsed_sentence is not None:
            test_sentences_bis.append(sentence)
            f.write('%s\n' % parsed_sentence)

print('Done')

# Get accuracy
# Get sentences parsed by our parser
with open('data/evaluation_data.parser.txt', 'r') as f:
    file = f.read()
    parsed_sentences = file.split('\n')

# Remove first two and last brackets to use parser from PYEVALB
initial_parsed_sentences = []
parsed_sentences_final = []
Exemplo n.º 2
0
# Building Parser
print("Building PCFG and Parser")
my_CYK_parser = CYK(corpus_train)
print("Done")

print("Start Parsing")

if args.test_sentence:
    sent = args.test_sentence
    print("#################")
    print("Sentence: ")
    print(sent + "\n")

    print("Parsing")
    my_parsing = my_CYK_parser.parse(sent)
    if my_parsing is None:
        print("Found no viable parsing.")
    else:
        print(my_parsing)

for sent in open(args.test_file):

    print("#################")
    print("Sentence: ")
    print(sent + "\n")

    print("Parsing")
    my_parsing = my_CYK_parser.parse(sent)
    if my_parsing is None:
        print("Found no viable parsing.")
Exemplo n.º 3
0
for idx_sentence in range(nb_test):

    print("##############################")

    real_parsing = real_parsings_test[idx_sentence]
    sent = sentences_test[idx_sentence]

    print("Sentence #" + str(idx_sentence))
    print(sent + "\n")

    print("Real Parsing")
    print(real_parsing + "\n")

    print("Our CYK Parsing")
    tic = time.time()
    my_parsing = my_CYK_parser.parse(sent, viz_oov=False)
    if my_parsing is None:
        print("Found no viable parsing.")
    else:
        print(my_parsing)
    tac = time.time()
    print("Done in " + str(round(tac - tic, 2)) + "sec\n")

    with open('results/evaluation_data.parser_output', 'a') as f:
        if my_parsing is None:
            f.write("Found no viable parsing." + "\n")
        else:
            f.write(my_parsing + "\n")

    if my_parsing is not None:
        # EVALPB works if we remove first and last brackets of the SEQUOIA format and the extra spaces that come with it