line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
package Fry::Lib::CDBI::Tags; |
3
|
1
|
|
|
1
|
|
2035
|
use strict qw/vars refs/; #?forget the subs cause makes hash assignment a pain |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1546
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#variables |
6
|
|
|
|
|
|
|
our $tagcolumn='tags'; |
7
|
|
|
|
|
|
|
#our cdbi_search = "search_abstract"; |
8
|
|
|
|
|
|
|
#functions |
9
|
|
|
|
|
|
|
sub _default_data { |
10
|
|
|
|
|
|
|
return { |
11
|
0
|
|
|
0
|
|
|
depend=>[qw/:CDBI::Basic/], |
12
|
|
|
|
|
|
|
vars=>{ otlnum=>'3',tag_delimiter=>',' }, |
13
|
|
|
|
|
|
|
cmds=>{tagcount=>{qw/a tc aa aliasInputAndSql/}, |
14
|
|
|
|
|
|
|
tagname=>{qw/a tn aa aliasInputAndSql/}, |
15
|
|
|
|
|
|
|
auto_outline=>{qw/a ao/},#aa aliasInputAndSql/}, |
16
|
|
|
|
|
|
|
sorted_tag_list=>{qw/a ts aa aliasInputAndSql/}, |
17
|
|
|
|
|
|
|
tagcount_obj=>{qw/a :tc/}, |
18
|
|
|
|
|
|
|
tagname_obj=>{qw/a :tn/}, |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
opts=>{otlnum=>{qw/a otl type var noreset 1 default 3/ }} |
21
|
|
|
|
|
|
|
# subs=>{qw/g init_tag_group/ } |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#shell commands |
26
|
|
|
|
|
|
|
sub auto_outline { |
27
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$class->lib->requireLibraries(':CDBI::Outline'); |
30
|
0
|
|
|
|
|
|
my @a = $class->aliasInputAndSql(@_); |
31
|
0
|
|
|
|
|
|
my @results = $class->${\$class->Var('cdbi_search')}(@a); |
|
0
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$class->obj_to_otl(\@_,\@results); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
sub tagcount { |
35
|
0
|
|
|
0
|
0
|
|
my $cls = shift; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my @results = $cls->${\$cls->Var('cdbi_search')}(@_); |
|
0
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
if (@results > 0) { |
39
|
0
|
|
|
|
|
|
$cls->tagcount_obj(@results) |
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
|
else { $cls->view("No search results\n") } |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
sub tagname { |
44
|
0
|
|
|
0
|
0
|
|
my $cls = shift; |
45
|
0
|
|
|
|
|
|
my @results = $cls->${\$cls->Var('cdbi_search')}(@_); |
|
0
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if (@results > 0) { |
47
|
0
|
|
|
|
|
|
$cls->tagname_obj(@results) |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
|
else { $cls->view("No search results\n") } |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
sub tagcount_obj { |
52
|
0
|
|
|
0
|
0
|
|
my ($cls,@obj) = @_; |
53
|
0
|
|
|
|
|
|
my $tags = $cls->get_tags_compact(@obj); |
54
|
0
|
|
|
|
|
|
$cls->print_tags_compact($tags); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
sub tagname_obj { |
57
|
0
|
|
|
0
|
0
|
|
my ($cls,@obj) = @_; |
58
|
0
|
|
|
|
|
|
my @sortedtags = $cls->listtags(@obj); |
59
|
0
|
|
|
|
|
|
$cls->print_tags(@sortedtags); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
sub sorted_tag_list { |
62
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
63
|
0
|
|
|
|
|
|
my @results = $class->${\$class->Var('cdbi_search')}(@_); |
|
0
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return sort $class->_unique_result_tags(@results); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
#internal methods |
67
|
|
|
|
|
|
|
sub obj_to_otl { |
68
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
69
|
0
|
|
|
|
|
|
my @aliasedinput= @{shift()}; |
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my @results = @{shift()}; |
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#gives unique tags but in order of most tags |
73
|
0
|
|
|
|
|
|
my @tagnames = map { $_->{name} } $class->listtags(@results); |
|
0
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if (@tagnames == 0) { $class->view("no taggnames,outline not possible\n"); return} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#delete first tagname since it's a repeat of parent tag |
77
|
0
|
0
|
|
|
|
|
shift @tagnames if ("@aliasedinput" =~ /$tagcolumn/); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#create autoquery |
80
|
0
|
|
|
|
|
|
my @savedtags = splice(@tagnames,0,$class->Var('otlnum')); |
81
|
0
|
|
|
|
|
|
my $input = "@aliasedinput"."(".join(',',@savedtags).")"; |
82
|
|
|
|
|
|
|
#print "i: $input:\n"; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$class->view($class->outlineSearches($input)); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
sub _all_result_tags { |
87
|
0
|
|
|
0
|
|
|
my ($class,@cdbi) = @_; |
88
|
0
|
|
|
|
|
|
my @tcolumn = map {$_->$tagcolumn} @cdbi; |
|
0
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return map {split(/${\$class->Var('tag_delimiter')}/,$_) } @tcolumn; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
sub _unique_result_tags { |
92
|
0
|
|
|
0
|
|
|
my ($class,@cdbi) = @_; |
93
|
0
|
|
|
|
|
|
my @tags = $class->_all_result_tags(@cdbi); |
94
|
0
|
|
|
|
|
|
my %uniq; |
95
|
0
|
|
|
|
|
|
for (@tags) { $uniq{$_}++ } |
|
0
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return keys %uniq; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
sub listtags { |
99
|
|
|
|
|
|
|
#d:returns tags and number of occurences in table |
100
|
0
|
|
|
0
|
0
|
|
my ($class,@cdbi) = @_; |
101
|
0
|
|
|
|
|
|
my @tags = $class->_all_result_tags(@cdbi); |
102
|
0
|
|
|
|
|
|
my (%uniqtag,$result); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
#count + get unique tags |
105
|
0
|
|
|
|
|
|
for (@tags) { $uniqtag{$_}{count}++; } |
|
0
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#combine count + tagname into @ of % |
108
|
0
|
|
|
|
|
|
@tags=(); |
109
|
0
|
|
|
|
|
|
for (keys %uniqtag) { |
110
|
0
|
|
|
|
|
|
push(@tags,{name=>$_,count=>$uniqtag{$_}{count}}); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
#sort descending |
114
|
0
|
|
|
|
|
|
my @sortedtags = sort {${$b}{count} <=> ${$a}{count}} @tags; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
return @sortedtags; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
sub get_tags_compact { |
118
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
119
|
0
|
|
|
|
|
|
my @sortedtags = $class->listtags(@_); |
120
|
0
|
|
|
|
|
|
my ($i,$j,@body); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
while ($i != @sortedtags -1){ |
123
|
0
|
|
|
|
|
|
my $previouscount; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
#print $sortedtags[$i]{count},": "; |
126
|
0
|
|
|
|
|
|
$body[$j]{count} = $sortedtags[$i]{count}; |
127
|
|
|
|
|
|
|
#print $sortedtags[$i]{name},$class->Var('delim')->{tag}; |
128
|
0
|
|
|
|
|
|
$body[$j]{tags} .= $sortedtags[$i]{name}. $class->Var('tag_delimiter'); |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$previouscount = $sortedtags[$i]{count}; |
131
|
0
|
|
|
|
|
|
$i++; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
#create taggroup |
134
|
0
|
|
|
|
|
|
my @taggroup; |
135
|
|
|
|
|
|
|
#prints groups of tags with same count |
136
|
0
|
|
|
|
|
|
while ($sortedtags[$i]{count} == $previouscount) { |
137
|
|
|
|
|
|
|
#print $sortedtags[$i]{name},$class->Var('delim')->{tag}; |
138
|
0
|
|
|
|
|
|
push(@taggroup,$sortedtags[$i]{name}); |
139
|
0
|
|
|
|
|
|
$previouscount = $sortedtags[$i]{count}; |
140
|
0
|
|
|
|
|
|
$i++; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
$body[$j]{tags} .= join($class->Var('tag_delimiter'),@taggroup); |
144
|
0
|
|
|
|
|
|
$j++; |
145
|
|
|
|
|
|
|
} |
146
|
0
|
|
|
|
|
|
return \@body; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
#format fns |
149
|
|
|
|
|
|
|
sub print_tags_compact { |
150
|
0
|
|
|
0
|
0
|
|
my ($cls,$tags) = @_; |
151
|
0
|
|
|
|
|
|
my $output; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
for (@$tags) { |
154
|
0
|
|
|
|
|
|
$output .= $_->{count}.": ".$_->{tags}."\n"; |
155
|
|
|
|
|
|
|
} |
156
|
0
|
|
|
|
|
|
$cls->view($output); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
sub print_tags { |
159
|
0
|
|
|
0
|
0
|
|
my ($class,@sortedtags) = @_; |
160
|
0
|
|
|
|
|
|
my $result; |
161
|
0
|
|
|
|
|
|
for (@sortedtags) { $result .= "$_->{count}: $_->{name}\n";} |
|
0
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
$class->view($result); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__END__ |