Beispiel #1
0
    def save(self,sql, data):
        try:
            conn = f.get_conn()
            conn.autocommit = False
            cur = conn.cursor()
            
            cur.executemany(sql, data)
            if sql == sqlEnglish:
                print("Affected RowCount is {}/{}".format(cur.rowcount,len(self.english)) )
            elif sql == sqlKorean:
                print("Affected RowCount is {}/{}".format(cur.rowcount,len(self.korean)) )
            else:
                print("Affected RowCount is ", cur.rowcount)
            conn.commit()

        except Exception as err:
            conn.rollback()
            print("Error!!", err)

        finally:
            try:
                cur.close()
            except:
                print("Error on close cursor")
            try:
                conn.close()
                print ("OOKKKK")
            except Exception as err2:
                print("Fail to connect!!", err2)
Beispiel #2
0
    def kortoEngequiv(self):
        # print("self.korsentences>>", self.korsentences)
        tags = []
        # res=[]
        # eng=[]
        n=1

        print(self.kortalk)
        for k, kort in enumerate(self.kortalk):
            strs = ''
            cue = kort[1]
            tid = kort[0]

            # 만일 첫 문장인 경우
            if cue == 1:
                sqlEngSearch = '''select eng from English 
                    where engcue between {} and {}
                    and talk_id = {}'''.format(cue, cue+2, tid)

            # 첫 문장이 아닌 경우
            else:     
                sqlEngSearch = '''select eng from English 
                    where engcue between {} and {}
                    and talk_id = {}'''.format(cue-1, cue+1, tid)

            # tags 가져오기
            tagSearch = 'select tags from Talk where talk_id = {}'.format(tid)
            conn = f.get_conn()
            cur = conn.cursor()
            cur.execute(sqlEngSearch)
            enrows = cur.fetchall() # tuple
            cur.close()
            cur = conn.cursor()
            cur.execute(tagSearch)
            tagrows = cur.fetchall()
            cur.close()
            
            a=[]
            # print("english >>>", enrows)
            for english in enrows:
                a.append(english[0]) # eng
            # print("aa>>", a)
            for m in tagrows:
                tag = m[0]
                
                # 같은 talk_id를 갖고 있는 경우 tag들의 중복 append 방지
                if tag in tags:
                    continue
                else:
                    tags.append(tag)
            # print("aaa>>", a)
            # 세 개의 문장을 하나의 string으로 만들기
            for i in a:
                strs += i + ' '
            show = {'number' : n, 'tid' : tid, 'cue':cue, 'korsentences':self.korsentences[k], 'result':strs}
            self.shows[n] = show
            self.shows['number'] = n
            n += 1
        pprint(self.shows)
        return self.shows
Beispiel #3
0
    def __init__ (self):

        # 전체 Talk의 수 구하기
        conn = f.get_conn()
        cur = conn.cursor()
        
        sqltalkcnt = ''' select (@rownum := @rownum + 1) r
                        from Talk t, (select @rownum := 0) rn
                        order by r desc
                        limit 1; '''

        sqlisdiff = 'select talk_id from Talk where diff = 0'
        
        cur.execute(sqltalkcnt)
        self.talkcnt = cur.fetchall()[0][0]
Beispiel #4
0
    def kortoEng(self, search):
        # int(self.talkcnt)+1
        for t in range(1, 10):
            if (t,) in self.diffs:
                continue

            # 검색
            sqlKorSearch = '''select korcue from Korean 
                        where kor like '%{}%'
                        and talk_id = {}'''.format(search, t)
            conn = f.get_conn()
            cur = conn.cursor()
            cur.execute(sqlKorSearch)
            rows = cur.fetchall()
            cur.close()

            # 검색어가 없는 경우
            if len(rows) == 0:
                continue
            # 검색어가 있는 경우
            else:
                for row in rows:
                    cue = row[0]
                    self.kortalk.append((t, cue))
                    sentence = ''
                    sqlkor = 'select kor from Korean where korcue between {} and {} and talk_id = {}'.format(cue-1, cue+1, t)
                    # print(sqlss)
                    cur = conn.cursor()
                    cur.execute(sqlkor)
                    rows2 = cur.fetchall()
                    cur.close()
                    # print(rows2)
                    for r in rows2:
                        sentence += (r[0]+' ')
                    # print(sentence)
                    self.korsentences.append(sentence)
Beispiel #5
0
            sqlSearch = '''select talk_id, engcue, eng from English 
                        where eng like '%{}%'
                        and talk_id = {}'''.format(search, t)
       
=======
            # 검색
            s = ''
            s = search[0]
            sqlEngSearch = '''select engcue from English 
                        where eng regexp '([{}{}]{})'
                        and talk_id = {}'''.format(s.lower(), s.upper(), search[1:], t)
            # sqlEngSearch = '''select engcue from English 
            #                     where eng like '%{}%'
            #                     and talk_id = {}'''.format(search, t)
>>>>>>> 97e557429b08ffdb80f9227f2de91259c4e30523
            conn = f.get_conn()
            cur = conn.cursor()
            cur.execute(sqlEngSearch)
            rows = cur.fetchall()
            cur.close()

            # 검색어가 없는 경우
            if len(rows) == 0:
                continue
            # 검색어가 있는 경우
            else:
<<<<<<< HEAD
                cur.execute(sqlSearch)
                rows = cur.fetchall()
                if len(rows) == 0:
                    continue