def get_attributes(self, solr_rec): """ gets attributes for a record, based on the predicates requested in the search and optional predicates passed by a client with a GET request with parameter 'attributes' """ qm = QueryMaker() solr_field_entities = {} for attribute in self.rec_attributes: entity = self.get_entity(attribute) if entity is not False: prop_slug = entity.slug # check to make sure we have the entity data type for linked fields if entity.data_type is False and entity.item_type == 'uri': lequiv = LinkEquivalence() dtypes = lequiv.get_data_types_from_object(entity.uri) if isinstance(dtypes, list): # set te data type and the act-field # print('Found for ' + prop_slug + ' ' + dtypes[0]) entity.data_type = dtypes[0] if prop_slug in self.entities: self.entities[ prop_slug] = entity # store entitty for later use field_parts = qm.make_prop_solr_field_parts(entity) solr_field = field_parts['prefix'] + '___pred_' + field_parts[ 'suffix'] # extract children of the solr_field so we know if # we have the most specific attributes, then we can get # values for the most specific attributes self.extract_attribute_children(solr_rec, solr_field) self.clean_attribute_hiearchies() if isinstance(self.attribute_hierarchies, dict): self.other_attributes = [] for field_slug_key, values in self.attribute_hierarchies.items(): entity = self.get_entity(field_slug_key) if entity is not False: attribute_dict = LastUpdatedOrderedDict() attribute_dict['property'] = entity.label attribute_dict['values_list'] = [] attribute_dict['value'] = '' string_val = False delim = '' for val in values: if isinstance(val, str): string_val = True parsed_val = self.parse_solr_value_parts(val) attribute_dict["values_list"].append( parsed_val['label']) attribute_dict['value'] += delim + str( parsed_val['label']) else: attribute_dict["values_list"].append(val) attribute_dict['value'] += delim + str(val) delim = self.ATTRIBUTE_DELIM if len(values) == 1 \ and string_val is False: attribute_dict['value'] = values[0] self.other_attributes.append(attribute_dict)
def get_dtypes_db(self, entity_uri): """ returns an entity data type """ # haven't found it yet, so look in database lequiv = LinkEquivalence() lequiv.predicates = self.predicates dtypes = lequiv.get_data_types_from_object(entity_uri) self.predicates = lequiv.predicates self.entity_dtypes[entity_uri] = dtypes return dtypes
def get_attributes(self, solr_rec): """ gets attributes for a record, based on the predicates requested in the search and optional predicates passed by a client with a GET request with parameter 'attributes' """ qm = QueryMaker() solr_field_entities = {} for attribute in self.rec_attributes: entity = self.get_entity(attribute) if entity is not False: prop_slug = entity.slug # check to make sure we have the entity data type for linked fields if entity.data_type is False and entity.item_type == 'uri': lequiv = LinkEquivalence() dtypes = lequiv.get_data_types_from_object(entity.uri) if isinstance(dtypes, list): # set te data type and the act-field # print('Found for ' + prop_slug + ' ' + dtypes[0]) entity.data_type = dtypes[0] if prop_slug in self.entities: self.entities[prop_slug] = entity # store entitty for later use field_parts = qm.make_prop_solr_field_parts(entity) solr_field = field_parts['prefix'] + '___pred_' + field_parts['suffix'] # extract children of the solr_field so we know if # we have the most specific attributes, then we can get # values for the most specific attributes self.extract_attribute_children(solr_rec, solr_field) self.clean_attribute_hiearchies() if isinstance(self.attribute_hierarchies, dict): self.other_attributes = [] for field_slug_key, values in self.attribute_hierarchies.items(): entity = self.get_entity(field_slug_key) if entity is not False: attribute_dict = LastUpdatedOrderedDict() attribute_dict['property'] = entity.label attribute_dict['values_list'] = [] attribute_dict['value'] = '' string_val = False delim = '' for val in values: if isinstance(val, str): string_val = True parsed_val = self.parse_solr_value_parts(val) attribute_dict["values_list"].append(parsed_val['label']) attribute_dict['value'] += delim + str(parsed_val['label']) else: attribute_dict["values_list"].append(val) attribute_dict['value'] += delim + str(val) delim = self.ATTRIBUTE_DELIM if len(values) == 1 \ and string_val is False: attribute_dict['value'] = values[0] self.other_attributes.append(attribute_dict)
def _get_dtypes_db(self, entity_uri): """ returns an entity data type """ # haven't found it yet, so look in database lequiv = LinkEquivalence() return lequiv.get_data_types_from_object(entity_uri)
def _get_dtypes_db(self, entity_uri): """ returns an entity data type """ # haven't found it yet, so look in database lequiv = LinkEquivalence() return lequiv.get_data_types_from_object(entity_uri)