AI-MicroStructure

 view release on metacpan or  search on metacpan

bin/chrono  view on Meta::CPAN

use warnings;
use Data::Printer;
use JSON;
use Try::Tiny;
use File::Copy;
use Data::Dumper;

my $file = shift;
my $encoder = JSON->new->allow_blessed->pretty(0);

sub soundex
{

    #my $dir = shift;
    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 );

bin/from-folder.pl  view on Meta::CPAN

        $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){

bin/micro  view on Meta::CPAN

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({
     servers => [ { address => 'localhost:11211', weight => 2.5 }],
     namespace => 'my:',
     connect_timeout => 0.2,
     io_timeout => 0.1,
     close_on_error => 1,
     compress_threshold => 100_000,
     compress_ratio => 0.9,
     max_failures => 1,

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

             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() );

bin/micro-sense  view on Meta::CPAN

my $fresh=1;
my $wn;
my $debug = 0;
my $words = 1;
my $count = 0;

if( grep{/\bdebug\b/} @ARGV ){$debug = 1; cleanArgs("debug"); };
if( grep{/\bwords\b/} @ARGV ){$words = 1; cleanArgs("words"); };


sub cleanArgs{
    my ($key) = @_;
    my @tmp=();
    foreach(@ARGV){
    push @tmp,$_ unless($_=~/$key/);}

    @ARGV=@tmp;
}

# convert to lower case, translate ' ' to '_' and eliminate any
# syntactic marker
sub lower#
{
    my $word = shift;
    $word =~ tr/A-Z /a-z_/;
    $word =~ s/\(.*\)$//;
    return $word;
}

# translate ' ' to '_'
sub underscore#
{
    $_[0] =~ tr/ /_/;
    return $_[0];
}

# Eliminate any syntactic marker
sub delMarker#
{
    $_[0] =~ s/\(.*\)$//;
    return $_[0];
}


sub trim
{
  my $string = shift;
  $string =  "" unless  $string;
  $string =~ s/^\s+//;
  $string =~ s/\s+$//;
  $string =~ s/\t//;
  $string =~ s/^\s//;
  return $string;
}

$structure{"x",1} = "\nData: Hello, my name is Data!\nThank you for reactivating me !";
$structure{"x",2} = "\nData: My post-hypnotic positron inducer  signals all systems within normal parameters!\n";
$structure{"x",3} = "\nData: Please think of an category and I will try to get some structures to it - press enter when ready\n";

sub forms
{
    my ($string) = shift;
    # The query string (word, pos and sense #)
    my ($word, $pos, $sense) = $string =~ /^([^\#]+)(?:\#([^\#]+)(?:\#(\d+))?)?$/;

    return $string;
}


sub intro {

 return sort grep{/^\nData: /} %structure;
}

my @s=AI::MicroStructure::WordBlacklist::getStopWordsSmall();
my $search = "(".join("|",@s).")";
$search =~ s/\'/\\'/g;
my $line = "";
my @xset;
$line = $ARGV[0];

bin/micro-soundex  view on Meta::CPAN

#!/usr/bin/perl

use File::Copy;
use Data::Dumper;
use Data::Printer;
sub soundex
{

p 	@_;
    my $dir = `pwd | tr -d "\n"`;
    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;

bin/micro-wiki  view on Meta::CPAN

    
my $url = $ARGV[0];
my @inx;
my @test;
my $search="";

my $TOP="wikipedia";
my $carry = {count=>0,max=>0};


sub nicefy { return reverse sort {length($a) <=> length($b)}@_ }
sub quantify {my	 $base = {}; map{$base->{$_} = $base->{$_}?$base->{$_}+1:1}@_;  return $base; }#return reverse sort {length($a) <=> length($b)}@_ }


sub list_iter {
           my @ar = @_;
           my $pos = 0;
           return sub {
               return if $pos >= @ar;
               my @r = ( $pos, $ar[$pos] );  # Note: returns ( index, value )
               $pos++;
               return @r;
           };
       }

sub down_iter {
           my @ar = @_;
           my $pos = 0;
           return sub {
               return if $pos >= @ar;
               my @r = ( $pos, $ar[$pos] );  # Note: returns ( index, value )
               $pos++;
               return @r;
           };
       }


sub checkIsThere {

return 0;
}

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;

lib/AI/MicroStructure.pm  view on Meta::CPAN

if( grep{/\bdrop\b/} @ARGV ){ $drop = 1; cleanArgs("drop");  };
if( grep{/\bverbose\b/} @ARGV ){ $verbose = 1; cleanArgs("verbose");  };
our $StructureName = $ARGV[0]; # default structure
our $structure = $ARGV[0]; # default structure
our $state  = AI::MicroStructure::Util::config();
our @CWD=();
push @CWD ,  $state->{path}->{"cwd/structures"};
our $config = $state->{cfg};
our $micro = AI::MicroStructure->new($Structure);
$absstructdir = $state->{path}->{"cwd/structures"};
sub cleanArgs{
   my ($key) = @_;
   my @tmp=();
   foreach(@ARGV){
   push @tmp,$_ unless($_=~/$key/);}
   @ARGV=@tmp;
}
# private class method
sub find_structures {
   my ( $class, @dirs ) = @_;
   $ALIEN{"base"} =  [map  @$_,
   map  { [ ( fileparse( $_, qr/\.pm$/ ) )[0] => $_ ] }
   map  { File::Glob::bsd_glob(
   File::Spec->catfile( $_, ($structdir,"*") ) ) } @dirs];
   return @{$ALIEN{"base"}};
}

# fetch the list of standard structures
sub find_modules {
 my $structures = {};
   foreach(@INC)
   {
   my @set =  grep /($str)/,   map  @$_,
   map  { [ ( fileparse( $_, qr/\.pm$/ ) )[0] => $_ ] }
   map  { File::Glob::bsd_glob(
     File::Spec->catfile( $_, qw( AI MicroStructure *.pm ) ) ) } $_;
   foreach(@set){
   $structures->{$_}=$_;# unless($_=~/(usr\/local|basis)/);
   }

lib/AI/MicroStructure/List.pm  view on Meta::CPAN

package AI::MicroStructure::List;
use strict;
use AI::MicroStructure (); # do not export metaname and friends
use AI::MicroStructure::RemoteList;
use List::Util qw( shuffle );
use Carp;

our @ISA = qw( AI::MicroStructure::RemoteList );
our $VERSION = '0.20';

sub init {
    my ($self, $data) = @_;
    my $class = caller(0);

    $data ||= AI::MicroStructure->load_data($class);
    croak "The optional argument to init() must be a hash reference"
      if ref $data ne 'HASH';

    no strict 'refs';
    no warnings;
    ${"$class\::Theme"} = ( split /::/, $class )[-1];
    @{"$class\::List"}  = do { my %seen;
         grep !$seen{$_}++, split /\s+/, $data->{names} };
    *{"$class\::import"} = sub {
        my $callpkg = caller(0);
        my $structure   = ${"$class\::Theme"};
        my $meta    = $class->new();
        *{"$callpkg\::meta$structure"} = sub { $meta->name(@_) };
      };
    ${"$class\::meta"} = $class->new();
}

sub name {
    my ( $self, $count ) = @_;
    my $class = ref $self;

    if( ! $class ) { # called as a class method!
        $class = $self;
        no strict 'refs';
        $self = ${"$class\::meta"};
    }

    if( defined $count && $count == 0 ) {

lib/AI/MicroStructure/RemoteList.pm  view on Meta::CPAN

=cut

package AI::MicroStructure::RemoteList;
use strict;
use warnings;
use Carp;

our $VERSION = '0.20';

# method that extracts the items from the remote content and returns them
sub extract {
    my $class = ref $_[0] || $_[0];
    no strict 'refs';
    my $func  = ${"$class\::Remote"}{extract};

    # provide a very basic default
    my $meth = ref $func eq 'CODE'
        ? sub { my %seen; return grep { !$seen{$_}++ } $func->( $_[1], $_[2] ); }
        : sub { return $_[1] };    # very basic default

    # put the method in the subclass symbol table (at runtime)
    *{"$class\::extract"} = $meth;

    # now run the function^Wmethod
    goto &$meth;
}

# methods related to the source URL
sub source {
    my $class = ref $_[0] || $_[0];
    no strict 'refs';

    return ${"$class\::Remote"}{source};
}

sub sources {
    my $class = ref $_[0] || $_[0];
    no strict 'refs';

    my $src = ${"$class\::Remote"}{source};
    if ( ref $src eq 'ARRAY' ) {
        return @$src;
    }
    elsif ( ref $src eq 'HASH' ) {
        return grep $_,
              defined $_[1] && $_[1] ne ':all'
            ? ref $_[1] ? @$src{ @{ $_[1] } }
                        : $src->{ $_[1] }
            : values %$src;
    }
    return $src;
}

sub has_remotelist { return defined $_[0]->source(); }

# main method: return the list from the remote source
sub remote_list {
    my $class = ref $_[0] || $_[0];
    return unless $class->has_remotelist();

    # check that we can access the network
    eval {
        require LWP::UserAgent;
        die "version 5.802 required ($LWP::VERSION installed)\n"
            if $LWP::VERSION < 5.802;
    };
    if ($@) {

t/t/0010.t  view on Meta::CPAN

         foreach my $k ( sort { $docs->{$b} <=> $docs->{$a} }
             keys %{ $docs } ) {
             print "Document $k had relevance ", $docs->{$k}, "\n";
         }






sub translate {

  return unless -f;
  (my $rel_name = $File::Find::name) =~ s{.*/}{}xs;

  my $name = md5_hex($rel_name);

  if (/\.(html|htm|txt|json)$/) {
    $files->{html}->{$name}=$rel_name;
      #ok(my $obj = AI::MicroStructure::Object->new($rel_name));
      #ok($set->insert($obj));

t/t/0011.t  view on Meta::CPAN



  }


our $files={};


find(\&translate, "$TOP");
#p $set;
sub translate {

  return unless -f;
  (my $rel_name = $File::Find::name) =~ s{.*/}{}xs;

  my $name = md5_hex($rel_name);

  if (/\.(html|htm)$/) {
    $files->{html}->{$name}=$rel_name;
  }
  elsif (/\.pdf$/) {

t/t/004.t  view on Meta::CPAN

#####################################################################
# Blurt
#####################################################################
blurt("one\ntwo\nthree", $TMP_FILE);
ok(-f $TMP_FILE, "$TMP_FILE exists");

#####################################################################
# Count all lines containing 'o'
#####################################################################
my $count = 0;
plough(sub { $count++ if /o/ }, $TMP_FILE);
is($count, 2, "Counting all lines containing pattern");

t/t/005.t  view on Meta::CPAN


ok(1);


__DATA__

# "alter" the shuffle method
{
    no warnings;
    my ( $i, $j ) = ( 0, 0 );
    *List::Util::shuffle = sub { sort @_ };    # item selection
    *AI::MicroStructure::any::shuffle =       # theme selection
        sub (@) { my @t = sort @_; push @t, shift @t for 1 .. $j; $j++; @t };
}

# compute the first 6 installed themes
my $meta   = AI::MicroStructure->new("any");
my @themes = ( grep { ! /^any$/ } sort $meta->structures() )[ 0 .. 5 ];

# the test list is computed now because of cache issues
my @tests
    = map { [ ( sort $meta->name( $themes[$_] => 0 ) )[ 0 .. $_ + 1 ] ] }
0..10;

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

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