AI-MicroStructure

 view release on metacpan or  search on metacpan

bin/micro-relation-test  view on Meta::CPAN

#!/usr/bin/perl -X

use JSON;
use JSON::XS;
use Data::Printer;
use Data::Dumper;
use WWW::Wikipedia;
use Try::Tiny;
my $lang =  $ENV{MICRO_LANG} || "en" ;

my $wiki = WWW::Wikipedia->new(language => $lang);


use Cache::Memcached::Fast;

         my $memd = new Cache::Memcached::Fast({
             servers => [ { address => 'localhost:11211', weight => 2.5 }],
             namespace => 'my:',
             connect_timeout => 0.2,
             io_timeout => 0.5,
             close_on_error => 1,
             compress_threshold => 100_000,
             compress_ratio => 0.9,
             compress_methods => [ \&IO::Compress::Gzip::gzip,
                                   \&IO::Uncompress::Gunzip::gunzip ],
             max_failures => 3,
             failure_timeout => 2,
             ketama_points => 150,
             nowait => 1,
             hash_namespace => 1,
             serialize_methods => [ \&Storable::freeze, \&Storable::thaw ],
             utf8 => ($^V ge v5.8.1 ? 1 : 0),
             max_size => 512 * 1024,
         });





sub  decruft  {
  my($file)  =  @_;
  my($cruftSet)  =  q{%§&|#[^+*(]),'";};
  my  $clean  =  $file;
  $clean=~s/\Q$_//g  for  split("",$cruftSet);

  return  $clean;
}


sub rel {

  my ($arg,$lang)  = @_;

  my $result = $wiki->search($arg);
  my $str = "";

  if (defined($result) &&  $result->text() ) {

    $str = join( "\n", $result->related() );


  }
  return $str;
}


foreach my $call(@ARGV)
{


   my $fromCache = $memd->get($call);


  if($fromCache){

    print $fromCache;


  }else{

    my $str = rel($call, $lang);

    $memd->set($call,$str);
  }
}

#

1;
__DATA__

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.581 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )