Esempio n. 1
0
def lmf2tex(lexical_entry, font):
    import output.tex as tex
    tex_entry = ""
    # lexeme, id and phonetic variants
    tex_entry += tex.format_lexeme(lexical_entry, font)
    # sound
    tex_entry += tex.format_audio(lexical_entry, font)
    # part of speech
    tex_entry += tex.format_part_of_speech(lexical_entry, font)
    # grammatical notes
    tex_entry += tex.format_notes(lexical_entry, font)
    # Order by sense number
    senses = lexical_entry.get_senses()
    senses.sort(key=lambda sense: sense.get_senseNumber(integer=True))
    for sense in senses:
        if sense.get_senseNumber() is not None:
            tex_entry += sense.get_senseNumber() + ") "
        # definition/gloss and translation
        tex_entry += tex.format_definitions(sense,
                                            font,
                                            languages=[
                                                config.xml.vernacular,
                                                config.xml.French,
                                                config.xml.national
                                            ])
        # example
        tex_entry += tex.format_examples(sense, font)
        # usage note
        tex_entry += tex.format_usage_notes(sense, font)
        # encyclopedic information
        tex_entry += tex.format_encyclopedic_informations(sense, font)
        # restriction
        tex_entry += tex.format_restrictions(sense, font)
    # synonym, antonym, morphology, related form
    tex_entry += tex.format_related_forms(lexical_entry, font)
    # borrowed word
    tex_entry += tex.format_borrowed_word(lexical_entry, font)
    # etymology
    tex_entry += tex.format_etymology(lexical_entry, font)
    # paradigms
    tex_entry += tex.format_paradigms(lexical_entry, font)
    tex_entry += tex.format_paradigms(lexical_entry, font)
    # semantic domain
    tex_entry += tex.format_semantic_domains(lexical_entry, font)
    # source
    tex_entry += tex.format_source(lexical_entry, font)
    # status
    tex_entry += tex.format_status(lexical_entry, font)
    # date
    tex_entry += tex.format_date(lexical_entry, font)
    # Handle reserved characters and fonts
    tex_entry = tex.handle_reserved(tex_entry)
    tex_entry = tex.handle_quotes(tex_entry)
    tex_entry = tex.handle_fv(tex_entry, font)
    tex_entry = tex.handle_fn(tex_entry, font)
    # Special formatting
    tex_entry = tex.handle_pinyin(tex_entry)
    tex_entry = tex.handle_caps(tex_entry)
    return tex_entry + EOL
Esempio n. 2
0
def lmf2tex(lexical_entry, font):
    tex_entry = ""
    if lmf2tex.is_first_entry:
        tex_entry += "\\setlength{\\parskip}{-0.5cm}" + EOL
        lmf2tex.is_first_entry = False
    # lexeme, id and phonetic variants
    tex_entry += format_lexeme(lexical_entry, font)
    # sound
    tex_entry += tex.format_audio(lexical_entry, font)
    # part of speech
    tex_entry += tex.format_part_of_speech(lexical_entry, font)
    # grammatical notes
    tex_entry += format_notes(lexical_entry, font)
    # Order by sense number
    senses = lexical_entry.get_senses()
    senses.sort(key=lambda sense: sense.get_senseNumber(integer=True))
    for sense in senses:
        if sense.get_senseNumber() is not None:
            # In LaTeX, "\ding{202}" represents '➊' character, "\ding{203}" '➋' character, etc.
            code = 201 + int(sense.get_senseNumber())
            tex_entry += "\ding{" + str(code) + "} "
        # paradigms
        tex_entry += format_paradigms(sense, font)
        # definition/gloss and translation
        tex_entry += format_definitions(sense, font, languages=[config.xml.vernacular, config.xml.French, config.xml.national])
        # example
        tex_entry += format_examples(sense, font)
        # usage note
        tex_entry += format_usage_notes(sense, font)
        # encyclopedic information
        tex_entry += format_encyclopedic_informations(sense, font)
        # restriction
        tex_entry += tex.format_restrictions(sense, font)
    # synonym, antonym, morphology, related form
    tex_entry += tex.format_related_forms(lexical_entry, font, language=config.xml.French)
    # borrowed word
    tex_entry += tex.format_borrowed_word(lexical_entry, font)
    # etymology
    tex_entry += tex.format_etymology(lexical_entry, font)
    # paradigms
    tex_entry += tex.format_paradigms(lexical_entry, font)
    # semantic domain
    tex_entry += tex.format_semantic_domains(lexical_entry, font)
    # source
    tex_entry += tex.format_source(lexical_entry, font)
    # status
    tex_entry += tex.format_status(lexical_entry, font)
    # date
    tex_entry += tex.format_date(lexical_entry, font)
    # Special formatting
    tex_entry = tex.handle_pinyin(tex_entry)
    tex_entry = tex.handle_caps(tex_entry)
    # Handle reserved characters and fonts
    tex_entry = tex.handle_quotes(tex_entry)
    tex_entry = tex.handle_reserved(tex_entry)
    tex_entry = tex.handle_fv(tex_entry, font)
    tex_entry = tex.handle_fn(tex_entry, font)
    return tex_entry + EOL
Esempio n. 3
0
def format_lexeme(lexical_entry, font):
    result = ""
    if len(lexical_entry.get_components()) != 0:
        lexeme = ""
        for component in lexical_entry.get_components():
            lexeme += component.get_lexeme() + ","
        # Remove last punctuation
        lexeme = lexeme.rstrip(",")
        # Apply font
        # lexeme = font[VERNACULAR](lexeme)
    else:
        if lexical_entry.is_subentry():
            lexeme = font[VERNACULAR](lexical_entry.get_lexeme())
        else:
            lexeme = ""
    if lexical_entry.is_subentry():
        # result += "\\subparagraph{\\dollar\\blacksquare\\dollar "
        # result += "\\begin{adjustwidth}{1em}{} "
        result += "\\begin{subentry}{"
    # print "totototototototototototototo"
    else:
        if len(lexical_entry.get_components()) != 0:
            result += "\\begin{entry}{"
        else:
            result += "\\begin{entry}{" + lexical_entry.get_lexeme()  # + "}"
        # result += "\\vspace{0.5cm} \\paragraph{\\hspace{-0.5cm} "
    if lexical_entry.get_homonymNumber() is not None:
        # Add homonym number to lexeme
        lexeme += " \\textsubscript{" + str(
            lexical_entry.get_homonymNumber()) + "}"
    if lexical_entry.get_contextual_variations() is not None and len(
            lexical_entry.get_contextual_variations()) != 0:
        # Format contextual variations
        for var in lexical_entry.get_contextual_variations():
            result += " " + font[VERNACULAR](var)
        result += " (de : " + lexeme + ")."
    else:
        # Format lexeme
        result += lexeme
    for form in lexical_entry.get_variant_forms(type="phonetics"):
        result += " / " + font[VERNACULAR](form)
    result += "} \\hypertarget{" + tex.format_uid(lexical_entry,
                                                  font) + "}{}" + EOL
    if not lexical_entry.is_subentry():
        # result += "\markboth{" + lexeme + "}{}" + EOL
        pass
    if len(lexical_entry.get_components()) != 0:
        # Add components part of speech
        result += "pc("
        for component in lexical_entry.get_components():
            if component.get_lexical_entry() is not None:
                result += tex.format_part_of_speech(
                    component.get_lexical_entry(), font)
                result = result.rstrip(". ") + ", "
        # Handle last punctuation
        result = result.rstrip(", ")
        result += ("). ")
    return result
Esempio n. 4
0
def lmf2tex(lexical_entry, font):
    import output.tex as tex
    tex_entry = ""
    # lexeme, id and phonetic variants
    tex_entry += tex.format_lexeme(lexical_entry, font)
    # sound
    tex_entry += tex.format_audio(lexical_entry, font)
    # part of speech
    tex_entry += tex.format_part_of_speech(lexical_entry, font)
    # grammatical notes
    tex_entry += tex.format_notes(lexical_entry, font)
    # Order by sense number
    senses = lexical_entry.get_senses()
    senses.sort(key=lambda sense: sense.get_senseNumber(integer=True))
    for sense in senses:
        if sense.get_senseNumber() is not None:
            tex_entry += sense.get_senseNumber() + ") "
        # definition/gloss and translation
        tex_entry += tex.format_definitions(sense, font, languages=[config.xml.vernacular, config.xml.French, config.xml.national])
        # example
        tex_entry += tex.format_examples(sense, font)
        # usage note
        tex_entry += tex.format_usage_notes(sense, font)
        # encyclopedic information
        tex_entry += tex.format_encyclopedic_informations(sense, font)
        # restriction
        tex_entry += tex.format_restrictions(sense, font)
    # synonym, antonym, morphology, related form
    tex_entry += tex.format_related_forms(lexical_entry, font)
    # borrowed word
    tex_entry += tex.format_borrowed_word(lexical_entry, font)
    # etymology
    tex_entry += tex.format_etymology(lexical_entry, font)
    # paradigms
    tex_entry += tex.format_paradigms(lexical_entry, font)
    tex_entry += tex.format_paradigms(lexical_entry, font)
    # semantic domain
    tex_entry += tex.format_semantic_domains(lexical_entry, font)
    # source
    tex_entry += tex.format_source(lexical_entry, font)
    # status
    tex_entry += tex.format_status(lexical_entry, font)
    # date
    tex_entry += tex.format_date(lexical_entry, font)
    # Handle reserved characters and fonts
    tex_entry = tex.handle_reserved(tex_entry)
    tex_entry = tex.handle_quotes(tex_entry)
    tex_entry = tex.handle_fv(tex_entry, font)
    tex_entry = tex.handle_fn(tex_entry, font)
    # Special formatting
    tex_entry = tex.handle_pinyin(tex_entry)
    tex_entry = tex.handle_caps(tex_entry)
    return tex_entry + EOL
Esempio n. 5
0
def format_lexeme(lexical_entry, font):
    result = ""
    if len(lexical_entry.get_components()) != 0:
        lexeme = ""
        for component in lexical_entry.get_components():
            lexeme += component.get_lexeme() + ","
        # Remove last punctuation
        lexeme = lexeme.rstrip(",")
        # Apply font
        lexeme = font[VERNACULAR](lexeme)
    else:
        lexeme = font[VERNACULAR](lexical_entry.get_lexeme())
    if lexical_entry.is_subentry():
        result += "\\subparagraph{\\dollar\\blacksquare\\dollar "
    else:
        result += "\\vspace{0.5cm} \\paragraph{\\hspace{-0.5cm} "
    if lexical_entry.get_homonymNumber() is not None:
        # Add homonym number to lexeme
        lexeme += " \\textsubscript{" + str(lexical_entry.get_homonymNumber()) + "}"
    if lexical_entry.get_contextual_variations() is not None and len(lexical_entry.get_contextual_variations()) != 0:
        # Format contextual variations
        for var in lexical_entry.get_contextual_variations():
            result += " " + font[VERNACULAR](var)
        result += " (de : " + lexeme + ")."
    else:
        # Format lexeme
        result += lexeme
    for form in lexical_entry.get_variant_forms(type = "phonetics"):
        result += " / " + font[VERNACULAR](form)
    result += "} \\hypertarget{" + tex.format_uid(lexical_entry, font) + "}{}" + EOL
    if not lexical_entry.is_subentry():
        result += "\markboth{" + lexeme + "}{}" + EOL
    if len(lexical_entry.get_components()) != 0:
        # Add components part of speech
        result += "pc("
        for component in lexical_entry.get_components():
            if component.get_lexical_entry() is not None:
                result += tex.format_part_of_speech(component.get_lexical_entry(), font)
                result = result.rstrip(". ") + ", "
        # Handle last punctuation
        result = result.rstrip(", ")
        result += ("). ")
    return result
Esempio n. 6
0
def lmf_to_tex(lexical_entry, font=None, partOfSpeech_mapping=partOfSpeech_tex, languages=[VERNACULAR, ENGLISH, NATIONAL, REGIONAL]):
    """! @brief Function to convert LMF lexical entry information to be written into LaTeX commands.
    @param lexical_entry The Lexical Entry LMF instance to display.
    @param font A Python dictionary describing fonts to use for different languages.
    @param partOfSpeech_mapping A Python dictionary giving abbreviations for LMF part of speech values.
    @param languages A list of languages to consider for LaTeX layout (all by default).
    @return A string representing the lexical entry in LaTeX format.
    """
    import output.tex as tex
    # Define font
    if font is None:
        font = config.xml.font
    tex_entry = ""
    # lexeme and id
    tex_entry += tex.format_lexeme(lexical_entry, font)
    # sound
    tex_entry += tex.format_audio(lexical_entry, font)
    # part of speech
    tex_entry += tex.format_part_of_speech(lexical_entry, font, mapping=partOfSpeech_mapping)
    # Order by sense number
    senses = lexical_entry.get_senses()
    senses.sort(key=lambda sense: sense.get_senseNumber(integer=True))
    for sense in senses:
        if sense.get_senseNumber() is not None:
            tex_entry += sense.get_senseNumber() + ") "
        # definition/gloss and translation
        tex_entry += tex.format_definitions(sense, font, languages)
        # TODO
        tex_entry += tex.format_lt(sense, font)
        tex_entry += tex.format_sc(sense, font)
        tex_entry += tex.format_rf(sense, font)
        # example
        tex_entry += tex.format_examples(sense, font)
        # usage note
        tex_entry += tex.format_usage_notes(sense, font)
        # encyclopedic information
        tex_entry += tex.format_encyclopedic_informations(sense, font)
        # restriction
        tex_entry += tex.format_restrictions(sense, font)
    # TODO
    tex_entry += tex.format_lexical_functions(lexical_entry, font)
    # synonym, antonym, morphology, related form
    tex_entry += tex.format_related_forms(lexical_entry, font)
    # variant form
    tex_entry += tex.format_variant_forms(lexical_entry, font)
    # borrowed word
    tex_entry += tex.format_borrowed_word(lexical_entry, font)
    # etymology
    tex_entry += tex.format_etymology(lexical_entry, font)
    # paradigms
    tex_entry += tex.format_paradigms(lexical_entry, font)
    # TODO
    tex_entry += tex.format_table(lexical_entry, font)
    # semantic domain
    tex_entry += tex.format_semantic_domains(lexical_entry, font)
    # bibliography
    tex_entry += tex.format_bibliography(lexical_entry, font)
    # TODO
    tex_entry += tex.format_picture(lexical_entry, font)
    # notes
    tex_entry += tex.format_notes(lexical_entry, font)
    # source
    tex_entry += tex.format_source(lexical_entry, font)
    # status
    tex_entry += tex.format_status(lexical_entry, font)
    # date
    tex_entry += tex.format_date(lexical_entry, font)
    # Handle reserved characters and fonts
    tex_entry = tex.handle_reserved(tex_entry)
    tex_entry = tex.handle_quotes(tex_entry)
    tex_entry = tex.handle_fv(tex_entry, font)
    tex_entry = tex.handle_fn(tex_entry, font)
    # Special formatting
    tex_entry = tex.handle_pinyin(tex_entry)
    tex_entry = tex.handle_caps(tex_entry)
    return tex_entry + EOL
Esempio n. 7
0
def lmf2tex(lexical_entry, font):
    import output.tex as tex
    tex_entry = ""
    if lmf2tex.is_first_entry:
        tex_entry += "\\setlength{\\parskip}{-0.5cm}" + EOL
        lmf2tex.is_first_entry = False
    # lexeme and id
    tex_entry += format_lexeme(lexical_entry, config.xml.font)
    # TODO: phonetic variants ? or variant form ?
    # sound
    tex_entry += tex.format_audio(lexical_entry, config.xml.font)
    # part of speech
    tex_entry += tex.format_part_of_speech(lexical_entry, config.xml.font)
    # grammatical notes
    tex_entry += format_notes(lexical_entry, config.xml.font)
    # Order by sense number
    senses = lexical_entry.get_senses()
    senses.sort(key=lambda sense: sense.get_senseNumber(integer=True))
    for sense in senses:
        if sense.get_senseNumber() is not None:
            # In LaTeX, "\ding{202}" represents '➊' character, "\ding{203}" '➋' character, etc.
            code = 201 + int(sense.get_senseNumber())
            tex_entry += "\ding{" + str(code) + "} "
        # definition/gloss and translation
        tex_entry += tex.format_definitions(sense,
                                            config.xml.font,
                                            languages=[
                                                config.xml.vernacular,
                                                config.xml.English,
                                                config.xml.national
                                            ])
        # example
        tex_entry += format_examples_compact(sense, config.xml.font)
        # usage note
        tex_entry += tex.format_usage_notes(sense, config.xml.font)
        # encyclopedic information
        tex_entry += tex.format_encyclopedic_informations(
            sense, config.xml.font)
        # restriction
        tex_entry += tex.format_restrictions(sense, config.xml.font)
    # synonym, antonym, morphology, related form
    tex_entry += tex.format_related_forms(lexical_entry, config.xml.font)
    # TODO: variant form?
    tex_entry += tex.format_variant_forms(lexical_entry, config.xml.font)
    # borrowed word
    tex_entry += tex.format_borrowed_word(lexical_entry, config.xml.font)
    # etymology
    tex_entry += tex.format_etymology(lexical_entry, config.xml.font)
    # paradigms
    tex_entry += format_paradigms(lexical_entry, config.xml.font)
    # semantic domain
    tex_entry += tex.format_semantic_domains(lexical_entry, config.xml.font)
    # TODO? bibliography
    tex_entry += tex.format_bibliography(lexical_entry, config.xml.font)
    # source
    tex_entry += tex.format_source(lexical_entry, config.xml.font)
    # status
    tex_entry += tex.format_status(lexical_entry, config.xml.font)
    # date
    tex_entry += tex.format_date(lexical_entry, config.xml.font)
    # Handle reserved characters and fonts
    tex_entry = handle_reserved(tex_entry)
    tex_entry = tex.handle_quotes(tex_entry)
    tex_entry = tex.handle_fv(tex_entry, config.xml.font)
    tex_entry = tex.handle_fn(tex_entry, config.xml.font)
    # Special formatting
    tex_entry = tex.handle_pinyin(tex_entry)
    tex_entry = tex.handle_caps(tex_entry)
    return tex_entry + EOL
Esempio n. 8
0
def lmf_to_tex(lexical_entry,
               font=None,
               partOfSpeech_mapping=partOfSpeech_tex,
               languages=[VERNACULAR, ENGLISH, NATIONAL, REGIONAL]):
    """! @brief Function to convert LMF lexical entry information to be written into LaTeX commands.
    @param lexical_entry The Lexical Entry LMF instance to display.
    @param font A Python dictionary describing fonts to use for different languages.
    @param partOfSpeech_mapping A Python dictionary giving abbreviations for LMF part of speech values.
    @param languages A list of languages to consider for LaTeX layout (all by default).
    @return A string representing the lexical entry in LaTeX format.
    """
    import output.tex as tex
    # Define font
    if font is None:
        font = config.xml.font
    tex_entry = ""
    # lexeme and id
    tex_entry += tex.format_lexeme(lexical_entry, font)
    # sound
    tex_entry += tex.format_audio(lexical_entry, font)
    # part of speech
    tex_entry += tex.format_part_of_speech(lexical_entry,
                                           font,
                                           mapping=partOfSpeech_mapping)
    # Order by sense number
    senses = lexical_entry.get_senses()
    senses.sort(key=lambda sense: sense.get_senseNumber(integer=True))
    for sense in senses:
        if sense.get_senseNumber() is not None:
            tex_entry += sense.get_senseNumber() + ") "
        # definition/gloss and translation
        tex_entry += tex.format_definitions(sense, font, languages)
        # TODO
        tex_entry += tex.format_lt(sense, font)
        tex_entry += tex.format_sc(sense, font)
        tex_entry += tex.format_rf(sense, font)
        # example
        tex_entry += tex.format_examples(sense, font)
        # usage note
        tex_entry += tex.format_usage_notes(sense, font)
        # encyclopedic information
        tex_entry += tex.format_encyclopedic_informations(sense, font)
        # restriction
        tex_entry += tex.format_restrictions(sense, font)
    # TODO
    tex_entry += tex.format_lexical_functions(lexical_entry, font)
    # synonym, antonym, morphology, related form
    tex_entry += tex.format_related_forms(lexical_entry, font)
    # variant form
    tex_entry += tex.format_variant_forms(lexical_entry, font)
    # borrowed word
    tex_entry += tex.format_borrowed_word(lexical_entry, font)
    # etymology
    tex_entry += tex.format_etymology(lexical_entry, font)
    # paradigms
    tex_entry += tex.format_paradigms(lexical_entry, font)
    # TODO
    tex_entry += tex.format_table(lexical_entry, font)
    # semantic domain
    tex_entry += tex.format_semantic_domains(lexical_entry, font)
    # bibliography
    tex_entry += tex.format_bibliography(lexical_entry, font)
    # TODO
    tex_entry += tex.format_picture(lexical_entry, font)
    # notes
    tex_entry += tex.format_notes(lexical_entry, font)
    # source
    tex_entry += tex.format_source(lexical_entry, font)
    # status
    tex_entry += tex.format_status(lexical_entry, font)
    # date
    tex_entry += tex.format_date(lexical_entry, font)
    # Handle reserved characters and fonts
    tex_entry = tex.handle_reserved(tex_entry)
    tex_entry = tex.handle_quotes(tex_entry)
    tex_entry = tex.handle_fv(tex_entry, font)
    tex_entry = tex.handle_fn(tex_entry, font)
    # Special formatting
    tex_entry = tex.handle_pinyin(tex_entry)
    tex_entry = tex.handle_caps(tex_entry)
    return tex_entry + EOL