Skip to content

Instantly share code, notes, and snippets.

@utkarshkukreti

utkarshkukreti/normalize.py Secret

Last active May 9, 2021
Embed
What would you like to do?
import change_manager
import wordnet
import wordnet_yaml
def normalize(text):
return text.strip().replace(" ", " ").replace("( ", "(").replace(" )", ")")
def main():
wn = change_manager.parse_wordnet("wn.xml")
for synset in wn.synsets:
synset.definitions = [
wordnet.Definition(normalize(d.text))
for d in synset.definitions
if d.text.strip()
]
if synset.ili_definition:
synset.ili_definition = wordnet.Definition(
normalize(synset.ili_definition.text)
)
for example in synset.examples:
example.text = normalize(example.text)
synset.examples = [
example for example in synset.examples if example.text.strip()
]
change_manager.save_all_xml(wn)
wordnet_yaml.save(wn)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment