示例#1
0
文件: property.py 项目: Bandeira/sps
    def find_replace(self, properties, value=None):
        matches = []
        match_ranks = []

        for i in range(0, len(self.__properties)):
            p = self.__properties[i]

            if b2.util.set.contains(p, properties):
                matches.append(i)
                match_ranks.append(len(p))

        best = sequence.select_highest_ranked(matches, match_ranks)

        if not best:
            return None

        if len(best) > 1:
            raise NoBestMatchingAlternative()

        best = best[0]

        original = self.__values[best]

        if value:
            self.__values[best] = value

        return original
示例#2
0
    def find_replace(self, properties, value=None):
        matches = []
        match_ranks = []

        for i in range(0, len(self.__properties)):
            p = self.__properties[i]

            if b2.util.set.contains(p, properties):
                matches.append(i)
                match_ranks.append(len(p))

        best = sequence.select_highest_ranked(matches, match_ranks)

        if not best:
            return None

        if len(best) > 1:
            raise NoBestMatchingAlternative()

        best = best[0]

        original = self.__values[best]

        if value:
            self.__values[best] = value

        return original