6 from config.mdf
import lmf_mdf, mdf_order
7 from utils.io
import open_write, EOL
8 from utils.error_handling
import OutputError
10 def mdf_write(object, filename, lmf2mdf=lmf_mdf, order=mdf_order):
11 """! @brief Write an MDF file.
12 @param object The LMF instance to convert into MDF output format.
13 @param filename The name of the MDF file to write with full path, for instance 'user/output.txt'.
14 @param lmf2mdf A Python dictionary describing the mapping between LMF representation and MDF markers. Default value is 'lmf_mdf' dictionary defined in 'pylmflib/config/mdf.py'. Please refer to it as an example.
15 @param order A Python list defining the order in which MDF markers must be written, for instance ["lx", "ps"]. Default value is 'mdf_order' list defined in 'pylmflib/config/mdf.py'.
19 if object.__class__.__name__ ==
"Lexicon":
20 for lexical_entry
in object.get_lexical_entries():
22 if type(marker)
is list:
24 parse_list(mdf_file, lmf2mdf, marker, lexical_entry)
26 value = lmf2mdf[marker](lexical_entry)
31 raise OutputError(object,
"Object to write must be a Lexicon.")
35 """! @brief Parse a group of markers and write them into an MDF file.
36 @param mdf_file The file to write in.
37 @param lmf2mdf A Python dictionary describing the mapping between LMF representation and MDF markers.
38 @param marker The MDF marker.
39 @param object The current processed object.
42 group = lmf2mdf[marker[0] +
"Group"](object)
49 value = lmf2mdf[mkr](element)
53 """! @brief Write a line into an MDF file.
54 @param mdf_file The file to write in.
55 @param marker The MDF marker.
56 @param value The corresponding value.
58 if type(value)
is not list:
61 mdf_file.write(
"\\" + marker +
" " + value + EOL)
65 mdf_file.write(
"\\" + marker +
" " + item + EOL)
def open_write
Open file in write mode (automatically decode file in unicode).
def write_line
Write a line into an MDF file.
def parse_list
Parse a group of markers and write them into an MDF file.
def mdf_write
Write an MDF file.