def __init__(self, rr_client): log.debug("EnhancedResourceRegistryClient init") self.RR = rr_client log.debug("Generating lookup tables for %s resources and their labels", len(RT.values())) self.resource_to_label = dict([(v, self._uncamel(v)) for v in RT.values() if type("") == type(v)]) self.label_to_resource = dict([(self._uncamel(v), v) for v in RT.values() if type("") == type(v)]) log.debug("Generating lookup tables for %s predicates and their labels", len(PRED.values())) self.predicate_to_label = dict([(v, self._uncamel(v)) for v in PRED.values() if type("") == type(v)]) self.label_to_predicate = dict([(self._uncamel(v), v) for v in PRED.values() if type("") == type(v)]) log.debug("Generating predicate lookup table") self.predicates_for_subj_obj = {} log.debug("Building predicate list") self._build_predicate_list() # various tests #m = re.match(r"(assign_)(\w+)(_to_)(\w+)((_with_)?)((\w+)?)", "assign_x_x_to_y_y_with_bacon") #raise BadRequest(m.groups()) #self.assign_x_x_to_y_y() #self.assign_instrument_model_to_instrument_device() # #mults = [] #for d, rng in self.predicates_for_subj_obj.iteritems(): # for r, preds in rng.iteritems(): # if 1 < len(preds): # mults.append(" --- %s to %s has %s" % (d, r, preds)) #raise BadRequest(str(mults)) # log.debug("done init")
def _build_lookups(cls): lookup_dict = {} log.debug("Generating lookup tables for %s resources and their labels", len(RT)) lookup_dict["resource_to_label"] = dict([(v, cls._uncamel(v)) for v in RT.values() if type("") == type(v)]) lookup_dict["label_to_resource"] = dict([(cls._uncamel(v), v) for v in RT.values() if type("") == type(v)]) log.debug("Generating lookup tables for %s predicates and their labels", len(PRED.values())) lookup_dict["predicate_to_label"] = dict([(v, cls._uncamel(v)) for v in PRED.values() if type("") == type(v)]) lookup_dict["label_to_predicate"] = dict([(cls._uncamel(v), v) for v in PRED.values() if type("") == type(v)]) log.debug("Generating predicate lookup table") lookup_dict["predicates_for_subj_obj"] = cls._build_predicate_list() return lookup_dict
def __init__(self, rr_client): log.debug("EnhancedResourceRegistryClient init") self.RR = rr_client log.debug("Generating lookup tables for %s resources and their labels", len(RT.values())) self.resource_to_label = dict([(v, self._uncamel(v)) for v in RT.values() if type("") == type(v)]) self.label_to_resource = dict([(self._uncamel(v), v) for v in RT.values() if type("") == type(v)]) log.debug( "Generating lookup tables for %s predicates and their labels", len(PRED.values())) self.predicate_to_label = dict([(v, self._uncamel(v)) for v in PRED.values() if type("") == type(v)]) self.label_to_predicate = dict([(self._uncamel(v), v) for v in PRED.values() if type("") == type(v)]) log.debug("Generating predicate lookup table") self.predicates_for_subj_obj = {} log.debug("Building predicate list") self._build_predicate_list() # various tests #m = re.match(r"(assign_)(\w+)(_to_)(\w+)((_with_)?)((\w+)?)", "assign_x_x_to_y_y_with_bacon") #raise BadRequest(m.groups()) #self.assign_x_x_to_y_y() #self.assign_instrument_model_to_instrument_device() # #mults = [] #for d, rng in self.predicates_for_subj_obj.iteritems(): # for r, preds in rng.iteritems(): # if 1 < len(preds): # mults.append(" --- %s to %s has %s" % (d, r, preds)) #raise BadRequest(str(mults)) # log.debug("done init")