Thread Probleme mit Referenzen und komplexen Datenstrukturen (8 answers)
Opened by Dingels at 2008-07-07 22:24

KurtZ
 2008-07-08 15:46
#111937 #111937
User since
2007-12-13
411 Artikel
BenutzerIn
[default_avatar]
Also IMHO hast du das Problem im Wesentlcihen schon von Anfang an gelöst, deinen Code hab ich nur mal aufgeräumt und direkt testbar gemacht ... wo ist dein Problem ?

NACHTRAG: OK du hattest $token und $lemma verwechselt


Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my %tagcount;

while (my $line=<DATA>) {
        my ($token,$tag,$lemma)= split /\s+/,$line;
        $tagcount{lc($lemma)}->{$tag}++;
};

#print Dumper \%tagcount;


foreach my $lemma (sort keys %tagcount) {
        my @tags_sortedby_count =
                sort { $tagcount{$lemma}->{$b} <=> $tagcount{$lemma}->{$a} }
                        keys %{ $tagcount{$lemma} };
        # Ausgabe
        print "$lemma ";
        foreach my $tag ( @tags_sortedby_count ) {
                print  "\t", $tag, " (", $tagcount{$lemma}->{$tag}, ")";
        }
        print "\n";
 }



__DATA__
Ich PRO.Pers.Subst.1.Nom.Sg.*6 Ich
habe VFIN.Haben.1.Sg.Pres.Ind haben
einen ART.Indef.Acc.Sg.Masc eine
Menschen N.Reg.Acc.Sg.Masc Mensch
allen PRO.Indef.Attr.-3.Acc.Pl.Fem alle
allen PRO.Indef.Attr.-3.Acc.Pl.Masc alle
all PRO.Indef.Attr.-3.Nom.Pl.Fem alle
allen PRO.Indef.Attr.-3.Acc.Sg.Fem alle
all PRO.Indef.Attr.-3.Acc.Pl.Neut alle
all PRO.Indef.Attr.-3.Acc.Pl.*6 alle
all PRO.Indef.Attr.-3.Nom.Pl.*6 alle
all PRO.Indef.Attr.-3.Acc.Sg.Fem alle
all PRO.Indef.Attr.-3.Acc.Pl.Neut alle
all PRO.Indef.Attr.-3.Acc.Pl.*6 alle
all PRO.Indef.Attr.-3.Nom.Pl.*6 alle
all PRO.Indef.Attr.-3.Acc.Pl.*6 alle
all PRO.Indef.Attr.-3.Nom.Pl.*6 alle


AUSGABE:
Code: (dl )
1
2
3
4
5
alle 	PRO.Indef.Attr.-3.Nom.Pl.*6 (3)	PRO.Indef.Attr.-3.Acc.Pl.*6 (3)	PRO.Indef.Attr.-3.Acc.Pl.Neut (2)	PRO.Indef.Attr.-3.Acc.Sg.Fem (2)	PRO.Indef.Attr.-3.Nom.Pl.Fem (1)	PRO.Indef.Attr.-3.Acc.Pl.Fem (1)	PRO.Indef.Attr.-3.Acc.Pl.Masc (1)
eine ART.Indef.Acc.Sg.Masc (1)
haben VFIN.Haben.1.Sg.Pres.Ind (1)
ich PRO.Pers.Subst.1.Nom.Sg.*6 (1)
mensch N.Reg.Acc.Sg.Masc (1)
TMTOWTDYOG (there's more than one way to dig your own grave)

View full thread Probleme mit Referenzen und komplexen Datenstrukturen