Example #1
0
text = text.upper()
a2 = text_to_automaton(text, lambda x: x.isalpha(), 0)

regex = Choice(Automaton(a1), Automaton(a2))
wt3 = regex_to_wordtree(regex, 16)

text = text.lower() + text.upper()
a4 = determinize(
    remove_lambdas(text_to_automaton(text, lambda x: x.isalpha(), 0)))
wt4 = automaton_to_wordtree(a4, 16)

words = ['hello', 'this', 'can', 'world', '']
for word in words:
    print("a1 accepts '" + word + "' : " + str(a1.accepts(word)))

reg = Repeat(Concat(Automaton(a1), Concat(Range(digi), Range(digi))))
aut = regex_to_automaton(reg)
aut = determinize(remove_lambdas(aut))

wt = remove_empty_subtrees(automaton_to_wordtree(aut, 16))
print("wt can produce " + str(wt.wordscount) + " words.")

wt2 = automaton_to_wordtree(a1, 16)
print("wt2 can produce " + str(wt2.wordscount) + " words.")

print("wt3 can produce " + str(wt3.wordscount) + " words.")
print("wt4 can produce " + str(wt4.wordscount) + " words.")

for i in range(10):
    print(wt4.randomrun())
Example #2
0
autdet = determinize(autcopy)
for test in tests:
    print('autdet accepts \'' + test + '\' : ' + str(autdet.accepts(test)))
print('autdet is deterministic : ' + str(autdet.is_deterministic()))


testswt = [ 'a',    'b',
            'ab',   'aa',
            'abd',  'aba',  'aad',
            'abcd',
            'abdcc',
            'abdcdd',
            'acddddc'   ]
for i in range(8):
    wt = remove_empty_subtrees(automaton_to_wordtree(autdet, i))
    if wt == None:
        print("wt(" + str(i) + ") accepts no word")
    else:
        print("autdet to wt(" + str(i) + ") : " + str(wt.wordscount) + " words accepted")
        for test in testswt:
            print('wt(' + str(i) + ') accepts \'' + test + '\' : ' + str(wt.accepts(test)))
            

length = 8
wt = remove_empty_subtrees(automaton_to_wordtree(autdet, length))
for i in range(8):
    print("random run of wt(" + str(length) + ") : " + wt.randomrun())

# reg : ([a] . (([bd] | [c]))*)
# aut is deterministic : False
Example #3
0
print("a2 accepts 'a' : " + str(a2.accepts('a')))
print("a2 accepts 'aa' : " + str(a2.accepts('aa')))
print("a2 accepts 'b' : " + str(a2.accepts('b')))
print("a2 accepts '' : " + str(a2.accepts('')))

autdet = determinize(autcopy)
for test in tests:
    print('autdet accepts \'' + test + '\' : ' + str(autdet.accepts(test)))
print('autdet is deterministic : ' + str(autdet.is_deterministic()))

testswt = [
    'a', 'b', 'ab', 'aa', 'abd', 'aba', 'aad', 'abcd', 'abdcc', 'abdcdd',
    'acddddc'
]
for i in range(8):
    wt = remove_empty_subtrees(automaton_to_wordtree(autdet, i))
    if wt == None:
        print("wt(" + str(i) + ") accepts no word")
    else:
        print("autdet to wt(" + str(i) + ") : " + str(wt.wordscount) +
              " words accepted")
        for test in testswt:
            print('wt(' + str(i) + ') accepts \'' + test + '\' : ' +
                  str(wt.accepts(test)))

length = 8
wt = remove_empty_subtrees(automaton_to_wordtree(autdet, length))
for i in range(8):
    print("random run of wt(" + str(length) + ") : " + wt.randomrun())

# reg : ([a] . (([bd] | [c]))*)
Example #4
0
regex = Choice(Automaton(a1), Automaton(a2))
wt3 = regex_to_wordtree(regex, 16)

text = text.lower() + text.upper()
a4 = determinize(
        remove_lambdas(
            text_to_automaton(text, lambda x : x.isalpha(), 0)
        )
    )
wt4 = automaton_to_wordtree(a4, 16)

words = ['hello', 'this', 'can', 'world', '']
for word in words:
    print("a1 accepts '" + word + "' : " + str(a1.accepts(word)))
    
reg = Repeat(Concat(Automaton(a1), Concat(Range(digi), Range(digi))))
aut = regex_to_automaton(reg)
aut = determinize(remove_lambdas(aut))
    
wt = remove_empty_subtrees(automaton_to_wordtree(aut, 16))
print("wt can produce " + str(wt.wordscount) + " words.")

wt2 = automaton_to_wordtree(a1, 16)
print("wt2 can produce " + str(wt2.wordscount) + " words.")

print("wt3 can produce " + str(wt3.wordscount) + " words.")
print("wt4 can produce " + str(wt4.wordscount) + " words.")

for i in range(10):
    print(wt4.randomrun())