forked from scaperot/PredictiveLyrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprototype.pl
78 lines (61 loc) · 1.63 KB
/
prototype.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
use strict;
use warnings;
use Lingua::EN::Ngram;
use File::Slurp qw /read_file/;
use Text::TermExtract;
my @songs = querysongs("Enter the songs you wish to input in the play order (please delimit by semicolon)\n");
print "$_\n" for @songs;
push @songs, "";
my @fulllist;
my @keypredictlist;
for(my $counter0 = 0; $counter0 < $#songs; $counter0++){
my $toread = $songs[$counter0];
my @list;
push @list, splittosections(readsong($toread));
push @list, " ";
for(my $counter1 = 0; $counter1 < $#list; $counter1++){
my $keys = keywords($list[$counter1],3);
push @keypredictlist, $keys;
push @fulllist, $keys;
push @fulllist, $list[$counter1];
push @fulllist, $keys;
}
}
print "$_\n============\n" for @fulllist;
=pod
my @songkeys;
for(my $counter1 = 0; $counter1 < $#songs;
=cut
######################################################################################
sub querysongs{
my ($query) = @_;
local $| = 1;
print $query;
chomp (my $song = <STDIN>);
my @songlist = split /;/, $song;
return @songlist;
}
sub readsong{
use File::Slurp;
my $songtoread = shift;
my $file = read_file($songtoread);
print $file;
return $file;
}
sub splittosections{
my $input = shift;
my @sections = split(/\n/, $input);
return @sections;
}
sub keywords{
my $songtoparse = shift;
my $number = shift;
my $extract = Text::TermExtract->new();
my @keywordholder;
$extract->exclude(['the','may']);
for my $keywords($extract->terms_extract($songtoparse,{max=>$number})){
push @keywordholder, $keywords;
}
my $keysequence = $keywordholder[0].$keywordholder[$1].$keywordholder[2];
return $keysequence;
}