2016-06-29 11 views
-1

Ich muss Python verwenden, um Sätze in Absätze für die Videoüberschrift zu trennen. Ich habe versucht, nltk.tokenize.texttiling zu verwenden, aber habe keine Ergebnisse erhalten. Hier ist der Auszug aus dem Text:Verwenden von Python zum Trennen von Sätzen in Absätze

– [Voiceover] Bob Dylan is, 
you must be 20 years old now, 
aren't you? 
– [Voiceover] Yeah, I must be 20. 
(laughing) 
– [Voiceover] Are you? 
– [Voiceover] Yeah, I'm 20, I'm 20. 
(guitar music) 
My hands are cold. 
It's a pretty cold studio. 
– [Voiceover] The coldest studio. 
– [Voiceover] Usually can do this. 
There I just want to do it once. 
(guitar strumming) 
– [Voiceover] When I first heard Bob Dylan 
was, I think, about three 
years ago in Minneapolis. 
– [Voiceover] At that time I 
was just sort of doing nothing. 
I was there working, I guess. 
I was making pretend I was 
going to school out there. 
I'd just come there from South Dakota. 
– [Voiceover] You've sung 
now at Goody's here in town. 
Have you sung at any of the coffee houses? 
+3

Ich habe nie Kopf von so etwas. Versuchen Sie auf jeden Fall, Transkripte menschlicher Konversation zu analysieren? Aus diesen Absätzen Absätze zu machen, erscheint völlig unsinnig - Absätze sind eine Möglichkeit, menschliches Schreiben zu organisieren, und sie gelten nicht für menschliche Konversation. –

+0

Wie würden Sie Sätze in Absätze trennen? Ein Absatz besteht aus Sätzen, aber Sätze bestehen aus Wörtern. – direprobs

+0

Sätze können mit NLTK-Modul gefunden werden, und wenn das Thema vollständig zwischen den Sätzen geändert wird, dann ist es der Hinweis auf den neuen Absatz. So funktioniert TextTiling. – Shurik

Antwort

0

Scheint ziemlich einfach, Sie regex verwenden können, dies zu tun, did't Ich weiß, welches Format Sie wollen, aber hier ist ein Beispiel

import re 

sentence = """ 
– [Voiceover] Bob Dylan is, 
you must be 20 years old now, 
aren't you? 
– [Voiceover] Yeah, I must be 20. 
(laughing) 
– [Voiceover] Are you? 
– [Voiceover] Yeah, I'm 20, I'm 20. 
(guitar music) 
My hands are cold. 
It's a pretty cold studio. 
– [Voiceover] The coldest studio. 
– [Voiceover] Usually can do this. 
There I just want to do it once. 
(guitar strumming) 
– [Voiceover] When I first heard Bob Dylan 
was, I think, about three 
years ago in Minneapolis. 
– [Voiceover] At that time I 
was just sort of doing nothing. 
I was there working, I guess. 
I was making pretend I was 
going to school out there. 
I'd just come there from South Dakota. 
– [Voiceover] You've sung 
now at Goody's here in town. 
Have you sung at any of the coffee houses? 

""" 

start_re = re.compile(r'\–\s\[.*?\]') 
result = re.split(start_re,sentence) 
result = filter(lambda x:x, [s.replace('\n','').strip() for s in result]) 
print result 

OUTPUT

["Bob Dylan is,you must be 20 years old now,aren't you?", 'Yeah, I must be 20.(laughing)', 'Are you?', "Yeah, I'm 20, I'm 20.(guitar music)My hands are cold.It's a pretty cold studio.", 'The coldest studio.', 'Usually can do this.There I just want to do it once.(guitar strumming)', 'When I first heard Bob Dylanwas, I think, about threeyears ago in Minneapolis.', "At that time Iwas just sort of doing nothing.I was there working, I guess.I was making pretend I wasgoing to school out there.I'd just come there from South Dakota.", "You've sungnow at Goody's here in town.Have you sung at any of the coffee houses?"] 
+0

Ich denke, das ist die Sätze zu finden, aber nicht Absätze. Ich verstehe, dass die Paragrafeidentifikation eine harte Aufgabe ist und die Grenze subtil ist, aber wenn Sie mir irgendeine andere Bibliothek vorschlagen können, anstatt ntk.tokenize.texttilling das würde sehr geschätzt werden. – Shurik

Verwandte Themen