Skip to content

Instantly share code, notes, and snippets.

@pmbaumgartner
Created June 23, 2022 20:20
Show Gist options
  • Save pmbaumgartner/31b0968a4e800bc43b0063e29cb74928 to your computer and use it in GitHub Desktop.
Save pmbaumgartner/31b0968a4e800bc43b0063e29cb74928 to your computer and use it in GitHub Desktop.
dependency matcher displacy example
from spacy import displacy
from spacy.tokens import Doc
from spacy.util import get_lang_class
from pathlib import Path
words = ["The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "fox"]
heads = [3, 3, 3, 4, 4, 4, 8, 8, 5]
deps = ["det", "amod", "amod", "nsubj", "ROOT", "prep", "pobj", "det", "amod"]
doc = Doc(get_lang_class("en")().vocab, words=words, heads=heads, deps=deps)
html = displacy.render(doc)
output_path = Path("depdendencymatchertest.html")
output_path.open("w", encoding="utf-8").write(html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment