Skip to content

Commit

Permalink
Overlap metric
Browse files Browse the repository at this point in the history
  • Loading branch information
jkvis committed Jul 1, 2024
1 parent 397b509 commit d7b308f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions algebra/lcs/lcs_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,30 @@ def traversal(source, path):

return traversal(self._source, [])

def uniq_atomics(self):
"""The set of unique atomics for the whole LCS graph."""
atomics = set()
for *_, variant in self.bfs_traversal():
for idx in range(variant[0].start, variant[0].end):
atomics |= {(idx, "del")}
for ch in set(variant[0].sequence):
atomics |= {(idx, ch)}
for ch in set(variant[0].sequence):
atomics |= {(variant[0].end, ch)}
return atomics

def overlap(self, other):
"""The set of common unique atomics and the set of all unique
atomics for two LCS graphs."""
lhs = self.uniq_atomics()
rhs = other.uniq_atomics()
return lhs.intersection(rhs), lhs.union(rhs)

def is_disjoint(self, other):
"""Are two LCS graphs disjoint."""
common, _ = self.overlap(other)
return len(common) == 0


def trim(lhs, rhs):
"""Find the lengths of the common prefix and common suffix between
Expand Down

0 comments on commit d7b308f

Please sign in to comment.