def __init__(self, root, logger_cb, height=250, width=1600): super().__init__(root, height=height, width=width) terminals_count = 18 self._top_data_line = DataLineView(self, "A", (50, 115), (50, 10)) self._bot_data_line = DataLineView(self, "B", (50, 135), (50, 245)) self._lcs = LCS(terminals_count=terminals_count, probabilities=[0, 0, 0, 0], line_state_change_handler=self.on_line_state_changed, logger_cb=logger_cb, on_message=self.on_message) self._terminal_views = [] column = 1 for i in range(int(terminals_count)): top_terminal = TerminalDeviceView(self, i, self._lcs.get_terminals, True) bot_terminal = TerminalDeviceView(self, i, self._lcs.get_terminals, False) top_terminal.place(x=110 + 80 * i, y=60) bot_terminal.place(x=110 + 80 * i, y=130) self._terminal_views.append(top_terminal) self._terminal_views.append(bot_terminal) self.update_idletasks() self._top_data_line.connect_terminal(top_terminal) self._bot_data_line.connect_terminal(bot_terminal) column += 1 self._bot_data_line.deactivate() self._top_data_line.activate() self._controller_view = ControllerView(self) self._controller_view.place(x=10, y=115) self.configure(bg="white")
def main(file1, file2): prs1 = Presentation(file1) slide_size = (prs1.slide_width, prs1.slide_height) slides1 = [slide_repr(slide, slide_size) for slide in prs1.slides] prs2 = Presentation(file2) slides2 = [slide_repr(slide, slide_size) for slide in prs2.slides] lcs = LCS(slides1, slides2) for ((l1, i1), (l2, i2)) in lcs.diff(): lines1 = [slides1[i + i1] for i in range(l1)] lines2 = [slides2[i + i2] for i in range(l2)] show_diff(lines1, lines2, i1, i2)
class LCSView(tk.Canvas): def __init__(self, root, logger_cb, height=250, width=1600): super().__init__(root, height=height, width=width) terminals_count = 18 self._top_data_line = DataLineView(self, "A", (50, 115), (50, 10)) self._bot_data_line = DataLineView(self, "B", (50, 135), (50, 245)) self._lcs = LCS(terminals_count=terminals_count, probabilities=[0, 0, 0, 0], line_state_change_handler=self.on_line_state_changed, logger_cb=logger_cb, on_message=self.on_message) self._terminal_views = [] column = 1 for i in range(int(terminals_count)): top_terminal = TerminalDeviceView(self, i, self._lcs.get_terminals, True) bot_terminal = TerminalDeviceView(self, i, self._lcs.get_terminals, False) top_terminal.place(x=110 + 80 * i, y=60) bot_terminal.place(x=110 + 80 * i, y=130) self._terminal_views.append(top_terminal) self._terminal_views.append(bot_terminal) self.update_idletasks() self._top_data_line.connect_terminal(top_terminal) self._bot_data_line.connect_terminal(bot_terminal) column += 1 self._bot_data_line.deactivate() self._top_data_line.activate() self._controller_view = ControllerView(self) self._controller_view.place(x=10, y=115) self.configure(bg="white") def get_terminal_views(self): return self._terminal_views def get_lcs_thread(self): return LCSRunThread(self._lcs.process) def on_line_state_changed(self, state): if state == LineState.WORKING_LINE_B: self._bot_data_line.activate() self._top_data_line.deactivate() elif state == LineState.GENERATION: self._top_data_line.generation() self._bot_data_line.deactivate() else: self._top_data_line.activate() self._bot_data_line.deactivate() def on_message(self, index, message_state): line_state = self._lcs.get_last_state() terminal = 2 * index + 1 if line_state == LineState.WORKING_LINE_B else 2 * index self._terminal_views[terminal].on_message(message_state)
def lcs_setup(self): self.lcs = LCS() self.lcs_strings = [] self.lcs_strings.append("TZAQWIBDCXE") self.lcs_strings.append("HXTBUWAICE") self.lcs_strings.append("ACADB") self.lcs_strings.append("CBDA") self.lcs_strings.append("BCDAACD") self.lcs_strings.append("ACDBAC") self.lcs_strings_solution = [] self.lcs_strings_solution.append(5) self.lcs_strings_solution.append(2) self.lcs_strings_solution.append(4) self.lcs_strings_solution_2 = [] self.lcs_strings_solution_2.append("TWICE") self.lcs_strings_solution_2.append("CB") self.lcs_strings_solution_2.append("CDAC")
def matchings(lines1, lines2): lcs_idxs = [] for i in range(len(lines1)): for j in range(len(lines2)): lcs_idxs.append(((i, j), LCS(lines1[i], lines2[j]))) list.sort(lcs_idxs, key=lambda li: li[1].size) ranges1 = [(0, len(lines2) - 1) for _ in range(len(lines1))] ranges2 = [(0, len(lines1) - 1) for _ in range(len(lines2))] matches1 = [None for _ in range(len(lines1))] matches2 = [None for _ in range(len(lines2))] while len(lcs_idxs) > 0: (i, j), lcs = lcs_idxs.pop() if matches1[i] is not None or matches2[j] is not None: continue if ranges1[i][0] > j or ranges1[i][1] < j or ranges2[j][ 0] > i or ranges2[j][1] < i: continue matches1[i] = (j, lcs) matches2[j] = (i, lcs) for i_ in range(len(lines1)): if i_ < i: ranges1[i_] = (ranges1[i_][0], min(ranges1[i_][1], j - 1)) if i_ > i: ranges1[i_] = (max(ranges1[i_][0], j + 1), ranges1[i_][1]) for j_ in range(len(lines2)): if j_ < j: ranges2[j_] = (ranges2[j_][0], min(ranges2[j_][1], i - 1)) if j_ > j: ranges2[j_] = (max(ranges2[j_][0], i + 1), ranges2[j_][1]) idx1 = 0 idx2 = 0 result = [] while True: while idx1 < len(matches1) and matches1[idx1] is None: result.append((idx1, None, None)) idx1 += 1 while idx2 < len(matches2) and matches2[idx2] is None: result.append((None, idx2, None)) idx2 += 1 if idx1 == len(matches1) or idx2 == len(matches2): break result.append((idx1, idx2, matches1[idx1][1])) idx1 += 1 idx2 += 1 return result
class TestNode(unittest.TestCase): def lcs_setup(self): self.lcs = LCS() self.lcs_strings = [] self.lcs_strings.append("TZAQWIBDCXE") self.lcs_strings.append("HXTBUWAICE") self.lcs_strings.append("ACADB") self.lcs_strings.append("CBDA") self.lcs_strings.append("BCDAACD") self.lcs_strings.append("ACDBAC") self.lcs_strings_solution = [] self.lcs_strings_solution.append(5) self.lcs_strings_solution.append(2) self.lcs_strings_solution.append(4) self.lcs_strings_solution_2 = [] self.lcs_strings_solution_2.append("TWICE") self.lcs_strings_solution_2.append("CB") self.lcs_strings_solution_2.append("CDAC") def lcs_test_tamanho(self): self.lcs_setup() arr_recebido = [] i = 0 while i < len(self.lcs_strings): j = i + 1 matriz, valor = self.lcs.lcs(self.lcs_strings[i], self.lcs_strings[j]) arr_recebido.append(valor) i += 2 for i in range(len(arr_recebido)): self.assertEqual( arr_recebido[i], self.lcs_strings_solution[i], f"Erro! o lcs recebido {arr_recebido[i]} esta diferente do esperado. O esperado seria {self.lcs_strings_solution[i]}" ) def lcs_test_string(self): self.lcs_setup() arr_recebido = [] i = 0 while i < len(self.lcs_strings): j = i + 1 matriz, valor = self.lcs.lcs(self.lcs_strings[i], self.lcs_strings[j]) arr_recebido.append( self.lcs.printing_lcs(matriz, self.lcs_strings[i], self.lcs_strings[j])) i += 2 for i in range(len(arr_recebido)): #print(arr_recebido[i], self.lcs_strings_solution[i]) self.assertEqual( arr_recebido[i], self.lcs_strings_solution_2[i], f"Erro! o lcs recebido {arr_recebido[i]} esta diferente do esperado. O esperado seria {self.lcs_strings_solution_2[i]}" )
data = db.queryv(q, doc_uji) q = "SELECT * FROM antrian_dataset as ad join dataset as ds on ad.id_data = ds.id_data WHERE id_antrian_dokumen = %s" data1 = db.queryall(q, antrian) #-------------------------------------------------- for td in data1: list_sentence = "" angka_sentence = 0 penelitian = data['penelitian'] while True: common_sentence, persent = LCS.longest_common_sentence(penelitian, td['penelitian']) common_words = common_sentence.split(' ') #berhenti ketika hasil plagiat kurang dari 3 kata if(len(common_words) <= 3): break else: list_sentence += '%s###' % common_sentence #mengumpulkan hasil lcs ke 1 variable angka_sentence += float(persent) buang_plagiarisme = penelitian.split(common_sentence) #membuang kalimat plagiat pada text uji penelitian = ' '.join(buang_plagiarisme) #menggabungkan kembali setelah meembuang kalimat plagiat q = "UPDATE antrian_dataset SET similarity_angka='%s', similarity_text='%s', status=%d, updated_at='%s' WHERE id_antrian_dataset='%s' "% (angka_sentence, list_sentence, 1, datetime.datetime.now(), td['id_antrian_dataset']) db.query(q)
def __init__(self): self.ori = LCS() self.pos = Vec3(0., 0., 0.) self.width = 1 self.color = (0.0, 0.5, 0.0)
class TurtleState: def __init__(self): self.ori = LCS() self.pos = Vec3(0., 0., 0.) self.width = 1 self.color = (0.0, 0.5, 0.0) def __str__(self): return str(self.pos) + " " + str(self.ori[0]) + " " + str( self.ori[1]) + " " + str(self.ori[2]) def yaw(self, angle): self.ori.rotY(angle) def pitch(self, angle): self.ori.rotZ(-angle) def roll(self, angle): self.ori.rotX(angle) def level(self): V = Vec3(0, 1, 0) H = self.getDir() L = self.getRight() # This is fishy ... all U = V.cross(H) L = H.cross(U) self.setUp(U) self.setRight(L) def move(self, length): x, y, z = self.ori[0] self.pos.x = self.pos.x + x * length self.pos.y = self.pos.y + y * length self.pos.z = self.pos.z + z * length def getPos(self): return self.pos def getDir(self): return self.ori.rowAsVec3(0) def setDir(self, v): self.ori.mat[0] = v.toList() def getUp(self): return self.ori.rowAsVec3(1) def setUp(self, v): self.ori.mat[1] = v.toList() def getRight(self): return self.ori.rowAsVec3(2) def setRight(self, v): self.ori.mat[2] = v.toList() def orientation(self): return self.ori.orientation() def copy(self): cc = TurtleState() cc.pos = Vec3(self.pos.x, self.pos.y, self.pos.z) cc.width = self.width cc.color = self.color cc.ori = self.ori.copy() return cc
def _on_clear_clicked(self): self._lcs = LCS(4, [0, 0, 0, 0])
#!/usr/bin/python from lcs import LCS a = [3, 1, 2, 4, 9, 5, 10, 6, 8, 7] b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] c = [4, 7, 2, 3, 10, 6, 9, 1, 5, 8] d = [3, 1, 2, 4, 9, 5, 10, 6, 8, 7] e = [2, 10, 1, 3, 8, 4, 9, 5, 7, 6] print LCS(a, b, lambda x, y: x == y) print LCS(a, c, lambda x, y: x == y) print LCS(a, d, lambda x, y: x == y) print LCS(a, e, lambda x, y: x == y) str1 = """ die einkommen der landwirte sind fuer die abgeordneten ein buch mit sieben siegeln um dem abzuhelfen muessen dringend alle subventionsgesetze verbessert werden """ str2 = """ die steuern auf vermoegen und einkommen sollten nach meinung der abgeordneten nachdruecklich erhoben werden dazu muessen die kontrollbefugnisse der finanzbehoerden dringend verbessert werden """ print LCS(str1.split(), str2.split(), lambda s1, s2: s1 == s2)