コード例 #1
0
    def test_truncation(self):
        s = []

        try:
            self.assertEqual("".join(self.f2.transduce(x for x in "a33333")),
                             "a333")
        except:
            s.append(1)
        print "trace 6:"
        trace(self.f2, "a33333")
        try:
            self.assertEqual("".join(self.f2.transduce(x for x in "123456")),
                             "123")
        except:
            s.append(2)
        print "trace 7:"
        trace(self.f2, "123456")
        try:
            self.assertEqual("".join(self.f2.transduce(x for x in "11")), "11")
        except:
            s.append(3)
        print "trace 8:"
        trace(self.f2, "11")
        try:
            self.assertEqual("".join(self.f2.transduce(x for x in "5")), "5")
        except:
            s.append(4)
        print "trace 9:"
        trace(self.f2, "5")

        print '\nNumber of failed truncation tests:', str(len(s))
        if len(s) != 0:
            print 'Failed truncation tests:', ','.join([str(x) for x in s])
コード例 #2
0
    def test_padding(self):
        s = []
        print 'trace padding 1:'
        trace(self.f3, "b1114")

        try:
            self.assertEqual("".join(self.f3.transduce(x for x in "3")), "300")
        except:
            s.append(1)
        print 'trace padding 2:'
        trace(self.f3, "300")
        try:
            self.assertEqual("".join(self.f3.transduce(x for x in "b56")),
                             "b560")
        except:
            s.append(2)
        print 'trace padding 3:'
        trace(self.f3, "b560")
        try:
            self.assertEqual("".join(self.f3.transduce(x for x in "c111")),
                             "c111")
        except:
            s.append(3)

        print '\nNumber of failed padding tests:', str(len(s))
        if len(s) != 0:
            print 'Failed padding tests:', ','.join([str(x) for x in s])
コード例 #3
0
    def test_letters(self):
        s = []
        try:
            self.assertEqual(
                "".join(self.f1.transduce(x for x in "washington")), "w25235")
        except:
            s.append(1)
        print "trace 1:"
        trace(self.f1, "washington")
        try:
            self.assertEqual(
                "".join(self.f1.transduce(x for x in "jefferson")), "j1625")
        except:
            s.append(2)
        print "trace 2:"
        trace(self.f1, "jefferson")
        try:
            self.assertEqual("".join(self.f1.transduce(x for x in "adams")),
                             "a352")
        except:
            s.append(3)
        print "trace 3:"
        trace(self.f1, "adams")
        try:
            self.assertEqual("".join(self.f1.transduce(x for x in "bush")),
                             "b2")
        except:
            s.append(4)

        print '\nNumber of failed letters tests:', str(len(s))
        if len(s) != 0:
            print 'Failed letters tests:', ','.join([str(x) for x in s])
コード例 #4
0
    return f3


if __name__ == '__main__':
    #print "Enter a Name"
    user_input = raw_input().strip()
    f1 = letters_to_numbers()
    f2 = truncate_to_three_digits()
    f3 = add_zero_padding()

    if user_input:
        print("%s -> %s" %
              (user_input, composechars(tuple(user_input), f1, f2, f3)))

    print "------------ Tracing --------------------"
    print "---------STEP 1-------------"
    print trace(f1, user_input)
    step1 = composechars(tuple(user_input), f1)
    print step1

    print "----------STEP 2------------"
    print trace(f2, step1)
    step2 = composechars(tuple(step1), f2)
    print step2

    print "----------STEP 3------------"
    print trace(f3, step2)
    step3 = composechars(tuple(step2), f3)
    print step3
コード例 #5
0
ファイル: fsm_tp.py プロジェクト: pratcooper/NLP
        _ = f.add_arc('1', '1', (letter), (letter))
# Evaluate it on some example words
print ''.join(f.transduce(['v', 'o', 'w', 'e', 'l']))
print ''.join(f.transduce('e x c e p t i o n'.split()))
print ''.join(f.transduce('c o n s o n a n t'.split()))

print f.transduce(['a','w'])

from fsmutils import composechars
S = "vowels"
output = composechars(S, f, f, f)

print output

from fsmutils import trace
trace(f, S)


# Add the rest of the arcs
f1 = fst.FST('new')
# All we need is a single state ...
f1.add_state('start')
f1.add_state('next')
# and this same state is the initial and the nal state
f1.initial_state = 'start'
f1.set_final('next')

cnt = 0
for letter in string.ascii_lowercase:
    if cnt == 0:
        f1.add_arc('start', 'next', (letter), (letter))
コード例 #6
0
# import the string module
import string
from fsmutils import trace

# define a list of all vowels for convenience
vowels = ['a','e','i','o','u']

# Instantiate an FST object with some name
f = fst.FST('devowelizer')

# All we need is a single state
f.add_state('1')

# and this same state is the initial and final state
f.initial_state = '1'
f.set_final('1')

# Now, we need to add an arc for each letter; if the letter is a vowel 
# then the transition outputs nothing but otherwise it outputs the same 
# letter that it consumed
for letter in string.ascii_lowercase:
	if letter in vowels:
		f.add_arc('1','1',(letter),())
	else:
		f.add_arc('1','1',(letter),(letter))

# Evaluate it on same example words
print ''.join(f.transduce(['v','o','w','e','l']))
print ''.join(f.transduce('e x c e p t i o n'.split()))
print trace(f,'b a n a n a')
コード例 #7
0
# import the fst module
import fst
from fsmutils import trace
# import the string module
import string
vowels = ['a', 'e', 'i', 'o', 'u']
# Instantiate an FST object with some name
f = fst.FST('devowelizer')
# All we need is a single state ...
f.add_state('1')
# and this same state is the initial and the nal state
f.initial_state = '1'
f.set_final('1')
# Now, we need to add an arc for each letter; if the letter is a vowel
# then the transition outputs nothing but otherwise it outputs the same
# letter that it consumed.
for letter in string.ascii_lowercase:
    if letter in vowels:
        _ = f.add_arc('1', '1', (letter), ())
    else:
        _ = f.add_arc('1', '1', (letter), (letter))
# Evaluate it on some example words
print ''.join(f.transduce(['v', 'o', 'w', 'e', 'l']))
print ''.join(f.transduce('e x c e p t i o n'.split()))
print ''.join(f.transduce('c o n s o n a n t'.split()))
print trace(f, 'e x c e p t i o n'.split())
コード例 #8
0
Created on Fri Sep 08 11:21:21 2017

@author: SHILPASHREE RAO
"""

import string
import sys
from fst import FST
from fsmutils import trace

vowels = ['a', 'e', 'i', 'o', 'u']

f = FST('devowelizer')

f.add_state('1')

f.initial_state = '1'
f.set_final('1')

for letter in string.ascii_lowercase:
    if letter in vowels:
        _ = f.add_arc('1', '1', (letter), ())
    else:
        _ = f.add_arc('1', '1', (letter), (letter))

print ''.join(f.transduce(['v', 'o', 'w', 'e', 'l']))
print ''.join(f.transduce('e x c e p t i o n'.split()))
print ''.join(f.transduce('c o n s o n a n t'.split()))

t = trace(f, ['v', 'o', 'w', 'e', 'l'])
print t
コード例 #9
0
    f.add_arc('900', '2', ('7'), ['soixante'])
    f.add_arc('900', '70', ('7'), ['soixante'])
    f.add_arc('900', '2a', ('7'), ['soixante'])

    f.add_arc('900', '1a', ('8'), ['quatre vingt'])

    f.add_arc('900', '2', ('9'), ['quatre vingt'])
    f.add_arc('900', '2a', ('9'), ['quatre vingt'])

    return f


if __name__ == '__main__':
    string_input = raw_input()
    user_input = int(string_input)
    f = french_count()
    if string_input:
        print user_input, '-->',
        print " ".join(f.transduce(prepare_input(user_input)))
        print " ".join(f.transduce(prepare_input(000)))
        print " ".join(f.transduce(prepare_input(16)))
        print " ".join(f.transduce(prepare_input(103)))
        print " ".join(f.transduce(prepare_input(104)))
        print " ".join(f.transduce(prepare_input(94)))
        print " ".join(f.transduce(prepare_input(95)))
        print " ".join(f.transduce(prepare_input(96)))
        print " ".join(f.transduce(prepare_input(97)))
        print " ".join(f.transduce(prepare_input(98)))
        print " ".join(f.transduce(prepare_input(99)))
        print(trace(f, str(user_input)))
コード例 #10
0
    # for 160 to 169
    f.add_arc('100', '60', str(6), [kFRENCH_TRANS[60]])

    # for 170 to 179
    f.add_arc('100', '70', str(7), [kFRENCH_TRANS[60]])

    # for 180 to 189
    f.add_arc('100', '80', str(8), [kFRENCH_TRANS[4]])

    # for 190 to 199
    f.add_arc('100', '90', str(9), [kFRENCH_TRANS[4]])

    #for 200 to 999
    for i in xrange(2, 10):
        f.add_arc('s', '100', str(i),
                  [kFRENCH_TRANS[i]] + [kFRENCH_TRANS[100]])

    return f


if __name__ == '__main__':
    string_input = raw_input()
    user_input = int(string_input)
    f = french_count()
    if string_input:
        print user_input, '-->',
        print " ".join(f.transduce(prepare_input(user_input)))

        from fsmutils import trace
        trace(f, prepare_input(100))
コード例 #11
0
            # When 4 in tenth and 9 in unit place
            f.add_arc('tenth_4', 'unit', [str(num)], [' ' + kFRENCH_TRANS[9]])
            # When 5 in tenth and 9 in unit place
            f.add_arc('tenth_5', 'unit', [str(num)], [' ' + kFRENCH_TRANS[9]])
            # When 6 in tenth and 9 in unit place
            f.add_arc('tenth_6', 'unit', [str(num)], [' ' + kFRENCH_TRANS[9]])
            # When 7 in tenth and 9 in unit place
            f.add_arc('tenth_7', 'unit', [str(num)],
                      [' ' + kFRENCH_TRANS[10] + ' ' + kFRENCH_TRANS[9]])
            # When 8 in tenth and 9 in unit place
            f.add_arc('tenth_8', 'unit', [str(num)], [' ' + kFRENCH_TRANS[9]])
            # When 9 in tenth and 9 in unit place
            f.add_arc('tenth_9', 'unit', [str(num)],
                      [' ' + kFRENCH_TRANS[10] + ' ' + kFRENCH_TRANS[9]])
            pass

        f.add_arc('tenth_0', 'unit', [str(num)], [kFRENCH_TRANS[num]])


# Larry, Chealsea - recruiter, Utkarsh SE

    return f

f = french_count()
print prepare_input(134)
n = 70
for n in range(0, 100):
    print "".join(f.transduce(prepare_input(n)))
print "".join(f.transduce(prepare_input(n)))
trace(f, prepare_input(n))