Example #1
0
    def index(self, indexer: Indexer):
        pattern = TrianglePattern(line_AB=AttributeState.KNOWN,
                                  line_AC=AttributeState.KNOWN,
                                  line_BC=AttributeState.KNOWN,
                                  angle_A=AttributeState.UNKNOWN)

        repleced_patterns = indexer.index_by_pattern(pattern)
        return [([p.line_AB, p.line_AC, p.line_BC], p.angle_A) \
                for p in repleced_patterns]
 def index(self, indexer: Indexer):
     pattern = TrianglePattern(angle_A=AttributeState.KNOWN,
                               angle_B=AttributeState.KNOWN,
                               angle_C=AttributeState.UNKNOWN)
     # After index pattern.angle_A and pattern.angle_B are
     # replaced by AttributeValue condition, and angle_C is
     # also replaced by AttributeValue condition whose value
     # is unkonwn.
     repleced_patterns = indexer.index_by_pattern(pattern)
     return [([p.angle_A, p.angle_B], p.angle_C) for p in repleced_patterns]
def basic_pattern():
    entity, target, conditions = get_problem()

    graph = DeductionGraph(conditions, target)
    indexer = Indexer(entity, graph)
    pattern = TrianglePattern(angle_A=AttributeState.KNOWN,
                              angle_B=AttributeState.KNOWN,
                              angle_C=AttributeState.KNOWN)
    conditions, entitis = indexer.index_by_pattern(pattern, True)
    print(entitis)
    print(conditions)
Example #4
0
 def index(self, indexer: Indexer):
     ret = []
     pattern = TrianglePattern(angle_A=AttributeState.KNOWN,
                               angle_B=AttributeState.UNKNOWN,
                               angle_C=AttributeState.UNKNOWN)
     repleced_patterns = indexer.index_by_pattern(pattern)
     for p in repleced_patterns:
         angle1 = p.angle_B.obj
         angle2 = p.angle_C.obj
         eq_cond = index_equivalent_value(indexer, angle1, 'angle', angle2,
                                          'angle')
         if eq_cond is not None:
             ret.append([[eq_cond, p.angle_A], [p.angle_B, p.angle_C]])
     return ret
 def index(self, indexer: Indexer):
     ret = []
     triangles = indexer.index_by_type(Triangle)
     pattern = TrianglePattern(angle_A=AttributeState.KNOWN,
                               angle_B=AttributeState.KNOWN,
                               angle_C=AttributeState.KNOWN)
     
     st_conds = indexer.index_by_type(SimilarTriangle)
     all_st = [cond.relationship for cond in st_conds]
     
     def get_corresp():
         th1_conds = [indexer.index_value_condition(th1_angle, 'angle') \
                 for th1_angle in th1.angles]
         th2_conds = [indexer.index_value_condition(th2_angle, 'angle') \
                 for th2_angle in th2.angles]
         cor_angle = []
         for cond1 in th1_conds:
             for cond2 in th2_conds:
                 if cond1.attr_value == cond2.attr_value:
                     cor_angle.append((cond1.obj, cond2.obj))
                     break
         return cor_angle, th1_conds, th2_conds
     
     replaced, entities = indexer.index_by_pattern(pattern, True)
     size = len(entities)
     for i in range(size):
         for j in range(i + 1, size):
             i_angles = set([replaced[i].angle_A, 
                             replaced[i].angle_B, 
                             replaced[i].angle_C])
             j_angles = set([replaced[j].angle_A, 
                             replaced[j].angle_B, 
                             replaced[j].angle_C])
             if i_angles == j_angles:
                 th1 = entities[i]
                 th2 = entities[j]
                 cor_angle, conds1, conds2 = get_corresp()
                 st = SimilarTriangle('_'.join([th1.id, th2.id]),
                                 th1, th2, cor_angle)
                 if st not in all_st:
                     ret.append([conds1+conds2, RelationshipBased(st)])
     return ret