Skip to content

Instantly share code, notes, and snippets.

@utkarshkukreti
Last active May 9, 2021 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utkarshkukreti/2630a3332d8313c192811d91c9e17313 to your computer and use it in GitHub Desktop.
Save utkarshkukreti/2630a3332d8313c192811d91c9e17313 to your computer and use it in GitHub Desktop.
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