#!/usr/bin/perl
# project.: x-on
# author..: Sebastian Kreß
# email...: lepidium@hotmail.com


## cleans a pubmed-corpus and creates a new file
#  with documents containing mesh-index-terms

use strict;

my $docc   = 0;
my $meshc  = 0;
my $otherc = 0;

my $in  = $ARGV[0];
my $out = $ARGV[1];
die "usage: $0 in out\n" unless ($out);
open(IN, $in);
open(OUT, ">$out");

$/ = "</PubmedArticle>";
while (my $input = <IN>){
    $docc++;
    print STDERR "\rprocessing document $docc";
    if ($input =~ /<meshheading>/ois){
	print OUT "$input\n";
	$meshc++;
    }
    else {
	$otherc++;
    }
}
print STDERR "\nfinished processing $docc documents (in: $meshc, out: $otherc)";
close IN;
close OUT;

1;

__END__

=head1 NAME

Xon::quant - Quantitative Approach to Automatic Pattern Matching

=head2 Author

Sebastian Kreß, lepidium@hotmail.com

=head2 Project

xon, Seminar für Computerlinguistik der Ruprecht-Karls-Universität Heidelberg

=head1 DESCRIPTION

This module takes a Pubmed-corpus and creates a copy with only documents containing manually indexed MeSH-headings.

=back
