<jupyter_start><jupyter_text>Because the syntactic relations form a tree, every word has **exactly one head**. You can therefore **iterate** over the **arcs** in the **tree** by **iterating** over the **words** in the sentence. This is usually the best way to match an arc of interest — from below:<jupyter_code># Importing the necessary symbols
from spacy.symbols import nsubj, VERB

# Finding a verb with a subject from below — good
verbs = set()
for possible_subject in doc:
    if possible_subject.dep == nsubj and possible_subject.head.pos == VERB:
        verbs.add(possible_subject.head)
# Printing the verbs
print(verbs)<jupyter_output>{shift}<jupyter_text>More on [Iterating over local tree](https://spacy.io/usage/linguistic-featuresnavigating-around) Children that occur before and after the Token* Token.lefts, Token.rights* Token.n_lefts, Token.n_rightsGet a whole phrase by its syntactic head using the `Token.subtree`* Token.ancestors, Token.is_ancestor()<jupyter_code># Creating a new document from the sentence
doc = nlp(u'Credit and mortgage account holders must submit their requests')
# Finding out the root token
root = [token for token in doc if token.head == token][0]

print('Root word token text - ', root.text)

# The other way may be

"""
for token in doc:
    # Rather than checking with static text of 'ROOT' can we get the text from spacy.symbols ?
    if token.dep_ == 'ROOT':
        root = token.dep_
        break
"""
# Getting the subject of the doc, that subject is always left to ROOT and it is first element of it
# subject is also the 'Token' instance
subject = list(root.lefts)[0]
print('Subject word token text -', subject.text, '\n')

# Iterating over the subtree
print('Descendant Text | Depenedency | No of Lefts | No of Rights | All Ancestors')
for descendant in subject.subtree:
    assert subject is descendant or subject.is_ancestor(descendant)
    print(descendant.text, '|', descendant.dep_, '|', descendant.n_lefts, '|', descendant.n_rights,
          '|', [ancestor.text for ancestor in descendant.ancestors])<jupyter_output>Root word token text -  submit
Subject word token text - holders 

Descendant Text | Depenedency | No of Lefts | No of Rights | All Ancestors
Credit | nmod | 0 | 2 | ['holders', 'submit']
and | cc | 0 | 0 | ['Credit', 'holders', 'submit']
mortgage | compound | 0 | 0 | ['account', 'Credit', 'holders', 'submit']
account | conj | 1 | 0 | ['Credit', 'holders', 'submit']
holders | nsubj | 1 | 0 | ['submit']<jupyter_text>Finally, the `.left_edge` and `.right_edge` attributes can be especially useful, because they give you the **first** and **last** token of the `subtree`. This is the easiest way to create a `Span` object for a syntactic phrase. Note that `.right_edge` gives a token within the subtree — so if you use it as the end-point of a range(for python lists), don't forget to +1!<jupyter_code># Creating new document from sentence
doc = nlp(u'Credit and mortgage account holders must submit their request')

# Left and right edges Edges and indexes of token in a doc, Observe .i of right_edge
print('left edge(LE) - ', doc[4].left_edge, ' LE Index -', doc[4].left_edge.i)
print('Right edge(RE) - ', doc[4].right_edge, ' RE Index -', doc[4].right_edge.i, '\n')

span = doc[doc[4].left_edge.i : doc[4].right_edge.i+1]

# Merging it to override the doc object
span.merge()
print('Text | POST Tag | Dep | HEAD Text')
for token in doc:
    print(token.text, '|', token.pos_, '|', token.dep_, '|', token.head.text)<jupyter_output>left edge(LE) -  Credit  LE Index - 0
Right edge(RE) -  holders  RE Index - 4 

Text | POST Tag | Dep | HEAD Text
Credit and mortgage account holders | NOUN | nsubj | submit
must | VERB | aux | submit
submit | VERB | ROOT | submit
their | ADJ | poss | request
request | NOUN | dobj | submit<jupyter_text>Disabling ParserIn the default models, the parser is loaded and enabled as part of the standard processing pipeline. We can disable it on demand, Disabling the parser will make **spaCy load and run much faster**.We can disable it a whole while loading the model, or we can also disable it for specific document<jupyter_code>en_model_disabled_parser_nlp = spacy.load('en', disable=['parser'])

doc1 = en_model_disabled_parser_nlp(u"This sentence shouldn't be parsed")

# TODO: Need to check why the word shouldn't is parsed ??
for token in doc1:
    print(token)

doc2 = en_model_disabled_parser_nlp(u'Same like above sentence.')

for token in doc2:
    print(token)

normal_model = spacy.load('en')

# TODO: Need to check why the word don't is parsed ??
doc = normal_model(u"I don't want this to be parsed", disable=['parser'])

for token in doc:
    print(token)
# Continued to Linguistic_features_entity_recognition.ipynb<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10947986577181208, 'fraction_numerical': 0.005453020134228188, 'mean_word_length': 4.506928406466512, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '477501', 'license': 'MIT', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1465, 'n_words': 584, 'path': 'natural-language-processing/spacy/Linguistic_features.ipynb', 'repo_name': 'pk-ai/training', 'size': '4768'}