示例#1
0
    def find_replace(self, properties, value=None):
        matches = []
        match_ranks = []
        
        for i in range(0, len(self.__properties)):
            p = self.__properties[i]
                        
            if 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 evaluate_conditionals_in_context (properties, context):
    """ Removes all conditional properties which conditions are not met
        For those with met conditions, removes the condition. Properies
        in conditions are looked up in 'context'
    """
    base = []
    conditionals = []

    for p in properties:
        if __re_has_condition.search (p):
            conditionals.append (p)
        else:
            base.append (p)

    result = base
    for p in conditionals:

        # Separate condition and property
        s = __re_separate_condition_and_property.match (p)

        # Split condition into individual properties
        conditions = s.group (1).split (',')

        # Evaluate condition        
        if set.contains (c, context):
            result.append (s.group (2))

    return result
示例#3
0
    def match_rank(self, property_set_to_match):
        """ Returns true if the generator can be run with the specified 
            properties.
        """
        # See if generator's requirements are satisfied by
        # 'properties'.  Treat a feature name in requirements
        # (i.e. grist-only element), as matching any value of the
        # feature.
        all_requirements = self.requirements()

        property_requirements = []
        feature_requirements = []
        for r in all_requirements:
            if get_value(r):
                property_requirements.append(r)

            else:
                feature_requirements.append(r)

        properties_to_match = property_set_to_match.raw()

        return set.contains (property_requirements, properties_to_match) \
            and set.contains (feature_requirements, get_grist (properties_to_match))
示例#4
0
    def match_rank (self, property_set_to_match):
        """ Returns true if the generator can be run with the specified 
            properties.
        """
        # See if generator's requirements are satisfied by
        # 'properties'.  Treat a feature name in requirements
        # (i.e. grist-only element), as matching any value of the
        # feature.
        all_requirements = self.requirements ()
        
        property_requirements = []
        feature_requirements = []
        for r in all_requirements:
            if get_value (r):
                property_requirements.append (r)

            else:
                feature_requirements.append (r)

        properties_to_match = property_set_to_match.raw ()
        
        return set.contains (property_requirements, properties_to_match) \
            and set.contains (feature_requirements, get_grist (properties_to_match))