-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_primo_synonyms.pl
executable file
·90 lines (68 loc) · 2.26 KB
/
merge_primo_synonyms.pl
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl -w
###############################################################################
# Reformat your list of course codes into Primo Synonym format #
# ie. HAH101 gets split to be HAH 101 #
# This tries to format the course codes as students may enter them into Primo #
###############################################################################
# Declare the subroutines
sub trim($);
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
print "Do you want to include the British English synonyms file? (y/n)";
$brit_english = <>;
$brit_english = trim($brit_english);
print "Please enter a file name of your custom synonyms file, default is custom_synonyms.txt";
$custom_file = <>;
$custom_file = trim($custom_file);
if($custom_file eq '')
{
$custom_file = 'custom_synonyms.txt';
}
$output_file = 'userSynonyms';
#################################################
#Merge the contents of the custom misspell file #
#################################################
if($brit_english =~ m/^y/)
{
open (BRIT, "english_userSynonyms.txt");
open (OUTPUT, '>',"$output_file");
while (<BRIT>) {
chomp;
print OUTPUT "$_\n";
}
close(BRIT);
close(OUTPUT);
}
#################################################
#Merge the contents of the custom misspell file #
#################################################
open (CUSTOM, "$custom_file");
open (OUTPUT_CUSTOM, '>>', "$output_file");
while (<CUSTOM>) {
chomp;
print OUTPUT_CUSTOM "$_\n";
}
close(CUSTOM);
close(OUTPUT_CUSTOM);
##############################
# Sort the new misspell file #
##############################
open (NAMES_FILE, '<', "$output_file") or die "Failed to read file : $! ";
my @not_sorted = <NAMES_FILE>; # read entire file in the array
close (NAMES_FILE);
@sorted = sort { lc($a) cmp lc($b) } @not_sorted ;
open(FILE, '>',"$output_file" ) || die "unable to open file write <$!>";
foreach(@sorted) {
if( $_ !~ /^\s*$/ )
{
print FILE "$_";
}
}
close(FILE);
system("cat userSynonyms | sed 's/=/ = /g' | awk '{printf \"%-30s%-2s%-30s%s %s\\n\", \$1,\$2,\$3,\$4,\$5}' > userSynonyms");
print "\n ####### \n Your new synonyms file has been saved to $output_file \n #######\n"