view release on metacpan or search on metacpan
This software is copyright (c) 2014 by hagen geissler santex@cpan.org.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
Terms of the Perl programming language system itself
a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
later version, or
b) the "Artistic License"
--- The GNU General Public License, Version 1, February 1989 ---
This software is Copyright (c) 2014 by hagen geissler santex@cpan.org.
This is free software, licensed under:
The GNU General Public License, Version 1, February 1989
GNU GENERAL PUBLIC LICENSE
Version 1, February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The license agreements of most software companies try to keep users
at the mercy of those companies. By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License. The
"Program", below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications. Each
licensee is addressed as "you".
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program. You may charge a fee for the physical act of
transferring a copy.
2. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:
a) cause the modified files to carry prominent notices stating that
you changed the files and the date of any change; and
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.
Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.
3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
b) accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,
c) accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.
4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions. You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.
7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.
8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
That's all there is to it!
--- The Artistic License 1.0 ---
This software is Copyright (c) 2014 by hagen geissler santex@cpan.org.
This is free software, licensed under:
The Artistic License 1.0
The Artistic License
Preamble
The intent of this document is to state the conditions under which a Package
may be copied, such that the Copyright Holder maintains some semblance of
artistic control over the development of the package, while giving the users of
the package the right to use and distribute the Package in a more-or-less
customary fashion, plus the right to make reasonable modifications.
Definitions:
- "Package" refers to the collection of files distributed by the Copyright
Holder, and derivatives of that collection of files created through
textual modification.
- "Standard Version" refers to such a Package if it has not been modified,
or has been modified in accordance with the wishes of the Copyright
Holder.
- "Copyright Holder" is whoever is named in the copyright or copyrights for
the package.
- "You" is you, if you're thinking about copying or distributing this Package.
- "Reasonable copying fee" is whatever you can justify on the basis of media
cost, duplication charges, time of people involved, and so on. (You will
not be required to justify it to the Copyright Holder, but only to the
computing community at large as a market that must bear the fee.)
- "Freely Available" means that no fee is charged for the item itself, though
there may be fees involved in handling the item. It also means that
recipients of the item may redistribute it under the same conditions they
received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications derived
from the Public Domain or from the Copyright Holder. A Package modified in such
a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided that
you insert a prominent notice in each changed file stating how and when you
changed that file, and provided that you do at least ONE of the following:
a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or an
equivalent medium, or placing the modifications on a major archive site
such as ftp.uu.net, or by allowing the Copyright Holder to include your
modifications in the Standard Version of the Package.
b) use the modified Package only within your corporation or organization.
c) rename any non-standard executables so the names do not conflict with
standard executables, which must also be provided, and provide a separate
manual page for each non-standard executable that clearly documents how it
differs from the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or executable
form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
together with instructions (in the manual page or equivalent) on where to
get the Standard Version.
b) accompany the distribution with the machine-readable source of the Package
with your modifications.
c) accompany any non-standard executables with their corresponding Standard
Version executables, giving the non-standard executables non-standard
names, and clearly documenting the differences in manual pages (or
equivalent), together with instructions on where to get the Standard
Version.
d) make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this Package. You
may not charge a fee for this Package itself. However, you may distribute this
Package in aggregate with other (possibly commercial) programs as part of a
larger (possibly commercial) software distribution provided that you do not
advertise this Package as a product of your own.
6. The scripts and library files supplied as input to or produced as output
from the programs of this Package do not automatically fall under the copyright
---
abstract: 'AI::MicroStructure Creates Concepts for words'
author:
- 'santex <santex@cpan.org>'
build_requires: {}
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 5.041, CPAN::Meta::Converter version 2.142690'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: AI-MicroStructure
no_index:
directory:
- misc
requires:
AI::Categorizer: '0'
AI::Categorizer::Document: '0'
AI::Categorizer::KnowledgeSet: '0'
AI::Categorizer::Learner::NaiveBayes: '0'
Algorithm::BaumWelch: '0'
AnyDBM_File: '0'
AnyEvent::Subprocess::Easy: '0'
Cache::Memcached::Fast: '0'
Carp: '0'
Class::Container: '0'
Config::Auto: '0'
Cwd: '0'
Data::Dumper: '0'
Data::Printer: '0'
Digest::MD5: '0'
Digest::SHA1: '0'
Exporter: '0'
Fcntl: '0'
File::Basename: '0'
File::Glob: '0'
File::HomeDir: '0'
File::Spec: '0'
Getopt::Long: '0'
HTML::SimpleLinkExtor: '0'
HTML::Strip: '0'
HTTP::Request::Common: '0'
IO::Async::Loop: '0'
IO::File: '0'
JSON: '0'
JSON::XS: '0'
LWP::UserAgent: '0'
Lingua::StopWords: '0'
List::Util: '0'
Mojolicious: '0'
Net::Async::WebSocket::Server: '0'
Parallel::Iterator: '0'
Params::Validate: '0'
Search::ContextGraph: '0'
Statistics::Basic: '0'
Statistics::Contingency: '0'
Statistics::Descriptive: '0'
Statistics::Distributions::Ancova: '0'
Statistics::MVA::BayesianDiscrimination: '0'
Statistics::MVA::HotellingTwoSample: '0'
Storable: '0'
Storable::CouchDB: '0'
Sysadm::Install: '0'
perl: v5.14.1
resources:
homepage: http://active-memory.de:2323
version: '0.20'
Makefile.PL view on Meta::CPAN
# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.041.
use strict;
use warnings;
use 5.014001;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
"ABSTRACT" => "AI::MicroStructure Creates Concepts for words",
"AUTHOR" => "santex <santex\@cpan.org>",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "AI-MicroStructure",
"EXE_FILES" => [
"bin/chrono",
"bin/from-folder.pl",
"bin/getcat",
"bin/getcat.pl",
"bin/getfiles.sh",
"bin/getnice",
"bin/leo",
"bin/linksearch",
"bin/linksearch~",
"bin/localfiles",
"bin/micro",
"bin/micro-dict",
"bin/micro-dict~",
"bin/micro-leo",
"bin/micro-relation",
"bin/micro-relation-test",
"bin/micro-rename",
"bin/micro-sense",
"bin/micro-soundex",
"bin/micro-steemer",
"bin/micro-wiki",
"bin/micro-wnet",
"bin/micrownet",
"bin/national",
"bin/newssearch",
"bin/park.pm",
"bin/pdflinks",
"bin/remote.pl"
],
"LICENSE" => "perl",
"MIN_PERL_VERSION" => "5.014001",
"NAME" => "AI::MicroStructure",
"PREREQ_PM" => {
"AI::Categorizer" => 0,
"AI::Categorizer::Document" => 0,
"AI::Categorizer::KnowledgeSet" => 0,
"AI::Categorizer::Learner::NaiveBayes" => 0,
"Algorithm::BaumWelch" => 0,
"AnyDBM_File" => 0,
"AnyEvent::Subprocess::Easy" => 0,
"Cache::Memcached::Fast" => 0,
"Carp" => 0,
"Class::Container" => 0,
"Config::Auto" => 0,
"Cwd" => 0,
"Data::Dumper" => 0,
"Data::Printer" => 0,
"Digest::MD5" => 0,
"Digest::SHA1" => 0,
"Exporter" => 0,
"Fcntl" => 0,
"File::Basename" => 0,
"File::Glob" => 0,
"File::HomeDir" => 0,
"File::Spec" => 0,
"Getopt::Long" => 0,
"HTML::SimpleLinkExtor" => 0,
"HTML::Strip" => 0,
"HTTP::Request::Common" => 0,
"IO::Async::Loop" => 0,
"IO::File" => 0,
"JSON" => 0,
"JSON::XS" => 0,
"LWP::UserAgent" => 0,
"Lingua::StopWords" => 0,
"List::Util" => 0,
"Mojolicious" => 0,
"Net::Async::WebSocket::Server" => 0,
"Parallel::Iterator" => 0,
"Params::Validate" => 0,
"Search::ContextGraph" => 0,
"Statistics::Basic" => 0,
"Statistics::Contingency" => 0,
"Statistics::Descriptive" => 0,
"Statistics::Distributions::Ancova" => 0,
"Statistics::MVA::BayesianDiscrimination" => 0,
"Statistics::MVA::HotellingTwoSample" => 0,
"Storable" => 0,
"Storable::CouchDB" => 0,
"Sysadm::Install" => 0
},
"VERSION" => "0.20",
"test" => {
"TESTS" => "t/t/*.t"
}
);
my %FallbackPrereqs = (
"AI::Categorizer" => 0,
"AI::Categorizer::Document" => 0,
"AI::Categorizer::KnowledgeSet" => 0,
"AI::Categorizer::Learner::NaiveBayes" => 0,
"Algorithm::BaumWelch" => 0,
"AnyDBM_File" => 0,
"AnyEvent::Subprocess::Easy" => 0,
"Cache::Memcached::Fast" => 0,
"Carp" => 0,
"Class::Container" => 0,
"Config::Auto" => 0,
"Cwd" => 0,
"Data::Dumper" => 0,
"Data::Printer" => 0,
"Digest::MD5" => 0,
"Digest::SHA1" => 0,
"Exporter" => 0,
"Fcntl" => 0,
"File::Basename" => 0,
"File::Glob" => 0,
"File::HomeDir" => 0,
"File::Spec" => 0,
"Getopt::Long" => 0,
"HTML::SimpleLinkExtor" => 0,
"HTML::Strip" => 0,
"HTTP::Request::Common" => 0,
"IO::Async::Loop" => 0,
"IO::File" => 0,
"JSON" => 0,
"JSON::XS" => 0,
"LWP::UserAgent" => 0,
"Lingua::StopWords" => 0,
"List::Util" => 0,
"Mojolicious" => 0,
"Net::Async::WebSocket::Server" => 0,
"Parallel::Iterator" => 0,
"Params::Validate" => 0,
"Search::ContextGraph" => 0,
"Statistics::Basic" => 0,
"Statistics::Contingency" => 0,
"Statistics::Descriptive" => 0,
"Statistics::Distributions::Ancova" => 0,
"Statistics::MVA::BayesianDiscrimination" => 0,
"Statistics::MVA::HotellingTwoSample" => 0,
"Storable" => 0,
"Storable::CouchDB" => 0,
"Sysadm::Install" => 0
);
unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
delete $WriteMakefileArgs{TEST_REQUIRES};
delete $WriteMakefileArgs{BUILD_REQUIRES};
$WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs;
}
delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION(6.52) };
WriteMakefile(%WriteMakefileArgs);
Anybody whisching to do categorization, memory, decision making, learning and inference.
requires as much concepts for a specific (word,idea,sensor input) as possible to base any further knowledge or decission on
to be able to fly you require only to types
```
micro new extraterrestrial_life
.--'"""""--.>_
.-' o\\b.\o._o.`-.
.-'.- ) \d888888888888b.
/.' b Y8888888888888888b.
.-'. 8888888888888888888888888b
/ o888 Y Y8888888888888888888888b
/ d888P/ /| Y"Y8888888888888888888b
J d8888/| Y .o._. "Y8888888888888Y" \
|d Y888b|obd88888bo. """Y88888Y' .od8
Fdd 8888888888888888888bo._'|| d88888|
Fd d 88\ Y8888Y "Y888888888b, d888888P
d-b 8888b Y88P' """""Y888b8888P"|
J 8\88888888P `m. """"" |
|| `8888888P' "Ymm._ _J
|\\ Y8888P ' .mmm.YM) .mMF"'
| \\ Y888J ' < (@)>.- ` /MFm. |
J \ `YY ""' :: MM @)>F
L /) 88 : | ""\|
| ( ( Yb . ' . | L
\ bo 8b . . J | The word extraterrestrial
\ "' . . . . L F has 1 concept's
o._.:. . . \mm,__J/ / we need to find out the which one
Y8::'|. / `Y8P J to use for our new,
`|' J: . . ' . . | F micro-structure,
| L ' . _: |
| `: . .:oood8bdb. | (1): a form of life assumed to exist outside the earth or its atmosphere extraterrestrial
F `:. "-._ `" F
/ `::. """' /
/ `::. "" /
_.-d( `:::. F
-888b. `::::. . J
Y888888b. `::::::::::'
Y88888888bo. `::::::d
`"Y8888888888boo.._ `"dd88b.
"""""""""""""""""""""""""""""""""""""""""""""""
Type: the number you choose 1..1
1
extraterrestrialbeing
extraterrestrial
alien
hypothetical_creature
imaginary_being
imaginary_creature
imagination
imaginativeness
vision
creativity
extraterrestrialbeing
extraterrestrial
alien
hypothetical_creature
```
â [sample](http://quantup.com)
â [PDF info](https://github.com/santex/active-memory/raw/master/start-here.pdf)
#### Dependencies
* cpan
* couchdb
* wordnet
* tesseract
* xpdf-utils (poppler-utils)
#### Copyright
Copyright (C) 2009-2012 Hagen "santex" Geissler
# Usage sample use
```
#try something like this
$ micro new ufo; # creates a structure called ufo
$ micro drop ufo; # deletes the structure called ufo
$ micro structures; # shows all structure's you currently have
#after creation of a structure you can access it in lots of ways
$ micro; # one word of a random structure
$ micro ufo; # one word of the ufo structure
$ micro ufo all; # all words of the ufo structure
$ micro ufo 5; # 5 random words of the ufo structure
$ micro any 10; # 10 random words of any structure you have created
$ micro --init # initializes active memory
$ micro --export # export relations from couchdb into git repo and tag data
# oneliners i like to use
$ for i in `micro structures`; do echo $i; done; # echos all the structures
$ for i in `micro ufo all`; do echo $i; done; # echos all words in ufo
$ for i in `micro structures`; do micro all $i; done; # echos all stuctures all words
$ for i in `micro ufo all`; do micro new $i; done; # new structure for all words in ufo
$ for i in `micro ufo all`; do micro-wiki $i; done; # push all words against the wiki plugin dont forget setting user & password in /usr/local/bin/micro-wiki
###################################################################################
# try to follow the logic combine
# your-word=micro new ? ->concept->concepts->relations->node
$ 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;
$ done
$ done
```
# compounding knowledge
```
.--'"""""--.>_
.-' o\\b.\o._o.`-.
.-'.- ) \d888888888888b.
/.' b Y8888888888888888b.
.-'. 8888888888888888888888888b
/ o888 Y Y8888888888888888888888b
/ d888P/ /| Y"Y8888888888888888888b
J d8888/| Y .o._. "Y8888888888888Y" \
|d Y888b|obd88888bo. """Y88888Y' .od8
Fdd 8888888888888888888bo._'|| d88888|
Fd d 88\ Y8888Y "Y888888888b, d888888P
d-b 8888b Y88P' """""Y888b8888P"|
J 8\88888888P `m. """"" |
|| `8888888P' "Ymm._ _J
|\\ Y8888P ' .mmm.YM) .mMF"'
| \\ Y888J ' < (@)>.- ` /MFm. |
J \ `YY ""' :: MM @)>F
L /) 88 : | ""\|
| ( ( Yb . ' . | L
\ bo 8b . . J |
\ "' . . . . L F
o._.:. . . \mm,__J/ /
Y8::'|. / `Y8P J
`|' J: . . ' . . | F
| L ' . _: |
| `: . .:oood8bdb. |
F `:. "-._ `" F
/ `::. """' /
/ `::. "" /
_.-d( `:::. F
-888b. `::::. . J
Y888888b. `::::::::::'
Y88888888bo. `::::::d
`"Y8888888888boo.._ `"dd88b.
```
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 );
}
# move($file,$targetdir);
return {$file=>[grep(!/000/,@res)]};
}
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];
}
p $ret;
1;
__DATA__
application "other",
category "other",
class ""konsole", "Konsole"",
command "{ "/usr/bin/konsole" }",
bin/from-folder.pl view on Meta::CPAN
use strict;
use File::Find;
use Storable qw(lock_store lock_retrieve);
use Getopt::Long;
use Digest::MD5 qw(md5_hex);
use Data::Dumper;
use Data::Printer;
use Env qw(PWD);
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;
}
}
find(\&translate, "$TOP");
p @{[keys %$files,reverse @ARGV,$storage]};
__DATA__
our $c = AI::MicroStructure::Context->new(@ARGV);
$c->retrieveIndex($PWD."/t/docs"); #"/home/santex/data-hub/data-hub" structures=0 text=1 json=1
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
#`rm $opts{cache_file}`;
$cache = lock_retrieve($opts{cache_file});
$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'));
#!/bin/bash
IFS=$'\n'
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
}
bin/getcat.pl view on Meta::CPAN
use File::Find::Rule;
use strict;
use warnings;
use JSON;
use Cache::Memcached::Fast;
use Try::Tiny;
use Data::Dumper;
use Digest::MD5 qw(md5 md5_hex md5_base64);
our $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,
max_size => 512 * 1024,
});
our $all = {};
our $json = JSON->new->allow_nonref;
sub mytry{
my $cmd = shift;
try {
#if($cmd){
my @ret = split "\n",`$cmd`;
return [@ret];
#}
};
}
sub trim
{
my $string = shift;
$string = "" unless $string;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
$string =~ s/\t//;
$string =~ s/^\n//;
$string =~ s/^\s//;
$string =~s/\x{ef}//g;
return $string;
}
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
#!/bin/bash
IFS=$'\n'
q=$1
dir=$2
if [ ! $MICRO_LANG ]
then
MICRO_LANG=en
fi
if [ ! $q ]
then
q="ufo"
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"
#!/bin/bash
if [ -z "${1}" ]; then
search='oil'
else
search=${1}
fi
if [ -z "${2}" ]; then
from='en'
else
from=${2}
fi
if [ -z "${3}" ]; then
to='de'
else
to=${3}
fi
onetwo='.{1,2}'
re="$1"
re="${re//[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]/.}"
re="${re//ue/$onetwo}"
re="${re//ae/$onetwo}"
re="${re//oe/$onetwo}"
re="${re//ss/$onetwo}"
bin/localfiles view on Meta::CPAN
use warnings;
use JSON;
use Cache::Memcached::Fast;
use AI::MicroStructure;
use Data::Dumper;
my $data={};
our $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,
max_size => 512 * 1024,
});
my @result = ();
my $rule;
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");
bin/localfiles view on Meta::CPAN
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 Getopt::Long;
use AI::MicroStructure;
use Data::Printer;
use Data::Dumper;
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({
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,
max_size => 512 * 1024,
});
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) = @_;
my @tmp=();
foreach(@ARGV){
push @tmp,$_ unless($_=~/$key/);}
@ARGV=@tmp;
}
my $structure;
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(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);
p $meta;
exit;
}
if(!$conf{"drop"} && !$conf{"write"}and $ARGV[0] !~/structures/){
# find out the structure name
$structure = shift || $AI::MicroStructure::structure;
if (!length $conf{category} && $structure =~ m{^([^/]+)/(.*)}s) {
$structure = $1;
$conf{category} = $2;
}
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};
if ( !$conf{remote} ) {
my $count = shift;
$count = 1 unless defined $count;
$count = 0 if $conf{check};
if($all){
@local = $meta->name(0,scalar "");
}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
#!/bin/bash
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(){
bin/micro-dict view on Meta::CPAN
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
}
function masher(){
if [ -f "$1" ]
then #+ valid file argument.
cmd=cat
else
cmd=echo
fi
$cmd $1 | tr A-Z a-z | # Convert to lowercase.
tr ' ' '\012' | # 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
#+ chars, change them to newlines.
egrep -v '^#' | # Delete lines starting with hashmark.
egrep -v "^[ ]*([A-Za-z][A-Za-z]|[A-Za-z])$" |
egrep -v '^$'
}
if [ "$2" == 1 ] # Need at least one
then
uniquemmasher $*;
bin/micro-dict~ view on Meta::CPAN
#!/bin/bash
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(){
bin/micro-dict~ view on Meta::CPAN
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"
}
function masher(){
if [ -f "$1" ]
then #+ valid file argument.
cmd=cat
else
cmd=echo
fi
$cmd $1 | tr A-Z a-z | # Convert to lowercase.
tr ' ' '\012' | # 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
#+ chars, change them to newlines.
egrep -v '^#' | # Delete lines starting with hashmark.
egrep -v "^[ ]*([A-Za-z][A-Za-z]|[A-Za-z])$" |
egrep -v '^$'
}
if [ "$2" == 1 ] # Need at least one
then
uniquemmasher $*;
bin/micro-relation view on Meta::CPAN
use WWW::Wikipedia;
use Try::Tiny;
my $lang = $ENV{MICRO_LANG} || "en" ;
my $wiki = WWW::Wikipedia->new(language => $lang);
use Cache::Memcached::Fast;
our $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,
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 = shift;
my $lang = shift;
if(defined(my $fromCache = $memd->get($arg))){
return $fromCache;
}
my $result = $wiki->search($arg);
my $str = "";
if (defined($result) && $result->text() ) {
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
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__
bin/micro-sense view on Meta::CPAN
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];
#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;
}
}
#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
#!/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;
$_ = 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-wiki view on Meta::CPAN
die("require a argument") unless($ARGV[0]);
our $doc ={};
our @links;
our $linkdata = {};
our $result;
our $odir = "";
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/+/ /;
bin/micro-wiki view on Meta::CPAN
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;
}
}
sub call {
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();
my $result = $wiki->search(ucfirst $url);
if (defined($result) && $result->text() ) {
my $clean_text = $hs->parse($result->text() );
$hs->eof;
require HTML::SimpleLinkExtor;
no warnings 'utf8';
my $e = HTML::SimpleLinkExtor->new();
$e->parse($response->decoded_content);
my @all_links = $e->links;
my @tags= map{$_=lc($_); $_=~s/\)|\/wiki\///g; $_=~s/ /_/g; $_=[split("_\\(",$_)] }grep {/([(].+?[)]|$url)/}@all_links ;# $result->related();
my @audio = grep{/^(\/\/|upload|http).*.(mp3|wave|ogg|OGG|WAVE|MP3)$/}@all_links;
my @pdf = grep{/^(\/\/|upload|http).*.(pdf|PDF)$/}@all_links;
my @book = grep{/books.google/i}@all_links;
foreach(@tags){
if($_->[1] && $_->[1]!~/\W/){
$doc->{tags}->{$_->[1]}->{$_->[0]} = $doc->{tags}->{$_->[1]}->{$_->[0]} ? $doc->{tags}->{$_->[1]}->{$_->[0]} +1:1;
}
}
$doc->{image}=[map{$_="http:$_"; }grep{/[1-9][0-9][0-9]px/}$e->img];
$doc->{cat}=[grep{/^.*.(Kategory|Category)+?/}@all_links];
$doc->{cat}=[sort grep{!/(category|wikipedia|article|page|List.*.of)/i}map{$a=$_; $a =~ s/^.*.://g; $_=$a;}@{$doc->{cat}}];
$doc->{list}=[grep{/List.*.of_/}@all_links];
$doc->{list}=[sort map{$a=$_; $a=~ s/^.*.List/List/g; $_=$a;}@{$doc->{list}}];
$doc->{book}= [@book] unless(!@book);
$doc->{pdf}= [@pdf] unless(!@pdf);
$doc->{audio}= [@audio] unless(!@audio);
$doc->{related} = quantify $result->related();
$doc->{links} = [sort grep{/http/}@all_links];
#eval '$couchdb->store("$url" ,$doc)' or warn "error: $@\n";
# createJsonFile($url,$doc);
p $doc;
return $doc;
}
}
our @out = ();
foreach my $urlx (@ARGV) {
bin/micrownet view on Meta::CPAN
#! /bin/bash
for i in $@; do
wn $i -hypon -hypen -synsv -synsn -hypen -synsv -synsn -synsa -grepn -grepa -grepv -synsa -perta -deria -famla -grepv -derin -famln |
sed 's/[[:space:]]*=> / /' | sed 's/HAS INSTANCE//g' | egrep -v "(Synonyms|Hypernyms|Grep|The |*.[ ]of[ ].*|Overview|Hyponyms|noun|[1-9]|^(\W+))" |
sed '/^$/d' | sed 's/ /_/g'| sed 's/,_/\n/g' | sort -u | egrep "(^$i|[_]$i)";
done;
#
#echo -e "\n"$i,$xx;
#
#
bin/pdflinks view on Meta::CPAN
IFS=$'\n';
pat="Category"
url="http://en.wikipedia.org/wiki/$1"
if [[ $1 =~ $pat ]]; then
url="http://en.wikipedia.org/wiki/$1";
else
url="http://en.wikipedia.org/wiki/Category:$1";
fi
echo $url;
for i in $(mojo get "$url" a attr href | sort -u | egrep "^\/wiki\/[A-Z]" | egrep -v "Portal|Wikipedia|Special:|Help:|Main_Page" | sed -s "s/\/wiki\///");
do
if [[ $i =~ $pat ]]; then
echo -e "\t\t\t./$0 $i"
#./pdflinks $i
else
echo $i;
fi
done
#url=$(echo "http://en.wikipedia.org/wiki/"$i);
#for ii in `mojo get $url a attr href | egrep pdf$ | sort -R`; do
# echo echo wget -rc "$ii"; done done
bin/remote.pl view on Meta::CPAN
package AI::MicroStructure::KnowHow;
use strict;
use AI::MicroStructure (); # do not export metaname and friends
#use AI::MicroStructure::RemoteKnowledge;
use List::Util qw( shuffle );
use Carp;
#our @ISA = qw( AI::MicroStructure::RemoteKnowledge );
sub init {
my $class = caller(0);
my $data = AI::MicroStructure->load_data($class);
no strict 'refs';
my $sep = ${"$class\::Separator"} ||= '/';
my $tail = qr/$sep?[^$sep]*$/;
# compute all categories
my @categories = ( [ $data->{names}, '' ] );
while ( my ( $h, $k ) = @{ shift @categories or []} ) {
if ( ref $h eq 'HASH' ) {
push @categories,
map { [ $h->{$_}, ( $k ? "$k$sep$_" : $_ ) ] } keys %$h;
}
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();
}
sub name {
my ( $self, $count ) = @_;
my $class = ref $self;
if ( !$class ) { # called as a class method!
$class = $self;
no strict 'refs';
$self = ${"$class\::meta"};
}
no strict 'refs';
if ( defined $count && $count !~ /A-Za-z/ && $count == 0 ) {
return wantarray
? shuffle @{ $self->{base} }
: scalar @{ $self->{base} };
}
$count ||= 1;
my $Knowledge = $self->{cache};
if ( @{ $self->{base} } ) {
push @$Knowledge, shuffle @{ $self->{base} } while @$Knowledge < $count;
}
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;
}
sub _compute_base {
my ($self) = @_;
my $class = ref $self;
# compute the base Knowledge for this category
no strict 'refs';
my %seen;
$self->{base} = [
grep { !$seen{$_}++ }
map { @{ ${"$class\::KnowHow"}{$_} } }
$self->{category} eq ':all'
? ( keys %{"$class\::KnowHow"} )
: ( $self->{category} )
];
return;
}
sub category { $_[0]->{category} }
sub categories {
my $class = shift;
$class = ref $class if ref $class;
no strict 'refs';
return keys %{"$class\::KnowHow"};
}
sub has_category {
my ($class, $category) = @_;
$class = ref $class if ref $class;
no strict 'refs';
return exists ${"$class\::KnowHow"}{$category};
}
sub theme {
my $class = ref $_[0] || $_[0];
no strict 'refs';
return ${"$class\::Theme"};
}
1;
package AI::MicroStructure::KnowHow;
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 {
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
map { ref $_ ? @$_ : $_ } $_[1] ? $src->{ $_[1] } : values %$src;
}
return $src;
}
sub has_remoteKnowledge { return defined $_[0]->source(); }
# main method: return the Knowledge from the remote source
sub remote_Knowledge {
my $class = ref $_[0] || $_[0];
return unless $class->has_remoteKnowledge();
# 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 ($@) {
carp "LWP::UserAgent not available: $@";
return;
}
# fetch the content
my @items;
my @srcs = $class->sources($_[1]);
my $ua = LWP::UserAgent->new( env_proxy => 1 );
foreach my $src (@srcs) {
my $res = $ua->request( HTTP::Request->new( GET => $src ) );
if ( ! $res->is_success() ) {
carp "Failed to get content at $src (" . $res->status_line();
return;
}
# extract, cleanup and return the data
# if decoding the content fails, we just deal with the raw content
push @items =>
$class->extract( $res->decoded_content() || $res->content() );
}
# return unique items
my %seen;
return grep { !$seen{$_}++ } @items;
}
#
# transformation subroutines
#
sub tr_nonword {
my $str = shift;
$str =~ tr/a-zA-Z0-9_/_/c;
$str;
}
sub tr_accent {
my $str = shift;
$str =~ tr{ÃÃÃÃÃÃ
ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃà áâãäåçèéêëìÃîïñòóôõöøùúûüýÿ}
{AAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy};
return $str;
}
my %utf2asc = (
"\xc3\x89" => 'E',
"\xc3\xa0" => 'a',
"\xc3\xa1" => 'a',
"\xc3\xa9" => 'e',
"\xc3\xaf" => 'i',
"\xc3\xad" => 'i',
"\xc3\xb6" => 'o',
"\xc3\xb8" => 'o',
"\xc5\xa0" => 'S',
"\x{0160}" => 'S',
# for pokemons
"\x{0101}" => 'a',
"\x{012b}" => 'i',
"\x{014d}" => 'o',
"\x{016b}" => 'u',
"\xe2\x99\x80" => 'female',
"\xe2\x99\x82" => 'male',
"\x{2640}" => 'female',
"\x{2642}" => 'male',
);
my $utf_re = qr/(@{[join( '|', sort keys %utf2asc )]})/;
sub tr_utf8_basic {
my $str = shift;
$str =~ s/$utf_re/$utf2asc{$1}/go;
return $str;
}
1;
package main;
use Data::Printer;
my $ps = AI::MicroStructure::KnowHow->new();
my @go = $ps->remote_Knowledge();
print @go;
bin/remote.pl view on Meta::CPAN
package AI::MicroStructure::Knowledge;
use strict;
use AI::MicroStructure (); # do not export metaname and friends
#use AI::MicroStructure::RemoteKnowledge;
use List::Util qw( shuffle );
use Carp;
our @ISA = qw( AI::MicroStructure::RemoteKnowledge );
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\::Knowledge"} = split /\s+/, $data->{names};
*{"$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();
}
sub name {
my ( $self, $count ) = @_;
my $class = ref $self;
if( ! $class ) { # called as a class method!
$class = $self;
no strict 'refs';
$self = ${"$class\::meta"};
}
no strict 'refs';
if( defined $count && $count == 0 ) {
return
wantarray ? shuffle @{"$class\::Knowledge"} : scalar @{"$class\::Knowledge"};
}
$count ||= 1;
my $Knowledge = $self->{cache};
{
no strict 'refs';
if (@{"$class\::Knowledge"}) {
push @$Knowledge, shuffle @{"$class\::Knowledge"} while @$Knowledge < $count;
}
}
splice( @$Knowledge, 0, $count );
}
sub new {
my $class = shift;
bless { cache => [] }, $class;
}
sub theme {
my $class = ref $_[0] || $_[0];
no strict 'refs';
return ${"$class\::Theme"};
}
1;
package AI::MicroStructure::pornstars;
use strict;
#use AI::MicroStructure::KnowHow;
our @ISA = qw( AI::MicroStructure::KnowHow );
__PACKAGE__->init();
our %Remote = (
source => {
female => 'http://en.wikipedia.org/wiki/Knowledge_of_female_porn_stars',
male => 'http://en.wikipedia.org/wiki/Knowledge_of_male_porn_stars'
},
extract => sub {
return
map { AI::MicroStructure::RemoteKnowledge::tr_accent($_) }
map { AI::MicroStructure::RemoteKnowledge::tr_utf8_basic($_) }
grep { ! /^Knowledge_|_Groups$/ }
map { s/[-\s']/_/g; s/[."]//g; $_ }
$_[0]
=~ m{^<li>(?:<[^>]*>)?(.*?)(?:(?: ?[-,(<]| aka | see ).*)?</li>}mig
},
,
);
1;
package main;
use Data::Printer;
my $ps = AI::MicroStructure::pornstars->new();
my @go = $ps->extract();
p @go;
p $ps;
lib/AI/MicroStructure.pm view on Meta::CPAN
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){
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)/);
}
}
return %$structures;
}
$MICRO{$_} = 0 for keys %{{__PACKAGE__->find_structures(@CWD)} };
$MODS{$_} = $_ for keys %{{__PACKAGE__->find_modules(@INC)} };
$search = join("|",keys %MICRO);
BEGIN{
use File::HomeDir;
my $fileDir = File::HomeDir->my_home . "/data-hub/structures/";
my $fileSpec = File::HomeDir->my_home . "/data-hub/structures/any.pm";
if ( -e $fileSpec ) {
} else {
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} =
[split("\n",`ls -R /home/santex/repos/KnowledgeInterDisciplinary/data/json | egrep -i "($con)";`)];
}
return $x;
}
sub import {
my $class = shift;
my @structures = ( grep { $_ eq ':all' } @_ )
? ( 'foo', grep { !/^(?:foo|:all)$/ } keys %MICRO ) # 'foo' is still first
: @_;
$Structure = $structures[0] if @structures;
$micro = AI::MicroStructure->new( $Structure );
# export the microname() function
no strict 'refs';
my $callpkg = caller;
*{"$callpkg\::microname"} = \µname; # standard theme
# load the classes in @structures
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 {
my $class = shift;
my %structures = @_;
for my $structure ( keys %structures ) {
croak "The structure $structure already exists!" if exists $MICRO{$structure};
my @badnames = grep { !/^[a-z_]\w*$/i } @{$structures{$structure}};
croak "Invalid names (@badnames) for structure $structure"
if @badnames;
my $code = << "EOC";
package AI::MicroStructure::$structure;
use strict;
use AI::MicroStructure::List;
our \@ISA = qw( AI::MicroStructure::List );
our \@List = qw( @{$structures{$structure}} );
__PACKAGE__->init();
1;
EOC
eval $code;
$MICRO{$structure} = 1; # loaded
# export the microstructure() function
no strict 'refs';
my $callpkg = caller;
*{"$callpkg\::micro$structure"} = sub { $micro->name( $structure, @_ ) };
}
}
# load the content of __DATA__ into a structure
# this class method is used by the other AI::MicroStructure classes
sub load_data {
my ($class, $structure ) = @_;
$data = {};
my $fh;
{ no strict 'refs'; $fh = *{"$structure\::DATA"}{IO}; }
my $item;
my @items;
$$item = "";
{
if(defined($fh)){
local $_;
while (<$fh>) {
/^#\s*(\w+.*)$/ && do {
push @items, $item;
$item = $data;
my $last;
my @keys = split m!\s+|\s*/\s*!, $1;
$last = $item, $item = $item->{$_} ||= {} for @keys;
$item = \( $last->{ $keys[-1] } = "" );
next;
};
$$item .= $_;
}
}
}
# clean up the items
for( @items, $item ) {
$$_ =~ s/\A\s*//;
$$_ =~ s/\s*\z//;
$$_ =~ s/\s+/ /g;
}
return $data;
}
#fitnes
sub fitnes {
my $self = shift;
return sha1_hex($self->structures());
##my ($config,$structure, $config ) = (shift,[$self->structures()]); FIXME
}
# main function
sub microname { $micro->name( @_ ) };
sub shitname {
my $self = shift;
my ( $structure, $count ) = ("any",1);
if (@_) {
( $structure, $count ) = @_;
( $structure, $count ) = ( $self->{structure}, $structure )
if $structure =~ /^(?:0|[1-9]\d*)$/;
}
else {
( $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);
if (@_) {
( $structure, $count ) = @_;
( $structure, $count ) = ( $self->{structure}, $structure )
if defined($structure) && $structure =~ /^(?:0|[1-9]\d*)$/;
}
else {
( $structure, $count ) = ( $self->{structure}, 1 );
}
if( ! exists $self->{micro}{$structure} ) {
if( ! $MICRO{$structure} ) {
eval "require '$absstructdir/$structure.pm';";
croak "MicroStructure list $structure does not exist!" if $@;
$MICRO{$structure} = 1; # loaded
}
$self->{micro}{$structure} =
"AI::MicroStructure::$structure"->new( %{ $self->{args} } );
}
$self->{micro}{$structure}->name( $count );
}
# corresponding method
sub namex {
my $self = shift;
my ( $structure, $count ) = ("any",1);
if (@_) {
( $structure, $count ) = @_;
( $structure, $count ) = ( $self->{structure}, $structure )
if defined($structure) && $structure =~ /^(?:0|[1-9]\d*)$/;
}
else {
( $structure, $count ) = ( $self->{structure}, 1 );
}
if( ! exists $self->{micro}{$structure} ) {
if( ! $MICRO{$structure} ) {
try {
eval "require '$absstructdir/$structure.pm';";
$MICRO{$structure} = 1; # loaded
croak "MicroStructure list $structure does not exist!" if $@;
}catch{
}
}
$self->{micro}{$structure} =
"AI::MicroStructure::$structure"->new( %{ $self->{args} } );
}
$self->{micro}{$structure}->name( $count );
}
# other methods
sub structures { wantarray ? ( sort keys %MICRO ) : scalar keys %MICRO }
sub has_structure { $_[1] ? exists $MICRO{$_[1]} : 0 }
sub configure_driver { $_[1] ? exists $MICRO{$_[1]} : 0 }
sub count {
my $self = shift;
my ( $structure, $count );
if (@_) {
( $structure, $count ) = @_;
( $structure, $count ) = ( $self->{structure}, $structure )
if $structure =~ /^(?:0|[1-9]\d*)$/;
}
if( ! exists $self->{micro}{$structure} ) {
return scalar ($self->{micro}{$structure}->new);
}
return 0;
}
sub trim
{
my $self = shift;
my $string = shift;
$string = "" unless $string;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
$string =~ s/\t//;
$string =~ s/^\s//;
return $string;
}
sub getBundle {
my $self = shift;
my @structures = grep { !/^(?:any)/ } AI::MicroStructure->structures;
my @micros;
my @search=[];
for my $structure (@structures) {
no strict 'refs';
eval "require '$absstructdir/$structure.pm';";
my %isa = map { $_ => 1 } @{"AI::MicroStructure::$structure\::ISA"};
if( exists $isa{'AI::MicroStructure::Locale'} ) {
for my $lang ( "AI::MicroStructure::$structure"->languages() ) {
push @micros,
["AI::MicroStructure::$structure"->new( lang => $lang ),$lang];
}
}
elsif( exists $isa{'AI::MicroStructure::MultiList'} ) {
for my $cat ( "AI::MicroStructure::$structure"->categories(), ':all' ) {
push @micros,
[ "AI::MicroStructure::$structure"->new( category => $cat ),$cat];
}
}
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} ) {
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; }
if($active==1){
$_=~s/,//g;
$_ = $self->trim($_);
$dat->{names}->{$_}=$_ unless(defined($dat->{names}->{$_}));
}
}
foreach(@{$data->{rows}->{"search"}}){
if($_ eq $line){ $active=1; }
if(1+$line eq $_){ $active=0; }
if($active==1){
$_=~s/,//g;
$_ = $self->trim($_);
$dat->{names}->{$_}=$_ unless(defined($dat->{names}->{$_}));
}
}
push @in , keys %{$dat->{names}};
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){
chomp;
if($_=~/^#\s*(\w+.*)$/) {
@a=split(" ",$1);
if($#a){
$data->{$a[0]}->{$a[1]}="";
}else{
$data->{$1}="";
}
$item=$1 unless($#a);
}else{
my @keys = split m!\s+|\s*/\s*!,$_;
foreach(sort @keys){
if($#a){
$data->{$a[0]}->{$a[1]} .= " $_" unless($_ eq "");
}else{
$data->{$item} .= " $_" unless($_ eq "");
}
}
};
}
}
return $data;
}
sub getBlank {
my $self = shift;
my $structure = shift;
my $data = shift;
my $usage = "";
$usage = "#!/usr/bin/perl -W\n";
$usage .= << "EOC";
package AI::MicroStructure::$structure;
use strict;
use AI::MicroStructure::List;
our \@ISA = qw( AI::MicroStructure::List );
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;
$usage .= "
__DATA__
# 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;
my $senseNr = shift;
my $data = shift;
my $usage = << 'EOT';
.--'"""""--.>_
.-' o\\b.\o._o.`-.
.-'.- ) \d888888888888b.
/.' b Y8888888888888888b.
.-'. 8888888888888888888888888b
/ o888 Y Y8888888888888888888888b
/ d888P/ /| Y"Y8888888888888888888b
J d8888/| Y .o._. "Y8888888888888Y" \
|d Y888b|obd88888bo. """Y88888Y' .od8
Fdd 8888888888888888888bo._'|| d88888|
Fd d 88\ Y8888Y "Y888888888b, d888888P
d-b 8888b Y88P' """""Y888b8888P"|
J 8\88888888P `m. """"" |
|| `8888888P' "Ymm._ _J
|\\ Y8888P ' .mmm.YM) .mMF"'
| \\ Y888J ' < (@)>.- ` /MFm. |
J \ `YY ""' :: MM @)>F
L /) 88 : | ""\|
| ( ( Yb . ' . | L
\ bo 8b . . J | <0>_
\ "' . . . . L F <1>_
o._.:. . . \mm,__J/ / <2>_
Y8::'|. / `Y8P J <3>_
`|' J: . . ' . . | F <4>_
| L ' . _: | <5>_
| `: . .:oood8bdb. | 1>_
F `:. "-._ `" F 2>_
/ `::. """' / 3>_
/ `::. "" / 4>_
_.-d( `:::. F 5>_
-888b. `::::. . J 6>_
Y888888b. `::::::::::' 7>_
Y88888888bo. `::::::d 8>_
`"Y8888888888boo.._ `"dd88b. 9>_
"""""""""""""""""""""""""""""""""""""""""""""""
EOT
$usage =~ s/<0>_/\033[0;32mThe word $search\033[255;34m/g;
$usage =~ s/<1>_/\033[0;32mhas $senseNr concept's\033[255;34m/g;
$usage =~ s/<2>_/\033[0;32mwe need to find out the which one\033[255;34m/g;
$usage =~ s/<3>_/\033[0;32mto use for our new,\033[255;34m/g;
$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
~$ micro
=head1 AUTHOR
Hagen Geissler <santex@cpan.org>
=head1 COPYRIGHT AND LICENCE
Hagen Geissler <santex@cpan.org>
=head1 SUPPORT AND DOCUMENTATION
[sample using concepts](http://active-memory.de:2323/nerd?param=perl#ajax/home)
[PDF info on my works](https://github.com/santex/AI-MicroStructure)
=head1 SEE ALSO
AI-MicroStructure
=cut
__DATA__
lib/AI/MicroStructure/Alias.pm view on Meta::CPAN
package AI::MicroStructure::Alias;
use strict;
use warnings;
use Carp;
our $VERSION = '0.20';
sub init {
my ( $self, $alias ) = @_;
my $class = caller(0);
eval "require AI::MicroStructure::$alias;";
croak "Aliased structure AI::MicroStructure::$alias failed to load: $@"
if $@;
no strict 'refs';
no warnings;
# copy almost everything over from the original
for my $k ( grep { ! /^(?:Theme|meta|import)$/ }
keys %{"AI::MicroStructure::$alias\::"} )
{
*{"$class\::$k"} = *{"AI::MicroStructure::$alias\::$k"};
}
# local things
${"$class\::Theme"} = ( split /::/, $class )[-1];
${"$class\::meta"} = $class->new();
*{"$class\::import"} = sub {
my $callpkg = caller(0);
my $structure = ${"$class\::Theme"};
my $meta = $class->new();
*{"$callpkg\::meta$structure"} = sub { $meta->name(@_) };
};
}
1;
__END__
=head1 NAME
AI::MicroStructure::Alias - Alias one structure to another
=head1 SYNOPSIS
package AI::MicroStructure::bonk;
use AI::MicroStructure::Alias;
our @ISA = qw( AI::MicroStructure::Alias );
__PACKAGE__->init('batman');
1;
=head1 NAME
AI::MicroStructure::bonk - The bonk structure
=head1 DESCRIPTION
This structure is just an alias of the C<batman> theme.
=cut
# no __DATA__ section required!
=head1 DESCRIPTION
C<AI::MicroStructure::Alias> is the base class for any structures that is
simply an alias of another structure.
=head1 METHOD
AI::MicroStructure::Alias defines a single method, C<init()> that
make aliases very easy to write (see the full example in L<SYNOPSIS>):
lib/AI/MicroStructure/List.pm view on Meta::CPAN
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 ) {
no strict 'refs';
return
wantarray ? shuffle @{"$class\::List"} : scalar @{"$class\::List"};
}
$count ||= 1;
my $list = $self->{cache};
{
no strict 'refs';
if (@{"$class\::List"}) {
push @$list, shuffle @{"$class\::List"} while @$list < $count;
}
}
splice( @$list, 0, $count );
}
sub new {
my $class = shift;
bless { cache => [] }, $class;
}
sub structure {
my $class = ref $_[0] || $_[0];
no strict 'refs';
return ${"$class\::Theme"};
}
1;
__END__
=head1 NAME
AI::MicroStructure::List - Base class for simple lists of names
=head1 SYNOPSIS
package AI::MicroStructure::beatles;
use AI::MicroStructure::List;
our @ISA = ( AI::MicroStructure::List );
__PACKAGE__->init();
1;
=head1 NAME
AI::MicroStructure::beatles - The fab four structure
=head1 DESCRIPTION
Ladies and gentlemen, I<The Beatles>. I<(hysteric cries)>
=cut
__DATA__
# names
john paul
george ringo
=head1 DESCRIPTION
C<AI::MicroStructure::List> is the base class for all structures that are
meant to return a random excerpt from a predefined list.
=head1 METHOD
AI::MicroStructure::List 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
use warnings;
use AI::MicroStructure (); # do not export metaname and friends
use AI::MicroStructure::MultiList;
use List::Util qw( shuffle );
use Carp;
our @ISA = qw( AI::MicroStructure::MultiList );
our $VERSION = '0.20';
sub init {
# alias the older package variable %Locale to %MultiList
no strict 'refs';
*{"$_[0]::Locale"} = \%{"$_[0]::MultiList"};
${"$_[0]::Separator"} = '_';
# 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 $@;
}
}
my $cat = $self->{category};
# support for territories
if ( $cat && $cat ne ':all' ) {
($cat) = $cat =~ /^([-A-Za-z_]+)/;
$cat = lc( $cat || '' );
1 while $cat
&& !exists ${"$class\::MultiList"}{$cat}
&& $cat =~ s/_?[^_]*$//;
}
# fall back to last resort
$self->{category} = $cat || ${"$class\::Default"};
$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};
}
1;
__END__
=head1 NAME
AI::MicroStructure::Locale - Base class for multilingual structures
=head1 SYNOPSIS
package AI::MicroStructure::digits;
use AI::MicroStructure::Locale;
our @ISA = ( AI::MicroStructure::Locale );
__PACKAGE__->init();
1;
=head1 NAME
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
=head1 DESCRIPTION
C<AI::MicroStructure::Locale> is the base class for all structures that are
meant to return a random excerpt from a predefined list I<that depends
on the language>.
The language is selected at construction time from:
=over 4
lib/AI/MicroStructure/MultiList.pm view on Meta::CPAN
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);
no strict 'refs';
# note: variables mentioned twice to avoid a warning
my $sep = ${"$class\::Separator"} = ${"$class\::Separator"} ||= '/';
my $tail = qr/$sep?[^$sep]*$/;
# compute all categories
my @categories = ( [ $data->{names}, '' ] );
while ( my ( $h, $k ) = @{ shift @categories or []} ) {
if ( ref $h eq 'HASH' ) {
push @categories,
map { [ $h->{$_}, ( $k ? "$k$sep$_" : $_ ) ] } keys %$h;
}
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();
}
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 ) {
no strict 'refs';
return wantarray
? shuffle @{ $self->{base} }
: scalar @{ $self->{base} };
}
$count ||= 1;
my $list = $self->{cache};
if ( @{ $self->{base} } ) {
push @$list, shuffle @{ $self->{base} } while @$list < $count;
}
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;
}
sub _compute_base {
my ($self) = @_;
my $class = ref $self;
# compute the base list for this category
no strict 'refs';
my %seen;
$self->{base} = [
grep { !$seen{$_}++ }
map { @{ ${"$class\::MultiList"}{$_} } }
$self->{category} eq ':all'
? ( keys %{"$class\::MultiList"} )
: ( $self->{category} )
];
return;
}
sub category { $_[0]->{category} }
sub categories {
my $class = shift;
$class = ref $class if ref $class;
no strict 'refs';
return keys %{"$class\::MultiList"};
}
sub has_category {
my ($class, $category) = @_;
$class = ref $class if ref $class;
no strict 'refs';
return exists ${"$class\::MultiList"}{$category};
}
sub structure {
my $class = ref $_[0] || $_[0];
no strict 'refs';
return ${"$class\::Theme"};
}
1;
__END__
=head1 NAME
AI::MicroStructure::MultiList - Base class for structures with multiple lists
=head1 SYNOPSIS
package AI::MicroStructure::digits;
use AI::MicroStructure::MultiList;
our @ISA = ( AI::MicroStructure::MultiList );
__PACKAGE__->init();
1;
=head1 NAME
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
zero one
=head1 DESCRIPTION
C<AI::MicroStructure::MultiList> is the base class for all structures
that are meant to return a random excerpt from a predefined list
I<divided in categories>.
The category is selected at construction time from:
=over 4
lib/AI/MicroStructure/MultiList.pm view on Meta::CPAN
AI::MicroStructure::MultiList offers several methods, so that the subclasses
are easy to write (see full example in L<SYNOPSIS>):
=over 4
=item new( category => $category )
The constructor of a single instance. An instance will not repeat items
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.
lib/AI/MicroStructure/RemoteList.pm view on Meta::CPAN
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 ($@) {
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],
[ content_type => 'application/x-www-form-urlencoded' ],
$src->[1]
)
: ( GET => $src )
);
my $res = $ua->request( $request );
if ( ! $res->is_success() ) {
carp "Failed to get content at $src (" . $res->status_line();
return;
}
# extract, cleanup and return the data
# if decoding the content fails, we just deal with the raw content
push @items =>
$class->extract( $res->decoded_content() || $res->content(),
$category || () );
}
# return unique items
my %seen;
return grep { !$seen{$_}++ } @items;
}
#
# transformation subroutines
#
sub tr_nonword {
my $str = shift;
$str =~ tr/a-zA-Z0-9_/_/c;
$str;
}
sub tr_accent {
my $str = shift;
$str =~ tr{ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ}
{AAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy};
return $str;
}
my %utf2asc = (
"æ" => 'ae',
"Æ" => 'AE',
"\xc5\xa0" => 'S',
"\x{0160}" => 'S',
# for pokemons
"\x{0101}" => 'a',
"\x{012b}" => 'i',
"\x{014d}" => 'o',
"\x{016b}" => 'u',
"\xe2\x99\x80" => 'female',
"\xe2\x99\x82" => 'male',
"\x{2640}" => 'female',
"\x{2642}" => 'male',
);
my $utf_re = qr/(@{[join( '|', sort keys %utf2asc )]})/;
sub tr_utf8_basic {
my $str = shift;
$str =~ s/$utf_re/$utf2asc{$1}/go;
return $str;
}
1;
__END__
=head1 NAME
AI::MicroStructure::RemoteList - Retrieval of a remote source for a structure
=head1 SYNOPSIS
package AI::MicroStructure::contributors;
use strict;
use AI::MicroStructure::List;
our @ISA = qw( AI::MicroStructure::List );
# data regarding the remote source
our %Remote = (
source =>
'http://search.cpan.org/dist/AI-MicroStructure/CONTRIBUTORS',
extract => sub {
my $content = shift;
my @items =
map { AI::MicroStructure::RemoteList::tr_nonword($_) }
map { AI::MicroStructure::RemoteList::tr_accent($_) }
$content =~ /^\* (.*?)\s*$/gm;
return @items;
},
);
__PACKAGE__->init();
1;
# and the usual documentation and list definition
=head1 DESCRIPTION
This base class adds the capability to fetch a fresh list of items from a
remote source to any structure that requires it.
To be able to fetch remote items, an C<AI::MicroStructure> structure must
define the package hash variable C<%Remote> with the appropriate keys.
The keys are:
lib/AI/MicroStructure/RemoteList.pm view on Meta::CPAN
The URL where the data is available. The content will be passed to the
C<extract> subroutine.
Because of the various way the data can be made available on the web
and can be used in L<AI::MicroStructure>, this scheme has evolved to
support several cases:
Single source URL:
source => $url
Multiple source URL:
source => [ $url1, $url2, ... ]
For structures with categories, it's possible to attach a URL for each
category:
source => {
category1 => $url1,
category2 => $url2,
...
}
In the case where the C<source> is an array or a hash reference, an
extra case is supported, in case the source data can only be obtained
via a C<POST> request. In that case, the source should be provided as
either:
source => [
[ $url1 => $data1 ],
[ $url2 => $data2 ],
...
]
or
source => {
category1 => [ $url1 => $data1 ],
category2 => [ $url2 => $data2 ],
...
}
It is possible to mix C<POST> and C<GET> URL:
source => [
$url1, # GET
[ $url2 => $data2 ], # POST
...
]
or
source => {
category1 => $url1, # GET
category2 => [ $url2 => $data2 ], # POST
...
}
This means that even if there is only one source and a C<POST> request
must be used, then it must be provided as a list of a single item:
source => [ [ $url => $data ] ]
=item C<extract>
A reference to a subroutine that extracts a list of items from a string.
The string is meant to be the content available at the URL stored in
the C<source> key.
The coderef may receive an optional parameter corresponding to the name of
the category (useful if the coderef must behave differently depending on
the category).
lib/AI/MicroStructure/Util.pm view on Meta::CPAN
package AI::MicroStructure::Util;
use strict;
use Cwd;
use Config::Auto;
use Env qw/PWD/;
sub get_cwd {
my @CWD; if (!-e ".micro") {
push @CWD, $ENV{HOME}."/data-hub";
} else {
push @CWD, getcwd();
}
return @CWD;
}
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",
};
return { "cwd" => @CWD, "path" => $path, "cfg" => $config };
}
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;
lib/AI/MicroStructure/WordBlacklist.pm view on Meta::CPAN
according accordingly across actually after afterwards again against
ain't all allow allows almost alone along already also although always
am among amongst an and another any anybody anyhow anyone anything
anyway anyways anywhere apart appear appreciate appropriate are aren't
around as aside ask asking associated at available away awfully b be
became because become becomes becoming been before beforehand behind
being believe below beside besides best better between beyond both brief
but by c c'mon c's came can can't cannot cant cause causes certain
certainly changes clearly co com come comes concerning consequently
consider considering contain containing contains corresponding could
couldn't course currently d definitely described despite did didn't
different do does doesn't doing don't done down downwards during e each
edu eg eight either else elsewhere enough entirely especially et etc
even ever every everybody everyone everything everywhere ex exactly
example except f far few fifth first five followed following follows
for former formerly forth four from further furthermore g get gets
getting given gives go goes going gone got gotten greetings h had
hadn't happens hardly has hasn't have haven't having he he's hello
help hence her here here's hereafter hereby herein hereupon hers
herself hi him himself his hither hopefully how howbeit however
i i'd i'll i'm i've ie if ignored immediate in inasmuch inc indeed
indicate indicated indicates inner insofar instead into inward is
isn't it it'd it'll it's its itself j just k keep keeps kept know
knows known l last lately later latter latterly least less lest let
let's like liked likely little look looking looks ltd m mainly many
may maybe me mean meanwhile merely might more moreover most
mostly much must my myself n name namely nd near nearly necessary
need needs neither never nevertheless new next nine no nobody non
none noone nor normally not nothing novel now nowhere o obviously of
off often oh ok okay old on once one ones only onto or other others otherwise ought
our ours ourselves out outside over overall own
p particular particularly per perhaps placed please plus possible presumably probably
provides q que quite qv r rather rd re really reasonably regarding regardless regards
relatively respectively right s said same saw say saying says second secondly see seeing seem seemed seeming seems seen self selves sensible sent serious seriously seven
several shall she should shouldn't since six
so some somebody somehow someone something sometime sometimes somewhat somewhere soon sorry specified specify specifying still sub such sup sure t t's take taken tell tends th than thank thanks thanx that that's thats the their theirs them themselves...
qqq rrr sss ttt uuu vvv www xxx yyy zzz .... unsere ihrer uns wurde wer gegen diesem bis nur wieder unserem einer war man bei wir einen vom einem unter jeder werden wie als durch zum hat vor unseres email bel ihnen unseren bzw lieber uft kommen nicht...
anderweitigen anderweitiger anderweitiges anerkannt anerkannte anerkannter anerkanntes anfangen anfing angefangen angesetze angesetzt angesetzten angesetzter ans anscheinend ansetzen ansonst ansonsten anstatt anstelle arbeiten auch auf aufgehört aufg...
lib/AI/MicroStructure/WordBlacklist.pm view on Meta::CPAN
1;
=head1 NAME
AI::MicroStructure::WordBlacklist
=head1 DESCRIPTION
Creates Concepts for words
=head1 SYNOPSIS
~$ micro new world
~$ micro structures
~$ micro any 2
~$ micro drop world
~$ micro
=head1 AUTHOR
Hagen Geissler <santex@cpan.org>
=head1 COPYRIGHT AND LICENCE
Hagen Geissler <santex@cpan.org>
=head1 SUPPORT AND DOCUMENTATION
â [PDF info on my works](https://github.com/santex)
=head1 SEE ALSO
AI-MicroStructure
AI-MicroStructure-Cache
AI-MicroStructure-Deamon
AI-MicroStructure-Relations
AI-MicroStructure-Concept
AI-MicroStructure-Data
AI-MicroStructure-Driver
AI-MicroStructure-Plugin-Pdf
AI-MicroStructure-Plugin-Twitter
AI-MicroStructure-Plugin-Wiki
__END__
__DATA__