def StructuralIsInstance(self, structure, item): depth = StructureDepth(structure) if depth >= 2: return None if depth == 0: return Binding(start=structure, end=structure, length=1) # So depth = 1 for idx, v in enumerate(structure[1:], 1): if v != structure[idx - 1] + 1: return None bindings = Binding(start=SObject.Create([structure[0]]), end=SObject.Create([structure[-1]]), length=SObject.Create([structure[-1] - structure[0] + 1])) bindings.GetBindingsForAttribute("start").AddCategoriesFrom(item.items[0]) bindings.GetBindingsForAttribute("end").AddCategoriesFrom(item.items[-1]) return bindings
def IsInstance(self, entity): magnitude = entity.magnitude if magnitude < 0: return None # Not an instance. root = math.sqrt(magnitude) if root != int(root): return None return Binding(sqroot=root)
def StructuralIsInstance(self, structure, item): if isinstance(structure, int): return None if len(structure) != self.size: return None bindings = {} for idx, structure_item in enumerate(structure, 1): bindings['pos_%d' % idx] = SObject.Create([structure_item]) bindings['pos_%d' % idx].AddCategoriesFrom(item.items[idx - 1]) return Binding(**bindings)
def IsInstance(self, item): if isinstance(item, SElement): # Probably the wrong thing to do. return None for item_part in item.items: if not item_part.DescribeAs(self.mapping.category): return self.IsDegenerateInstance(item) # So all items can be described as members of category... for idx, itempart in enumerate(item.items[1:], 1): if not self.mapping.IsPairConsistent(item.items[idx - 1], itempart): return self.IsDegenerateInstance(item) # Okay, so valid return Binding(start=item.items[0].DeepCopy(), length=SObject.Create([len(item.items)]))
def IsInstance(self, entity): magnitude = entity.magnitude remainder = magnitude % self.n if remainder == self.x: return Binding(k=(magnitude - self.x) / self.n) return None
def IsDegenerateInstance(self, item): if not item.DescribeAs(self.mapping.category): return None return Binding(start=item, length=SObject.Create([1]))
def NumericIsInstance(self, val): try: index = self.number_list.index(val) return Binding(index=index) except ValueError: return None
def NumericIsInstance(self, val): return Binding()