示例#1
0
文件: test2.py 项目: sbusard/MePGen
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())
示例#2
0
文件: test.py 项目: sbusard/MePGen
from mepgen.regex.regex import *
from mepgen.regex.transformation import regex_to_automaton
from mepgen.automaton.transformation import remove_lambdas, determinize, automaton_to_wordtree
from mepgen.wordtree.transformation import remove_empty_subtrees

# Checking determinism
reg = Concat(Range('a'), Repeat(Choice(Range('bd'), Range('c'))))
print("reg : " + str(reg))
aut = regex_to_automaton(reg)
print('aut is deterministic : ' + str(aut.is_deterministic()))

reg2 = Repeat(Concat(Range('a'), Range('b')))
print("reg2 : " + str(reg2))
aut2 = regex_to_automaton(reg2)
print('aut2 is deterministic : ' + str(aut2.is_deterministic()))

reg3 = Repeat(Choice(Range('a'), Range('b')))
print("reg3 : " + str(reg3))
aut3 = regex_to_automaton(reg3)
print('aut3 is deterministic : ' + str(aut3.is_deterministic()))

reg4 = Repeat(Range('a'))
print("reg4 : " + str(reg4))
aut4 = regex_to_automaton(reg4)
print('aut4 is deterministic : ' + str(aut4.is_deterministic()))

# Checking acceptance
tests = [
    'ab', 'ac', 'a', 'abcbc', 'accccc', 'abcc', 'cb', 'cac', 'acca',
    'abcbbcac', 'abcd', 'abce', 'ebbbb', ''
]
示例#3
0
from mepgen.automaton.transformation import reject_short_words, remove_lambdas
from mepgen.regex.regex import *
from mepgen.regex.transformation import regex_to_automaton

reg = Repeat(Range('a'))
aut = regex_to_automaton(reg)

tests = ['', 'a', 'b', 'aa', 'ab', 'ba', 'aaa', 'aaaa', 'aaaaa']
for test in tests:
    print("aut '{0}' : {1}".format(test, aut.accepts(test) and "accepting" or "not accepting"))
    
autrlw = reject_short_words(remove_lambdas(aut), 4)
for test in tests:
    print("autrlw '{0}' : {1}".format(test, autrlw.accepts(test) and "accepting" or "not accepting"))
示例#4
0
文件: test.py 项目: ancailliau/MePGen
from mepgen.regex.regex import *
from mepgen.regex.transformation import regex_to_automaton
from mepgen.automaton.transformation import remove_lambdas, determinize, automaton_to_wordtree
from mepgen.wordtree.transformation import remove_empty_subtrees
    
    
# Checking determinism
reg = Concat(Range('a'),Repeat(Choice(Range('bd'),Range('c'))))
print("reg : " + str(reg))
aut = regex_to_automaton(reg)
print('aut is deterministic : ' + str(aut.is_deterministic()))  

reg2 = Repeat(Concat(Range('a'),Range('b')))
print("reg2 : " + str(reg2))
aut2 = regex_to_automaton(reg2)
print('aut2 is deterministic : ' + str(aut2.is_deterministic()))

reg3 = Repeat(Choice(Range('a'),Range('b')))
print("reg3 : " + str(reg3))
aut3 = regex_to_automaton(reg3)
print('aut3 is deterministic : ' + str(aut3.is_deterministic()))

reg4 = Repeat(Range('a'))
print("reg4 : " + str(reg4))
aut4 = regex_to_automaton(reg4)
print('aut4 is deterministic : ' + str(aut4.is_deterministic()))


# Checking acceptance
tests = [   'ab',
            'ac',