- spaCy Tutorial
- spaCy - Home
- spaCy - Introduction
- spaCy - Getting Started
- spaCy - Models and Languages
- spaCy - Architecture
- spaCy - Command Line Helpers
- spaCy - Top-level Functions
- spaCy - Visualization Function
- spaCy - Utility Functions
- spaCy - Compatibility Functions
- spaCy - Containers
- Doc Class ContextManager and Property
- spaCy - Container Token Class
- spaCy - Token Properties
- spaCy - Container Span Class
- spaCy - Span Class Properties
- spaCy - Container Lexeme Class
- Training Neural Network Model
- Updating Neural Network Model
- spaCy Useful Resources
- spaCy - Quick Guide
- spaCy - Useful Resources
- spaCy - Discussion
spaCy - Doc._ _getitem_ _ Method
This method of Doc class is used to get a token object at a particular position say n. Here, n is an integer. It also supports the negative indexing and follows the usual Python semantics.
For example, doc[-2] is doc[len(doc) - 2].
Argument
The table below explains its argument −
NAME | TYPE | DESCRIPTION |
---|---|---|
N | integer | It represents the index of the token. |
We can also get a span object which starts at a position say start and ends at a position say end. Both these positions are token index.
Example 1
An example of Doc._ _getitem_ _ method is given below −
import spacy doc = nlp_model("This is Tutorialspoint.com") doc[0].text
Output
When you run the code, you will see the following output −
'This'
Example 2
Refer the example of Doc._ _getitem_ _ method given below −
doc[-1].text
Output
When you run the code, you will see the following output −
'Tutorialspoint.com'
Example 3
Here is an another example of Doc._ _getitem_ _ method −
span = doc[1:3] span.text
Output
When you run the code, you will see the following output −
'is Tutorialspoint.com'
spacy_containers.htm
Advertisements