Biblio-Thesaurus-SQLite
view release on metacpan or search on metacpan
lib/Biblio/Thesaurus/SQLite.pm view on Meta::CPAN
$db->query('SELECT lang FROM lang LIMIT 1')->into(my $lang);
print F $baselang, '==', $lang, "\n\n";
for my $row ($db->query('SELECT * FROM lang')->hashes) {
print F $row->{ori}, '==', $row->{dest}, "\n";
}
}
# process the main data
for my $row ($db->query('SELECT DISTINCT term FROM rel')->flat) {
print F "\n\n$row\n";
for my $row2 ($db->query('SELECT rel, def FROM rel WHERE term = ?', $row)->hashes) {
print F $row2->{rel}, ' ', $row2->{def}, "\n";
}
}
close(F);
}
##
# this method tries to output the result of a term as a xhtml table
# maybe to use with a cgi module
# @param the term to find data
# @param the sqlite database file
sub getTermAsXHTML {
my $termo = shift or die;
my $dbfile = shift or die;
# connect to the database
my $db = DBIx::Simple->connect('dbi:SQLite:' . $dbfile)
or die DBIx::Simple->error;
# try to see if we got any results avaiable
my $count;
$db->query(
'SELECT COUNT(term) FROM rel WHERE term = ?'
, $termo
)->into($count);
return ( '<h3>Termo <emph>' . $termo .
'</emph> nao encontrado</h3>' )
if $count == 0;
# now starting the output of the table
my $res = '<b1>' . $termo . '<b1><table><th><td>Relacao</td>' .
'<td>Definição</td></th>' . "\n";
# this is ugly....
for my $row ($db->query('SELECT * FROM rel WHERE term = ?',
$termo)->hashes) {
$res .= '<tr><td>' . $row->{rel} .
'</td><td>' . $row->{def} .
'</td></tr>' . "\n";
}
$res .= '</table>';
return $res;
}
##
# Does the same thing as the previous method, but outputs the data in an
# ISO Thesaurus format
# @param .....
# @param guess w00t ?
sub getTermAsISOthe {
my $termo = shift or die;
my $dbfile = shift or die;
# connect to the database
my $db = DBIx::Simple->connect('dbi:SQLite:' . $dbfile)
or die DBIx::Simple->error;
my $count;
$db->query(
'SELECT COUNT(term) FROM rel WHERE term = ?'
, $termo
)->into($count);
return '' if $count == 0;
my $res = $termo . "\n";
for my $row ($db->query('SELECT * FROM rel WHERE term = ?',
$termo)->hashes) {
$res .= '- ' . $row->{rel} . ' -> ' .
$row->{def} . "\n";
}
chomp($res);
return $res;
}
##
# bla bla bla (i'm tired of this...)
# ....
# ....
sub getTermAsPerl {
my $termo = shift or die;
my $dbfile = shift or die;
my %res; # our data!
$res{$termo} = {};
# connect to the database
my $db = DBIx::Simple->connect('dbi:SQLite:' . $dbfile)
or die DBIx::Simple->error;
my $count;
$db->query(
'SELECT COUNT(term) FROM rel WHERE term = ?'
, $termo
)->into($count);
return Dumper \%res if $count == 0;
for my $row ($db->query('SELECT * FROM rel WHERE term = ?',
$termo)->hashes) {
my $mainhash = $res{$termo};
my $termoarray = $mainhash->{$row->{rel}};
$termoarray = [] unless defined $termoarray;
push @$termoarray, $row->{def};
$mainhash->{$row->{rel}} = $termoarray;
$res{$termo} = $mainhash;
}
( run in 0.709 second using v1.01-cache-2.11-cpan-39bf76dae61 )