示例#1
0
文件: test2.py 项目: sbusard/MePGen
#punc = '@&"\'(§!)-$,;:=<#°_*%£?./+>{}€[]'
punc = '\'"()[]{}.,;:-@&'

text = text.lower()
a1 = text_to_automaton(text, lambda x: x.isalpha(), 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.")
示例#2
0
s0.add_successor('c', s1)
s0.add_successor('b', s3)
s0.add_successor('d', s5)

s1.add_successor('a', s2)

s3.add_successor('a', s4)
s3.add_successor('b', s4)

s5.add_successor('d', s6)


aut = Automaton(s0, set([s4,s6]))
aut = determinize(remove_lambdas(aut))

wt = automaton_to_wordtree(aut, 2)
#wt = remove_empty_subtrees(wt)

#   >s0 -a,c>   s1  -a>     (s2)
#   4           1           1
#       a:1/4       a:1
#       c:1/4
#       -b>     s3  -a,b>   (s4)
#               2           1
#       b:1/2       a:1/2
#                   b:1/2

# aa -> 1/4
# ca -> 1/4
# ba -> 1/4
# bb -> 1/4
示例#3
0
文件: test.py 项目: ancailliau/MePGen
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
示例#4
0
文件: test.py 项目: sbusard/MePGen
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]))*)
示例#5
0
text = text.lower()
a1 = text_to_automaton(text, lambda x : x.isalpha(), 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.")