def _verify(self, dependencies, value, op, typ): attr_value = dependencies[0] value = self._parse_key_value(None, value, typ) if attr_value.can_compare(value) and comp(attr_value, value, op): answer = 'yes' else: answer = 'no' return answer
def QueryAttrQualifier(self, dependencies, inputs): entity_ids, _ = dependencies[0] entity_id = entity_ids[0] key, value, qual_key = inputs[0], inputs[1], inputs[2] value = self._parse_key_value(key, value) for attr_info in self.entities[entity_id]['attributes']: if attr_info['key']==key and attr_info['value'].can_compare(value) and \ comp(attr_info['value'], value, '='): for qk, qvs in attr_info['qualifiers'].items(): if qk == qual_key: return qvs[0] return None
def _filter_attribute(self, entity_ids, tgt_key, tgt_value, op, typ): tgt_value = self._parse_key_value(tgt_key, tgt_value, typ) res_ids = [] res_facts = [] for i in entity_ids: for attr_info in self.entities[i]['attributes']: k, v = attr_info['key'], attr_info['value'] if k == tgt_key and v.can_compare(tgt_value) and comp( v, tgt_value, op): res_ids.append(i) res_facts.append(attr_info) return (res_ids, res_facts)
def _filter_qualifier(self, entity_ids, facts, tgt_key, tgt_value, op, typ): tgt_value = self._parse_key_value(tgt_key, tgt_value, typ) res_ids = [] res_facts = [] for i, f in zip(entity_ids, facts): for qk, qvs in f['qualifiers'].items(): if qk == tgt_key: for qv in qvs: if qv.can_compare(tgt_value) and comp( qv, tgt_value, op): res_ids.append(i) res_facts.append(f) return (res_ids, res_facts)
def QueryAttrUnderCondition(self, dependencies, inputs): entity_ids, _ = dependencies[0] entity_id = entity_ids[0] key, qual_key, qual_value = inputs[0], inputs[1], inputs[2] qual_value = self._parse_key_value(qual_key, qual_value) for attr_info in self.entities[entity_id]['attributes']: if key == attr_info['key']: flag = False for qk, qvs in attr_info['qualifiers'].items(): if qk == qual_key: for qv in qvs: if qv.can_compare(qual_value) and comp( qv, qual_value, "="): flag = True break if flag: break if flag: v = attr_info['value'] break return v