Ejemplo n.º 1
0
def main():
    if len(sys.argv) < 0:
        usage()
        sys.exit(1)
    
    fname_xpath = sys.argv[1]
    bare_name = fname_xpath[:-len(XPATH_EXT)]
    delta_fwd_fname = bare_name + FWD_EXT;
    delta_bk_fname = bare_name + BK_EXT;
    token_fname = bare_name + TOKENS_EXT;

    print fname_xpath
    qr = qtree.generate_query_tree(fname_xpath)
    nr, delta, no_states = nfa.gen_nfa_delta(qr)
    delta_fwd_table = nfa.gen_delta_table(nr, delta, no_states, qr)
    delta_bk_table = nfa.gen_delta_table(nr, delta, no_states, qr, False)

    write_table(delta_fwd_fname, delta_fwd_table)
    write_table(delta_bk_fname, delta_bk_table)
    write_token_file(token_fname, qtree.extract_token_list(qr))
Ejemplo n.º 2
0
import sys

import fa
import qtree
import qtree_nfa

UNKNOWN_TOKEN = '[u]'

fname_xpath = sys.argv[1]
fname_alpha = fname_xpath[:-5] + 'tokens'
fname_multi_dfa = fname_xpath[:-5] + 'mdfa'

query_list = list(qtree.query_list(fname_xpath))
qr = qtree.generate_query_tree(query_list)
nr = qtree_nfa.qtree2nfa(qr)
alphabet = nr.alphabet

file_header = [len(query_list), len(alphabet)]

sorted_alphabet = sorted(alphabet.difference(set([UNKNOWN_TOKEN])))
#alphabet_relabeling = dict(zip(sorted_alphabet, xrange(len(sorted_alphabet))))
#alphabet_relabeling[UNKNOWN_TOKEN] = len(sorted_alphabet)

f_alpha = open(fname_alpha, 'w')
for letter in sorted_alphabet:
    f_alpha.write('{0}\n'.format(letter))
f_alpha.close()

sorted_alphabet.append(UNKNOWN_TOKEN)

state_table = list()
import sys

import fa
import qtree
import qtree_nfa

UNKNOWN_TOKEN = '[u]'

fname_xpath = sys.argv[1]
fname_alpha = fname_xpath[:-5] + 'tokens'
fname_multi_dfa = fname_xpath[:-5] + 'mdfa'

query_list = list(qtree.query_list(fname_xpath))
qr = qtree.generate_query_tree(query_list)
nr = qtree_nfa.qtree2nfa(qr)
alphabet = nr.alphabet

file_header = [len(query_list), len(alphabet)]

sorted_alphabet = sorted(alphabet.difference(set([UNKNOWN_TOKEN])))
#alphabet_relabeling = dict(zip(sorted_alphabet, xrange(len(sorted_alphabet))))
#alphabet_relabeling[UNKNOWN_TOKEN] = len(sorted_alphabet)

f_alpha = open(fname_alpha, 'w')
for letter in sorted_alphabet:
    f_alpha.write('{0}\n'.format(letter))
f_alpha.close()

sorted_alphabet.append(UNKNOWN_TOKEN)

state_table = list()