Package: pylmflib
Latest version: 1.0Date: October 21, 2015Author: Céline BuretMaintainer: Séverine GuillaumeDocumentation:http://himalco.huma-num.fr/documentation/index.htmHome page:https://github.com/buret/pylmflibLicense: gpl-3.0Platform: Unix, Linux, Windows, MACPackage index owner: Céline BuretIntroductionWhat 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 ofpylmflibis to provide a software package which integrates conversion functions from MDF format to several output formats: LaTeX (PDF), docx, HTML, etc.pylmflibimplements the LMF standard. For more details, please seehttp://www.lexicalmarkupframework.org.What can be done with pylmflib?With the help ofpylmflib, users can: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?pylmflibis 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, seehttp://www.python.org.How to cite pylmflib?If you are usingpylmflibfor non-commercial, scientific projects, please cite the library in its current state along with the version that you used:Buret, Céline (2015): pylmflib. Python Library for Automatic Tasks in Multi-Languages Dictionaries. Version 1.0 (Uploaded on 2015-10-21). URL:http://www.pylmflib.org.InstallationBasic setupUse pip to installpylmflibpackage from PyPI:$ pip install pylmflibUsageIn order to use the library, open Python2 in your terminal and importpylmflibas follows:>>> from pylmflib import *DependenciesIndispensable third party librariesHere is the list of the libraries without whichpylmflibwon’t work.Regex:http://pypi.python.org/pypi/regexRecommended third party librariesHere is a list of the libraries without whichpylmflibcore functions will work, but which are anyway used quite frequently in a lot of modules.Docx:https://pypi.python.org/pypi/python-docxODF:https://pypi.python.org/pypi/odfpySetup for development versionPrerequisiteInstall git.Setup with gitIf you want to regularly work onpylmflib, open a (git) terminal and type in the following:$ git clone https://github.com/buret/pylmflibInstructions for a basic installation on Linux and MacPrerequisites on Linux and MacBefore being able to runpylmflib, you will need to follow these steps:1. git$ sudo apt-get install git
$ git clone https://github.com/buret/pylmflib pylmflib2. setuptools$ wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo pythonpython-docxDownloadpython-docx-0.8.5.tar.gz:https://pypi.python.org/pypi/python-docx$ tar xvzf python-docx-0.8.5.tar.gz
$ cd python-docx-0.8.5/
$ sudo python setup.py install4. xsltproc$ sudo apt-get install xsltproc5. xelatex$ sudo apt-get install texlive
$ sudo apt-get install texlive-xetexCharis SILDownload :http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=charissil_downloadInstall :http://scripts.sil.org/cms/scripts/page.php?item_id=DecompressUtilMingLiUDownload :http://www.fontpalace.com/font-download/MingLiU/ArialUnicodeMSDownload :https://code.google.com/p/tuanphamvu/downloads/detail?name=Arial%20Unicode%20MS.rar&can=2&q=Copy audio files if any.pylmflib installation on Linux and MacWe recommend to use the stable version ofpylmflib(1.0). Make sure thatregexis installed on you system prior to installingpylmflib. In order to install this version, simply download it fromhttps://github.com/buret/pylmfliborhttps://pypi.python.org/pypi/pylmflib/1.0, unpack the directory, thencdinto it, and type in the prompt:$ python setup.py installYou may need sudo-rights to carry out these command.At this stage, you can run the unit tests:$ test/test_all.pyAnd you could run all provided examples:$ examples/Bambara/bambara.py
$ examples/japhug/dict_japhug.py
$ examples/khaling/dict_khaling.py
$ examples/na/dict_na.py
$ examples/test/scenario.py
$ examples/yuanga/dict_yuanga.pyInstallation instructions on WindowsPrerequisites on WindowsBefore being able to installpylmflib-1.0, you will need to install:pip-7.1.2VCForPython27.msipython-docx-0.8.5lxml-2.0.3In some cases, you may need to install:setuptools-18.4ez_setup.pyget-pip.pypylmflib installation on WindowsThe current version ofpylmflibfor Python2 should basically also run on Windows. In order to installpylmflibon a Windows machine, I recommend to use the Cygwin terminal and installpylmflibin the same way in which one would otherwise install it on Linux or Mac machines.WorkaroundsTo use the library without installing it, i.e. without running the setup-command, a simple way to usepylmflibis to include it in your sys-path just before you call the library:>>> import sys
>>> sys.path.append("path_to_pylmflib)CodeSource code is available at:https://github.com/buret/pylmflibpylmflibhas been developed in Python 2.7.5.It is under GPL licence.Basic modulesThe library in its current state consists of the following modules:commonconfigcoreinputmorphologymorphosyntaxmrdoutputresourcesutilsBasic formatsIn the following, we list some of the formats that are frequently used bypylmflib, be it that they are taken as input formats, or that they are produced as output from the classes and methods provided bypylmflib:MDFXML LMFLaTeXdocxHere 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 TEIHTMLODTFormats that have to be added to the library in the future:xls / csvElanXML ITEXML LIFTXML LexiqueProXML OLIFXML ToolboxCoding conventionsPlease respect the coding rules used in the library.TestFor tests, I use theunittest``Pythonlibrary. To run the tests, just enter the main directory and call ``test/test_all.pyon the command line. Please do not commit any changes without all tests running without failure or error.All tests are in a directorytest/within the main directory. For each Python source file in the source directory, there is a test file with a prefixtest_. For example, the tests of thecoremodule, which has its source inpylmflib/core/, are located intest/test_core_xxx.py. Within the test files, there is a class defined for each class in the original source files, with a prefixTest. For example, there is a classTestLexicalEntrydefined intest_core_lexical_entry.pyas there is a classLexicalEntryinlexical_entry.py. For each method of a class, the test class has a method with the prefixtest_. For example, the methodcreate_related_form()of theLexicalEntryclass is tested with the methodtest_create_related_form()of the test class.DocumentationIf you contribute topylmflib, 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 topylmflib, the contributors add documentation inline in their code, following the style used in the project.Then, they runDoxygenusing theDoxyfileprovided underdoc/Doxygen.The general website structure is added around the code. You can find its content by browsing thedoc/Doxygen/html/directory.ExamplesWorkflow exampleThis is an example workflow that illustrates some of the functionalities ofpylmflib. We start with a small dataset from the Bambara language.Getting startedFirst, make sure to have the Python LMF library downloaded, extracted and installed properly. The dataset that will be used is located underexamples/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.pyAs 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 databaseBambaraDemo.dbin MDF format ;Bambara.xml, which is the XML LMF representation of the dictionary.You can also directly run the conversion and XeLaTeX command by runningbambara.shorbambara.batdepending on your operating system.Python scriptsbambara.pyIt is the main script, the one which callspylmflibfunctions:read_configread_mdfread_sort_orderwrite_xml_lmfwrite_texwrite_mdfwrite_docSo the basic steps are:to read the configuration defined inconfig.xml(see the tutorial chapter below for details) ;to read the MDF file, so in this case theBambaraDemo.dbToolbox dictionary ;to read the alphabetical order defined insort_order.xml(see the tutorial chapter below for details) ;to convert the MDF text format into a structured XML format, based on LMF standard ;to generate an output LaTeX file ;to generate an MDF file, similar to the input one ;to generate an output document file.In this script, user also has access to allpylmflibobjects methods, which are fully documented at:http://himalco.huma-num.fr/documentation/index.htmsetting.pyTo be able to customise some Python variables, it is possible to write asetting.py file, in which user can:define the items to sort: in this case, we choose to sort thelxMDF marker contents, but it could be any other field ;customise input MDF markers used by modifying themdf_lmfPyhton variable ;customise output MDF markers by modifying thelmf_mdfPython variable.It is also possible to customise Python functions. See the other examples below for more advanced use.startup.pyThis file is needed to define working path and path to the library. Normally, you should not have to modify it.Basic exampleA simple example is presented underexamples/test. All available output formats are generated:XML LMFLaTeXMDFdocxODTHTMLXML TEINote 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 examplesIt is possible to fully customise the desired output. There are three examples to generate customised PDF printable dictionaries, located underexamples/japhug,examples/khalingandexamples/na.In all cases, the filesetting.pyhas been deeply modified. The most important function islmf2tex(), 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.htmDocx exampleIt is also possible to customise a document output. There is an example to generate a customised docx editable dictionary, located underexamples/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 insetting.py, withorderthensd_ordervariables.Moreover, part of speech authorised values have been deeply extended by modifying theps_partOfSpeechPython variable.TutorialConfiguration filesThis part is an overview of the configuration files you may have to customise.config.xmlThe root element is namedConfig. 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: defineGlobalInformationandLexiconattributes ofLexicalResource(author, version, dictionary description and title, identifier, etc.) ; among these settings, two are very important to define:entrySourcemust point to the dictionary MDF input file, andlocalPathmust 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.texIf user wants to insert an introduction in his dictionary, here is the file to write it. It has to use LaTeX commands.preamble.texThis 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 thelmf2tex()function by using non-basic LaTeX commands.sort_order.xmlIf you want your dictionary classified by a specific alphabetical order or if you use IPA or special characters, you have to write your ownsort_order.xmlfile. 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 optionsThe 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 -hCode warningsWhile 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 errorsAny error will raise a Python exception, giving some details about the cause.