AI-MicroStructure
view release on metacpan or search on metacpan
$cache = {} unless $cache;
warn "New cache!\n" unless defined $cache;
};
END{
# lock_store($set,$opts{cache_file});
print Dumper [$set];
}
our $files={};
my $style = {};
$style->{explicit} = 1;
our $c = AI::MicroStructure::Context->new(@ARGV);
$c->retrieveIndex($TOP);#"data-hub" structures=0 text=1 json=1
my $cg = $c->{graph}->{content};
my @ranked_docs = $cg->simple_search( 'peanuts' );
# get back both related terms and docs for more power
my ( $docs, $words ) = $cg->search('dna');
p $docs;
p $words;
# you can use a document as your query
( $docs, $words ) = $cg->find_similar('First Document');
p $docs;
p $words;
# Or you can query on a combination of things
( $docs, $words ) =
$cg->mixed_search( { docs => [ 'First Document' ],
terms => [ 'snake', 'pony' ]}
);
p $docs;
p $words;
# Print out result set of returned documents
foreach my $k ( sort { $docs->{$b} <=> $docs->{$a} }
keys %{ $docs } ) {
print "Document $k had relevance ", $docs->{$k}, "\n";
}
sub translate {
return unless -f;
(my $rel_name = $File::Find::name) =~ s{.*/}{}xs;
my $name = md5_hex($rel_name);
if (/\.(html|htm|txt|json)$/) {
$files->{html}->{$name}=$rel_name;
#ok(my $obj = AI::MicroStructure::Object->new($rel_name));
#ok($set->insert($obj));
}
elsif (/\.pdf$/) {
$files->{pdf}->{$name}=$rel_name;
}
}
#p $set;
find(\&translate, "$TOP");
p $set;
1;
( run in 0.467 second using v1.01-cache-2.11-cpan-39bf76dae61 )