What I would like to do
I would like to preprocess sentences include conjunctions like below. I don’t care the tense of verb and transformation following the subject. What I want to is to hold new two sentences that have subjects and verbs individually.
**Pattern1**
They entered the house and she glanced at the dark fireplace.
["They entered the house ", "she glanced at the dark fireplace"]
**Pattern2**
Felipa and Alondra sing a song.
["Felipa sing a song”, "Alondra sing a song"]
**Pattern3**
“Jessica watches TV and eats dinner.
["Jessica watch TV, “Jessica eat dinner”]
Problem
I was able to solve the sentence of Pattern1 with the below code, but I'm stack with thinking the solutions for Pattern2 and 3 with the below code no.2.
With using the NLP library spaCy, I was able to figure out conjunctions is recognized as CCONJ
.
However, there is no clues to realize what I want to do like the above.
Please give me your advice!
Current Code
Pattern1
text = "They entered the house and she glanced at the dark fireplace."
if 'and' in text:
text = text.replace('and',',')
l = [x.strip() for x in text.split(',') if not x.strip() == '']
l
#output
['They entered the house', 'she glanced at the dark fireplace.']
working code
text = "Felipa and Alondra sing a song."
doc_dep = nlp(text)
for k in range(len(doc_dep)):
token = doc_dep[k]
print(token.text, token.lemma_, token.pos_, token.tag_, token.dep_)
if token.pos_ == 'CCONJ':
print(token.text)
#output
Felipa felipa NOUN NN nsubj
SPACE _SP
and and CCONJ CC cc
and
SPACE _SP
Alondra Alondra PROPN NNP nsubj
sing sing VERB VBP ROOT
a a DET DT det
song song NOUN NN dobj
. . PUNCT . punct
text = "Jessica watches TV and eats dinner."
doc_dep = nlp(text)
for k in range(len(doc_dep)):
token = doc_dep[k]
print(token.text, token.lemma_, token.pos_, token.tag_, token.dep_)
if token.pos_ == 'CCONJ':
print(token.text)
#output
Jessica Jessica PROPN NNP nsubj
watches watch VERB VBZ ROOT
TV tv NOUN NN dobj
and and CCONJ CC cc
and
eats eat VERB VBZ conj
dinner dinner NOUN NN dobj
. . PUNCT . punct
Development Environment
python 3.7.4
spaCy version 2.3.1
jupyter-notebook : 6.0.3