Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python nltk detecting clauses in sentences

import spacy
import deplacy
en = spacy.load('en_core_web_sm')

text = "This all encompassing experience wore off for a moment and in that moment, my awareness came gasping to the surface of the hallucination and I was able to consider momentarily that I had killed myself by taking an outrageous dose of an online drug and this was the most pathetic death experience of all time."

doc = en(text)
#deplacy.render(doc)

seen = set() # keep track of covered words

chunks = []
for sent in doc.sents:
    heads = [cc for cc in sent.root.children if cc.dep_ == 'conj']

    for head in heads:
        words = [ww for ww in head.subtree]
        for word in words:
            seen.add(word)
        chunk = (' '.join([ww.text for ww in words]))
        chunks.append( (head.i, chunk) )

    unseen = [ww for ww in sent if ww not in seen]
    chunk = ' '.join([ww.text for ww in unseen])
    chunks.append( (sent.root.i, chunk) )

chunks = sorted(chunks, key=lambda x: x[0])

for ii, chunk in chunks:
    print(chunk)
        
Comment

PREVIOUS NEXT
Code Example
Python :: dataproc initialization_actions error 
Python :: leer video con opencv 
Python :: function of this cod in django in django performance = serializers.SerializerMethodField() # def get_performance(self, instance): # return PerformanceSerializer(instance.performance).data 
Python :: chrome crushs in selenium 
Python :: WAP THAT ASKS A USER FOR A NUMBER OF YEARS AND THEN PRINTS OUT THE NUMBER OF DAYS, HOURS ,MINUTES AND SECONDS IN THAT NO. OF YEARS. 
Python :: Python String to array using list() method 
Python :: example python 
Python :: Sort list in-place (Original list is modified) 
Python :: japanese translator google 
Python :: Use Python to calculate (((1+2)*3)/4)^5 
Python :: how to apply tanH on pd dataframe 
Python :: python sns save plot lable axes 
Python :: get method to create a set of counters in python 
Python :: encanto meaning spanish 
Python :: how to loop over all dates in python 
Python :: pinyin to pinyin numbers python 
Python :: off-by-one error in python 
Python :: how to add 2 integers in python 
Python :: discord.py custom status 
Python :: Issue TypeError: ‘numpy.float64’ object cannot be interpreted as an integer 
Python :: spark group by alias 
Python :: jinja 2 iterate over dictionary 
Python :: get ascii value of char python online 
Python :: get multiples of a number between two numbers python 
Python :: get parameter value dynamo python 
Python :: tb to pb with python calculator 
Python :: what is proc file 
Python :: python check if dictionary empty 
Python :: python3 main.py 
Python :: python reverse words and swap case 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =