Python Natural Language Processing
上QQ阅读APP看书,第一时间看更新

What is syntactic analysis?

Syntactic analysis is defined as analysis that tells us the logical meaning of certain given sentences or parts of those sentences. We also need to consider rules of grammar in order to define the logical meaning as well as correctness of the sentences.

Let's take an example: If I'm considering English and I have a sentence such as School go a boy, this sentence does not logically convey its meaning, and its grammatical structure is not correct. So, syntactic analysis tells us whether the given sentence conveys its logical meaning and whether its grammatical structure is correct.

Syntactic analysis is a well-developed area of NLP that deals with the syntax of NL. In syntactic analysis, grammar rules have been used to determine which sentences are legitimate. The grammar has been applied in order to develop a parsing algorithm to produce a structure representation or a parse tree.

Here, I will generate the parse tree by using the nltk and Python wrapper libraries for Stanford CoreNLP called pycorenlp. Refer the following code snippet in Figure 3.10 and in Figure 3.11. The output is given in Figure 3.12:

Figure 3.10: Code snippet for syntactic analysis

How you can use Stanford parser for syntactic analysis is demonstrated in next Figure 3.11:

Figure 3.11: Code snippet for syntactic analysis

You can see the output of the preceding two code snippet as follows. Refer to Figure 3.12:

Figure 3.12: Output of parsing as part of syntactic analysis

We will see the parsing tools and its development cycle related details in Chapter 5, Feature Engineering and NLP Algorithms.