line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AI::MicroStructure::Util; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
42
|
use strict; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
255
|
|
4
|
8
|
|
|
8
|
|
39
|
use Cwd; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
541
|
|
5
|
8
|
|
|
8
|
|
6453
|
use Config::Auto; |
|
8
|
|
|
|
|
46100
|
|
|
8
|
|
|
|
|
266
|
|
6
|
8
|
|
|
8
|
|
9129
|
use Env qw/PWD/; |
|
8
|
|
|
|
|
22930
|
|
|
8
|
|
|
|
|
47
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub get_cwd { |
9
|
8
|
50
|
|
8
|
0
|
15
|
my @CWD; if (!-e ".micro") { |
|
8
|
|
|
|
|
128
|
|
10
|
8
|
|
|
|
|
39
|
push @CWD, $ENV{HOME}."/data-hub"; |
11
|
|
|
|
|
|
|
} else { |
12
|
0
|
|
|
|
|
0
|
push @CWD, getcwd(); |
13
|
|
|
|
|
|
|
} |
14
|
8
|
|
|
|
|
29
|
return @CWD; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub load_config { |
18
|
|
|
|
|
|
|
|
19
|
8
|
|
|
8
|
0
|
33
|
my @CWD = AI::MicroStructure::Util::get_cwd(); |
20
|
8
|
|
|
|
|
21
|
my $config = {};#Config::Auto::parse(".micro", path => @CWD) || {}; |
21
|
8
|
50
|
33
|
|
|
69
|
if (-e ".micro" && -e $ENV{HOME}."/.micro") { |
22
|
0
|
|
|
|
|
0
|
my $c = Config::Auto::parse($ENV{HOME}."/.micro"); |
23
|
0
|
|
0
|
|
|
0
|
foreach (keys %{$c}) { $config->{$_} ||= $c->{$_}; } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
24
|
|
|
|
|
|
|
} |
25
|
8
|
50
|
|
|
|
37
|
if($config->{default}) { |
26
|
0
|
|
|
|
|
0
|
shift @CWD; |
27
|
0
|
|
|
|
|
0
|
push @CWD, $config->{default}; |
28
|
0
|
0
|
|
|
|
0
|
if (-e "$CWD[0]/.micro") { |
29
|
0
|
|
|
|
|
0
|
my $c = Config::Auto::parse("$CWD[0]/.micro"); |
30
|
0
|
|
0
|
|
|
0
|
foreach (keys %{$config}) { $c->{$_} ||= $config->{$_}; } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
31
|
0
|
|
|
|
|
0
|
$config = $c; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
8
|
|
|
|
|
16
|
my $structdir = "structures"; |
35
|
8
|
|
|
|
|
43
|
my $path = { |
36
|
|
|
|
|
|
|
"structures" => $structdir, |
37
|
|
|
|
|
|
|
"cwd/structures" => "$CWD[0]/$structdir", |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
8
|
|
|
|
|
42
|
return { "cwd" => @CWD, "path" => $path, "cfg" => $config }; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub config { |
46
|
|
|
|
|
|
|
|
47
|
8
|
|
|
8
|
0
|
60
|
my $state = AI::MicroStructure::Util::load_config(); my @CWD = $state->{cwd}; |
|
8
|
|
|
|
|
26
|
|
48
|
8
|
|
50
|
|
|
68
|
$state->{cfg}->{query} ||= "micro"; |
49
|
8
|
|
50
|
|
|
50
|
$state->{cfg}->{tempdir} ||= "/tmp/micro-temp/"; |
50
|
8
|
|
50
|
|
|
50
|
$state->{cfg}->{couchdb} ||= "http://localhost:5984/"; |
51
|
8
|
|
50
|
|
|
53
|
$state->{cfg}->{conceptimg} ||= "http://qunatup.com/tiny/concept2.php"; |
52
|
8
|
|
50
|
|
|
44
|
$state->{cfg}->{wikipedia} ||= "http://en.wikipedia.org/wiki/"; |
53
|
8
|
|
50
|
|
|
48
|
$state->{cfg}->{db} ||= "table"; |
54
|
8
|
|
50
|
|
|
47
|
$state->{cfg}->{out} ||= "json"; |
55
|
|
|
|
|
|
|
$state->{cfg}->{jsonout} = sprintf("%s/%s/", |
56
|
|
|
|
|
|
|
$state->{cwd}, |
57
|
8
|
|
|
|
|
52
|
$state->{cfg}->{db}); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
8
|
|
|
|
|
32
|
return $state; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
1; |