Biblio-Thesaurus-SQLite
view release on metacpan or search on metacpan
lib/Biblio/Thesaurus/SQLite.pm view on Meta::CPAN
package Biblio::Thesaurus::SQLite;
use 5.008006;
use strict;
use warnings;
require Exporter;
use DBIx::Simple;
use Data::Dumper;
use Biblio::Thesaurus;
use locale;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [
qw(ISOthe2TheSql
TheSql2ISOthe
getTermAsXHTML
getTermAsISOthe
getTermAsPerl
setTerm
deleteTerm
changeTerm
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();
our $VERSION = '0.10';
our ($rel,@terms,$term);
##
# This method converts a ISO Thesaurus file in a SQLite database
# @param ficheiro de texto iso thesaurus
# @param ficheiro com base de dados sqlite
sub ISOthe2TheSql {
my $file = shift or die;
my $dbfile = shift or die;
# parse the thesaurus file
my $the = thesaurusLoad($file);
# connect to the database
my $db = DBIx::Simple->connect('dbi:SQLite:' . $dbfile)
or die DBIx::Simple->error;
# clear the database! TODO: check if the database exists and try
# to append the new data
$db->query('DROP TABLE rel');
$db->query('CREATE TABLE rel (term, rel, def)');
$db->query('DROP TABLE meta');
$db->query('CREATE TABLE meta (term, val)');
$db->query('DROP TABLE lang');
$db->query('CREATE TABLE lang (ori, lang, dest)');
# parse metadata (we need this cause I dunno if Biblio::Thesaurus
# handles this the right way O:-))
open(F, "<$file") or die;
$db->begin_work;
my $lang_dest = '';
while(<F>) {
chomp;
# this is metadata (starting with %)
if($_ =~ /^\%([^\s]+)\s+(.*)/) {
my @vals = split(/\s+/, $2);
for (@vals) {
$db->query(
'INSERT INTO meta VALUES (?, ?)',
$1, $_
);
}
}
# this is language data
( run in 1.248 second using v1.01-cache-2.11-cpan-ceb78f64989 )