AI-MicroStructure

 view release on metacpan or  search on metacpan

bin/remote.pl  view on Meta::CPAN

        }
        else {    # leaf
            my @items = split /\s+/, $h;
            while ($k) {
                push @{ ${"$class\::KnowHow"}{$k} }, @items;
                $k =~ s!$tail!!;
            }
        }
    }

    ${"$class\::Default"} = $data->{default} || ':all';
    ${"$class\::Theme"} = ( split /::/, $class )[-1];

    *{"$class\::import"} = sub {
        my $callpkg = caller(0);
        my $theme   = ${"$class\::Theme"};
        my $meta    = $class->new;
        *{"$callpkg\::meta$theme"} = sub { $meta->name(@_) };
    };

    ${"$class\::meta"} = $class->new();

bin/remote.pl  view on Meta::CPAN

    }
    splice( @$Knowledge, 0, $count );
}

sub new {
    my $class = shift;

    no strict 'refs';
    my $self = bless { @_, cache => [] }, $class;

    # compute some defaults
    $self->{category} ||= ${"$class\::Default"};

    # fall back to last resort (FIXME should we carp()?)
    $self->{category} = ${"$class\::Default"}
        if $self->{category} ne ':all'
        && !exists ${"$class\::KnowHow"}{ $self->{category} };

    $self->_compute_base();
    return $self;
}

bin/remote.pl  view on Meta::CPAN

use strict;
use warnings;
use Carp;

# 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] ); }
        : 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 {

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

use File::Basename;
use File::Spec;
use File::Glob;
use Data::Dumper;
use Data::Printer;
use AI::MicroStructure::Util;
use Carp qw(croak);
our $absstructdir = "";
our $structdir = "";
our $VERSION = '0.20';
our $Structure = 'any'; # default structure
our $CODESET = 'utf8';
our $LANG = '';
our %MICRO;
our %MODS;
our %ALIEN;
our $str = "[A-Z]";
our $special = "any";
our $search;
our $data={};
our $item="";
our @items;
our @a=();
our ($init,$new,$drop,$available,$lib,
     $list,$use,$off,$switch,$mirror,
     $version,$help,$write,$verbose)  = (0,0,0,0,0,0,0,0,0,0,0,0,0,0);
eval "\$$_=1; " for @ARGV;
if( grep{/\bnew\b/} @ARGV ){ $new = 1; cleanArgs("new"); }
if( grep{/\bwrite\b/} @ARGV ){ $write = 1; cleanArgs("write");  };
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){

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

    for my $structure( @structures ) {
        eval "require AI::MicroStructure::$structure; import AI::MicroStructure::$structure;";
        croak $@ if $@;
        *{"$callpkg\::micro$structure"} = sub { $micro->name( $structure, @_ ) };
    }
}
sub new {
    my ( $class, @args ) = ( @_ );
    my $structure;
    $structure = shift @args if @args % 2;
    $structure = $Structure unless $structure; # same default everywhere
    # defer croaking until name() is actually called
    bless { structure => $structure, args => { @args }, micro => {} ,state=>$state}, $class;
}
sub _rearrange{
   my $self = shift;
   $self->{'payload'} = shift if @_;
   return %$self;
}
# CLASS METHODS
sub add_structure {

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

  foreach my $key(sort keys %{$data} ) {
   next unless($_);
   #ref $hash->{$_} eq "HASH"
   if(ref $data->{$key} eq "HASH"){
   $ret .= "\n".$self->save_cat($data->{$key});
   }else{
   $dat = $data->{$key};
   $dat =~ s/^|,/\n/g;
   $dat =~ s/\n\n/\n/g;
   $dat =~ s/->\n|[0-9]\n//g;
   $ret .= "# ".($key=~/names|default|[a-z]/?$key:"names ".$key);
   $ret .= "\n ".$dat."\n";
   }
  }
  return $ret;
}
sub save_default {
  my $self = shift;
  my $data = shift;
  my $line = shift;
  my $dat = {};
  my @in = ();
  my $active=0;
  $line = $Structure unless($line);
  foreach(@{$data->{rows}->{"coordinate"}}){
   if($_ eq $line){ $active=1; }
   if(1+$line eq $_){ $active=0; }

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

  @{$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;
 my $senseNr = shift;
 my $data = shift;
my $usage = << 'EOT';
               .--'"""""--.>_
            .-'  o\\b.\o._o.`-.

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

The constructor of a single instance. An instance will not repeat items
until the list is exhausted.

=item init()

init() must be called when the subclass is loaded, so as to read the
__DATA__ section and fully initialise it.

=item name( $count )

Return $count names (default: C<1>).

Using C<0> will return the whole list in list context, and the size of the
list in scalar context.

=item structure()

Return the structure name.

=back

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

    # call the parent class init code
    goto &AI::MicroStructure::MultiList::init;
}

sub new {
    my $class = shift;

    no strict 'refs';
    my $self = bless { @_, cache => [] }, $class;

    # compute some defaults
    if( ! exists $self->{category} ) {
        $self->{category} =
            exists $self->{lang}
            ? $self->{lang}
            : $ENV{LANGUAGE} || $ENV{LANG} || '';
        if( !$self->{category} && $^O eq 'MSWin32' ) {
            eval { require Win32::Locale; };
            $self->{category} = Win32::Locale::get_language() unless $@;
        }
    }

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


    AI::MicroStructure::digits - The numbers structure

    =head1 DESCRIPTION

    You can count on this module. Almost.

    =cut

    __DATA__
    # default
    en
    # names en
    zero one two three four five six seven eight nine
    # names fr
    zero un deux trois quatre cinq six sept huit neuf
    # names it
    zero uno due tre quattro cinque sei sette otto nove
    # names yi
    nul eyn tsvey dray fir finf zeks zibn akht nayn

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


the given C<lang> or C<category> parameter,

=item 2.

the current locale, as given by the environment variables C<LANGUAGE>,
C<LANG> or (under Win32) Win32::Locale.

=item 3.

the default language for the selected structure.

=back

The language codes should conform to the RFC 3066 and ISO 639 standard.

=head1 METHODS

AI::MicroStructure::Locale offers several methods, so that the subclasses
are easy to write (see full example in L<SYNOPSIS>):

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


The C<lang> or C<category> parameter(both are synonymous) should be
expressed as a locale category. If none of those parameters is given
AI::MicroStructure::Locale will try to find the user locale (with the
help of environment variables C<LANGUAGE>, C<LANG> and the module
C<Win32::Locale>).

POSIX locales are defined as C<language[_territory][.codeset][@modifier]>.
If the specific territory is not supported, C<AI::MicroStructure::Locale>
will use the language, and if the language isn't supported either,
the default is used.

=item init()

init() must be called when the subclass is loaded, so as to read the
__DATA__ section and fully initialise it.

=item name( $count )

Return $count names (default: C<1>).

Using C<0> will return the whole list in list context, and the size of the
list in scalar context (according to the C<lang> parameter passed to the
constructor).

=item lang()

=item category()

Return the selected language for this instance.

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

        }
        else {    # leaf
            my @items = split /\s+/, $h;
            while ($k) {
                push @{ ${"$class\::MultiList"}{$k} }, @items;
                $k =~ s!$tail!!;
            }
        }
    }

    ${"$class\::Default"} = ${"$class\::Default"} = $data->{default} || ':all';
    ${"$class\::Theme"} = ${"$class\::Theme"} = ( split /::/, $class )[-1];

    *{"$class\::import"} = sub {
        my $callpkg = caller(0);
        my $structure   = ${"$class\::Theme"};
        my $meta    = $class->new;
        *{"$callpkg\::meta$structure"} = sub { $meta->name(@_) };
    };

    ${"$class\::meta"} = ${"$class\::meta"} = $class->new();

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

    }
    splice( @$list, 0, $count );
}

sub new {
    my $class = shift;

    no strict 'refs';
    my $self = bless { @_, cache => [] }, $class;

    # compute some defaults
    $self->{category} ||= ${"$class\::Default"};

    # fall back to last resort (FIXME should we carp()?)
    $self->{category} = ${"$class\::Default"}
        if $self->{category} ne ':all'
        && !exists ${"$class\::MultiList"}{ $self->{category} };

    $self->_compute_base();
    return $self;
}

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


    AI::MicroStructure::digits - The numbers structure

    =head1 DESCRIPTION

    You can count on this module. Almost.

    =cut

    __DATA__
    # default
    :all
    # names primes even
    two
    # names primes odd
    three five seven
    # names composites even
    four six eight
    # names composites odd
    nine
    # names other

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

The category is selected at construction time from:

=over 4

=item 1.

the given C<category> parameter,

=item 2.

the default category for the selected structure.

=back

Categories and sub-categories are separated by a C</> character.

=head1 METHODS

AI::MicroStructure::MultiList offers several methods, so that the subclasses
are easy to write (see full example in L<SYNOPSIS>):

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

until the list is exhausted.

    $meta = AI::MicroStructure::digits->new( category => 'primes' );
    $meta = AI::MicroStructure::digits->new( category => 'primes/odd' );

The special category C<:all> will use all the items in all categories.

    $meta = AI::MicroStructure::digits->new( category => ':all' );

If no C<category> parameter is given, C<AI::MicroStructure::MultiList>
will use the class default. If the class doesn't define a default,
then C<:all> is used.

=item init()

init() must be called when the subclass is loaded, so as to read the
__DATA__ section and fully initialise it.

=item name( $count )

Return $count names (default: C<1>).

Using C<0> will return the whole list in list context, and the size of the
list in scalar context (according to the C<category> parameter passed to the
constructor).

=item category()

Return the selected category for this instance.

=item categories()

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

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 {

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

    eval {
        require LWP::UserAgent;
        die "version 5.802 required ($LWP::VERSION installed)\n"
            if $LWP::VERSION < 5.802;
    };
    if ($@) {
        carp "LWP::UserAgent not available: $@";
        return;
    }

    # figure out the default category (for an instance)
    my $category = ref $_[0] ? $_[1] || $_[0]->{category} : $_[1];

    # fetch the content
    my @items;
    my @srcs = $class->sources($category);
    my $ua   = LWP::UserAgent->new( env_proxy => 1 );
    foreach my $src (@srcs) {
        my $request = HTTP::Request->new(
            ref $src
            ? ( POST => $src->[0],

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

}

sub load_config {

    my @CWD = AI::MicroStructure::Util::get_cwd();
    my $config = {};#Config::Auto::parse(".micro", path => @CWD) || {};
    if (-e ".micro" && -e $ENV{HOME}."/.micro") {
        my $c = Config::Auto::parse($ENV{HOME}."/.micro");
        foreach (keys %{$c}) { $config->{$_} ||= $c->{$_}; }
    }
    if($config->{default}) {
        shift @CWD;
        push @CWD, $config->{default};
        if (-e "$CWD[0]/.micro") {
            my $c = Config::Auto::parse("$CWD[0]/.micro");
            foreach (keys %{$config}) { $c->{$_} ||= $config->{$_}; }
            $config = $c;
        }
    }
    my $structdir = "structures";
    my $path = {
      "structures" => $structdir,
      "cwd/structures" => "$CWD[0]/$structdir",

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

1;

=encoding iso-8859-1

=head1 NAME

AI::MicroStructure::foo - The foo structure

=head1 DESCRIPTION

The classic. This is the default structure.

As from version 0.85, this structure is multilingual.

=head1 CONTRIBUTORS

Philippe "BooK" Bruhat.

Jérôme Fenal and Sébastien Aperghis-Tramoni contributed to the French structure.

Dutch structure contributed by Abigail.

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


=back

=head1 SEE ALSO

L<AI::MicroStructure>, L<Acme::MetaSyntactic::Locale>.

=cut

__DATA__
# default
en
# names en
foo    bar   baz  foobar fubar qux  quux corge grault
garply waldo fred plugh  xyzzy thud
# names fr
toto titi tata tutu pipo
bidon test1 test2 test3
truc chose machin chouette bidule
# names nl
aap noot mies wim zus jet

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


AI::MicroStructure::germany - The numbers structure

=head1 DESCRIPTION

You can count on this module. Almost.

=cut

__DATA__
# default
Dresden
# names Dresden
01067 01069 01097 01099 01108 01109 01127 01129 01139 01156 01157 01159 01169 01187 01189 01217 01219 01237 01239 01257 01259 01277 01279 01307 01309 01324 01326 01328 01462 01465 01478 
# names Radebeul
01445 
# names Radeberg
01454 
# names Wachau
01454 
# names Ottendorf-Okrilla

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

  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";

      $seite = $browser->get($seite);

#  ok($seite->is_success,"default user is there on couch on table");





}

1;

__DATA__

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

    is_deeply(
        [ sort @categories ],
        [ grep { $_ ne ':all' } sort keys %tests ],
        "All categories (instances)"
    );

    for my $args ( [], map { [ category => $_ ] } @categories, ':all', 'zz' ) {
        my $meta = AI::MicroStructure::mongers->new(@$args);
        my $category = $args->[1] || 'fr/lyon';
        $category = 'fr/lyon'
            if $category eq 'zz';    # check fallback to default

        my ( $one, $four ) = ( 1, 4 );
        ( $one, $four ) = ( 0, 0 ) if $category eq 'mars';    # empty list
        my @mongers = $meta->name();
        is( $meta->category(), $category, "category() is $category" );
        is( @mongers, $one, "Single item ($one $category)" );
        @mongers = $meta->name(4);
        is( @mongers, $four, "Four items ($four $category)" );

        @mongers = sort $meta->name(0);

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

    ok( !$meta->has_category('fr/rennes'), "instance hasn't 'fr/rennes'" );
}

package AI::MicroStructure::mongers;
use AI::MicroStructure::MultiList;
our @ISA = ('AI::MicroStructure::MultiList');
__PACKAGE__->init();
1;

__DATA__
# default
fr/lyon
# names fr paris
grinder lacravate echo book
# names fr lyon perrache
book
# names fr lyon ailleurs
jq dm stomakc
# names fr marseille
maddingue arhuman
# names uk london



( run in 0.836 second using v1.01-cache-2.11-cpan-0a6323c29d9 )