Introduction

What is pylmflib?

The Python LMF library is a suite of open-source Python modules for dictionary format conversion. It performs automatic tasks for multi-languages dictionaries, such as conversion between different formats used for dictionaries.

The main idea of pylmflib is to provide a software package which integrates conversion functions from MDF format to several output formats: LaTeX (PDF), docx, HTML, etc.

What can be done with pylmflib?

convert a dictionary from a regular MDF format issued from Toolbox to a PDF printable document,

convert a dictionary from a regular MDF format issued from Toolbox to a docx editable document,

customise markers used in Toolbox to match the LMF internal format,

keep an archivable format of their dictionary in XML LMF,

display their dictionary online using an XSL conversion from XML LMF to HTML.

How can pylmflib be used?

pylmflib is a library written in the Python programming language. It can be used directly in the Python interpreter or imported into Python scripts.
For more information about Python, see http://www.python.org.

How to cite pylmflib?

If you are using pylmflib for non-commercial, scientific projects, please cite the library in its current state along with the version that you used:

Prerequisites on Windows

pylmflib installation on Windows

The current version of pylmflib for Python2 should basically also run on Windows. In order to install pylmflib on a Windows machine, I recommend to use the Cygwin terminal and install pylmflib in the same way in which one would otherwise install it on Linux or Mac machines.

Workarounds

To use the library without installing it, i.e. without running the setup-command, a simple way to use pylmflib is to include it in your sys-path just before you call the library:

Code

Basic modules

The library in its current state consists of the following modules:

common

config

core

input

morphology

morphosyntax

mrd

output

resources

utils

Basic formats

In the following, we list some of the formats that are frequently used by pylmflib, be it that they are taken as input formats, or that they are produced as output from the classes and methods provided by pylmflib:

MDF

XML LMF

LaTeX

docx

Here is a list of formats that can be used, but need to be further developed, i.e. integration has been done but implementation has to be completed:

XML TEI

HTML

ODT

Formats that have to be added to the library in the future:

xls / csv

Elan

XML ITE

XML LIFT

XML LexiquePro

XML OLIF

XML Toolbox

Coding conventions

Please respect the coding rules used in the library.

Test

For tests, I use the unittest``Python library. To run the tests, just enter the main directory and call ``test/test_all.py on the command line. Please do not commit any changes without all tests running without failure or error.

All tests are in a directory test/ within the main directory. For each Python source file in the source directory, there is a test file with a prefix test_. For example, the tests of the core module, which has its source in pylmflib/core/, are located in test/test_core_xxx.py. Within the test files, there is a class defined for each class in the original source files, with a prefix Test. For example, there is a class TestLexicalEntry defined in test_core_lexical_entry.py as there is a class LexicalEntry in lexical_entry.py. For each method of a class, the test class has a method with the prefix test_. For example, the method create_related_form() of the LexicalEntry class is tested with the method test_create_related_form() of the test class.

Documentation

If you contribute to pylmflib, you should document your code.
The first step for documentation is the documentation within the code.

Currently, documentation is created using the following steps:

Whenever code is added to pylmflib, the contributors add documentation inline in their code, following the style used in the project.

Then, they run Doxygen using the Doxyfile provided under doc/Doxygen.

The general website structure is added around the code. You can find its content by browsing the doc/Doxygen/html/ directory.

Examples

Workflow example

This is an example workflow that illustrates some of the functionalities of pylmflib. We start with a small dataset from the Bambara language.

Getting started

First, make sure to have the Python LMF library downloaded, extracted and installed properly. The dataset that will be used is located under examples/Bambara.

This folder includes a Python script that runs the whole code from the beginning to the end. In order to start the conversion, go under the main directory and run this script:

$ python examples/Bambara/bambara.py

As a result, the following files will appear in the result directory:

Bambara.docx, that shows an example of a Microsoft Word document that you can obtain ;

Bambara.tex, that you must compile using XeLaTeX to get a PDF printable dictionary ;

Bambara.txt, which is similar to the input database BambaraDemo.db in MDF format ;

Bambara.xml, which is the XML LMF representation of the dictionary.

You can also directly run the conversion and XeLaTeX command by running bambara.sh or bambara.bat depending on your operating system.

Python scripts

bambara.py

It is the main script, the one which calls pylmflib functions:

read_config

read_mdf

read_sort_order

write_xml_lmf

write_tex

write_mdf

write_doc

So the basic steps are:

to read the configuration defined in config.xml (see the tutorial chapter below for details) ;

to read the MDF file, so in this case the BambaraDemo.db Toolbox dictionary ;

to read the alphabetical order defined in sort_order.xml (see the tutorial chapter below for details) ;

to convert the MDF text format into a structured XML format, based on LMF standard ;

It is also possible to customise Python functions. See the other examples below for more advanced use.

startup.py

This file is needed to define working path and path to the library. Normally, you should not have to modify it.

Basic example

A simple example is presented under examples/test. All available output formats are generated:

XML LMF

LaTeX

MDF

docx

ODT

HTML

XML TEI

Note that conversion scripts from XML LMF to HTML, ODT and XML TEI are here as examples to show what is possible to do. They have to be reworked to generate user-friendly outputs.

PDF examples

It is possible to fully customise the desired output. There are three examples to generate customised PDF printable dictionaries, located under examples/japhug, examples/khaling and examples/na.

In all cases, the file setting.py has been deeply modified. The most important function is lmf2tex(), which role is to organise data information in the LaTeX output file. If user do not provide this Python function, there is a default function for basic presentation. Again, coding details about this function is available at:
http://himalco.huma-num.fr/documentation/index.htm

Docx example

It is also possible to customise a document output. There is an example to generate a customised docx editable dictionary, located under examples/yuanga.

Moreover, in this case, entries are not classified by alphabetical order, but by semantic domain.

Chapter titles of the output docx document are defined in setting.py, with order then sd_order variables.

Moreover, part of speech authorised values have been deeply extended by modifying the ps_partOfSpeech Python variable.

Tutorial

Configuration files

This part is an overview of the configuration files you may have to customise.

config.xml

The root element is named Config. It contains following elements that user has to set.

Language: define the vernacular, national, regional and other languages that you have to use in your multi-languages dictionary, by setting the ISO-639-3 code value (usually composed of three letters).

Font: define fonts to use for LaTeX output format if needed ; for each defined language, a font has to be defined using LaTeX commands.

LMF: define GlobalInformation and Lexicon attributes of LexicalResource (author, version, dictionary description and title, identifier, etc.) ; among these settings, two are very important to define: entrySource must point to the dictionary MDF input file, and localPath must point to the folder where your audio files are located if you have any.

MDF: here you can define your own part of speech values if you do not use standard ones defined in MDF.

LaTeX: not implemented.

introduction.tex

If user wants to insert an introduction in his dictionary, here is the file to write it. It has to use LaTeX commands.

preamble.tex

This file is used to define all LaTeX packages that will be needed to compile your LaTeX output file. You have to update it if you customise the lmf2tex() function by using non-basic LaTeX commands.

sort_order.xml

If you want your dictionary classified by a specific alphabetical order or if you use IPA or special characters, you have to write your own sort_order.xml file. Format is simple: for each character, you have to define a rank value.

For any of the settings defined above, please refer to examples for the exact syntax to respect.

Library options

The library provides several options. There are all described in the help menu, that you can display by running for instance:

$ python examples/Bambara/bambara.py -h

Code warnings

While running your Python script, you may notice that lots of warning messages are generated by the library. Indeed, all values that are not defined in your configuration files or allowed by the MDF or LMF standards are reported, as part of speech and paradigm label values. Note that it does not block the script execution. The library also reports unresolved cross references and sound files that are not found.

Execution errors

Any error will raise a Python exception, giving some details about the cause.