Beispiel #1
0
def name_open():
    global root_home
    root_home.destroy()
    na.name()
Beispiel #2
0
 def test3(self):
     self.assertEqual(name.name('11 11', '-6.7'), '11 11 -6.7')
 def test_int_name(self):
     first = "Kyle"
     last = 1
     with self.assertRaises(TypeError):
         name(first, last)
Beispiel #4
0
 def test2(self):
     self.assertEqual(name.name("two", "one"),"two one")
Beispiel #5
0
 def test4(self):
     self.assertEqual(name.name("John Jesus", "Perez Almejo De La Cruz"), "John Jesus Perez Almejo De La Cruz")
Beispiel #6
0
 def test_name_1(self):
     self.assertEqual(name.name("Steve", "Johnson"), "Steve Johnson")
Beispiel #7
0
 def test_name1(self):
     self.assertEqual(name.name("Joy", "Zhang"), "Joy Zhang")
     self.assertEqual(name.name("Vivian", "Song"), "Vivian Song")
 def randomize(self):
     common.usedRandomize()
     self.value = name()
     self.value.randomize()
Beispiel #9
0
 def test_nameInvalid(self):
   self.assertEqual(name(5, "test"), None)
Beispiel #10
0
 def test_1(self):
     self.assertEqual(name.name("hi", 3), 1)
Beispiel #11
0
 def test_2(self):
     self.assertEqual(name.name(2, 4), 1)
Beispiel #12
0
 def test_4(self):
     self.assertEqual(name.name("Katie", "Holmes"), "KatieHolmes")
Beispiel #13
0
 def test2(self):
     self.assertEqual(name.name('Billy', 'Bob'), 'Jane Doe')
Beispiel #14
0
 def test1(self):
     self.assertEqual(name.name('Matthew', 'Gragg'), 'Matthew Gragg')
Beispiel #15
0
 def test_name_2(self):
     self.assertEqual(name.name(), "")
Beispiel #16
0
 def test_name(self):
   self.assertEqual(name("Nathan", "Liu"), "Nathan Liu")
Beispiel #17
0
 def test_name_3(self):
     self.assertEqual(name.name("Josh", 9), "Josh 9")
Beispiel #18
0
 def test_nameEmpty(self):
   self.assertEqual(name("Nathan", ""), None)
Beispiel #19
0
 def test_name3(self):
     self.assertEqual(name.name("Joe", 6), "Error")
     self.assertEqual(name.name(5, 6), "Error")
Beispiel #20
0
# InvertImage(name(), cv2.imread(name(), 0))
# exit()

# INITIALISATION
border_lookup = {3, 6, 7, 12, 14, 15, 24, 28, 30, 31, 48, 56, 60, 62,63, 96, 112, 120, 124, 126, 127, 129, 131, 135, 143, 159, 191, 192, 193, 195, 199, 207, 223, 224, 225,227, 231, 239, 240, 241, 243, 247, 248, 249, 251,252, 253, 254,}
phase1_lookup = {7, 14, 28, 56, 112, 131, 193, 224}
phase2_lookup = {7, 14, 15, 24, 28, 30, 48, 56, 60, 112, 120, 131,135, 192, 193, 195, 224, 225, 240}
phase3_lookup = {7, 14, 15, 28, 30, 31, 56, 60, 62, 112, 120, 124, 131, 135, 143, 193, 195, 199, 224, 225, 227, 240, 241, 248}
phase4_lookup = {7, 14, 15, 28, 30, 31, 56, 60, 62, 63, 112, 120, 124, 126, 131, 135, 143, 159, 193, 195, 199, 207, 224, 225, 227, 231, 240, 241, 243, 248, 249, 252}
phase5_lookup = {3, 6, 7, 12, 14, 15, 24, 28, 30, 31, 48, 56, 60, 62, 63, 96, 112, 120, 124, 126, 127, 129, 131, 135, 143, 159, 191, 192, 193, 195, 199, 207, 223,224, 225, 227, 231, 239, 240, 241, 243, 247, 248, 249, 251, 252, 253, 254}
one_pixel_lookup = {2, 5, 13, 20, 21, 22, 32, 48, 52, 54, 65, 67,69, 80, 81, 84, 88, 97, 99, 128, 133, 141, 208, 216}
lookup_arrays = [phase1_lookup, phase2_lookup, phase3_lookup, phase4_lookup, phase5_lookup]
change = True

# BACKGROUND = 0, FOREGROUND = 1
image = cv2.imread(name(), 0)
n, m = len(image), len(image[0])
image[image<=128] = 0
image[image>128] = 255
image[image==255] = 1

start = time.time()
iteration = 1
while change and iteration<100:
	change = False

	# IDENTIFYING BORDER PIXELS (Phase 0)
	borders = set()
	for i in range(n):
		for j in range(m):
			wt = CalculateWeight(i, j, image)
Beispiel #21
0
 def test_name2(self):
     self.assertEqual(name.name("1", "3"), "1 3")
     self.assertEqual(name.name("a", "b"), "a b")
Beispiel #22
0
 def test_whole_name(self):
     first = "Kyle"
     last = "Huang"
     self.assertEqual(name(first, last), "Kyle Huang")
Beispiel #23
0
 def test3(self):
     self.assertEqual(name.name("1", "2"), "1 2")
Beispiel #24
0
 def test_no_first(self):
     first = ""
     last = "Huang"
     self.assertEqual(name(first, last), " Huang")
Beispiel #25
0
    def DFA(self,string,result):
        self.build_bianma()
        state = 'state0'
        tmp = ''
        while len(string)>0:
            if string[0] == ' ' or string[0] == '\n' or string[0] == '\t':
                if state == 'state0':
                    string = string[1:]
                elif state == 'Char':
                    if string[0] == ' ':
                        tmp += string[0]
                        string[1:]
                    else:
                        print 'illegal char'
                        break
                elif state == 'sharp':
                    if string[0] == ' ':
                        tmp += string[0]
                        string = string[1:]
                    elif string[0] == '\n':
                        result.append((state,tmp))
                        string = string[1:]
                        state = 'state0'
                        tmp = ''
                    else:
                        print 'sharp error'
                        break
                elif state == 'string':
                    if string[0] == '/n':
                        print 'strint error'
                        break
                    else:
                        tmp += string[0]
                        string = string[1:]
                elif state == 'f_d':
                    result.append((50,int(tmp)))
                    tmp = ''
                    state = 'state0'
                    string = string[1:]
                elif state == 'float':
                    result.append((52,float(tmp)))
                    tmp = ''
                    state ='state0'
                    string = string[1:]
                elif state == 'v_k':
                    if tmp in self.keywords:
                        result.append((self.bianma[tmp],tmp))
                    else:
                        n = name(tmp)
                        self.names[tmp] = n
                        result.append((54,tmp))
                    state = 'state0'
                    tmp = ''
                    string = string[1:]


            else:
                if state == 'state0':
                    if string[0] in self.symbols:#handle symbols
                        result.append((self.bianma[string[0]],string[0]))
                        string = string[1:]
                    elif string[0] == "#":#handle sharp
                        state = "sharp"
                        string = string[1:]
                    elif string[0] == "'":#handle Char
                        state = 'Char'
                        string = string[1:]
                    elif string[0] == '"':#handle string
                        state = 'string'
                        string = string[1:]
                    elif string[0]  in self.numbers:#handle int and float
                        tmp += string[0]
                        state = 'f_d'
                        string = string[1:]
                    else:#handle var and key
                        state = 'v_k'
                        tmp += string[0]
                        string = string[1:]

                elif state == 'v_k':
                    if string[0] in self.symbols:
                        if tmp in self.keywords:
                            result.append((self.bianma[tmp],tmp))
                        else:
                            n = name(tmp)
                            self.names[tmp] = n
                            result.append((54,tmp))
                        state = 'state0'
                        tmp = ''
                    else:
                        tmp += string[0]
                        string = string[1:]
                elif state == 'float':
                    if string[0] in self.numbers:
                        tmp += string[0]
                        string = string[1:]
                    else:
                        result.append((52,float(tmp)))
                        tmp = ''
                        state = 'state0'

                elif state == 'f_d':
                    if string[0] in self.numbers:
                        if tmp[0] != '0':
                            tmp += string[0]
                            string = string[1:]
                        else:
                            print 'Int error'
                            break
                    elif string[0] == '.':
                        tmp += string[0]
                        state = 'float'
                        string = string[1:]
                    else:
                        result.append((50,int(tmp)))
                        state = 'state0'
                        tmp = ''


                elif state == 'string':
                    if string[0] == '"' and tmp[-1] != '\\':
                        result.append((51,tmp))
                        state = 'state0'
                        tmp = ''
                        string = string[1:]
                    else:
                        tmp += string[0]
                        string = string[1:]
                elif state == 'Char':
                    if string[0] == "'":
                        result.append((53,tmp))
                        tmp = ''
                        state = 'state0'
                        string = string[1:]
                    else:
                        if len(tmp) == 0:
                            tmp += string[0]
                            string = string[1:]
                        else:
                            if tmp == '\\' and string[0] in self.special:
                                tmp += string[0]
                                string = string[1:]
                            else:
                                print 'Char error'
                                break

                elif state == 'sharp':
                    tmp += string[0]
                    string = string[1:]

        with open('my_result','w') as f:
            for re in result:
                f.write(str(re[0])+','+str(re[1]))
                f.write('\n')

        with open('names','wb') as f:
            pickle.dump(self.names,f)
Beispiel #26
0
    def DFA(self,string,result):
        state = 'state0'
        tmp = ''
        while len(string)>0:
            if string[0] == ' ' or string[0] == '\n' or string[0] == '\t':
                if state == 'state0':
                    string = string[1:]
                elif state == 'Char':
                    if string[0] == ' ':
                        tmp += string[0]
                        string[1:]
                    else:
                        print 'illegal char'
                        break
                elif state == 'sharp':
                    if string[0] == ' ':
                        tmp += string[0]
                        string = string[1:]
                    elif string[0] == '\n':
                        result.append((state,tmp))
                        string = string[1:]
                        state = 'state0'
                        tmp = ''
                    else:
                        print 'sharp error'
                        break
                elif state == 'string':
                    if string[0] == '/n':
                        print 'strint error'
                        break
                    else:
                        tmp += string[0]
                        string = string[1:]
                elif state == 'f_d':
                    result.append(('Int',int(tmp)))
                    tmp = ''
                    state = 'state0'
                    string = string[1:]
                elif state == 'float':
                    result.append((state,float(tmp)))
                    tmp = ''
                    state ='state0'
                    string = string[1:]
                elif state == 'v_k':
                    if tmp in self.keywords:
                        result.append((tmp,tmp))
                    else:
                        n = name(tmp)
                        self.names.append(n)
                        result.append(('var',len(self.names)-1))
                    state = 'state0'
                    tmp = ''
                    string = string[1:]

            
            else:
                if state == 'state0':
                    if string[0] in self.symbols:#handle symbols
                        result.append((string[0],string[0]))
                        string = string[1:]
                    elif string[0] == "#":#handle sharp
                        state = "sharp"
                        string = string[1:]
                    elif string[0] == "'":#handle Char
                        state = 'Char'
                        string = string[1:]
                    elif string[0] == '"':#handle string
                        state = 'string'
                        string = string[1:]
                    elif string[0]  in self.numbers:#handle int and float
                        tmp += string[0]
                        state = 'f_d'
                        string = string[1:]
                    else:#handle var and key
                        state = 'v_k'
                        tmp += string[0]
                        string = string[1:]

                elif state == 'v_k':
                    if string[0] in self.symbols:
                        if tmp in self.keywords:
                            result.append((tmp,tmp))
                        else:
                            n = name(tmp)
                            self.names.append(n)
                            result.append(('var',len(self.names)-1))
                        state = 'state0'
                        tmp = ''
                    else:
                        tmp += string[0]
                        string = string[1:]
                elif state == 'float':
                    if string[0] in self.numbers:
                        tmp += string[0]
                        string = string[1:]
                    else:
                        result.append((state,float(tmp)))
                        tmp = ''
                        state = 'state0'

                elif state == 'f_d':
                    if string[0] in self.numbers:
                        if tmp[0] != '0':
                            tmp += string[0]
                            string = string[1:]
                        else:
                            print 'Int error'
                            break
                    elif string[0] == '.':
                        tmp += string[0]
                        state = 'float'
                        string = string[1:]
                    else:
                        result.append(('Int',int(tmp)))
                        state = 'state0'
                        tmp = ''


                elif state == 'string':
                    if string[0] == '"' and tmp[-1] != '\\':
                        result.append((state,tmp))
                        state = 'state0'
                        tmp = ''
                        string = string[1:]
                    else:
                        tmp += string[0]
                        string = string[1:]
                elif state == 'Char':
                    if string[0] == "'":
                        result.append((state,tmp))
                        tmp = ''
                        state = 'state0'
                        string = string[1:]
                    else:
                        if len(tmp) == 0:
                            tmp += string[0]
                            string = string[1:]
                        else:
                            if tmp == '\\' and string[0] in self.special:
                                tmp += string[0]
                                string = string[1:]
                            else:
                                print 'Char error'
                                break

                elif state == 'sharp':
                    tmp += string[0]
                    string = string[1:]
        
        with open('result1','w') as f:
            for re in result:
                f.write(str(re[0])+','+str(re[1]))
                f.write('\n')
        
        with open('names','wb') as f:
            pickle.dump(self.names,f)
        for n in self.names:
            print 'var_name'
            print n.var_name