Example #1
0
 def remake_lt(ld, ltid):
     # use iter_words, because iter_lines needs ltline registered in table
     # but ltline on new_ltid is now on construction in this function...
     new_lt = None
     cnt = 0
     for l_w in ld.db.iter_words(ltid=ltid):
         print l_w
         if new_lt is None:
             new_lt = l_w
         else:
             new_lt = lt_common.merge_lt(new_lt, l_w, sym)
         cnt += 1
     print "result : " + str(new_lt)
     print
     return new_lt, cnt
 def remake_lt(ld, ltid):
     # use iter_words, because iter_lines needs ltline registered in table
     # but ltline on new_ltid is now on construction in this function...
     new_lt = None
     cnt = 0
     for l_w in ld.db.iter_words(ltid = ltid):
         print l_w
         if new_lt is None:
             new_lt = l_w
         else:
             new_lt = lt_common.merge_lt(new_lt, l_w, sym)
         cnt += 1
     print "result : " + str(new_lt)
     print 
     return new_lt, cnt
Example #3
0
 def process_line(self, l_w, l_s):
     n_parent = self.n_root
     while True:
         for n_child in n_parent:
             _logger.debug("comparing with ltid {0}".format(
                 n_child.lt.ltid))
             nc_lt = n_child.lt.ltw
             sr = self.seq_ratio(nc_lt, l_w)
             _logger.debug("seq_ratio : {0}".format(sr))
             if sr >= self.threshold:
                 _logger.debug("merged with ltid {0}".format(
                     n_child.lt.ltid))
                 new_lt = lt_common.merge_lt(nc_lt, l_w, self.sym)
                 if new_lt == nc_lt:
                     self.ltm.count_lt(n_child.lt.ltid)
                 else:
                     self.ltm.replace_and_count_lt(n_child.lt.ltid, new_lt)
                     _logger.debug("ltid {0} replaced".format(
                         n_child.lt.ltid))
                     _logger.debug("-> {0}".format(str(n_child.lt)))
                 return n_child.lt, False
             else:
                 if self.equal(nc_lt, l_w):
                     _logger.warning(
                         "comparing same line, but seqratio is small...")
         else:
             if len(n_parent) < self.max_child:
                 _logger.debug("no node to be merged, add new node")
                 n = self._new_node(l_w, l_s)
                 n_parent.join(n)
                 return n.lt, True
             else:
                 _logger.debug("children : {0}".format(
                     [e.lt.ltid for e in n_parent.l_child]))
                 l_sim = [(edit_distance(n_child.lt.ltw, l_w,
                                         self.sym), n_child)
                          for n_child in n_parent]
                 n_parent = max(l_sim, key=lambda x: x[0])[1]
                 _logger.debug("go down to node(ltid {0})".format(
                     n_parent.lt.ltid))
 def process_line(self, l_w, l_s):
     n_parent = self.n_root
     while True:
         for n_child in n_parent:
             _logger.debug(
                     "comparing with ltid {0}".format(n_child.lt.ltid))
             nc_lt = n_child.lt.ltw
             sr = self.seq_ratio(nc_lt, l_w)
             _logger.debug("seq_ratio : {0}".format(sr))
             if sr >= self.threshold:
                 _logger.debug(
                         "merged with ltid {0}".format(n_child.lt.ltid))
                 new_lt = lt_common.merge_lt(nc_lt, l_w, self.sym)
                 if new_lt == nc_lt:
                     self.ltm.count_lt(n_child.lt.ltid)
                 else:
                     self.ltm.replace_and_count_lt(n_child.lt.ltid, new_lt)
                     _logger.debug(
                             "ltid {0} replaced".format(n_child.lt.ltid))
                     _logger.debug("-> {0}".format(str(n_child.lt)))
                 return n_child.lt, False
             else:
                 if self.equal(nc_lt, l_w):
                     _logger.warning(
                         "comparing same line, but seqratio is small...")
         else:
             if len(n_parent) < self.max_child:
                 _logger.debug("no node to be merged, add new node")
                 n = self._new_node(l_w, l_s)
                 n_parent.join(n)
                 return n.lt, True
             else:
                 _logger.debug("children : {0}".format(
                         [e.lt.ltid for e in n_parent.l_child]))
                 l_sim = [(edit_distance(n_child.lt.ltw, l_w, self.sym),
                         n_child) for n_child in n_parent]
                 n_parent = max(l_sim, key=lambda x: x[0])[1]
                 _logger.debug("go down to node(ltid {0})".format(
                         n_parent.lt.ltid))
Example #5
0
def merge_ltid(ld, ltid1, ltid2, sym):
    ld.set_ltm()
    print("merge following log templates...")
    print _str_lt(ltid1)
    print _str_lt(ltid2)
    print

    ltw1 = ld.lt(ltid1).ltw
    cnt1 = ld.lt(ltid1).cnt
    l_s = ld.lt(ltid1).lts
    ltw2 = ld.lt(ltid2).ltw
    cnt2 = ld.lt(ltid2).cnt
    if not len(ltw1) == len(ltw2):
        sys.exit("log template length is different, failed")
    new_ltw = lt_common.merge_lt(ltw1, ltw2, sym)

    ld.ltm.replace_lt(ltid1, new_ltw, l_s, cnt1 + cnt2)
    ld.ltm.remove_lt(ltid2)
    ld.db.update_log({"ltid": ltid2}, {"ltid": ltid1})

    ld.commit_db()

    print("> new log template : ltid {0}".format(ltid1))
    print _str_lt(ltid1)
def merge_ltid(ld, ltid1, ltid2, sym):
    ld.set_ltm()
    print("merge following log templates...")
    print _str_lt(ltid1)
    print _str_lt(ltid2)
    print

    ltw1 = ld.lt(ltid1).ltw
    cnt1 = ld.lt(ltid1).cnt
    l_s = ld.lt(ltid1).lts
    ltw2 = ld.lt(ltid2).ltw
    cnt2 = ld.lt(ltid2).cnt
    if not len(ltw1) == len(ltw2):
        sys.exit("log template length is different, failed")
    new_ltw = lt_common.merge_lt(ltw1, ltw2, sym)

    ld.ltm.replace_lt(ltid1, new_ltw, l_s, cnt1 + cnt2)
    ld.ltm.remove_lt(ltid2)
    ld.db.update_log({"ltid" : ltid2}, {"ltid" : ltid1})

    ld.commit_db()

    print("> new log template : ltid {0}".format(ltid1))
    print _str_lt(ltid1)