Fix context size and codestyle

This commit is contained in:
Patrick Jentsch 2020-04-14 09:51:33 +02:00
parent 9a1efbe5f3
commit 7c8ae161a9
3 changed files with 14 additions and 9 deletions

View File

@ -130,7 +130,8 @@ class StructuralAttribute(Attribute):
else: else:
cpos_list_lbound = first_cpos cpos_list_lbound = first_cpos
rc_rbound = \ rc_rbound = \
self.cpos_by_id(min((last_id + context), (self.attrs['size'] - 1)))[1] self.cpos_by_id(min((last_id + context),
(self.attrs['size'] - 1)))[1]
if rc_rbound != last_cpos: if rc_rbound != last_cpos:
rc_lbound = min((last_cpos + 1), rc_lbound = min((last_cpos + 1),
(self.collection.corpus.attrs['size'] - 1)) (self.collection.corpus.attrs['size'] - 1))

View File

@ -30,14 +30,16 @@ class Corpus(Model):
for attr in self.positional_attributes.list(): for attr in self.positional_attributes.list():
cpos_attr_values = attr.values_by_cpos(cpos_list) cpos_attr_values = attr.values_by_cpos(cpos_list)
for i, cpos in enumerate(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.attrs['name']] = \
cpos_attr_values[i]
for attr in self.structural_attributes.list(): for attr in self.structural_attributes.list():
if attr.attrs['has_values']: if attr.attrs['has_values']:
continue continue
cpos_attr_ids = attr.ids_by_cpos(cpos_list) cpos_attr_ids = attr.ids_by_cpos(cpos_list)
for i, cpos in enumerate(cpos_list): for i, cpos in enumerate(cpos_list):
if cpos_attr_ids[i] != -1: if cpos_attr_ids[i] != -1:
lookups['cpos_lookup'][cpos][attr.attrs['name']] = cpos_attr_ids[i] lookups['cpos_lookup'][cpos][attr.attrs['name']] = \
cpos_attr_ids[i]
occured_attr_ids = list(filter(lambda x: x != -1, occured_attr_ids = list(filter(lambda x: x != -1,
set(cpos_attr_ids))) set(cpos_attr_ids)))
if not occured_attr_ids: if not occured_attr_ids:
@ -53,7 +55,8 @@ class Corpus(Model):
for subattr in subattrs: for subattr in subattrs:
subattr_values = subattr.values_by_ids(occured_attr_ids) subattr_values = subattr.values_by_ids(occured_attr_ids)
for i, subattr_value in enumerate(subattr_values): for i, subattr_value in enumerate(subattr_values):
subattr_name = subattr.attrs['name'][(len(attr.attrs['name']) + 1):] subattr_name = \
subattr.attrs['name'][(len(attr.attrs['name']) + 1):]
lookups[lookup_name][occured_attr_ids[i]][subattr_name] = \ lookups[lookup_name][occured_attr_ids[i]][subattr_name] = \
subattr_value subattr_value
return lookups return lookups

View File

@ -37,9 +37,10 @@ class Subcorpus(Model):
return {"matches": []} return {"matches": []}
first_match = max(0, offset) first_match = max(0, offset)
last_match = min((offset + cutoff - 1), (self.attrs['size'] - 1)) last_match = min((offset + cutoff - 1), (self.attrs['size'] - 1))
match_boundaries = \ match_boundaries = zip(self.dump(self.attrs['fields']['match'],
zip(self.dump(self.attrs['fields']['match'], first_match, last_match), # noqa first_match, last_match),
self.dump(self.attrs['fields']['matchend'], first_match, last_match)) # noqa self.dump(self.attrs['fields']['matchend'],
first_match, last_match))
cpos_list = [] cpos_list = []
matches = [] matches = []
for match_start, match_end in match_boundaries: for match_start, match_end in match_boundaries:
@ -50,7 +51,7 @@ class Subcorpus(Model):
else: else:
lc_rbound = max(0, (match_start - 1)) lc_rbound = max(0, (match_start - 1))
if lc_rbound != match_start: if lc_rbound != match_start:
lc_lbound = max(0, (match_start - 1 - context)) lc_lbound = max(0, (match_start - context))
lc = (lc_lbound, lc_rbound) lc = (lc_lbound, lc_rbound)
cpos_list_lbound = lc_lbound cpos_list_lbound = lc_lbound
else: else:
@ -58,7 +59,7 @@ class Subcorpus(Model):
rc_lbound = min((match_end + 1), rc_lbound = min((match_end + 1),
(self.collection.corpus.attrs['size'] - 1)) (self.collection.corpus.attrs['size'] - 1))
if rc_lbound != match_end: if rc_lbound != match_end:
rc_rbound = min((match_end + 1 + context), rc_rbound = min((match_end + context),
(self.collection.corpus.attrs['size'] - 1)) (self.collection.corpus.attrs['size'] - 1))
rc = (rc_lbound, rc_rbound) rc = (rc_lbound, rc_rbound)
cpos_list_rbound = rc_rbound cpos_list_rbound = rc_rbound