Esempio n. 1
0
def write_tex(*args, **kwds):
    # A LaTeX file contains one or several lexicons and informations about the lexical resource
    wrapper_rw(tex_write, *args, **kwds)
    # Count total number of entries to report to user
    entries_nb = 0
    for lexicon in args[0].get_lexicons():
        entries_nb += lexicon.count_lexical_entries()
    log("Successfully wrote %s LMF entries into LaTeX file '%s'." % (entries_nb, args[1]))
Esempio n. 2
0
def write_xml_lmf(*args, **kwds):
    # An XML LMF file contains one lexical resource, itself containing lexicon(s)
    wrapper_rw(lmf_write, *args, **kwds)
    # Count total number of entries to report to user
    entries_nb = 0
    for lexicon in args[0].get_lexicons():
        entries_nb += lexicon.count_lexical_entries()
    log("Successfully wrote %s LMF entries into XML LMF file '%s'." % (entries_nb, args[1]))
Esempio n. 3
0
def write_odt(*args, **kwds):
    # Import only when needed because it requires installation of Python package 'odf'
    from pylmflib.output.odt import odt_write
    # A document file contains one or several lexicons and informations about the lexical resource
    wrapper_rw(odt_write, *args, **kwds)
    # Count total number of entries to report to user
    entries_nb = 0
    for lexicon in args[0].get_lexicons():
        entries_nb += lexicon.count_lexical_entries()
    log("Successfully wrote %s LMF entries into document file '%s'." % (entries_nb, args[1]))
Esempio n. 4
0
def read_xml_lmf(*args, **kwds):
    # To access options
    from pylmflib import options
    global options
    # An XML LMF file contains one lexical resource, itself containing lexicon(s)
    lexical_resource = wrapper_rw(lmf_read, *args, **kwds)
    # Count total number of entries to report to user
    entries_nb = 0
    for lexicon in lexical_resource.get_lexicons():
        entries_nb += lexicon.count_lexical_entries()
        if options.cross_references:
            # Verify lexicon coherence
            lexicon.check_cross_references()
    log("Successfully created %s LMF entries from XML LMF file '%s'." % (entries_nb, args[0]))
    return lexical_resource
Esempio n. 5
0
def read_mdf(*args, **kwds):
    from pylmflib import wrapper
    # To access options
    from pylmflib import options
    global options
    # Find lexicon configuration if any
    try:
        id = kwds['id']
    except KeyError:
        id = None
    if id is not None and wrapper.lexical_resource is not None:
        lexicon = wrapper.lexical_resource.get_lexicon(id)
        # Add lexicon argument
        kwds.update({'lexicon': lexicon})
    # An MDF file contains one lexicon only, but wrapper_rw() function encapsulates it into a lexical resource
    lexical_resource = wrapper_rw(mdf_read, *args, **kwds)
    for lexicon in lexical_resource.lexicon:
        if options.cross_references:
            # Verify lexicon coherence
            lexicon.check_cross_references()
        log("Successfully created %s LMF entries from MDF file '%s'." % (lexicon.count_lexical_entries(), lexicon.get_entrySource()))
    return lexical_resource
Esempio n. 6
0
 def test_log(self):
     import os
     ## Test with options
     self.options.log_filename = "test/log.txt"
     msg = "These are options."
     log(msg, self.options)
     # Test log file
     expected_line = "These are options." + EOL
     log_file = open_read(self.options.log_filename)
     self.assertEqual(log_file.readline(), expected_line)
     log_file.close()
     ## Test without options
     msg = "This is a message."
     log(msg)
     # Test log file
     expected_lines = ["These are options." + EOL,
                       "This is a message." + EOL]
     log_file = open_read(self.options.log_filename)
     self.assertListEqual(log_file.readlines(), expected_lines)
     ## Test verbose mode (need to reset log filename)
     self.options.verbose = True
     log_filename = self.options.log_filename
     self.options.log_filename = None
     log(msg, self.options)
     # Test that log file remains unchanged
     log_file = open_read(log_filename)
     self.assertListEqual(log_file.readlines(), expected_lines)
     ## Test unwrittable file
     self.options.log_filename = "/usr/log.txt"
     test = False
     try:
         log(msg, self.options)
     except Error:
         test = True
     self.assertTrue(test)
     ## Remove log file
     os.remove(log_filename)
Esempio n. 7
0
def write_mdf(*args, **kwds):
    # As an MDF file can only contain one lexicon, create as many MDF files as lexicons in the lexical resource (TODO: rename files)
    for lexicon in args[0].get_lexicons():
        wrapper_rw(mdf_write, lexicon, *args[1:], **kwds)
        log("Successfully wrote %s LMF entries into MDF file '%s'." % (lexicon.count_lexical_entries(), args[1]))
Esempio n. 8
0
def read_config(*args, **kwds):
    lexical_resource = wrapper_rw(config_read, *args, **kwds)
    log("Successfully read config")
    return lexical_resource
Esempio n. 9
0
def read_sort_order(*args, **kwds):
    sort_order = wrapper_rw(order_read, *args, **kwds)
    log("Successfully read sort order: " + str(sort_order))
    return sort_order