Created
October 31, 2020 14:42
-
-
Save elyasha/a4befbdb27239f3813425207ca619c3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import spacy | |
from nltk import Tree | |
from squids import squids_text | |
dependency_parser = spacy.load('en') | |
parsed_squids = dependency_parser(squids_text) | |
# Assign my_sentence a new value: | |
my_sentence = "I am learning Parsing Text" | |
my_parsed_sentence = dependency_parser(my_sentence) | |
def to_nltk_tree(node): | |
if node.n_lefts + node.n_rights > 0: | |
parsed_child_nodes = [to_nltk_tree(child) for child in node.children] | |
return Tree(node.orth_, parsed_child_nodes) | |
else: | |
return node.orth_ | |
for sent in parsed_squids.sents: | |
to_nltk_tree(sent.root).pretty_print() | |
for sent in my_parsed_sentence.sents: | |
to_nltk_tree(sent.root).pretty_print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment