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.

Revisions

  1. pmbaumgartner created this gist Jun 23, 2022.
    13 changes: 13 additions & 0 deletions dep-displacy.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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)