Ignore:
Timestamp:
2002-07-03T12:57:49+12:00 (22 years ago)
Author:
sjboddie
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/protemix/rename.pl

    r3192 r3207  
    1111use unicode;
    1212
    13 my %classifications = (
    14                'Pharmacokinetics' => ['Absorption', 'Distribution', 'Metabolism', 'Elimination',
    15                            'Effect of Food', 'Drug Interactions', 'Special Populations'],
    16                'Pharmacodynamics' => ['Trace Metal', 'Excretion', 'Selectivity', 'Copper', 'Zinc',
    17                           'Manganese', 'Iron', 'Distribution', 'Tissue', 'Brain',
    18                           'Heart', 'Plasma', 'Fetal', 'Liver', 'Kidney'],
    19                'Safety/Side Effects/Toxicity' => ['Acute Toxicity', 'Repeated Dose Toxicity',
    20                              'Studies in Rodents', 'Studies in Dogs',
    21                              'Overdosage', 'Reproductive Toxicity',
    22                              'Teratogenicity', 'Mutagenecity', 'Carcinogenicity'],
    23                'Other' => ['Superoxide Dismutase', 'Ferroxidase I', 'Ferroxidase II',
    24                    'Metallothienein', 'Ceruloplasmin'],
    25                'Efficacy' => ['Heart', 'Complications', 'Microvascular', 'Renal', 'Diabetes'],
    26                'Contraindications' => [],
    27                'Precautions' => []
    28                );
    29 
    3013my @meta_files = ();
    3114
    3215&recursive_rename("import");
     16
     17# read in log.Type.txt and log.Category.txt
     18my $classifications = &read_cat_files();
     19
    3320# process meta files
    3421foreach my $mfile (@meta_files) {
     
    149136    $metafile .= "  <Metadata name=\"Title\">$title</Metadata>\n";
    150137
    151     # currently just write some random values for classification metadata
    152     my @c1 = ('Animal', 'Human', 'Other');
    153     my $rand = int(rand 3);
    154     my $classtext = "    <Metadata name=\"Class1\">" . $c1[$rand] . "</Metadata>\n";
    155     my @c2 = ('Pharmacokinetics', 'Pharmacodynamics', 'Safety/Side Effects/Toxicity',
    156           'Other', 'Efficacy', 'Contraindications', 'Precautions');
    157     $rand = int(rand 7);
    158     my $c2val = $c2[$rand];
    159     $classtext .= "    <Metadata name=\"Class2\">$c2val</Metadata>\n";
    160     if (defined $classifications{$c2val}) {
    161     if (scalar(@{$classifications{$c2val}})) {
    162         my $numvals = scalar(@{$classifications{$c2val}});
    163         $rand = int(rand $numvals);
    164         my $c3val = $classifications{$c2val}->[$rand];
    165         $classtext .= "    <Metadata name=\"Class3\">$c3val</Metadata>\n";
    166     }
    167     } else {
    168     print STDERR "ERROR: '$c2val' not in clasifications list\n";
    169     }
    170 
    171138    my $dir = File::Basename::dirname($filename);
     139    my ($subdirs) = $dir =~ /import\/(.*)$/;
    172140
    173141    opendir(DIR, $dir) || die;
    174142    my @files = readdir DIR;
    175143    foreach my $file (@files) {
    176     if ($file =~ s/\.html?$//i) {
    177         $metafile .= "  <Page filename=\"$file\">\n$classtext  </Page>\n";
     144    if ($file =~ /\.html?$/i) {
     145        my $fstub = $file;
     146        $fstub =~ s/\.html?$//i;
     147        $metafile .= "  <Page filename=\"$fstub\">\n";
     148        if (defined ($classifications->{'type'}->{"$subdirs/$file"})) {
     149        $metafile .= "    <Metadata name=\"Class1\">" .
     150            $classifications->{'type'}->{"$subdirs/$file"} . "</Metadata>\n";
     151        } else {
     152        print STDERR "$subdirs/$file has no type metadata\n";
     153        }
     154        if (defined ($classifications->{'category'}->{"$subdirs/$file"})) {
     155        $metafile .= "    <Metadata name=\"Class2\">" .
     156            $classifications->{'category'}->{"$subdirs/$file"} . "</Metadata>\n";
     157        } else {
     158        print STDERR "$subdirs/$file has no category metadata\n";
     159        }
     160        $metafile .= "  </Page>\n";
    178161    }
    179162    }
     
    186169}
    187170
     171sub read_cat_files {
    188172
     173    my $class = {'type' => {}, 'category' => {}};
     174   
     175    open (TYPE, "import/log.Type.txt") || die;
     176    my $line = "";
     177    while (defined ($line = <TYPE>)) {
     178    my ($filename, $cat) = split(/ /, $line);
     179    chomp $cat;
     180    $filename =~ s/^.*?Protemix\(ii\)/OCR2/;
     181    $filename =~ s/^.*?Protemix\(i\)/OCR1/;
     182    $class->{'type'}->{$filename} = $cat;
     183    }
     184    close TYPE;
     185   
     186    open (CAT, "import/log.Category.txt") || die;
     187    $line = "";
     188    while (defined ($line = <CAT>)) {
     189    my ($filename, $cat) = split(/ /, $line);
     190    chomp $cat;
     191    $filename =~ s/^.*?Protemix\(ii\)/OCR2/;
     192    $filename =~ s/^.*?Protemix\(i\)/OCR1/;
     193    $class->{'category'}->{$filename} = $cat;
     194    }
     195    close CAT;
     196
     197    return $class;
     198}
Note: See TracChangeset for help on using the changeset viewer.