nlp - Extract clauses from sentence in python -


I have a list of sections from the given sentences. I am implementing the rules of my own grammar by parsing the sentence out of sentence. The result I get is:

  **************************************************** ************** (S (section (VP (VP they were / PRP / VBD / VBN immediately / RB) and / cc (VP a / dt lot / RB)) (NP (NP good / JJ price / NN) and / cc (NP excellent / NN))) (section (VP all / dt) in / (NP (NP around (NP shoe / NN)) (NP with / in ( NP traction / NN))) ./. ********************************************************************************************* **************************************************************************************************** *** *********  

Results listed above, section out To result in the following statements should be.

were immediately distributed and very good value and excellent

With all traction near some slippers.

I've tried using flat and chomsky_normal_form but could not get the desired results. Tags How to get rid of each section in a single line to get rid of?

You can make an application you want to remove all your string s is lowercase appears, you receive the following one-liners:

Python list comprehension < / Strong>

  print '' .join ('' to join in C for C (if 'a'. & Lt; = C & lt; = 'Z' or c == '') .split ())  

It connects all the characters between "a" and "z" or "" ( ".include ). To suppress many spaces, this result is divided for each other and it is connected again with a space in the form of a separator. Regular expression

If you want, regular expression ( import again ), this less statement yields the same results :

  print '' .join (re.findall ('[az] +', s))  

Edit

If you want to process each section individually, then apply the entire code to the s and then the same code in each part (preceded Except for the header only): s.split ("clause") for the part

  [1:]: print '' .join (re.findall ('[az] +', part))  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -