DEV Community

Suttipong Kullawattana
Suttipong Kullawattana

Posted on • Updated on

How to Extract Tree by spaCy

In this article, I will present the process of reading a document. for the analysis of the natural language structure of the tree These processes are useful for those working in the analysis of natural language structure from documents. This may lead to applications with applications to process language structures to prepare data. (Pre-Processing) in the process of doing Data Science, which is very important. if we can't handle the initial modeling process effectively It may be a model that has no quality.

which the algorithm to process There are steps as follows.

  • Import libraries spaCy, NLTK for natural language. processing, I will import pos_tag (Part-of-Speech Processing), word_tokenize (reading words from the Token), and Tree (drawing a tree structure).
  • Import a natural language processing model from the spaCy library using “en_core_web_sm”, a smaller language processing model. Suitable for general language processing.
  • read text from the text file.
  • Methods to draw tree structures It uses the tree node reading method, which uses the Tree algorithm to draw it.
  • Calling the Plot tree structure from an imported language readable from a file.
  • Determining the pattern of words and drawing (result.draw()) by checking words from Token.

Image description

The result of drawing a tree from a language structure.

*Sentence 1: * “A small company manufactures customized bicycles.”

Image description

Drawing the sentence structure “A small company manufactures customized bicycles.” with NLTK.

Image description

Drawing the sentence structure “A small company manufactures customized bicycles.” with spaCy.

*Sentence 2: * “Whenever the sales department receives an order, a new process instance is created.”

Image description

Drawing a sentence structure “Whenever the sales department receives an order, a new process instance is created.” with NLTK.

Image description

Drawing a sentence structure “Whenever the sales department receives an order, a new process instance is created.” with spaCy.

Top comments (0)