diff --git a/app/corpora/cqi_over_sio/utils.py b/app/corpora/cqi_over_sio/utils.py index e59c17b1..a69d4809 100644 --- a/app/corpora/cqi_over_sio/utils.py +++ b/app/corpora/cqi_over_sio/utils.py @@ -9,8 +9,7 @@ def lookups_by_cpos(corpus: CQiCorpus, cpos_list: List[int]) -> Dict: for attr in corpus.positional_attributes.list(): cpos_attr_values: List[str] = attr.values_by_cpos(cpos_list) for i, cpos in enumerate(cpos_list): - lookups['cpos_lookup'][cpos][attr.attrs['name']] = \ - cpos_attr_values[i] + lookups['cpos_lookup'][cpos][attr.name] = cpos_attr_values[i] for attr in corpus.structural_attributes.list(): # We only want to iterate over non subattributes, identifiable by # attr.has_values == False @@ -20,19 +19,19 @@ def lookups_by_cpos(corpus: CQiCorpus, cpos_list: List[int]) -> Dict: for i, cpos in enumerate(cpos_list): if cpos_attr_ids[i] == -1: continue - lookups['cpos_lookup'][cpos][attr.attrs['name']] = cpos_attr_ids[i] + lookups['cpos_lookup'][cpos][attr.name] = cpos_attr_ids[i] occured_attr_ids = [x for x in set(cpos_attr_ids) if x != -1] - if not occured_attr_ids: + if len(occured_attr_ids) == 0: continue subattrs = corpus.structural_attributes.list(filters={'part_of': attr}) - if not subattrs: + if len(subattrs) == 0: continue - lookup_name: str = f'{attr.attrs["name"]}_lookup' + lookup_name: str = f'{attr.name}_lookup' lookups[lookup_name] = {} for attr_id in occured_attr_ids: lookups[lookup_name][attr_id] = {} for subattr in subattrs: - subattr_name = subattr.attrs['name'][(len(attr.attrs['name']) + 1):] # noqa + subattr_name = subattr.name[(len(attr.name) + 1):] # noqa for i, subattr_value in enumerate(subattr.values_by_ids(occured_attr_ids)): # noqa lookups[lookup_name][occured_attr_ids[i]][subattr_name] = subattr_value # noqa return lookups