| ## This programme analyses a Praat text-grid corpus of French interrogatives (caution: it does not filter sentence mood types -the corpus has to consist of questions only) according to their semantic and phonomorphosyntactic forms. | |
| ### call e.g. as... | |
| ### Corpus_builder_Praat.pl "Maya_l'Abeille.txt" "Maya" | |
| ### ...if you saved the questions of "Maya l'Abeille" under that file name. | |
| ##Preparations before using this programme: | |
| ### Praat writes by default to ".TextGrid", so you have to change the ending to ".txt" to make it readable. | |
| ### If you want to make sure that all inverted structures are found, the verb and subject of each question should be annotated as "_v" and "_s" whenever the subject is non-clitic (otherwise only pronominal inversion can be detected so far) | |
| ### To make sure that relative pronouns are not counted as question words, "qui/qu'/que" functioning as RP can be marked by "_rp" | |
| ### Then, you need to combine all of the files of your (sub-)corpus, e.g. by putting all text files into one folder and using the command "for %f in (*.txt) do type "%f" >> output.txt"(see http://www.wikihow.com/Merge-Text-(.Txt)-Files-in-Command-Prompt) | |
| ### Unfortunately this does not always work => replace the unwritten files manually. | |
| ### Make sure you did not use any question marks in your annotations since question marks are used as separators. | |
| ### Since special characters are not always recognized, you might want to use the following characters: A for à, AA for â, U for ù, E for é, EE for è, EEE for ê, C for ç, CC for Ç, I for î | |
| ######################################################################## | |
| # PART 1: Question Extracter & Annotater | |
| ######################################################################## | |
| #In the beginning | |
| $filename = $ARGV[1]; #the second entry of the command line is the file name! | |
| open(F, $ARGV[0]) or die("Can't open file $ARGV[0]!\n"); #opens the text file (=the first addition to the programme in the command line) | |
| open(F1, ">$filename 1.sentences_with_intonation.txt") or die("can't write to file!\n"); #creates/overwrites the file in which the output is saved | |
| #Go through the original text | |
| while ($line = <F>) #for as long as there are lines, do the following for each line: | |
| { | |
| #set the nuclear configuration according to the last mentioned T*T% | |
| if ($line =~ /Tones/) #if the line contains "Tones" (which is the tier name before indicating the tones) | |
| {$TA = ""; $TB = ""} #(re)assign the empty string | |
| if ($line =~ /\!H\*/) #if the current line contains "!H*"('a high tonal accent downstepped') | |
| {$TA = "!H*"} #(re)assign the value "!H*" for $TA (the final accent tone) | |
| elsif ($line =~ /\!H%/) #if the current line contains "!H%"('a high boundary tone downstepped') | |
| {$TB = "!H%"} #(re)assign the value "!H%" for $TB (the final accent tone) | |
| else | |
| { | |
| if ($line =~ /H\*/) #if the current line contains "H*"('a high tonal accent'), | |
| {$TA = "H*"} #(re)assign the value "H*" for $TA (the final accent tone) | |
| if ($line =~ /L\*/) #if the current line contains "L*"('a low tonal accent'), | |
| {$TA = "L*"} #(re)assign the value "L*" for $TA (the final accent tone) | |
| if ($line =~ /H%/) #if the current line contains "H%"('a high boundary tone'), | |
| {$TB = "H%"} #(re)assign the value "H%" for $TB (the boundary tone) | |
| if ($line =~ /L%/) #if the current line contains "L%"('a low boundary tone'), | |
| {$TB = "L%"} #(re)assign the value "L%" for $TB (the boundary tone) | |
| } | |
| #replace the whole sentence line by the sentence only (i.e. delete everything else) and add its ID + its nuclear configuration | |
| if ($TA eq "" or $TB eq "") #if the nuclear configuration is incomplete | |
| {if ($line =~ /text = (.*)\?/) #leaves out all text that is not the sentence | |
| {$line =~ s/(.*)text = (.*)\?/n.a. $2?/; #substitutes the string by nothing but the interrogative and adds the nuclear configuration to its front | |
| print (F1 $line); #prints the adjusted line in the new file | |
| } | |
| } | |
| elsif ($line =~ /text = (.*)\?/) #leaves out all text that is not the sentence | |
| {$line =~ s/(.*)text = (.*)\?/$TA$TB $2?/; #substitutes the string by nothing but the interrogative and adds the nuclear configuration to its front | |
| print (F1 $line); #prints the adjusted line in the new file | |
| } | |
| #set $id as "on"(1) when a line contains "ID" and then again as "off" (0) when "Situation" appears | |
| if ($line =~ /ID/) | |
| {$id = 1} | |
| if ($line =~ /(S|s)ituation/) | |
| {$id = 0} | |
| if ($id == 1) | |
| { | |
| if($line =~ /text = "(.*)"/){$ID = $1} #when $id equals 1 and the current line contains "text = "..."", set $ID = ... | |
| } | |
| #set $print as "on"(1) when a line contains "prag" (or anything longer like "pragmatic question type") and then again as "off" (0) when "Tones" appears | |
| if ($line =~ /\"(P|p)rag(.*)?\"/) | |
| {$print = 1} | |
| if ($line =~ /(C|c)omment/) | |
| {$print = 0} | |
| if ($print == 1) | |
| { | |
| if($line =~ /text = "(.*)"/){print (F1 "$ID $1\n")} | |
| } | |
| } | |
| #Close the written file, reopen it to read it in, and open the next file to be written | |
| close(F1); #close the corpus file | |
| open(F1, "$filename 1.sentences_with_intonation.txt") or die("can't write to file!\n"); #reopens the corpus file to read it in | |
| open(F1b, ">$filename 2.sentences_with_intonation_and_pragmatic_type.txt")or die("can't write to file!\n"); #creates/overwrites another file | |
| open(F2, ">$filename 3.formally_annotated_corpus.txt") or die("can't write to file!\n"); #creates/overwrites another file in which the annotated output is saved | |
| while ($line = <F1>) | |
| {if ($line =~ /\w/) | |
| {if ($line =~ /"(.*)"/) | |
| {chomp $line}; #remove new line characters | |
| print (F1b $line)} | |
| } | |
| close (F1b); | |
| open (F1b, "$filename 2.sentences_with_intonation_and_pragmatic_type.txt")or die("can't open file!\n"); | |
| #Go through the corpus | |
| while ($line = <F1b>) | |
| { | |
| #Annotate the morphosyntactic forms | |
| ## Elliptical constructions | |
| if | |
| ($line =~ /, n'est-ce pas( )?\?/ or $line =~ /"(\(.*\) )?((Ou|Et|Mais|Rien de) )?(\S)*( (\S)*)?(, (\S)*)?( )?\?/ and $line !~ /((Q|q)u'est-ce)|(c|C)'est(.*)\?/) #if the line consists of two words only (or two words + 1 word, separated by a comma) | |
| { | |
| if ($line =~ /"(\(.*\))?(Tu|T'(a|e)s|Vous|C'est) (\S)*(, (\S)*)?( )?\?/ #if the line consists of "Tu, "Vous" or "C'est" + a second word (or two words separated by a comma) | |
| or $line =~ /"((\S)+, )?(\S)+ (\S)+( (\S)+)*, n'est-ce pas( )?\?/) | |
| {print (F2 "DEC_$line")} #annotate it as a declarative interrogative | |
| elsif ($line =~ /(est-ce|(A|a)|(E|e))s-tu|((A|a)vez|(EEE|E|ê)tes)-vous/) | |
| {print (F2 "INV_$line")} #annotate it as an inverted interrogative | |
| else #otherwise | |
| {print(F2 "ELL_$line")} #annotate it as an elliptical one | |
| } | |
| ## "est-ce que" structures | |
| elsif($line =~ /(\(.*\))?(E|e)st-ce (que|qu'|qui|tu|vous|nous)/) #if the current line contains either "est-ce que", "est-ce qu'" or "est-ce qui" (or "est-ce" + "tu/nous/vous") | |
| { | |
| print(F2 "ESK_$line") #print the annotated sentence in the file | |
| } | |
| ## inverted structures | |
| elsif ($line =~ /(e-j|es-t|(A|a)(i)?s-tu|t-i|t-e|ez-v|ons-n|(O|o)(U|ù) (es|sont)|_v(.*)_s)/) #if the current line contains either a verb (=>verbal ending) followed by a hyphen, or the verb is placed before the subject (=>)? | |
| { | |
| print(F2 "INV_$line") #print the annotaded sentence in the file | |
| } | |
| ## morphosyntactically unmarked structures | |
| else { #if the current line is neither inverted nor does it contain "est-ce que/qu'/qui" | |
| print(F2 "DEC_$line") #print the annotated sentence in the file | |
| } | |
| } | |
| #Close the written file, reopen it to read it in, and open the next two files to be written | |
| close(F2); #closes the written annotated corpus file | |
| open(F2, "$filename 3.formally_annotated_corpus.txt") or die("can't open the file!\n"); #reopens the annotated corpus file to read it in | |
| open(F3, ">$filename 4.semantically_annotated_corpus.txt")or die("can't write to file!\n"); #opens/create a new file to edit the corpus | |
| open(F4, ">$filename 5.fully_annotated_corpus.txt")or die("can't write to file!\n"); #opens/create a new file to edit the corpus | |
| #categorize the sentences as yes-no, disjunctive or wh-interrogatives | |
| ##Set the counters to zero (otherwise printing the counters will result in printing no number if there is no token of one type) | |
| $num_yni = 0; | |
| $num_whi = 0; | |
| $num_dsi = 0; | |
| ##Go through the formally annotated corpus | |
| while ($line = <F2>) | |
| { | |
| #"ou quoi" => disjunctive interrogatives (DSI) | |
| if ($line =~ / ou quoi( )?\?/) #if the current line contains "ou quoi" before the question mark | |
| { | |
| print(F3 "DSI_$line") #print DSI together with the sentence in the file | |
| } | |
| ## => if the interrogative contains 'or what', it is a disjunctive one | |
| #tag-only YNI | |
| elsif ($line =~ /N'est-ce pas|Hein/) | |
| { | |
| $line =~ s/DEC/ELL/; print(F3 "YNI_$line") | |
| } | |
| #wh-interrogatives (WHI) | |
| elsif ($line =~ /(.*)((Q|q)u'|Qui |quoi )est-ce/) #if the current line contains "Qu'est-ce", "Qui est-ce que" or (à, de, ....)"quoi est-ce que" | |
| {$line =~ s/DEC/ESK/; print(F3 "WHI_$line")} #annotate it as WHI | |
| elsif ($line =~ /(.*)(( q|Q)(uand|u'|ue|uoi|ui|uel)|(C|c)(omment|ombien)|(P|p)ourquoi|(O|o)(ù|U))( |\?|,)/) #if the current line contains a question word | |
| { | |
| if ($line =~ /INV/){print(F3 "WHI_$line")} #if the line contains "INV", print the whole sentence in the file and add "WHI" in front of it | |
| elsif ($line =~ /ELL/){print(F3 "WHI_$line")} #if the line contains "ELL", print the whole sentence in the file and add "WHI" in front of it | |
| elsif ($line =~ /(.*)(( q|Q)(uand|u'|uoi|ui|uel)|(C|c)(omment|ombien)|(P|p)ourquoi|(O|o)(ù|U)) est-ce qu/){print(F3 "WHI_$line")} | |
| elsif (($line !~ /(.*)Est-ce qu| ce que |On peut savoir|(C|c)'est(.*)qu(e|i)|((V|v)ous|(T|t)u)(.*)(que|qui|quel(le)?)/) or ($line =~ /(P|p)ourquoi (.*) que/)) #and the line does not contain the interrogative particle "est-ce que" nor the relative pronoun "ce que" nor the presentative "c'est... que" (=>"que" is really a question word) | |
| { | |
| if ($line =~ /DEC(.*)(Q(uand|u'|ue|ui|uel|uoi)|Lequel|C(omment|ombien)|(P|p)ourquoi|Pour qu|O(U|ù)) / #if the current line is marked as declarative and starts with a question word | |
| or $line =~ /DEC(.*)((((Et|(H(ey,|é,|E,) m|M)ais)( )?((à|A)|de|par|pour)?)|(À|A|De|Par|Pour)) (q(uand|u'|ue|ui|uel|uoi)|lequel|c(omment|ombien)|pourquoi|pour qu|o(U|ù))) /) #or a conjunction/preposition + question word | |
| {$line =~ s/DEC/FRO/; print(F3 "WHI_$line")} #replace "DEC" by "FRO" (since the interrogative element is fronted) | |
| elsif ($line =~ /DEC/) #if that is not the case, but the line is marked as declarative | |
| {$line =~ s/DEC/SIT/; print(F3 "WHI_$line")} | |
| } | |
| else {print(F3 "YNI_$line")} | |
| } #if the question word presumed is actually part of "este-ce que" or "c'est ... que" print "YNI" in front of the whole sentence | |
| ## => if the interrogative contains a question word, it is a constituent one | |
| #disjunctive interrogatives (DSI) | |
| elsif ($line =~ / ou / and $line =~ /L%/){ #if the current line contains "ou" AND is uttered with falling intonation | |
| print(F3 "DSI_$line"); #print the number of occurrences and the whole sentence in the file | |
| } | |
| ## => if the interrogative contains "or" AND is uttered with falling intonation, it is a disjunctive one | |
| #yes-no interrogative (YNI) | |
| else { #otherwise... | |
| print(F3 "YNI_$line") #print the number of occurrences and the whole sentence in the file | |
| } | |
| ## => in any other case, it is a polar interrogative | |
| } | |
| close(F3); | |
| open(F3, "$filename 4.semantically_annotated_corpus.txt"); | |
| while ($line = <F3>) | |
| { | |
| #copy the short form of the pragmatic type in front of the sentence | |
| if($line =~ /[^\(](((G|g)enuine)|(info(.*)?-seeking)|precision) (Q|q)/) | |
| {$line =~ s/(.*)%/$1% GEN:/; $line =~ s/(.*)n\.\a./$1n.a. GEN:/;print(F4 "$line")} | |
| elsif($line =~ /[^\(](C|c)onfirmation-seeking (Q|q)/) | |
| {$line =~ s/(.*)%/$1% CON:/; $line =~ s/(.*)n\.a\./$1n.a. CON:/;print(F4 "$line")} | |
| elsif($line =~ /[^\(](E|e)cho (Q|q)/) | |
| {$line =~ s/(.*)%/$1% ECH:/; $line =~ s/(.*)n\.a\./$1n.a. ECH:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(](P|p)rompting (Q|q)/) | |
| {$line =~ s/(.*)%/$1% PRO:/; $line =~ s/(.*)n\.a\./$1n.a. PRO:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(](S|s)elf-(add?ress?|direct)ed (Q|q)/) | |
| {$line =~ s/(.*)%/$1% SEL:/; $line =~ s/(.*)n\.a\./$1n.a. SEL:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(](E|e)xam|(P|p)lay (Q|q)/) | |
| {$line =~ s/(.*)%/$1% EXA:/; $line =~ s/(.*)n\.a\./$1n.a. EXA:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(](I|i)ntroductory|(T|t)hought-guiding|(N|n)ew topic (Q|q)/) | |
| {$line =~ s/(.*)%/$1% NEW:/; $line =~ s/(.*)n\.a\./$1n.a. NEW:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(]((S|s)uggest(ing|ive)|offering) (Q|q)/) | |
| {$line =~ s/(.*)%/$1% OFF:/; $line =~ s/(.*)n\.a\./$1n.a. OFF:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(](T|t)easing (Q|q)/) | |
| {$line =~ s/(.*)%/$1% TEA:/; $line =~ s/(.*)n\.a\./$1n.a. TEA:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(](A|a)nswer-offering (Q|q)/) | |
| {$line =~ s/(.*)%/$1% ANS:/; $line =~ s/(.*)n\.a\./$1n.a. ANS:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(](R|r)(eproach|eprimanding) (Q|q)/) | |
| {$line =~ s/(.*)%/$1% REP:/; $line =~ s/(.*)n\.a\./$1n.a. REP:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(](R|r)eminding (Q|q)/) | |
| {$line =~ s/(.*)%/$1% REM:/; $line =~ s/(.*)n\.a\./$1n.a. REM:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(](R|r)hetorical (Q|q)/) | |
| {$line =~ s/(.*)%/$1% RHE:/; $line =~ s/(.*)n\.a\./$1n.a. RHE:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(]((I|i)mperative|(R|r)equest) (Q|q)/) | |
| {$line =~ s/(.*)%/$1% REQ:/; $line =~ s/(.*)n\.a\./$1n.a. REQ:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(](P|p)ermission (Q|q)/) | |
| {$line =~ s/(.*)%/$1% PER:/; $line =~ s/(.*)n\.a\./$1n.a. PER:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(](S|s)urprise (Q|q)/) | |
| {$line =~ s/(.*)%/$1% SUR:/; $line =~ s/(.*)n\.a\./$1n.a. SUR:/; print(F4 "$line")} | |
| elsif($line =~ /[^\(](I|i)nterview (Q|q)/) | |
| {$line =~ s/(.*)%/$1% ITV:/; $line =~ s/(.*)n\.a\./$1n.a. ITV:/; print(F4 "$line")} | |
| else {print(F4 "OTHER $line")} | |
| } | |
| close(F4); |