EMPTY COMMIT - assert statement vs function call

and one if statement simplified and unused variable
This commit is contained in:
Ozbolt Menegatti 2019-06-08 15:43:53 +02:00
parent 46e169095c
commit 9117734b91

43
wani.py
View File

@ -140,15 +140,14 @@ class Order(Enum):
@staticmethod
def new(order):
if order is not None:
if order == "to-from":
if order is None:
return Order.Any
elif order == "to-from":
return Order.ToFrom
elif order == "from-to":
return Order.FromTo
else:
raise NotImplementedError("What kind of ordering is: {}".format(order))
else:
return Order.Any
def match(self, from_w, to_w):
@ -359,8 +358,8 @@ class ComponentRendition:
elif feature['selection'] == "all":
self.representation_factory = WordFormAllCR
elif feature['selection'] == 'agreement':
assert(feature['head'][:4] == 'cid_')
assert(feature['msd'] is not None)
assert feature['head'][:4] == 'cid_'
assert feature['msd'] is not None
self.representation_factory = WordFormAgreementCR
self.more['agreement'] = feature['msd'].split('+')
self.more['other'] = feature['head'][4:]
@ -453,15 +452,15 @@ def build_morphology_regex(restriction):
match_type = True
if "filter" in feature_dict:
assert(feature_dict['filter'] == "negative")
assert feature_dict['filter'] == "negative"
match_type = False
del feature_dict['filter']
assert(len(feature_dict) == 1)
assert len(feature_dict) == 1
key, value = next(iter(feature_dict.items()))
restr_dict[key] = (value, match_type)
assert('POS' in restr_dict)
assert 'POS' in restr_dict
category = restr_dict['POS'][0].capitalize()
cat_code = CODES[category]
rgx = [cat_code] + CATEGORY_BASES[cat_code]
@ -471,7 +470,7 @@ def build_morphology_regex(restriction):
for attribute, (value, typ) in restr_dict.items():
index = TAGSET[cat_code].index(attribute.lower())
assert(index >= 0)
assert index >= 0
if '|' in value:
match = "".join(CODES[val] for val in value.split('|'))
@ -502,7 +501,7 @@ def build_lexis_regex(restriction):
for feature in restriction:
restr_dict.update(feature.items())
assert("lemma" in restr_dict)
assert "lemma" in restr_dict
match_list = restr_dict['lemma'].split('|')
return match_list, lambda text: text in match_list
@ -681,7 +680,7 @@ class Component:
break
else:
assert(type(match) is list)
assert type(match) is list
to_ret[-1].extend(match)
good = True
@ -704,10 +703,10 @@ class SyntacticStructure:
st.id = xml.get('id')
st.lbs = xml.get('LBS')
assert(len(list(xml)) == 1)
assert len(list(xml)) == 1
system = next(iter(xml))
assert(system.get('type') == 'JOS')
assert system.get('type') == 'JOS'
components, dependencies, definitions = list(system)
deps = [(dep.get('from'), dep.get('to'), dep.get('label'), dep.get('order'))
@ -723,7 +722,7 @@ class SyntacticStructure:
for el in comp:
if el.tag.startswith("restriction"):
assert(restrs[n] is None)
assert restrs[n] is None
restrs[n] = el
elif el.tag.startswith("representation"):
st.add_representation(n, el, forms)
@ -757,10 +756,10 @@ class SyntacticStructure:
c.type = ComponentType.Core2w
def add_representation(self, n, rep_el, forms):
assert(rep_el.tag == "representation")
assert rep_el.tag == "representation"
to_add = []
for el in rep_el:
assert(el.tag == "feature")
assert el.tag == "feature"
if 'rendition' in el.attrib or 'selection' in el.attrib:
to_add.append(el)
else:
@ -813,7 +812,7 @@ def get_lemma_features(et):
else:
raise RuntimeError("Strange rgx for lemma_feature...")
assert(rgx_str[0].isupper())
assert rgx_str[0].isupper()
result[rgx_str[0]] = rgx_str.strip().replace(' ', '-')
return result
@ -848,7 +847,7 @@ class Word:
last_num = last_num[1:]
self.int_id = int(last_num)
assert(None not in (self.id, self.lemma, self.msd))
assert None not in (self.id, self.lemma, self.msd)
@staticmethod
def pcWord(pc, do_msd_translate):
@ -1050,7 +1049,7 @@ class Writer:
else:
cols.extend(["Representative_form", "RF_scenario"])
assert(len(cols) == self.length())
assert len(cols) == self.length()
cols = ["C{}_{}".format(i + 1, thd) for i in range(MAX_NUM_COMPONENTS) for thd in cols]
cols = ["Structure_ID"] + cols + ["Colocation_ID"]
@ -1236,7 +1235,7 @@ def match_file(words, structures):
return matches
def main(input_file, structures_file, args):
def main(structures_file, args):
structures, lemma_msds = load_structures(structures_file)
colocation_ids = ColocationIds()
@ -1347,5 +1346,5 @@ if __name__ == '__main__':
logging.basicConfig(stream=sys.stderr, level=args.verbose.upper())
start = time.time()
main(args.input, args.structures, args)
main(args.structures, args)
logging.info("TIME: {}".format(time.time() - start))