I have a dictionary of synonyms:
synonym = {"this": ["this", "same"],
"all": ["all", "any", "*"],
"alluptolastyear": ["alluptolastyear", "uptolastyear"],
"dekadbefore": ["dekadbefore", "lastdekad", "formerdekad", "precedingdekad"],
"dekadafter": ["dekadafter", "nextdekad", "followingdekad"],
"yearbefore": ["yearbefore", "lastyear", "formeryear"],
"monthbefore": ["monthbefore", "lastmonth", "precedingmonth"]}
Each array stores synonyms, referenced through the keys.
I read two strings from an XML file, and try to compare them.
For example:
"this"and"same"are equal (synonyms)- ‘”lastyear”‘ and ‘”formeryear”‘ are equal (synonyms)
"all"and"nextdekad"are different- of course, each key value is found in its corresponding array, so each key is a synonym of its array’s strings.
Could some help me to write a pythonic comparison of those strings using the synonym dictionary?
Try this:
Also, we can rewrite the part
a in synonym[k] and b in synonym[k] for k in synonymtoa in words and b in words for words in synonym.values()such that: