MyThes Thesaurus migration for OpenOffice.org

This document contains a macro that transforms thesaurus from version 1 to myThes version used in OOo 2.0

Usage:

run the macro migrateThes inside this document from an OOo 1.x version

The source thesaurus has to be enabled as it is accessed through API

parameters to setup inside the macro : (should be easy to understand)

encoding ="ISO8859-1"

supported encoding by OOo (ISO8859-1, ISO8859-2, ISO8859-3, ISO8859-4, ISO8859-5, ISO8859-6, ISO8859-7, ISO8859-8, ISO8859-9, ISO8859-10, KOI8-R, CP-1251, ISO8859-14, ISCII-DEVANAGARI)

curLocale.language="fr"

curLocale.country="FR"

inFile="/home/lgodard/OpenOffice.org1.1.4/share/dict/ooo/th_fr_FR.idx"

means the idx file of the thesaurus version 1

outFile="/home/lgodard/dvlptOOo/lingucomponent/thesaurus/th_fr_FR_v2.dat"

means the output file (the .dat file of version 2)

Once the dat file is created, the idx file for v2 is created using a perl script

cat th_fr_FR_v2.dat | ./th_gen_idx.pl > th_fr_FR_v2.idx

where th_gen_idx.pl (from K. Hendricks)

#!/usr/bin/perl

# perl program to take a thesaurus structured text data file

# and create the proper sorted index file (.idx)

#

# typcially invoked as follows:

# cat th_en_US_new.dat | ./th_gen_idx.pl > th_en_US_new.idx

#

sub by_entry {

my ($aent, $aoff) = split('\|',$a);

my ($bent, $boff) = split('\|',$b);

$aent cmp $bent;

}

# main routine

my $ne = 0; # number of entries in index

my @tindex=(); # the index itself

my $foffset = 0; # file position offset into thesaurus

my $rec=""; # current string and related pieces

my $rl=0; # misc string length

my $entry=""; # current word being processed

my $nm=0; # number of meaning for the current word

my $meaning=""; # current meaning and synonyms

my $p; # misc uses

my $encoding; # encoding used by text file

# top line of thesaurus provides encoding

$encoding=<STDIN>;

$foffset = $foffset + length($encoding);

chomp($encoding);

# read thesaurus line by line

# first line of every block is an entry and meaning count

while ($rec=<STDIN>){

$rl = length($rec);

chomp($rec);

($entry, $nm) = split('\|',$rec);

$p = 0;

while ($p < $nm) {

$meaning=<STDIN>;

$rl = $rl + length($meaning);

chomp($meaning);

$p++;

}

push(@tindex,"$entry|$foffset");

$ne++;

$foffset = $foffset + $rl;

}

# now we have all of the information

# so sort it and then output the encoding, count and index data

@tindex = sort by_entry @tindex;

print STDOUT "$encoding\n";

print STDOUT "$ne\n";

foreach $one (@tindex) {

print STDOUT "$one\n";

}

This can be found in the myThes package created by Kevin B. Hendricks available on http://lingucomponent.openoffice.org/thesaurus.html

Licence

This macro is given by InDesko (http://www.indesko.com) under free LGPL licence

Author : Laurent Godard – lgodard@indesko.com

Laurent Godard

2005-03-01T12:08:09