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

51
wani.py
View File

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