# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import spacy

nlp = spacy.load("en_core_web_sm")

# ## POS tagging

doc = nlp("My name is Vyshak and Im a Computer Science student")
for token in doc:
    print(token.text, token.lemma_, token.pos_, token.tag_, token.dep_,token.shape_, token.is_alpha, token.is_stop)

# ## Dependency Parsing
# ### Noun chunks

# Noun chunks are “base noun phrases” – flat phrases that have a noun as their head. You can think of noun chunks as a noun plus the words describing the noun – for example, “the lavish green grass” or “the world’s largest tech fund”. To get the noun chunks in a document, simply iterate over Doc.noun_chunks

for chunk in doc.noun_chunks:
    print(chunk.text, chunk.root.text, chunk.root.dep_,chunk.root.head.text)

# ### Navigating the parse tree
# spaCy uses the terms head and child to describe the words connected by a single arc in the dependency tree. The term dep is used for the arc label, which describes the type of syntactic relation that connects the child to the head. As with other attributes, the value of .dep is a hash value. You can get the string value with .dep_.

for token in doc:
    print(token.text, token.dep_, token.head.text, token.head.pos_,[child for child in token.children])

# ## Visualizing dependencies
#

from spacy import displacy
displacy.render(doc, style='dep')

displacy.serve(doc, style="ent")





StarcoderdataJupyterScriptsDedupFiltered