LEXED

Copyright (c) 2006-2008 Université Bordeaux 1 - Inria Bordeaux - LaBRI Méthodes Formelles
Lionel Clément

Français

Lexed

A lexicalizer

This tool allows to search a dictionary entry from a string. The finished automata-based algorithm is especially fast, and offers a good alternative to hashes for large dictionnaries. Lexed can be used interactively or via client/server socket. C++ Library available.

Downloading:
lexed-4.7.0.tar.gz

Compilation

To install under unix type
./configure [--prefix=<directory>]
make
sudo make install
make clean

Utilisation

For help
lexed -h
man lexed
To build an automata
lexed [ -d <directory > ] [ -p <filename prefix> ] build <lexicon>
The lexicon contains for every line the word followed by associated information, separated by a character (tabulation by default).
"." is default directory.
"lexicon" is default filename prefix.
To use an automata
lexed [ -d <directory > ] [ -p <filename prefix> ] [ -f <pref> <or> <suff> <uw> ] consult <inputfile > outputfile
inputfile contains one word to match by line
Other options
[ -P <port> ] TCP port.
[ -i ] Indexation mode only.
[ -F ] Don't load dictionary informations in memory.
[ -t <char> ] Separator characters.
[ -r <search> <replace> -s <number> ] Number and allowed characters for commutation in fuzzy search.
[ -a <number> ] Number of characters for addition in fuzzy search.
[ -e <number> ] Number of characters for deletion in fuzzy search.

An example in C++

Compilation :

$c++ `lexed-config --cflags --libs` foo.cc

Execution :

$echo "mot1 1
mot2 2
mot1 3" | lexed build
$./a.out lexicon.fsa lexicon.tbl mot1

File foo.cc

#include <lexedtree.h>

extern TYPEPTR LexedInitial;
extern int LexedIndexation;
extern int LexedMemory;
extern char *LexedBuffer;

int main (int argn,
  char **argv)
{
  FILE *Fichier, *FichierTbl;
  Fichier = fopen(argv[1], "r");
  long unsigned int Taille;
  TYPEPTR Offset;

  // On veut charger les données en mémoire
  LexedMemory=1;

  // Chargement de l'automate
  if (Fichier == NULL){
    fprintf(stderr, "File not found\n");
    exit (0);
  }
  else{
    if (!LoadFSA(Fichier)){
      fprintf(stderr, "error while loading file\n");
      fclose (Fichier);
      exit (0);
    } else {
      fclose (Fichier);
    }
  }
  
  // Chargement des données...
  if (LexedMemory){
    fputs("*** Load File\n", stderr);
    FichierTbl = fopen (argv[2], "r");
    if (FichierTbl){
      fseek (FichierTbl, 0, SEEK_END);
      Taille = ftell(FichierTbl);
      rewind (FichierTbl);
      LexedBuffer = new char [Taille];
      LexedBuffer[0]=0;
      fread (LexedBuffer, 1, Taille, FichierTbl);
      fclose (FichierTbl);
    }else{
      fprintf (stderr, "File not found\n");
      return 1;
    }
  }
  // ... ou consultation directe dans fichier
  else {
    fputs("*** Open file\n", stderr);
    FichierTbl = fopen (argv[2], "r");
  }

  // recherche d'un mot
  Offset=SearchStatic(LexedInitial, argv[3]);

  // affichage des données associées à ce mot
  if ((Offset==(TYPEPTR)~0UL)){
    printf ("Unknown word\n");
  } else {
    int ResultSize=0;
    int ResultIndex=0;
    char **Result=NULL;
    char **strings;
    sPrintResults(Offset, &Result, &ResultSize, &ResultIndex, FichierTbl);
    for (strings=Result; ResultIndex; strings++, ResultIndex--){
      printf("%s\n", *strings);
      free(*strings);
    }
  }
  if (!LexedMemory)
    fclose (FichierTbl);
  
  return 0;
}