示例#1
0
 def test_commonprefix(self):
     self.assertEqual(genericpath.commonprefix([]), "")
     self.assertEqual(
         genericpath.commonprefix(["/home/swenson/spam",
                                   "/home/swen/spam"]), "/home/swen")
     self.assertEqual(
         genericpath.commonprefix(["/home/swen/spam", "/home/swen/eggs"]),
         "/home/swen/")
     self.assertEqual(
         genericpath.commonprefix(["/home/swen/spam", "/home/swen/spam"]),
         "/home/swen/spam")
示例#2
0
    def inflect(self, vector, word):
        suffix = commonprefix([vector[0][::-1], word[::-1]])
        prefix = word[:-len(suffix)]

        bform_prefix = vector[0][:-len(suffix)]
        bform_prefix_len = len(vector[0][:-len(suffix)])
        return map(lambda w: prefix + w[bform_prefix_len:], filter(lambda ww: ww.startswith(bform_prefix) ,vector)) #check if word prefix is the same in all forms
 def test_commonprefix(self):
     self.assertEqual(
         genericpath.commonprefix([]),
         ""
     )
     self.assertEqual(
         genericpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"]),
         "/home/swen"
     )
     self.assertEqual(
         genericpath.commonprefix(["/home/swen/spam", "/home/swen/eggs"]),
         "/home/swen/"
     )
     self.assertEqual(
         genericpath.commonprefix(["/home/swen/spam", "/home/swen/spam"]),
         "/home/swen/spam"
     )
示例#4
0
    def inflect(self, vector, word):
        suffix = commonprefix([vector[0][::-1], word[::-1]])
        prefix = word[:-len(suffix)]

        bform_prefix = vector[0][:-len(suffix)]
        bform_prefix_len = len(vector[0][:-len(suffix)])
        return map(
            lambda w: prefix + w[bform_prefix_len:],
            filter(lambda ww: ww.startswith(bform_prefix),
                   vector))  #check if word prefix is the same in all forms
示例#5
0
def common_prefix(s1, s2):
    """
    Return the common leading subsequence of two sequences.
    """
    if not s1 or not s2:
        return None
    common = genericpath.commonprefix((s1, s2,))
    if common:
        return common
    else:
        return None
示例#6
0
    def _path_distance(link1, link2):
        # Test never passes if the domains have changed
        if link1.parsed.netloc != link2.parsed.netloc:
            return False

        source = link2.parsed.path.split('/')
        this = link1.parsed.path.split('/')
        shared = commonprefix([source, this])

        # /foo and /bar also will never pass
        if len(shared) < len(source) and len(shared) < len(this):
            return False

        return len(this) - len(source)
示例#7
0
文件: tests.py 项目: miracle2k/track0
    def _path_distance(link1, link2):
        # Test never passes if the domains have changed
        if link1.parsed.netloc != link2.parsed.netloc:
            return False

        source = link2.parsed.path.split('/')
        this = link1.parsed.path.split('/')
        shared = commonprefix([source, this])

        # /foo and /bar also will never pass
        if len(shared) < len(source) and len(shared) < len(this):
            return False

        return len(this) - len(source)
示例#8
0
def create_concat_filename(input_path, *input_paths) -> str:
    if not input_paths:
        assert isinstance(input_path, str)
        return input_path

    common_prefix = genericpath.commonprefix([input_path] + list(input_paths))
    common_suffixes, search_idx = [], len(common_prefix)
    for next_path in input_paths:
        matcher = difflib.SequenceMatcher(None, input_path, next_path)
        match = matcher.find_longest_match(search_idx, len(input_path),
                                           search_idx, len(next_path))
        common_suffixes.append(next_path[match.a:match.b + match.size])

    shortest_common_suffix = min(common_suffixes, key=lambda _: len(_))

    for suffix in common_suffixes:
        assert shortest_common_suffix in suffix, (
            f'Suffix mismatch, {shortest_common_suffix} not in {suffix}')

    return f'{common_prefix}_{common_suffixes[0]}'
示例#9
0
 def update_event(self, inp=-1):
     self.set_output_val(0, genericpath.commonprefix(self.input(0)))