lib/AI/MicroStructure/Relations.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 93 CC 4 SCAR 18.7
CC
4
Cov
0%
gofor
20.0
new
2.0
inspect
2.0
CRAP 6.5
1 #!/usr/bin/perl -X
2 package AI::MicroStructure::Relations;
3 use strict;
4 use warnings;
5 use utf8; # for translator credits
6 use Data::Dumper;
7 use AI::MicroStructure::Cache;
8 use WWW::Wikipedia;
9 use JSON::XS;
10 use Statistics::Basic qw(:all);
11  
12 our $supports = {};
13 our $scale = 1;
14  
15 sub new {
16 my $class = shift;
17  
18 no strict 'refs';
19 my $self = bless { @_,storage=> AI::MicroStructure::Cache->new,
20 cache=>{},
21 dominant => [] }, $class;
22  
23 return $self;
24 }
25  
26 sub gofor {
27 my $self = shift;
28 my $next = shift;
29 my $opt = shift;
30  
31  
32
33 my $wiki = WWW::Wikipedia->new();
34 my $result = $wiki->search($next);
35  
36  
37 eval( 'use IO::Page' );
38  
39 if(defined($result) and $result){
40  
41 use AnyEvent::Subprocess::Easy qw(qx_nonblock);
42 my $micosense = qx_nonblock("micro-sense $next")->recv;
43 my $sense = JSON::XS->new->pretty(1)->decode($micosense);
44 delete($sense->{rows}->{search});
45
46 push @{$self->{storage}->{category}},{$next=>$sense} unless(!@{$sense->{senses}});
47
48 $self->{storage}->{related}->{$next} = [grep{!/\(/}map{$_=~ s/ /_/g; $_=ucfirst $_;} $result->related()];
49
50  
51 foreach my $elem ($result->related()){
52  
53 $elem =~ s/ /_/g;
54
55 $self->{storage}->{data}->{$elem} = defined($self->{storage}->{data}->{$elem}) ?
56 $self->{storage}->{data}->{$elem}+1:1;
57  
58  
59 # if($_ &&
60 # !defined($self->{storage}->{data}->{$elem})) {
61  
62 # $wiki = WWW::Wikipedia->new();
63 # $result = $wiki->search($_);
64
65 # $result = $wiki->search($_);
66  
67 # $self->{storage}->{$_}->{related} = [grep{!/\(/}map{$_=~ s/ /_/g; $_=ucfirst $_;}$result->related()] unless(!$result);
68  
69  
70 # $self->{storage}->{$_}->{related} = [grep{!/\(/}map{$_=~ s/ /_/g; $_=ucfirst $_;}$result->related()] unless(!$result);
71  
72 # }
73  
74  
75  
76  
77 }
78  
79 $self->{storage}->store($self->{storage});
80 }
81 return ();
82  
83  
84 }
85  
86  
87 sub inspect {
88  
89  
90 my $self = shift;
91 my $times = shift;
92  
93
94 foreach(sort {$a cmp $b} keys %{$self->{storage}->{data}} ){
95  
96  
97 $self->{storage}->{dominant}->{$self->{storage}->{data}->{$_}} = $_;
98  
99 }
100
101 $self->{storage}->insert($self->{storage});
102 return $self->{storage};
103 }
104  
105  
106 1;
107 # ABSTRACT: this is part of AI-MicroStructure the package handels relations between concepts
108  
109  
110 =head1 NAME
111  
112 AI::MicroStructure::Relations
113  
114 =head1 DESCRIPTION
115  
116 Gets Relations for Concepts based on words
117  
118 =head1 SYNOPSIS
119  
120
121 ~$ micro new world
122
123 ~$ micro structures
124
125 ~$ micro any 2
126
127 ~$ micro drop world
128
129 ~$ micro
130
131  
132 =head1 AUTHOR
133  
134 Hagen Geissler <santex@cpan.org>
135  
136 =head1 COPYRIGHT AND LICENCE
137  
138 Hagen Geissler <santex@cpan.org>
139  
140 =head1 SUPPORT AND DOCUMENTATION
141  
142 ☞ [sample using concepts](http://quantup.com)
143  
144 ☞ [PDF info on my works](https://github.com/santex)
145  
146
147 =head1 SEE ALSO
148  
149 AI-MicroStructure
150 AI-MicroStructure-Cache
151 AI-MicroStructure-Deamon
152 AI-MicroStructure-Relations
153 AI-MicroStructure-Concept
154 AI-MicroStructure-Data
155 AI-MicroStructure-Driver
156 AI-MicroStructure-Plugin-Pdf
157 AI-MicroStructure-Plugin-Twitter
158 AI-MicroStructure-Plugin-Wiki
159  
160
161 __END__
162 __DATA__
163