varunreeves has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl5 &main_loop; ########################################################## ## Details of this program: ## The program is divided into the following steps and can be underst +ood as follows: ## 1.The location of files are initialized to scalar variables for ea +sy location of the files themselves wherever needed ## 2.The subroutine init_vector is called with an argument(namely: pl +ant,train,place/person).It will for each of the given argument ## by the user store the weight as a "value"of an array of hash whe +re the key value is the "term"and the index is the serial no of the ## .I document i.e the document.Also the subroutine will be designe +d in such a way that by just changing the fixed weight value in the ## subroutine we can easily implement either of the two proposed we +ighing schemes of part 2. ## 3.The subroutine for calculation of centroids is defined. ## 4.Then there will be subroutines for calculation of full cosine si +milarity which will take the inputs from the two centroid vectors ## and return their similarity values,the differences in their valu +es and hence the sorted array.This is then printed out here ## itself. ## Also printed out in the end is the ratio of correct /total coun +ts. ## ## ## ## ########################################################## ########################################################## ## INIT_INPUT_FILENAMES, ## ## This function specifies the names and locations of ## input files used by the program. ## ## Parameter: $type ("stemmed" or "unstemmed") ## ## If $type == "stemmed", the filenames are initialized ## to the versions stemmed , while ## in the default ("unstemmed") case initializes to files ## containing raw, unstemmed tokens. ## ## ########################################################## sub init_input_filenames{ local($type) = @_; $DIR="."; if ($type eq "stemmed") { $plant ="$DIR/plant.stemmed"; $plant_hist ="$DIR/plant.stemmed.hist"; $plant_titles ="$DIR/plant.titles"; $tank ="$DIR/tank.stemmed"; $tank_hist ="$DIR/tank.stemmed.hist"; $tank_titles ="$DIR/tank.titles"; $perplace ="$DIR/perplace.stemmed"; $perplace_hist ="$DIR/perplace.stemmed.hist"; $perplace_titles ="$DIR/perplace.titles"; $common_words ="$DIR/common_words.stemmed"; } else { $plant ="$DIR/plant.tokenized"; $plant_hist ="$DIR/plant.tokenized.hist"; $plant_titles ="$DIR/plant.titles"; $tank ="$DIR/tank.tokenized"; $tank_hist ="$DIR/tank.tokenized.hist"; $tank_titles ="$DIR/tank.titles"; $perplace ="$DIR/perplace.tokenized"; $perplace_hist ="$DIR/perplace.tokenized.hist"; $perplace_titles ="$DIR/perplace.titles"; $common_words ="$DIR/common_words"; } } sub main_loop{ print "Please enter the choice for using the stemmed(1) or unstemm +ed documents(2)\n enter choice:"; $opt_st = <STDIN>; if ($opt_st !~/[12]/){$opt_st = 1;} chomp($opt_st); if($opt_st == 1){ &init_input_filenames("stemmed"); }else{ &init_input_filenames("tokenized"); } print "Please enter the choice for the parameter for which the sim +ilarity values would be calculated:plant(1),tank(2),person/place(3)\n + enter choice:\n opt1:"; $opt1 = <STDIN>; chomp($opt1); if ($opt1 !~/[123]/){$opt1 = 1;} print $opt1; print "Please enter a number for the options you want to have for +weighing : normal(1),eponential decay(2),stepped (3)\n"; print "enter choice for opt2:"; $opt2 = <STDIN>; print"I am a aperl monk"; chomp($opt2); if($opt2 !~ /[123]/){$opt2 = 1;} print $opt2;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with a perl code
by GrandFather (Saint) on May 03, 2009 at 22:37 UTC | |
|
Re: Help with a perl code
by ELISHEVA (Prior) on May 03, 2009 at 12:55 UTC | |
by varunreeves (Initiate) on May 03, 2009 at 13:14 UTC | |
by ysth (Canon) on May 03, 2009 at 17:56 UTC |