view release on metacpan or search on metacpan
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
$ micro new biology
$ micro new biological_process
$ for i in `micro structures`; do
$ for y in `micro all $i `; do
$ echo "$i=$y";
$ micro new $y;
$ done
$ done
#!!!!!###Hard cpu to expect ### make sure couch is on ###### or disable the store methode in micro-wiki and print $doc or consume otherweise
# test as single before you loope
$ micro-wiki ufo
# proceed
$ for i in `micro structures`; do
$ for y in `micro all $i `; do
$ echo "$i=$y";
$ micro-wiki $y;
open my $info, $file or die "Could not open $file: $!";
my @line = map{try{$encoder->decode($_)};}<$info>;
close $info;
my $i = $#line;
print $i;
my $ret = {};
foreach(@line){
my $duration = $_->{_end} -$_->{_start};
my @test = split /\/|\.| |-/,$_->{name};
$ret->{$_->{application}}->{$_->{name}} = [$ret->{$_->{application}}->{$_->{name}} ?
$ret->{$_->{application}}->{$_->{name}} + 1 : 1 ,$duration];
bin/from-folder.pl view on Meta::CPAN
my ($TOP,$storage) ;
$TOP = $ARGV[0] unless(!@ARGV);
$storage = $ARGV[1] unless(!@ARGV);
$storage = "/tmp" unless($storage);
our $cache = {};
our $files={};
our $curSysDate = `date +"%F"`;
$curSysDate=~ s/\n//g;
our %opts = (cache_file =>
sprintf("%s/%s_.cache",
$storage,$curSysDate));
GetOptions (\%opts, "cache_file=s");
sub translate
{
return unless -f;
(my $rel_name = $File::Find::name) =~ s{.*/}{}xs;
my $name = md5_hex($rel_name);
my $go = 0;
foreach(@ARGV){
my $t = $_;
if( ! -d $t && $rel_name !~ m/($t)/i){
$go ++;
print $rel_name."\n";
}
}
if (/\.(html|htm)$/) {
$files->{html}->{$name}=$rel_name;
}elsif (/\.txt$/) {
$files->{latex}->{$name}=$rel_name;
}elsif (/\.json$/) {
$files->{text}->{$name}=$rel_name;
bin/from-folder.pl view on Meta::CPAN
my $style = {};
$style->{explicit} = 1;
ok($c->simpleMixedSearch($style,$_)) && ok($c->play($style,$_)) for
qw(atom antimatter planet);
ok(print Dumper $c->intersect($style,$_)) for
qw(atom antimatter planet);
ok(print Dumper $c->similar($style,$_)) for
qw(atom antimatter planet);
#p @out;
1;
package main;
$|++;
use strict;
use Fi le::Find;
use Data::Dumper;
use Storable qw(lock_store lock_retrieve);
use Getopt::Long;
our $curSysDate = `date +"%F"`;
$curSysDate=~ s/\n//g;
our %opts = (cache_file =>
sprintf("/tmp/%s.cache",
$curSysDate));
GetOptions (\%opts, "cache_file=s");
our $cache = {};
our @target = split("\/",$opts{cache_file});
my $set = AI::MicroStructure::ObjectSet->new();
eval {
local $^W = 0; # because otherwhise doesn't pass errors
bin/from-folder.pl view on Meta::CPAN
$cache = {} unless $cache;
warn "New cache!\n" unless defined $cache;
};
END{
lock_store($cache,$opts{cache_file});
print Dumper [$set->size,$set->members];
}
find(\&translate, "$TOP/./");
sub translate {
return unless -f;
(my $rel_name = $File::Find::name) =~ s{.*/}{}xs;
$set->insert(AI::MicroStructure::Object->new($rel_name));
}
#print Dumper join "-", soundex(("rock'n'roll", 'rock and roll', 'rocknroll'));
urldecode(){
echo -e "$(sed 's/+/ /g; s/%/\\x/g')"
}
if [ ! $MICRO_LANG ]
then
MICRO_LANG=en
fi
search=$1;
search=$(perl -e "print ucfirst($search)");
nogo="http:\/\/|Articles|Artikel|Wikipedia|Commons|Tracking_|Hidden_|Talk_|_talk|Use_dmy_dates|_Diskussion|Pages_containing "
function getcat(){
search=$(perl -e "print ucfirst('$1')");
q="http://$MICRO_LANG.wikipedia.org/wiki/$search";
for i in `mojo get "$q" a attr href | egrep "^\/wiki\/(Category|Kategorie)" | egrep -vi "("$nogo")" | sort | sed -s "s/\/wiki\///"`; do q=$i; echo $i | urldecode; done
}
getcat $search
#qq=$(echo "$search" | sed "s/^.*.://" | tr "_" "|");
#q=$1; cat=$(for i in `getcat "$q"`; do getcat "$i"; done); echo "$cat" | data-freq | egrep -v "http" | sed -s "s/^.*.: //" | egrep -i "($qq)"
#q=$1; cat=$(for i in `getcat "$q"`; do qq=$(echo "$q" | sed -s "s/^.*.\://"); getcat "$i"; done); echo "$cat" | egrep -vi "http:" | data-freq | sort -n
#echo -e "\n"
bin/getcat.pl view on Meta::CPAN
sub check {
my $name = shift;
my $prog = shift;
my $ret = "";
if(defined(my $ret = $memd->get(md5_hex(sprintf("%s_%s",$name,$prog))))){
return $ret;
}else{
my $cmd = sprintf("%s %s",$prog,$name);
my $ret = mytry($cmd);
$memd->set(md5_hex(sprintf("%s_%s",$name,$prog)),$ret);
return $ret;
}
}
die() unless(@ARGV);
my @cat = check(shift,"getcat");
printf("%s\n",join("\n",reverse sort @{$cat[0]}));
1;
bin/getnice view on Meta::CPAN
fi
if [ ! $dir ]
then
dir="/home/santex/data-hub/stock/KnowledgeInterDisciplinary/"
fi
j=$(for i in `egrep -rli "$q" | grep List_of_`; do
echo $i;
#echo $i | xargs -0 json-printer \-f | egrep "^\".*.$" | egrep -v ":|http|wiki|index|\/|Externallinks|References|Seealso|Listof|#|[1-9][0-9][0-9][0-9]" | tr -d "\",";
done);
echo "$j"| egrep -i "^$q|_$q"
onetwo='.{1,2}'
re="$1"
re="${re//[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]/.}"
re="${re//ue/$onetwo}"
re="${re//ae/$onetwo}"
re="${re//oe/$onetwo}"
re="${re//ss/$onetwo}"
# have to use perl for grepping because of umlauts
q=$(lynx -dump -nolist 'http://dict.leo.org/'$from$to'?lp='$from$to'&lang='$from'&searchLoc=0&cmpType=strict§Hdr=on&spellToler=on&search='$search'&relink=on' | perl -n -e "print if /$re/i")
#perl -MHTML::Entities -le ' print \$q,encode_entities(\$q),\n';
#echo "$q";
perl -MEncode -le "print decode('utf-8','$q');";
bin/localfiles view on Meta::CPAN
foreach(@ARGV){
$rule = File::Find::Rule->file->name("*$_*.*")->start("/home/santex/data-hub/stock/" ,"/home/santex/Pictures/1");
while ( defined ( my $image = $rule->match ) ) {
push @result,$image;
}
print join("\n", @result);
}
__DATA__
my $micro = AI::MicroStructure->new("any");
my $path = $micro->{state}->{cwd};
my $picdir = sprintf("%s/%s",$ENV{"HOME"},"Pictures/1");
my $pubdir = sprintf("%s/%s",$ENV{"HOME"},"public_html");
push @INC ,-d $path ? $path : $ENV{"HOME"};
push @INC ,-d $picdir ? $picdir :"";
push @INC ,-d $pubdir ? $picdir :"";
my $xx=$memd->get("localfile_".$match);
if(!$xx){
my @images = File::Find::Rule->file()
->name('*'.lc($match).'*\.(png|jpg|gif|svg)')
->in(@INC);
#my $dat = {};
#foreach(@images){
#my @d = split("/",$_);
# $dat->{shift @d} = $_;
#}
#@images = values $dat;#@images[0..500] unless $#images<500;
#$data->{images}=[@images];
#my $cmd = sprintf( "montage '%s' /home/santex/Pictures/montage/".$match."-all.jpg",join("' '",@{$data->{images}}));
#`$cmd`;
my @files = File::Find::Rule->file()
->name('*'.ucfirst($match).'*\.(pdf|json|txt|xml)')
->in(@INC);
# print join "\n",sort{$a cmp $b}@files;
$data->{files}=[@files];
my $j = encode_json($data);
$memd->set("localfiles_".$match,$j);
print $j;
}else{
$data = decode_json( $xx);
print $xx;
}
use JSON::XS;
use Try::Tiny;
use Cache::Memcached::Fast;
my %conf = ( );
our $keys = {};
GetOptions( \%conf, "whitespace|ws!", "version","structures", "help", "remote","new",
"init", "export", "import",
"check", "category=s", "sources" ,"drop");
our ($new, $write,$drop,$all,$verbose) =(0,0,0,0,0);
our $kkey = sprintf "%s",join("_",@ARGV);
our $argkey = md5_hex($kkey);
our $memd = "";
sub check {
}
sub init {
$memd = new Cache::Memcached::Fast({
if(!$#ARGV){
push @ARGV,"any";
}
if($kkey =~ /debug/){
my $NORMAL=`tput sgr0`;
my $REVERSE=`tput smso`;
print "$REVERSE $_ $NORMAL " for @ARGV;
print "\n";
}else{
}
if(defined(my $ret = $memd->get($argkey)) && ($kkey !~ m/(any|structures)/i) && @ARGV){
print "$ret\n";
exit;
#die($ret);
}else{
}
}
init();
if( grep{/\ball\b/} @ARGV ){ $all = 1; cleanArgs("all"); };
our $main = AI::MicroStructure->new();
# check if this is an active memory or initialize it
if($conf{"init"}) {
if (-e ".micro") {
print STDERR "this is already an active memory!\n";
} else {
print `git init && touch .micro && echo .pmc > .gitignore && echo '*~' >> .gitignore && echo '*swp' >> .gitignore && echo .micro >> .gitignore && git add -f .micro .gitignore && git commit -m 'active memory born'`;
}
exit;
} else {
if (!-e ".micro" && !-e $ENV{HOME}."/.micro") {
print STDERR "this directory is not an active memory!\n";
exit;
}
}
my $state = AI::MicroStructure::Util::load_config(); my @CWD=$state->{cwd}; my $config=$state->{cfg};
our $structdir = "structures";
our $absstructdir = "$CWD[0]/$structdir";
if ($conf{"export"}) {
my $cwd = $CWD[0];
my $hash = $main->fitnes();
my $url = sprintf("%s/%s/_all_docs", $config->{couchdb}, $config->{db});
print `cd $cwd && mkdir -p relations && wget -O relations/any.json $url && git add relations/any.json $structdir/*.pm && git commit -m 'active memory release' && git tag $hash`; # FIXME check for errors FIXME also that we commit per structure and...
exit;
}
my (@remote, @local);
# real processing starts here
$\ = $/;
my $sep = $conf{whitespace} ? ' ' : $\;
my $j = $main->structures();
if($j == 0 || $j eq "any"){
print $main->help;
exit(0);
}
sub is_integer {
defined $_[0] && $_[0] =~ /^[+-]?\d+$/;
}
sub cleanArgs{
my ($key) = @_;
@local = grep{!/any/}AI::MicroStructure->new()->structures();
if(defined($ARGV[1]) && is_integer($ARGV[1])){
my $index = rand $#local;
$index = $index-$ARGV[1];
$index = $index?$index:0;
@local = @local[$index+1..$index+$ARGV[1]];
}
my $val = sprintf "%s",join $sep, @local, @remote;
$memd->set($argkey,$val);
print "$val";
exit;
}
if(defined($ARGV[0]) && $ARGV[0] =~ m/structures/){
@local = grep{!/any/}AI::MicroStructure->new()->structures();
if(defined($ARGV[1]) && is_integer($ARGV[1])){
my $index = rand $#local;
$index = $index-$ARGV[1];
$index = $index?$index:0;
@local = @local[$index+1..$index+$ARGV[1]];
}
my $val = sprintf "%s", join $sep, @local, @remote;
$memd->set($argkey,$val);
print "$val";
exit;
}
if($conf{"new"} and $ARGV[0] !~/structures/ and $ARGV[0] =~ m{^([^/]+)/(.*)}s) {
$structure = $1;
$conf{category} = $2;
my $meta = AI::MicroStructure->new( $structure, category => "new" );
$memd->set($argkey,$meta);
}
AI::MicroStructure->new( $structure, category => "new" )
unless AI::MicroStructure->has_structure( $structure );
# my $module = "AI::MicroStructure::$structure";
my $module = "$absstructdir/$structure.pm";
if(!-f $module){
print "no\n\e[00;33m $module\e[00m";
print "create like\n\e[00;33mmicro $structure new verbose\e[00m";
exit;
}
# load the remote structure if needed
if ( $conf{remote} || $conf{check} || $conf{sources}) {
eval "require '$module';";
die "structure '$structure' is not updatable!\n"
unless $module->has_remotelist();
}
# informative options
print STDERR
"meta, a simple front-end to AI::MicroStructure version $AI::MicroStructure::VERSION\n"
if $conf{version};
print STDERR $main->help if $conf{help};
print map "$_\n", AI::MicroStructure->structures if $conf{structures};
if ( $conf{sources} ) {
my @sources = $module->sources( $conf{category} );
my $var = map "$_\n", @sources;
$memd->set($argkey,$var);
print $var;
exit;
}
exit if $conf{structures} || $conf{version} || $conf{help} || $conf{sources};
my $meta = AI::MicroStructure->new( $structure, category => $conf{category} );
@remote = $module->remote_list( $conf{category} )
if $conf{remote} || $conf{check};
}else{
@local = $meta->name($count);
}
}
if ( $conf{check} ) {
my %seen;
$seen{$_}++ for @remote;
$seen{$_}-- for @local;
foreach my $key ( sort keys %seen ) {
next unless $seen{$key};
print $seen{$key} > 0 ? "+ $key" : "- $key";
}
}
else {
my $val = sprintf "%s" ,join $sep, @local, @remote;
$memd->set($argkey,$val);
print "$val";
exit;
}
}
END{
# print Dumper [$structure,\@ARGV,%conf,$argkey];
}
1;
bin/micro-dict view on Meta::CPAN
IFS=$'\n';
#REMOVETHESE="gov|search|cid|aaa|bbb|ccc|ddd|eee|fff|ggg|hhh|iii|jjj|kkk|lll|mmm|nnn|ooo|ppp|qqq|rrr|sss|ttt|eee|fff|ggg|hhh|iii|jjj|kkk|lll|mmm|nnn|ooo|ppp|qqq|rrr|sss|ttt|uuu|vvv|www|xxx|yyy|zzz|org|wiki|png|jpg|thumb|pdf|ref|idx|php|html|json|abc|...
# egrep -v "($REMOVETHESE)" |
#+ options to sort. Changed from
stop=$(perl -MAI::MicroStructure::WordBlacklist -E "my \$s=AI::MicroStructure::WordBlacklist::getStopWords('de'); my @s = keys %\$s; print join('|',@s);")
function uniquemmasher(){
if [ -f "$1" ]
then #+ valid file argument.
cmd=cat
else
cmd=echo
fi
stop=$(perl -MAI::MicroStructure::WordBlacklist -E "my \$s=AI::MicroStructure::WordBlacklist::getStopWords('de'); my @s = keys %\$s; print join('|',@s);")
IFS=$'\n';
$cmd $1 | tr A-Z a-z | # Convert to lowercase.
tr ' ' '_' | # New: change spaces to newlines.
#tr -cd '\012[a-z][0-9]' | # Get rid of everything
#+ non-alphanumeric (in orig. script).
tr -c '\012a-z' '\012' | # Rather than deleting non-alpha
egrep -v '^#' | # Delete lines starting with hashmark.
egrep -v "^[ ]*([A-Za-z][A-Za-z]|[A-Za-z])$" | egrep -v "^$" | egrep -v -i "^ (denkbarer|ganze|bez|ver�ffentlichtes|uns�gliches|ungew�hnliche|vollstaendig|erstem|Inf.|titel|unsaeglichem|beforehand|denkbares|yours|contains|gedurft|seithe...
stop=$(perl -MAI::MicroStructure::WordBlacklist -E "my \$s=AI::MicroStructure::WordBlacklist::getStopWords('de'); my @s = keys %\$s; print join('|',@s);")
cat /tmp/micro-dict.tmp | sort -n | egrep -v "^.*.[\ ].*.[1-9][\:][\ ][\ ]($stop)";
#if [ ! "$(echo "$stop" | egrep -i zzzzzzzzzzzz)" ]; then echo cool; fi
}
bin/micro-dict~ view on Meta::CPAN
IFS=$'\n';
#REMOVETHESE="gov|search|cid|aaa|bbb|ccc|ddd|eee|fff|ggg|hhh|iii|jjj|kkk|lll|mmm|nnn|ooo|ppp|qqq|rrr|sss|ttt|eee|fff|ggg|hhh|iii|jjj|kkk|lll|mmm|nnn|ooo|ppp|qqq|rrr|sss|ttt|uuu|vvv|www|xxx|yyy|zzz|org|wiki|png|jpg|thumb|pdf|ref|idx|php|html|json|abc|...
# egrep -v "($REMOVETHESE)" |
#+ options to sort. Changed from
stop=$(perl -MAI::MicroStructure::WordBlacklist -E "my \$s=AI::MicroStructure::WordBlacklist::getStopWords('de'); my @s = keys %\$s; print join('|',@s);")
function uniquemmasher(){
if [ -f "$1" ]
then #+ valid file argument.
cmd=cat
else
cmd=echo
fip
stop=$(perl -MAI::MicroStructure::WordBlacklist -E "my \$s=AI::MicroStructure::WordBlacklist::getStopWords('de'); my @s = keys %\$s; print join('|',@s);")
res=$($cmd $1 | tr A-Z a-z | # Convert to lowercase.
tr ' ' '_' | # New: change spaces to newlines.
tr -c '\012a-z' '\012' | # Rather than deleting non-alpha
egrep -v "^[ ]*([A-Za-z][A-Za-z]|[A-Za-z])$" | egrep -v "^$");
echo "$res"
bin/micro-leo view on Meta::CPAN
onetwo='.{1,2}'
re="$1"
re="${re//[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]/.}"
re="${re//ue/$onetwo}"
re="${re//ae/$onetwo}"
re="${re//oe/$onetwo}"
re="${re//ss/$onetwo}"
# have to use perl for grepping because of umlauts
lynx -dump -nolist 'http://dict.leo.org/'$2$3'?lp='$2$3'&lang='$2'&searchLoc=0&cmpType=strict§Hdr=on&spellToler=on&search='$1'&relink=on' | perl -n -e "print if /$re/i;"
bin/micro-relation view on Meta::CPAN
try{
$str = join( "\n", $result->related() );
$str = decruft($str);
$memd->set($arg,$str);
};
}
return $str;
}
try{
print rel(eval qw{$_}, $lang) for @ARGV;
};
#
1;
__DATA__
bin/micro-relation-test view on Meta::CPAN
foreach my $call(@ARGV)
{
my $fromCache = $memd->get($call);
if($fromCache){
print $fromCache;
}else{
my $str = rel($call, $lang);
$memd->set($call,$str);
}
}
bin/micro-sense view on Meta::CPAN
my $search = "(".join("|",@s).")";
$search =~ s/\'/\\'/g;
my $line = "";
my @xset;
$line = $ARGV[0];
#while($count++ < 2) {
if($count==1 && !$line){
print intro();
next;
}
chomp($line = <STDIN>) unless($line);
@set=();
$wn = `wn $line -over -hypen -hypon -synsn -smemn -membn -subsn -meron -holon -derin -domnn -famln -coorn -hmern -grepn`;
# print forms($wn);
# die;
foreach(split("\n",$wn)){
if($_ =~ /^([0-9].*?)[.](.*?)$/){
my($sense,$text)=($1,$2);
my @set = map{$_=~s/"|'|`//g; trim($_)}grep{/[a-z|A-Z]/}split("\\(|--|\\)|; \"",$text);
push @{$data->{'senses'}->{$sense}->{"basics"}},@set;
bin/micro-sense view on Meta::CPAN
#last if $line =~ /quit/;
#next if $line =~ /^[a-z|A-Z]/i;
# redo;
#}
#//map{$_=map{ trim($_)}split("=>",$_)unless($_=~/Coordinate Terms/)}
#print Dumper [split("sense",`wn $line -coorn`)];
push @{$data->{'search'}},grep{/[a-z|A-Z]/}split("\n|,",lc `micro-wnet $line words`) unless(!$words);
#push @{$data->{'coordinate'}},map{$_=trim($_); @_=grep(/[A-Z]|[0-9]|[a-z]/,map{$_=trim($_)}split("\n|=>",$_))}split(/Sense/,`wn $line -coorn`) unless(!$words);
#shift @{$data->{'coordinate'}} && shift @{$data->{'search'}} for(0..1);
#@{$data->{'search'}};
END{
$data = {"rows"=>$data,"senses"=>[sort keys %{$data->{'senses'}}]};
my $utf8_encoded_json_text = encode_json($data);
if($debug == 1) {
print Dumper $data,$wn;
}
print $utf8_encoded_json_text;
}
bin/micro-soundex view on Meta::CPAN
my $file = shift;
push @_,$file;
local( @res ) = map {$_=$_}@_; local($i, $t,$_);
for ( @res ) { tr/a-zA-Z//cd; tr/a-zA-Z/A-ZA-Z/s;
($i,$t) = /(.)(.*)/;
$t =~ tr/BFPVCGJKQSXZDTLMNRAEHIOUWY/111122222222334556/sd;
$_ = substr(($i||'Z').$t.'000', 0, 4 );
}
my $maindir = substr($res[0],0,1);
my $targetdir = sprintf("%s/%s/%s",$dir, $maindir,substr($res[0],0,2));
if(! -d $targetdir){
# `mkdir -p $targetdir`;
}
# move($file,$targetdir);
return [$dir,$targetdir,@res,substr($res[0],0,2),$file];
}
#print Dumper glob '*/*json';
print Dumper soundex(@ARGV);
bin/micro-steemer view on Meta::CPAN
pdftotext "$1" "$2";
#pdftohtml -i "$1" "$2.html";
#mv "$2" /tmp/test/pages;
#mv "$2.*.html" /tmp/test/pages;
#mv "$2.*.png" /tmp/test/pages;
#mv "$2.*.jpg" /tmp/test/pages;
FROM="$1"
TO="$2"
#awk '/MARKER/{n++}{print > ".out" n }' "$TO.txt";
bin/micro-wiki view on Meta::CPAN
sub URLDecode {
my $theURL = $_[0];
$theURL =~ tr/+/ /;
$theURL =~ s/%([a-fA-F0-9]{2,2})/chr(hex($1))/eg;
$theURL =~ s/<!--(.|\n)*-->//g;
return $theURL;
}
sub URLEncode {
my $theURL = $_[0];
$theURL =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;
return $theURL;
}
sub smartdecode {
use URI::Escape qw( uri_unescape );
use utf8;
my $x = my $y = uri_unescape($_[0]);
return $x if utf8::decode($x);
return $y;
}
sub imgTranslate {
my ($idx,$url) = @_;
print $idx;
print $url;
if($url){
my $ua = LWP::UserAgent->new;
$response = $ua->get(sprintf("%s%s",$config->{wikipedia}, ucfirst($url)));
$e->parse($response->decoded_content);
return $e->links;
}
}
bin/micro-wiki view on Meta::CPAN
my ($idx,$url) = @_;
my $ua = LWP::UserAgent->new;
my $content ;
my $response ="";
my @book = ();
$response = $ua->get(sprintf("%s%s",$config->{wikipedia}, ucfirst($url)));
my $doc={};
my $linkdata={};
my $wiki = WWW::Wikipedia->new();
my $hs = HTML::Strip->new();
bin/remote.pl view on Meta::CPAN
return $str;
}
1;
package main;
use Data::Printer;
my $ps = AI::MicroStructure::KnowHow->new();
my @go = $ps->remote_Knowledge();
print @go;
p $ps;
1;
__DATA__
package AI::MicroStructure::Knowledge;
use strict;
use AI::MicroStructure (); # do not export metaname and friends
#use AI::MicroStructure::RemoteKnowledge;
use List::Util qw( shuffle );
lib/AI/MicroStructure.pm view on Meta::CPAN
mkdir($fileDir);
warn "missing:$fileSpec";
}
}
sub getComponents{
my $x= {};
$x->{"all_structures"} = [keys %MICRO];
$x->{"count_struct"} = sprintf(keys %MICRO);
$x->{"structures"} = {};
foreach my $con (@{$x->{"all_structures"}}){
next unless($con!~/any/);
my @in = split("\n",eval{`cat $state->{path}->{"cwd/structures"}/$con.pm`;});
$x->{"structures"}->{$state->{path}->{"cwd/structures"}}->{$con}->{name} =
[grep{$_}grep {!/(our|my|use|sub|use|package|#|__|1)/}split("\n",`cat $state->{path}->{"cwd/structures"}/$con.pm`)];#,
$x->{"structures"}->{$state->{path}->{"cwd/structures"}}->{$con}->{files} =
lib/AI/MicroStructure.pm view on Meta::CPAN
( $structure, $count ) = ( $self->{structure}, 1 );
}
if( ! exists $self->{micro}{$structure} ) {
my ( $structure, $category ) = split /\//, $structure, 2;
if( ! $MICRO{$structure} ) {
try{
# `micro new $structure`;
eval "require '$absstructdir/$structure.pm';";
$MICRO{$structure} = 1; # loaded
$self->{micro}{$structure} = AI::MicroStructure->new($structure,category => $category);
print $self->{micro}{$structure}->name( $count );
return;
} catch{
}
}
}
}
# corresponding method
sub name {
my $self = shift;
my ( $structure, $count ) = ("any",1);
lib/AI/MicroStructure.pm view on Meta::CPAN
else {
push @micros, ["AI::MicroStructure::$structure"->new(),''];
}
}
my $all ={};
for my $test (@micros) {
my $micro = $test->[0];
my %items;
my $items = $micro->name(0);
$items{$_}++ for $micro->name(0);
my $key=sprintf("%s",$micro->structure);
$all->{$key}=[$test->[1],$micro->name($items)];
}
return $all;
}
sub save_cat {
my $self = shift;
my $data = shift;
my $dat;
my $ret = "";
foreach my $key(sort keys %{$data} ) {
lib/AI/MicroStructure.pm view on Meta::CPAN
push @in , values %{$data->{names}};
$dat->{names} = join(" ",@in);
$dat->{names} =~ s/$line(.*?)\-\>(.*?) [1-9] /$1 $2/g;
$dat->{names} =~ s/ / /g;
my @file = grep{/$Structure/}map{File::Glob::bsd_glob(
File::Spec->catfile( $_, ($structdir,"*.pm") ) )}@CWD;
if(@file){
open(SELF,"+<$file[0]") || die $!;
while(<SELF>){last if /^__DATA__/}
truncate(SELF,tell SELF);
print SELF $self->save_cat($dat);
truncate(SELF,tell SELF);
close SELF;
}
}
sub openData{
my $self = shift;
my @datax = ();
if(<DATA>){
@datax = <DATA>;
while(@datax){
lib/AI/MicroStructure.pm view on Meta::CPAN
our \@List = qw( \@{\$structures{\$structure}} );
__PACKAGE__->init();
1;
EOC
my $new = {};
foreach my $k
(grep{!/^[0-9]/}map{$_=$self->trim($_)}@{$data->{rows}->{"search"}}){
$k =~ s/[ ]/_/g;
$k =~ s/[\(]|[\)]//g;
next if($k=~/synonyms|hypernyms/);
print $k;
$new->{$k}=[map{$_=[map{$_=$self->trim($_)}split("\n|, ",$_)]}
grep{!/synonyms|hypernyms/}split("sense~~~~~~~~~",
lc `micro-wnet $k`)];
next unless(@{$new->{$k}});
# $new->{$k}=~s/Sense*\n(.*?)\n\n/$1/g;
# @{$new->{$k}} = [split("\n|,",$new->{$k})];
$data->{rows}->{"ident"}->{md5_base64($new->{$k})} = $new->{$k};
}
my $list = join("\n",sort keys %$new);
# $list =~ s/_//g;
lib/AI/MicroStructure.pm view on Meta::CPAN
# names
".$list;
}
sub save_new {
my $self = shift;
my $StructureName = shift;
my $data = shift;
if($StructureName){
#$StructureName = lc $self->trim(`micro`) unless($StructureName);
my $file = "$absstructdir/$StructureName.pm";
print `mkdir -p $absstructdir` unless(-d $absstructdir);
my $fh;
open($fh,">$file") || warn @{[$file,$!]};
print $fh $self->getBlank($StructureName,$data);
close $fh;
$Structure = $StructureName;
push @CWD,$file;
return 1;
}
}
sub drop {
my $self = shift;
my $StructureName = shift;
my @file = grep{/$StructureName.pm/}map{File::Glob::bsd_glob(
File::Spec->catfile( $_, ($structdir,"*.pm") ) )}@CWD;
my $fh = shift @file;
if(`ls $fh`)
{
print `rm $fh`;
}
#push @CWD,$file[1];
return 1;
}
sub help{
}
END{
if($init){}
if($available){}
if($lib){}
if($list){
p @{[__PACKAGE__->getComponents]};
}
if($use){}
if($off){}
if($switch){}
if($mirror){}
if($version){
printf($VERSION);
exit(0);
}
if($help) {
printf(__PACKAGE__->help());
exit(0);
}
if($drop == 1) {
__PACKAGE__->drop($StructureName);
exit 0;
}
if($new==1){
use Term::ReadKey;
use JSON;
my $data = decode_json(lc`micro-sense $StructureName words`);
my $char;
my $line;
my $senses=@{$data->{"senses"}};
$senses= 0 unless($senses);
if(!$verbose){
printf("\n
\033[0;34m
%s
Type: the number you choose 1..$senses
\033[0m",__PACKAGE__->usage($StructureName,$senses,$data));
}
$line = 1 unless($senses != 1);
if($verbose){
$line=1;
}
chomp($line = <STDIN>) unless($line);
my $d = join("#",@{$data->{rows}->{search}});
my @d = grep{/^$line#/}split("sense~~~~~~~~~",$d);
@{$data->{rows}->{"search"}}=split("#",join("",@d));
if($line>0){
__PACKAGE__->save_new($StructureName,$data,$line);
exit 0;
}else{
printf "your logic is today impaired !!!\n";
exit 0;
}
}
if($write == 1) {
__PACKAGE__->save_default();
}
}
sub usage {
my $self = shift;
my $search = shift;
lib/AI/MicroStructure.pm view on Meta::CPAN
$usage =~ s/<4>_/\033[0;32mmicro-structure,\033[255;34m/g;
$usage =~ s/<5>_//g;
my @row = ();
my $ii=0;
foreach my $sensnrx (sort keys %{$data->{"rows"}->{"senses"}})
{
my $row = $data->{"rows"}->{"senses"}->{$sensnrx};
my $txt="";
foreach(@{$row->{"basics"}}[1..2]){
next unless($_);
$txt .= sprintf("\033[0;31m %s\033[255;34m",$_);
}
$txt .= sprintf("",$_);
$usage =~ s/$sensnrx>_/($sensnrx):$txt/g;
if($sensnrx>9){
$usage .= sprintf("\n(%d):%s",$sensnrx,$txt);
}
}
foreach my $ii (0..16){
$usage =~ s/$ii>_//g;
}
return $usage;
}
1;
__END__
#print Dumper $micro;
# ABSTRACT: AI::MicroStructure Creates Concepts for words
=head1 NAME
AI::MicroStructure
=head1 DESCRIPTION
Creates Concepts for words
=head1 SYNOPSIS
~$ micro new world
~$ micro structures
~$ micro any 2
~$ micro drop world
lib/AI/MicroStructure/Locale.pm view on Meta::CPAN
$self->_compute_base();
return $self;
}
sub categories {
my $class = shift;
$class = ref $class if ref $class;
no strict 'refs';
my @p = keys %{"$class\::MultiList"};
print @p;
return \@p;
}
sub has_category {
my ($class, $category) = @_;
$class = ref $class if ref $class;
no strict 'refs';
return exists ${"$class\::MultiList"}{$category};
}
lib/AI/MicroStructure/Util.pm view on Meta::CPAN
sub config {
my $state = AI::MicroStructure::Util::load_config(); my @CWD = $state->{cwd};
$state->{cfg}->{query} ||= "micro";
$state->{cfg}->{tempdir} ||= "/tmp/micro-temp/";
$state->{cfg}->{couchdb} ||= "http://localhost:5984/";
$state->{cfg}->{conceptimg} ||= "http://qunatup.com/tiny/concept2.php";
$state->{cfg}->{wikipedia} ||= "http://en.wikipedia.org/wiki/";
$state->{cfg}->{db} ||= "table";
$state->{cfg}->{out} ||= "json";
$state->{cfg}->{jsonout} = sprintf("%s/%s/",
$state->{cwd},
$state->{cfg}->{db});
return $state;
}
1;
use Data::Dumper;
use Data::Printer;
use AI::MicroStructure;
use AI::MicroStructure::Object;
use AI::MicroStructure::ObjectSet;
use AI::MicroStructure::Context;
use Search::ContextGraph;
use Env qw(PWD);
#print Dumper join "-", soundex(("rock'n'roll", 'rock and roll', 'rocknroll'));
our $meta = AI::MicroStructure->new();
our @t = $meta->structures();
my $TOP = "";
#"/home/santex/wwwstuff/wikileaks.org";
$TOP = "$PWD/t/canned/docs";
if($TOP eq ""){
$TOP = $meta->{state}->{path}->{"cwd/structures"} unless(!$meta->{state}->{path}->{"cwd/structures"});
}
our $curSysDate = `date +"%F"`;
$curSysDate=~ s/\n//g;
our %opts = (cache_file =>
sprintf("%s/%s/%s_.cache",
$PWD,"canned",$curSysDate));
GetOptions (\%opts, "cache_file=s");
our $cache = {};
our @target = split("\/",$opts{cache_file});
ok(my $set = AI::MicroStructure::ObjectSet->new());
eval {
local $^W = 0; # because otherwhise doesn't pass errors
$cache = {} unless $cache;
warn "New cache!\n" unless defined $cache;
};
END{
# lock_store($set,$opts{cache_file});
print Dumper [$set];
}
our $files={};
my $style = {};
$style->{explicit} = 1;
$cg->mixed_search( { docs => [ 'First Document' ],
terms => [ 'snake', 'pony' ]}
);
p $docs;
p $words;
# Print out result set of returned documents
foreach my $k ( sort { $docs->{$b} <=> $docs->{$a} }
keys %{ $docs } ) {
print "Document $k had relevance ", $docs->{$k}, "\n";
}
sub translate {
return unless -f;
use Digest::MD5 qw(md5_hex);
use Data::Dumper;
use Data::Printer;
use AI::MicroStructure;
#use AI::MicroStructure::Object;
use AI::MicroStructure::ObjectSet;
#use AI::MicroStructure::ObjectParser;
use Env qw(PWD);
#print Dumper join "-", soundex(("rock'n'roll", 'rock and roll', 'rocknroll'));
our $meta = AI::MicroStructure->new();
our @t = $meta->structures;
my $TOP = "";
#$TOP = "/tmp/test";#$ARGV[0] unless(!@ARGV);
$TOP = "$PWD/t/canned/docs";
# if($TOP eq ""){
# }
#mkpath dirname($TOP),1;
our $curSysDate = `date +"%F"`;
$curSysDate=~ s/\n//g;
our %opts = (cache_file =>
sprintf("%s/%s/%s_.cache",
$PWD,"t/canned",$curSysDate));
GetOptions (\%opts, "cache_file=s");
our $cache = {};
our @target = split("\/",$opts{cache_file});
ok(my $set = AI::MicroStructure::ObjectSet->new());
eval {
local $^W = 0; # because otherwhise doesn't pass errors
$cache = {} unless $cache;
warn "New cache!\n" unless defined $cache;
};
END{
lock_store($set,$opts{cache_file});
print Dumper [$set->size,$set->members];
}
our $files={};
find(\&translate, "$TOP");
#p $set;
my $style = {};
$style->{explicit} = 1;
ok($c->simpleMixedSearch($style,$_)) && ok($c->play($style,$_)) for
qw(atom antimatter planet);
ok(print Dumper $c->intersect($style,$_)) for
qw(atom antimatter planet);
ok(print Dumper $c->similar($style,$_)) for
qw(atom antimatter planet);
#p @out;
1;
package main;
$|++;
use strict;
use File::Find;
use Data::Dumper;
use Storable qw(lock_store lock_retrieve);
use Getopt::Long;
our $curSysDate = `date +"%F"`;
$curSysDate=~ s/\n//g;
our %opts = (cache_file =>
sprintf("/tmp/%s.cache",
$curSysDate));
GetOptions (\%opts, "cache_file=s");
our $cache = {};
our @target = split("\/",$opts{cache_file});
my $set = AI::MicroStructure::ObjectSet->new();
eval {
local $^W = 0; # because otherwhise doesn't pass errors
$cache = {} unless $cache;
warn "New cache!\n" unless defined $cache;
};
END{
lock_store($cache,$opts{cache_file});
print Dumper [$set->size,$set->members];
}
find(\&translate, "$TOP/./");
sub translate {
</ul>
<li>dus</li>
<li>Ja</li>
</ul>
<li>Foo</li>
</ul>
</p>
EOT
ok(sprintf($html));
__DATA__
$cg->add_documents( %docs );
my ($docs, $words ) = $cg->search('snake');
is(scalar(keys(%$docs)), 2, "only two matches");
ok($docs->{"First Document"}, "contains first document");
ok($docs->{"Third Document"}, "contains third document");
is(sprintf("%2.2f", $docs->{"First Document"}), 18.86, 'correct relevance on search doc #1');
is(sprintf("%2.2f", $docs->{"Third Document"}), 35.35, 'correct relevance on search doc #3');
( $docs, $words ) = $cg->search('snake');
is(sprintf("%2.2f", $docs->{"Third Document"}), 35.35, "repeating search does not change results" );
( $docs, $words ) = $cg->search('pony');
#Test search starting at singleton node
#is(sprintf("%2.2f", $docs->{"Second Document"}), '50.00', "search starting at singleton");
# Try adding a duplicate title
eval{ $cg->add_documents( %docs ); };
ok( $@ =~ /^Tried to add document with duplicate identifier:/,
"complained about duplicate title");
my %new_docs = (
'Fourth Document' => { 'elephant' => 1, 'fox' => 2, 'boa' => 1 },
'Fifth Document' => { 'bull' => 1, 'eagle' => 1 }
);
is ( $cg->doc_count(), 5, "document count is correct" );
# Check that the word count is right
my @words = $cg->term_list();
is ( scalar @words, 9, "word count is correct" );
my $flat = join '', sort @words;
is ( $flat, 'boabullcamelconstrictoreagleelephantfoxponysnake', "word list is correct" );
( $docs, $words ) = $cg->search('pony');
is(sprintf("%2.2f", $docs->{"Second Document"}), '50.00', "singleton search did not change");
my $raw = $cg->raw_search('T:pony');
is(sprintf("%2.2f", $raw->{"D:Second Document"}), '50.00', "raw search gives same result");
( $docs, $words ) = $cg->search('snake');
is(sprintf("%2.2f", $docs->{"First Document"}), 28.36, 'result changed for non-singleton search');
( $docs, $words ) = $cg->find_similar('First Document');
is(sprintf("%2.2f", $docs->{"First Document"}), 122.34, 'find similar search correct');
is(sprintf("%2.2f", $docs->{"Fourth Document"}), 5.57, 'find similar search correct');
# Try storing the sucker
if ( !$XS ) {
my $path = "Search::ContextGraph::Test::Stored";
eval { $cg->store( $path ) };
ok( !length $@, "able to store object to file" );
my $x = Search::ContextGraph->retrieve( $path );
ok( UNIVERSAL::isa( $x, 'Search::ContextGraph'), "reload object from stored file" );
#cleanup
eval { unlink $path; };
ok( !length $@, "remove stored file" );
($docs, $words ) = $cg->find_similar('First Document');
is(sprintf("%2.2f", $docs->{"First Document"}), 122.34, 'reloaded search object works fine');
}
my $y = Search::ContextGraph->new( debug => 1, xs => $XS );
$path = sprintf("$PWD/t/canned/sample.tdm");
$y->load_from_tdm( $path );
ok( !length $@, "able to load TDM file $@" );
is( $y->doc_count(), 177, "correct document count" );
is( $y->term_count(), 2036, "correct term count" );
($docs, $words) = $y->mixed_search( { terms => [ 111, 109, 23 ], docs => [33,21,12] });
is( scalar keys %$words,141, "Got right number of results");
is(sprintf("%2.2f", $docs->{163}), 1.09, "mixed search got right doc value");
is(sprintf("%2.2f", $words->{248}), 0.52, "mixed search got right term value");
}
use Storable::CouchDB;
use Test::More tests =>8;
BEGIN {
use_ok('LWP');
use_ok('Storable::CouchDB');
my $s = Storable::CouchDB->new;
ok("sprintf $s->retrieve('doc')"); #undef if not exists
ok("sprintf $s->store('doc1' => 'data');");
ok('sprintf $s->store("doc2" => {"my" => "data"});');
ok('sprintf $s->store("doc3" => ["my", "data"]);');
ok("sprintf $s->store('doc4' => undef);");
ok("sprintf $s->delete('doc');");
my $browser = LWP::UserAgent->new();
my $seite = "http://127.0.0.1:5984";
# $seite = $browser->get($seite);
# ok($seite->is_success,"couch is there");
$seite = "http://127.0.0.1:5984";