Python LMF library
 All Classes Namespaces Files Functions Variables
tex.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 """! @package config
5 """
6 
7 from utils.io import EOL
8 from common.defs import VERNACULAR, ENGLISH, NATIONAL, REGIONAL
9 
10 ## Mapping between LMF part of speech LexicalEntry attribute value and LaTeX layout (output)
11 partOfSpeech_tex = dict({
12  "adjective" : "adj", # Leipzig, MDF
13  "adposition" : "adp",
14  "adverb" : "adv", # Leipzip, MDF
15  "affirmative particle" : "affm", # MDF
16  "affix" : "aff",
17  "article" : "art", # MDF
18  "auxiliary" : "aux", # MDF
19  "classifier" : "clf", # Leipzip, MDF -> CLASS
20  "comparative particle" : "cmpar", # MDF
21  "conditional particle" : "cond", # MDF
22  "conjunction" : "cnj", # MDF
23  "coordinating conjunction" : "lnk", # MDF
24  "declarative punctuation" : "decl", # MDF
25  "demonstrative determiner" : "dem", # MDF
26  "determiner" : "det",
27  "existential pronoun" : "exist", # MDF
28  "ideophone" : "ideo",
29  "impersonal verb" : "vimp",
30  "interjection" : "intj", # MDF
31  "interrogative determiner" : "int", # MDF
32  "interrogative particle" : "q", # MDF
33  "intransitive verb" : "vi", # MDF
34  "modal" : "mdl", # MDF
35  "negation" : "neg", # Leipzip, MDF
36  "negative particle" : "neg", # Leipzip, MDF
37  "noun" : "n", # MDF
38  "numeral" : "num", # MDF
39  "particle" : "ptcl", # MDF
40  "participle adjective" : "part", # MDF
41  "possessive pronoun" : "poss", # Leipzig, MDF
42  "possessive relative pronoun" : "possr", # MDF
43  "postposition" : "post", # MDG
44  "preposition" : "prep", # MDF
45  "presentative pronoun" : "loc", # MDF
46  "pronoun" : "pro", # MDF
47  "proper noun" : "propn", # MDF
48  "reciprocal pronoun" : "rec", # MDF
49  "reflexive determiner" : "rflx", # MDF
50  "reflexive verb" : "vr", # MDF
51  "relative determiner" : "rel", # MDF
52  "time noun" : "time", # MDF
53  "transitive verb" : "vt", # MDF
54  "verb" : "v" # MDF
55 })
56 
57 ## Mapping between LMF paradigmLabel Paradigm attribute value and LaTeX layout (output)
58 paradigmLabel_tex = dict({
59 })
60 
61 ## Function giving order in which information must be written in LaTeX and mapping between LMF representation and LaTeX (output)
62 def lmf_to_tex(lexical_entry, font=None, partOfSpeech_mapping=partOfSpeech_tex, languages=[VERNACULAR, ENGLISH, NATIONAL, REGIONAL]):
63  """! @brief Function to convert LMF lexical entry information to be written into LaTeX commands.
64  @param lexical_entry The Lexical Entry LMF instance to display.
65  @param font A Python dictionary describing fonts to use for different languages.
66  @param partOfSpeech_mapping A Python dictionary giving abbreviations for LMF part of speech values.
67  @param languages A list of languages to consider for LaTeX layout (all by default).
68  @return A string representing the lexical entry in LaTeX format.
69  """
70  import output.tex as tex
71  # Define font
72  if font is None:
73  font = config.xml.font
74  tex_entry = ""
75  # lexeme and id
76  tex_entry += tex.format_lexeme(lexical_entry, font)
77  # sound
78  tex_entry += tex.format_audio(lexical_entry, font)
79  # part of speech
80  tex_entry += tex.format_part_of_speech(lexical_entry, font, mapping=partOfSpeech_mapping)
81  # Order by sense number
82  senses = lexical_entry.get_senses()
83  senses.sort(key=lambda sense: sense.get_senseNumber(integer=True))
84  for sense in senses:
85  if sense.get_senseNumber() is not None:
86  tex_entry += sense.get_senseNumber() + ") "
87  # definition/gloss and translation
88  tex_entry += tex.format_definitions(sense, font, languages)
89  # TODO
90  tex_entry += tex.format_lt(sense, font)
91  tex_entry += tex.format_sc(sense, font)
92  tex_entry += tex.format_rf(sense, font)
93  # example
94  tex_entry += tex.format_examples(sense, font)
95  # usage note
96  tex_entry += tex.format_usage_notes(sense, font)
97  # encyclopedic information
98  tex_entry += tex.format_encyclopedic_informations(sense, font)
99  # restriction
100  tex_entry += tex.format_restrictions(sense, font)
101  # TODO
102  tex_entry += tex.format_lexical_functions(lexical_entry, font)
103  # synonym, antonym, morphology, related form
104  tex_entry += tex.format_related_forms(lexical_entry, font)
105  # variant form
106  tex_entry += tex.format_variant_forms(lexical_entry, font)
107  # borrowed word
108  tex_entry += tex.format_borrowed_word(lexical_entry, font)
109  # etymology
110  tex_entry += tex.format_etymology(lexical_entry, font)
111  # paradigms
112  tex_entry += tex.format_paradigms(lexical_entry, font)
113  # TODO
114  tex_entry += tex.format_table(lexical_entry, font)
115  # semantic domain
116  tex_entry += tex.format_semantic_domains(lexical_entry, font)
117  # bibliography
118  tex_entry += tex.format_bibliography(lexical_entry, font)
119  # TODO
120  tex_entry += tex.format_picture(lexical_entry, font)
121  # notes
122  tex_entry += tex.format_notes(lexical_entry, font)
123  # source
124  tex_entry += tex.format_source(lexical_entry, font)
125  # status
126  tex_entry += tex.format_status(lexical_entry, font)
127  # date
128  tex_entry += tex.format_date(lexical_entry, font)
129  # Handle reserved characters and fonts
130  tex_entry = tex.handle_reserved(tex_entry)
131  tex_entry = tex.handle_quotes(tex_entry)
132  tex_entry = tex.handle_fv(tex_entry, font)
133  tex_entry = tex.handle_fn(tex_entry, font)
134  # Special formatting
135  tex_entry = tex.handle_pinyin(tex_entry)
136  tex_entry = tex.handle_caps(tex_entry)
137  return tex_entry + EOL
def lmf_to_tex
Function giving order in which information must be written in LaTeX and mapping between LMF represent...
Definition: tex.py:62