1 / 16

Korpuslinguistik für und mit Computerlinguistik

Korpuslinguistik für und mit Computerlinguistik. Seminar SS 2003 Sitzung 1: UNIX, Perl Gerold Schneider. UNIX: Grundbefehle. cat (catalog) head, tail more, less |, <, > (pipe, in ,out) man (manual pages). ls (list): Verzeichnisinhalt cd (change dir.) pwd (present working dir.)

lotta
Download Presentation

Korpuslinguistik für und mit Computerlinguistik

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Korpuslinguistik für und mit Computerlinguistik Seminar SS 2003 Sitzung 1: UNIX, Perl Gerold Schneider

  2. UNIX: Grundbefehle • cat (catalog) • head, tail • more, less • |, <, > (pipe, in ,out) • man (manual pages) • ls (list): Verzeichnisinhalt • cd (change dir.) • pwd (present working dir.) • cp (copy) • mv (move) • rm (remove) • rmdir (rm dir) • mkdir (make dir) • pico, nano, emacs (ed.s) • chmod (change mod.) Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  3. UNIX: Linguists´ toolbox • grep, egrep ((extended) global regular expression) • tr (transform) • wc (word count) • sort • uniq • cut (cut columns) • paste (paste columns) Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  4. Bsp. 1: Wortliste, Konkordanz • Lexikon eines Textes: Text in 1-Wort-pro-Zeile Format konvertieren, dann sortieren, Duplikate entfernen cat my.txt | tr -s " " "\n" |sort | uniq • Häufigkeit mitzählen cat my.txt | tr -s " " "\n" |sort | uniq -c • Preprocessing cat my.txt | tr -s " " "\n" | tr -s "[A-Z]" "[a-z]" | tr -d '[.,;:?\!"\(\)+-&=]' | sort | uniq -c • Konkordanz, Anzahl Types, Types per Token ? • Zipf interaktiv: http://users.info.unicaen.fr/~giguet/java/zipf.html Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  5. Bsp. 2: N-Gramme • Preprocessing cat my.txt | tr -s " " "\n" | tr "[A-Z]" "[a-z]" | tr -d "[.,:;'?\!]" > my.tmp • Selber Text ohne erstes Wort cat my.tmp | tail +2 > my.tmp2 • Bigramme paste -d" " my.tmp my.tmp2 > bigramme • Liste der häufigsten Bigramme ? • Welche Wörter sind am häufigsten vor und nach der Präposition „mit“ ? Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  6. Bsp. 3: Kontexte • Kontexte aller Wörter in einer bestimmten Fenstergrösse F • Vorgehen: • F-Gramme erstellen, analog zu Bigrammen • Herausschneiden der Kontextworte cut -d" " -f 1,2 mygrams > kontexts cut -d" " -f 1,3 mygrams >> kontexts cut -d" " -f 1,4 mygrams >> kontexts ... cut -d" " -f 1,F mygrams >> kontexts • Lokale, syntaktische und semantische Distanz Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  7. Perl: Motivation • UNIX ist streng zeilenweise orientiert. Zeilensprünge können z.B. nicht mittels tr entfernt werden. • tr erlaubt nur buchstabenweises Ersetzen, und die Ausgabe darf nicht länger sein als die Eingabe. Dies verunmöglicht z.B. die Erstellung einer Buchstabenkonkordanz. • UNIX ist nicht flexibel genug. Die gesammelten Daten stehen z.B. nicht als Variablen/Listen/Hashes zur Verfügung •  Mächtigere Werkzeug sind nötig: z.B. Perl Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  8. Perl: Zeilenfilterskelett #!usr/bin/perl ## Pfad zum Perl-Interpreter while(<>) { ## zeilenweise Daten einlesen s/ersetzmich/durchdas/; print; ## Ausgabe des Ergebnisses } Aufruf aus der Kommandozeile cat myin.txt | perl myperlscript.pl > myout.txt Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  9. Perl: Umordungsschema #!usr/bin/perl ## Pfad zum Perl-Interpreter $/="\n"; ## Datensatzbegrenzer while(<>) { ## Datensatzweise Daten einlesen ($f1,$f2,$flast) = split(/\,/,$_); ## Felder lesen $flast =~ s/\n//; ## chop Datensatzbegrenzer $swapwas = $f1.$flast.$f2; print "$swapwas\n"; ## Ausgabe des Ergebnisses } Beispiel: prolog(wort,NN,12).  prolog(wort,12,NN). Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  10. Perl: Geordnetes Einsammeln mit Hashes: Wortliste #!/usr/bin/perl $/ = ""; #Datensatzbegrenzer: Paragraph $* = 1; #mehrzeilige Matches while (<>){ s/-\n//g; tr/A-Z/a-z/; #Trennzeichen weg,Kleinbuchstaben @words = split (/\W*\s+\W*/,$_); foreach $word (@words) { $wordcount{$word}++; } } foreach $word (sort keys (%wordcount)) { printf "%20s,%d\n",$word,$wordcount{$word}; } Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  11. Perl: Geordnetes Einsammeln mit Hashes: Bigramme while(<>) { s/^\s+//; @words = split(/\W*\s+\W*/,$_); for ($count=0;$count<=$#words-1;++$count) { $wordcount{$words[$count]. " " . $words[$count+1]}++; } } foreach $wordpair (sort keys(%wordcount)) { printf "%20s,%d\n",$wordpair,$wordcount{$wordpair}; } Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  12. Perl: Geordnetes Einsammeln mit Hashes: Endungshäufigkeiten (3B.) while(<>) { s/^\s+//; @words = split(/\s+/,$_); for ($count=0;$count<=$#words;++$count) { @chars = split(//,$words[$count]);# split w/o sep. if ($#chars > 1) {# at least 3 letters in this word $ending{ $chars[$#chars-2] . " " . $chars[$#chars-1] . "" . $chars[$#chars]}++; } } } foreach $end (sort keys(%ending)) { printf "%20s,%d\n",$end,$ending{$end}; } Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  13. Perl: Evaluation I • Gegeben sei die Ausgabenliste einer jeweils binären, maschinell getroffenen Entscheidung E=[0|1], aligniert mit der entsprechenden richtigen menschlichen Entscheidung („gold standard“) G =[0|1], also eine Matrix {E,M}. als 0 klassif. als 1 klassifiziert Accuracy= 2*Precision= 2*Recall= Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  14. Perl: Evaluation II while(<>) { if /0\,0/{$caseI ++}; if /1\,0/{$caseII ++}; if /0\,1/{$caseIII++}; if /1\,1/{$caseIV ++}; } $accuracy = ... $precision= ... $recall = ... Accuracy= Precision= Recall= Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  15. Perl: Aufgaben 4 + 12 (Microproject in Genf) I Schreibmaschine mit Stemming-Spellchecker fürs Französische • Schritt 1: Einlesen eines grossen Textcorpus, ermitteln der häufisten Endungen (siehe Endungsprogramm) • Schritt 2: Manuell morphologische Endungen ermitteln, Stemmingregeln schreiben, stemmen: $word =~s/s$//; $word =~s/ée$//; $word =~s/ées$//; $word =~s/es$//; $word =~s/er$//; $word =~s/ait$//; $word =~s/able$//; $word =~s/é$//; $word =~s/elles$//; $word =~s/elle$//; $word =~s/ant$//; Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

  16. Perl: Aufgaben 4 + 12 (Microproject in Genf) II • Schritt 3: Gestemmten Korpus einlesen in Hash, Schreibmaschinenschleife durchaufen bis „STOP“ eingegeben wird. Dann den Brief ausgeben und die eingegebenen Worte stemmen, ausser sie sind im Ausnahmenlexikon (dans, sans, ...) und mit dem gestemmten Korpus vergleichen. if ($table{$word}) { print "Le mot $word est accepté.\n"; } elsif (!$table{$word}) { print "Le mot $word n'est pas dans l'index, changez-le!\n"; Gerold Schneider: Korpuslinguistik für Computerlinguistik, I

More Related