0

I am trying to generate a tree like this:

I am not able to find any relevant information in regard to it. Please help.

Parse

(ROOT
  (S
    (NP (PRP$ My) (NN dog))
    (ADVP (RB also))
    (VP (VBZ likes)
      (S
        (VP (VBG eating)
          (NP (NN sausage)))))
    (. .)))

Thanks.

cantSleepNow
  • 9,691
  • 5
  • 31
  • 42
smng231
  • 1
  • 1
  • 1
  • You can't find any relevant information? Google "nltk tree", that'll solve that problem. – alexis Nov 06 '16 at 21:10
  • I did. but most of them are about how to traverse a tree that is already in the above form or about how to do a parts of speech tagging – smng231 Nov 06 '16 at 22:07
  • 1
    Well then you should edit your question and be more specific about what you already know, and what you need help with. This is how this site works: Show where you are and ask for help with what you need to know to do the next step. – alexis Nov 07 '16 at 08:51

2 Answers2

1

The NLTK comes with a number of parsers based on CFG and other grammar formalisms, but they are teaching tools of very little practical use: They can only handle a tiny subset of English syntax. (If this is what you are after, your question is a duplicate of this SO question.)

To parse ordinary English text with the nltk, you'll need to install a third-party parser that the nltk knows how to interface with. Your best bet is probably the Stanford Parser, as you probably already knew since you tagged your question . You'll need the latest version of the nltk (or version 3.1 at least, but later is better.) The abovementioned SO question has some other suggestions in the answers; no idea if they are any good.

Community
  • 1
  • 1
alexis
  • 48,685
  • 16
  • 101
  • 161
0

you can use StanfordCoreNLP to achieve that

download :

pip install pycorenlp

start your server in this (stanford-corenlp-full-2018-01-31) directory with this command -

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000

from pycorenlp import StanfordCoreNLP
nlp = StanfordCoreNLP('http://localhost:9000')
 output = nlp.annotate(textInput, properties={
    'annotators': 'parse',
    'outputFormat': 'json',
    'timeout': 1000,
})
print(output['sentences'][0]["parse"])

sample input :

Is there any way to associate spotify music with a specific ambient so when I say to Siri Start Beach Ambient

output :

(ROOT (SQ (VBZ Is) (NP (EX there)) (NP (NP (DT any) (NN way)) (S (VP (TO to) (VP (VB associate) (NP (JJ spotify) (NN music)) (PP (IN with) (NP (NP (DT a) (JJ specific)) (ADJP (JJ ambient) (RB so) (SBAR (WHADVP (WRB when)) (S (NP (PRP I)) (VP (VBP say) (PP (TO to) (NP (NNP Siri) (NNP Start) (NNP Beach) (NNP Ambient))))))))))))) (. .))) hope this may help.

Satyaaditya
  • 537
  • 8
  • 26