Exemplo n.º 1
0
 def set_spelling_variant(self, spelling_variant):
     """! @brief Set spelling variant.
     Attribute 'spellingVariant' is owned by FormRepresentation, which is owned by Lemma.
     @param spelling_variant The spelling variant to set.
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_spelling_variant(spelling_variant)
     return self
Exemplo n.º 2
0
 def set_tone(self, tone):
     """! @brief Set tone.
     Attribute 'tone' is owned by FormRepresentation, which is owned by Lemma.
     @param tone The tone to set.
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_tone(tone)
     return self
Exemplo n.º 3
0
 def set_contextual_variation(self, contextual_variation):
     """! @brief Set contextual variation.
     Attribute 'contextualVariation' is owned by FormRepresentation, which is owned by Lemma.
     @param contextual_variation The contextual variation to set.
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_contextual_variation(contextual_variation)
     return self
Exemplo n.º 4
0
 def set_dialect(self, dialect):
     """! @brief Set dialect.
     Attribute 'dialect' is owned by FormRepresentation, which is owned by Lemma.
     @param dialect The dialect to set.
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_dialect(dialect)
     return self
Exemplo n.º 5
0
 def set_transliteration(self, transliteration):
     """! @brief Set transliteration.
     Attribute 'transliteration' is owned by FormRepresentation, which is owned by Lemma.
     @param transliteration The transliteration to set.
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_transliteration(transliteration)
     return self
Exemplo n.º 6
0
 def set_lexeme(self, lexeme):
     """! @brief Set lexeme.
     Attribute 'lexeme' is owned by Lemma.
     @param lexeme The lexeme to set.
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_lexeme(lexeme)
     return self
Exemplo n.º 7
0
 def set_script_name(self, script_name):
     """! @brief Set script name.
     Attribute 'scriptName' is owned by FormRepresentation, which is owned by Lemma.
     @param script_name The script name to set.
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_script_name(script_name)
     return self
Exemplo n.º 8
0
 def set_geographical_variant(self, geographical_variant):
     """! @brief Set geographical variant.
     Attribute 'geographicalVariant' is owned by FormRepresentation, which is owned by Lemma.
     @param geographical_variant The geographical variant to set.
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_geographical_variant(geographical_variant)
     return self
Exemplo n.º 9
0
 def set_phonetic_form(self, phonetic_form, script_name=None):
     """! @brief Set phonetic form.
     Attribute 'phoneticForm' is owned by FormRepresentation, which is owned by Lemma.
     @param phonetic_form The phonetic form to set.
     @param script_name The name of the script used to write the phonetic form, e.g. pinyin.
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_phonetic_form(phonetic_form, script_name)
     return self
Exemplo n.º 10
0
 def set_variant_comment(self, comment, language=None):
     """! @brief Set variant comment and language.
     Attributes 'comment' and 'language' are owned by FormRepresentation, which is owned by Lemma.
     @param comment Variant comment.
     @param language Language of comment.
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_variant_comment(comment, language)
     return self
Exemplo n.º 11
0
 def set_variant_form(self, variant_form, type="unspecified"):
     """! @brief Set variant form and type.
     Attributes 'variantForm' and 'type' are owned by FormRepresentation, which is owned by Lemma.
     @param variant_form Variant form.
     @param type Type of variant, in range 'type_variant_range' defined in 'common/range.py'.
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_variant_form(variant_form, type)
     return self
Exemplo n.º 12
0
 def set_citation_form(self, citation_form, script_name=None):
     """! @brief Set citation form.
     Attribute 'citationForm' is owned by FormRepresentation, which is owned by Lemma.
     @param citation_form The citation form to set.
     @param script_name The name of the script used to write the citation form, e.g. devanagari.
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_citation_form(citation_form, script_name)
     return self
Exemplo n.º 13
0
 def test_xml_lmf_write(self):
     import sys, os
     # Create LMF objects
     lexical_entry = LexicalEntry()
     lexical_entry.lemma = Lemma()
     lexical_entry.partOfSpeech = "toto"
     lexical_entry.status = "draft"
     lexical_entry.lemma.lexeme = "hello"
     # Write XML LMF file and test result
     utest_path = sys.path[0] + '/'
     xml_lmf_filename = utest_path + "lmf_output.xml"
     xml_lmf_write(lexical_entry, xml_lmf_filename)
     xml_lmf_file = open(xml_lmf_filename, "r")
     expected_lines = [
         """<?xml version="1.0" encoding="utf-8"?>""" + EOL,
         """<LexicalEntry id="0">""" + EOL,
         """    <feat att="status" val="draft"/>""" + EOL,
         """    <Lemma>""" + EOL,
         """        <feat att="lexeme" val="hello"/>""" + EOL,
         """    </Lemma>""" + EOL,
         """    <feat att="partOfSpeech" val="toto"/>""" + EOL,
         """</LexicalEntry>""" + EOL
     ]
     self.assertListEqual(expected_lines, xml_lmf_file.readlines())
     xml_lmf_file.close()
     del lexical_entry.lemma
     lexical_entry.lemma = None
     del lexical_entry
     # Remove XML LMF file
     os.remove(xml_lmf_filename)
Exemplo n.º 14
0
 def set_audio(self, media_type="audio", file_name=None, author=None, quality=None, start_position="T00:00:00", duration=None, external_reference=None, audio_file_format=None):
     """! @brief Set audio resource.
     Attributes 'mediaType', 'fileName', 'author', 'quality', 'startPosition', 'durationOfEffectiveSpeech', 'externalReference', 'audioFileFormat' are owned by Material/Audio, which is owned by FormRepresentation, itself owend by Lemma.
     @param media_type The media type to set.
     @param file_name Name of the audio file.
     @param author Author of the recording.
     @param quality Quality of the recording, in range 'quality_range' defined in 'common/range.py'.
     @param start_position Start position of the form in the recording, in format 'Thh:mm:ss,msms', e.g. "T00:05:00".
     @param duration Duration of the effcetive speech, in format 'PThhHmmMssS', e.g. "PT00:05:00".
     @param external_reference Reference of the audio file, if not directly provided.
     @param audio_file_format Format of the audio file, e.g. "wav".
     @return LexicalEntry instance.
     """
     # Create a Lemma instance if not yet created
     if self.lemma is None:
         self.lemma = Lemma()
     self.lemma.set_audio(media_type, file_name, author, quality, start_position, duration, external_reference, audio_file_format)
     return self
Exemplo n.º 15
0
 def test_mdf_write(self):
     import sys, os
     # Create LMF objects
     lexical_entry = LexicalEntry()
     lexical_entry.lemma = Lemma()
     lexical_entry.partOfSpeech = "toto"
     lexical_entry.status = "draft"
     lexical_entry.lemma.lexeme = "hello"
     lexicon = Lexicon()
     lexicon.add_lexical_entry(lexical_entry)
     # Write MDF file and test result
     utest_path = sys.path[0] + '/'
     mdf_filename = utest_path + "output.txt"
     mdf_write(lexicon, mdf_filename)
     mdf_file = open(mdf_filename, "r")
     expected_lines = [
         "\\lx hello" + EOL, "\\ps toto" + EOL, "\\st draft" + EOL, EOL
     ]
     self.assertListEqual(expected_lines, mdf_file.readlines())
     mdf_file.close()
     # Customize mapping
     lmf2mdf = dict({
         "lx":
         lambda lexical_entry: lexical_entry.get_status(),
         "ps":
         lambda lexical_entry: lexical_entry.get_partOfSpeech(),
         "st":
         lambda lexical_entry: lexical_entry.get_lexeme()
     })
     order = ["st", "lx", "ps"]
     # Write MDF file and test result
     mdf_write(lexicon, mdf_filename, lmf2mdf, order)
     mdf_file = open(mdf_filename, "r")
     expected_lines = [
         "\\st hello" + EOL, "\\lx draft" + EOL, "\\ps toto" + EOL, EOL
     ]
     self.assertListEqual(expected_lines, mdf_file.readlines())
     mdf_file.close()
     del lexical_entry.lemma
     lexical_entry.lemma = None
     del lexical_entry, lexicon
     # Remove MDF file
     os.remove(mdf_filename)
Exemplo n.º 16
0
 def test_build_sub_elements(self):
     # Create LMF objects and an empty XML element
     instance = LexicalEntry()
     instance.lemma = Lemma()
     instance.partOfSpeech = "toto"
     instance.status = "draft"
     instance.lemma.lexeme = "hello"
     element = Element("LexicalEntry")
     # Build sub-elements and test result
     build_sub_elements(instance, element)
     lemma = element.find("Lemma")
     lexeme = lemma.find("feat")
     self.assertEqual(lexeme.attrib["att"], "lexeme")
     self.assertEqual(lexeme.attrib["val"], "hello")
     [status, partOfSpeech] = element.findall("feat")
     self.assertEqual(partOfSpeech.attrib["att"], "partOfSpeech")
     self.assertEqual(partOfSpeech.attrib["val"], "toto")
     self.assertEqual(status.attrib["att"], "status")
     self.assertEqual(status.attrib["val"], "draft")
     del instance.lemma
     instance.lemma = None
     del instance, element
Exemplo n.º 17
0
    def test_doc_write(self):
        import sys, os
        # Create LMF objects
        lexical_entry = LexicalEntry()
        lexical_entry.lemma = Lemma()
        lexical_entry.partOfSpeech = "toto"
        lexical_entry.status = "draft"
        lexical_entry.lemma.lexeme = "hello"
        lexicon = Lexicon()
        lexicon.add_lexical_entry(lexical_entry)
        lexical_resource = LexicalResource()
        lexical_resource.add_lexicon(lexicon)
        # Write document file and test result
        utest_path = sys.path[0] + '/'
        doc_filename = utest_path + "output.docx"
        doc_write(lexical_resource, doc_filename)
        doc_file = open(doc_filename, "r")
        doc_file.readlines()
        doc_file.close()

        # Customize mapping
        def lmf2doc(lexicon, document, items, sort_order, paradigms, reverse):
            return "test"

        # Write document file and test result
        doc_write(lexical_resource, doc_filename, None, lmf2doc)
        doc_file = open(doc_filename, "r")
        doc_file.readlines()
        doc_file.close()
        del lexical_entry.lemma
        lexical_entry.lemma = None
        del lexical_entry, lexicon
        lexicon = None
        del lexical_resource
        # Remove document file
        os.remove(doc_filename)
Exemplo n.º 18
0
    def test_tex_write(self):
        import sys, os
        # Create LMF objects
        lexical_entry = LexicalEntry()
        lexical_entry.lemma = Lemma()
        lexical_entry.partOfSpeech = "toto"
        lexical_entry.status = "draft"
        lexical_entry.lemma.lexeme = "hello"
        lexicon = Lexicon()
        lexicon.add_lexical_entry(lexical_entry)
        lexical_resource = LexicalResource()
        lexical_resource.add_lexicon(lexicon)
        # Write LaTeX file and test result
        utest_path = sys.path[0] + '/'
        tex_filename = utest_path + "output.tex"
        tex_write(lexical_resource, tex_filename)
        tex_file = open(tex_filename, "r")
        begin_lines = [
            EOL, "\\begin{document}" + EOL, "\\maketitle" + EOL,
            "\\newpage" + EOL, EOL,
            "\\def\\mytextsc{\\bgroup\\obeyspaces\\mytextscaux}" + EOL,
            "\\def\\mytextscaux#1{\\mytextscauxii #1\\relax\\relax\\egroup}" +
            EOL, "\\def\\mytextscauxii#1{%" + EOL,
            "\\ifx\\relax#1\\else \\ifcat#1\\@sptoken{} \\expandafter\\expandafter\\expandafter\\mytextscauxii\\else"
            + EOL,
            "\\ifnum`#1=\\uccode`#1 {\\normalsize #1}\\else {\\footnotesize \\uppercase{#1}}\\fi \\expandafter\\expandafter\\expandafter\\mytextscauxii\\expandafter\\fi\\fi}"
            + EOL, EOL, "\\setlength\\parindent{0cm}" + EOL, EOL,
            "\\addmediapath{.}" + EOL, "\\addmediapath{./mp3}" + EOL,
            "\\addmediapath{./wav}" + EOL, "\\graphicspath{{" +
            os.path.abspath('.') + "/pylmflib/output/img/}}" + EOL, EOL,
            "\\newpage" + EOL, "\\begin{multicols}{2}" + EOL, EOL
        ]
        end_lines = ["\end{multicols}" + EOL, "\end{document}" + EOL]
        expected_lines = [
            "\\newpage" + EOL,
            "\\section*{\\centering- \\textbf{\ipa{H}} \\textbf{\ipa{h}} -}" +
            EOL,
            #"\\pdfbookmark[1]{\ipa{ H h }}{ H h }" + EOL,
            "\\paragraph{\\hspace{-0.5cm} \\textbf{\ipa{hello}}} \\hypertarget{01}{}"
            + EOL,
            "\markboth{\\textbf{\\ipa{hello}}}{}" + EOL,
            "\\textit{Status:} draft" + EOL,
            "\lhead{\\firstmark}" + EOL,
            "\\rhead{\\botmark}" + EOL,
            EOL
        ]
        self.assertListEqual(begin_lines + expected_lines + end_lines,
                             tex_file.readlines())
        tex_file.close()
        # Customize mapping
        my_lmf_tex = dict({
            "Lemma.lexeme":
            lambda lexical_entry: "is " + lexical_entry.get_lexeme(
            ) + "." + EOL,
            "LexicalEntry.id":
            lambda lexical_entry: "The lexical entry " + str(lexical_entry.
                                                             get_id()) + " ",
            "LexicalEntry.partOfSpeech":
            lambda lexical_entry: "Its grammatical category is " +
            lexical_entry.get_partOfSpeech() + "." + EOL,
            "LexicalEntry.status":
            lambda lexical_entry: "Warning: " + lexical_entry.get_status(
            ) + " version!" + EOL
        })
        my_order = [
            "LexicalEntry.id", "Lemma.lexeme", "LexicalEntry.partOfSpeech",
            "LexicalEntry.status"
        ]

        def lmf2tex(entry, font):
            result = ""
            for attribute in my_order:
                result += my_lmf_tex[attribute](entry)
            return result

        # Write LaTeX file and test result
        tex_write(lexical_resource, tex_filename, None, None, lmf2tex, font)
        tex_file = open(tex_filename, "r")
        expected_lines = [
            "\\newpage" + EOL,
            "\\section*{\\centering- \\textbf{\ipa{H}} \\textbf{\ipa{h}} -}" +
            EOL,
            #"\\pdfbookmark[1]{\ipa{ H h }}{ H h }" + EOL,
            "The lexical entry 01 is hello." + EOL,
            "Its grammatical category is toto." + EOL,
            "Warning: draft version!" + EOL,
            "\lhead{\\firstmark}" + EOL,
            "\\rhead{\\botmark}" + EOL,
            EOL
        ]
        self.assertListEqual(begin_lines + expected_lines + end_lines,
                             tex_file.readlines())
        tex_file.close()
        del lexical_entry.lemma
        lexical_entry.lemma = None
        del lexical_entry, lexicon
        lexicon = None
        del lexical_resource
        # Remove LaTeX file
        os.remove(tex_filename)
Exemplo n.º 19
0
 def setUp(self):
     # Instantiate a Lemma object
     self.lemma = Lemma()
Exemplo n.º 20
0
class TestLemmaFunctions(unittest.TestCase):
    def setUp(self):
        # Instantiate a Lemma object
        self.lemma = Lemma()

    def tearDown(self):
        # Release instantiated objects
        del self.lemma

    def test_init(self):
        self.assertListEqual(self.lemma.form_representation, [])
        self.assertIsNone(self.lemma.hyphenation)
        self.assertIsNone(self.lemma.lexeme)

    def test_set_lexeme(self):
        lexeme = "This is a lexeme."
        self.assertIs(self.lemma.set_lexeme(lexeme), self.lemma)
        self.assertEqual(self.lemma.lexeme, lexeme)

    def test_get_lexeme(self):
        lexeme = "My lexeme."
        self.lemma.lexeme = lexeme
        self.assertEqual(self.lemma.get_lexeme(), lexeme)

    def test_create_form_representation(self):
        # Test create form representation
        repr = self.lemma.create_form_representation()
        self.assertIsInstance(repr, FormRepresentation)
        # Release FormRepresentation instance
        del repr

    def test_add_form_representation(self):
        # Create form representations
        repr1 = FormRepresentation()
        repr2 = FormRepresentation()
        # Test add form representations to the lemma
        self.assertIs(self.lemma.add_form_representation(repr1), self.lemma)
        self.assertListEqual(self.lemma.form_representation, [repr1])
        self.assertIs(self.lemma.add_form_representation(repr2), self.lemma)
        self.assertListEqual(self.lemma.form_representation, [repr1, repr2])
        # Release FormRepresentation instances
        del self.lemma.form_representation[:]
        del repr1, repr2

    def test_find_form_representations(self):
        # Create several form representations with different types
        repr1 = FormRepresentation().set_variantForm("form1").set_type(
            "phonetics")
        repr2 = FormRepresentation().set_variantForm("form2").set_type(
            "orthography")
        repr3 = FormRepresentation().set_variantForm("form3").set_type(
            "phonetics")
        repr4 = FormRepresentation().set_variantForm("form4").set_type(
            "archaic")
        # Add form representations to the lemma
        self.lemma.form_representation = [repr1, repr2, repr3, repr4]
        # Test find form representations
        self.assertListEqual(
            self.lemma.find_form_representations("orthography"),
            [repr2.variantForm])
        # List is randomly ordered => create a set to avoid random results
        self.assertEqual(
            set(self.lemma.find_form_representations("phonetics")),
            set([repr1.variantForm, repr3.variantForm]))
        # Release FormRepresentation instances
        del self.lemma.form_representation[:]
        del repr1, repr2, repr3, repr4

    def test_get_form_representations(self):
        # List of FormRepresentation instances is empty
        self.assertListEqual(self.lemma.get_form_representations(), [])
        # Create FormRepresentation instances and add them to the list
        repr1 = FormRepresentation()
        repr2 = FormRepresentation()
        self.lemma.form_representation = [repr1, repr2]
        # Test get form representations
        self.assertListEqual(self.lemma.get_form_representations(),
                             [repr1, repr2])
        # Delete FormRepresentation instances
        del self.lemma.form_representation[:]
        del repr1, repr2

    def test_get_form_representation(self):
        # List of FormRepresentation instances is empty
        test = False
        try:
            self.lemma.get_form_representation(0)
        except IndexError:
            test = True
        self.assertTrue(test)
        # Create FormRepresentation instances and add them to the list
        repr1 = FormRepresentation()
        repr2 = FormRepresentation()
        self.lemma.form_representation = [repr1, repr2]
        # Test get form representation
        self.assertIs(self.lemma.get_form_representation(0), repr1)
        self.assertEqual(self.lemma.get_form_representation(1), repr2)
        # Delete FormRepresentation instances
        del self.lemma.form_representation[:]
        del repr1, repr2

    def test_set_variant_form(self):
        form = "alternative"
        # There is no FormRepresentation
        self.assertIs(self.lemma.set_variant_form(form), self.lemma)
        self.assertEqual(len(self.lemma.form_representation), 1)
        self.assertEqual(self.lemma.form_representation[0].variantForm, form)
        self.assertEqual(self.lemma.form_representation[0].type, "unspecified")
        # Test set a second variant form
        type = "archaic"
        self.assertIs(self.lemma.set_variant_form(form, type), self.lemma)
        self.assertEqual(len(self.lemma.form_representation), 2)
        self.assertEqual(self.lemma.form_representation[1].variantForm, form)
        self.assertEqual(self.lemma.form_representation[1].type, type)

    def test_get_variant_forms(self):
        form1 = "form1"
        form2 = "form2"
        form3 = "form3"
        # There is no FormRepresentation
        self.assertListEqual(self.lemma.get_variant_forms(), [])
        # Create a FormRepresentation instance
        repr1 = FormRepresentation()
        repr1.variantForm = form1
        repr1.type = "A"
        self.lemma.form_representation.append(repr1)
        self.assertEqual(self.lemma.get_variant_forms(type="A"), [form1])
        self.assertEqual(self.lemma.get_variant_forms(type="B"), [])
        repr2 = FormRepresentation()
        repr2.variantForm = form2
        repr2.type = "B"
        self.lemma.form_representation.append(repr2)
        self.assertEqual(self.lemma.get_variant_forms(type="A"), [form1])
        self.assertEqual(self.lemma.get_variant_forms(type="B"), [form2])
        repr3 = FormRepresentation()
        repr3.variantForm = form3
        repr3.type = "A"
        self.lemma.form_representation.append(repr3)
        self.assertEqual(self.lemma.get_variant_forms(type="A"),
                         [form1, form3])
        self.assertEqual(self.lemma.get_variant_forms(type="B"), [form2])
        # Release FormRepresentation instances
        del self.lemma.form_representation[:]
        del repr1, repr2, repr3

    def test_set_variant_comment(self):
        comment = "useful comment"
        # There is no FormRepresentation
        self.assertIs(self.lemma.set_variant_comment(comment), self.lemma)
        self.assertEqual(len(self.lemma.form_representation), 1)
        self.assertEqual(self.lemma.form_representation[0].comment, comment)
        self.assertIsNone(self.lemma.form_representation[0].language)
        # Test set a second comment
        lang = "English"
        self.assertIs(self.lemma.set_variant_comment(comment, lang),
                      self.lemma)
        self.assertEqual(len(self.lemma.form_representation), 2)
        self.assertEqual(self.lemma.form_representation[1].comment, comment)
        self.assertEqual(self.lemma.form_representation[1].language, lang)

    def test_set_tone(self):
        tone = "This is a tone."
        self.assertIs(self.lemma.set_tone(tone), self.lemma)
        self.assertEqual(self.lemma.form_representation[0].tone, tone)

    def test_get_tones(self):
        tone1 = "My tone."
        tone2 = "Another tone."
        # There is no FormRepresentation
        self.assertListEqual(self.lemma.get_tones(), [])
        # Create a FormRepresentation instance
        repr1 = FormRepresentation()
        repr1.tone = tone1
        self.lemma.form_representation.append(repr1)
        self.assertEqual(self.lemma.get_tones(), [tone1])
        repr2 = FormRepresentation()
        repr2.tone = tone2
        self.lemma.form_representation.append(repr2)
        self.assertEqual(self.lemma.get_tones(), [tone1, tone2])
        # Release FormRepresentation instances
        del self.lemma.form_representation[:]
        del repr1, repr2

    def test_set_geographical_variant(self):
        geo = "geo"
        self.assertIs(self.lemma.set_geographical_variant(geo), self.lemma)
        self.assertEqual(self.lemma.form_representation[0].geographicalVariant,
                         geo)

    def test_set_phonetic_form(self):
        form = "form"
        self.assertIs(self.lemma.set_phonetic_form(form), self.lemma)
        self.assertEqual(self.lemma.form_representation[0].phoneticForm, form)

    def test_get_phonetic_forms(self):
        form1 = "form1"
        form2 = "form2"
        # There is no FormRepresentation
        self.assertListEqual(self.lemma.get_phonetic_forms(), [])
        # Create a FormRepresentation instance
        repr1 = FormRepresentation()
        repr1.phoneticForm = form1
        self.lemma.form_representation.append(repr1)
        self.assertEqual(self.lemma.get_phonetic_forms(), [form1])
        repr2 = FormRepresentation()
        repr2.phoneticForm = form2
        self.lemma.form_representation.append(repr2)
        self.assertEqual(self.lemma.get_phonetic_forms(), [form1, form2])
        # Release FormRepresentation instances
        del self.lemma.form_representation[:]
        del repr1, repr2

    def test_set_contextual_variation(self):
        ctx = "ctx"
        self.assertIs(self.lemma.set_contextual_variation(ctx), self.lemma)
        self.assertEqual(self.lemma.form_representation[0].contextualVariation,
                         ctx)

    def test_get_contextual_variations(self):
        var1 = "var1"
        var2 = "var2"
        # There is no FormRepresentation
        self.assertListEqual(self.lemma.get_contextual_variations(), [])
        # Create a FormRepresentation instance
        repr1 = FormRepresentation()
        repr1.contextualVariation = var1
        self.lemma.form_representation.append(repr1)
        self.assertEqual(self.lemma.get_contextual_variations(), [var1])
        repr2 = FormRepresentation()
        repr2.contextualVariation = var2
        self.lemma.form_representation.append(repr2)
        self.assertEqual(self.lemma.get_contextual_variations(), [var1, var2])
        # Release FormRepresentation instances
        del self.lemma.form_representation[:]
        del repr1, repr2

    def test_set_spelling_variant(self):
        var = "var"
        self.assertIs(self.lemma.set_spelling_variant(var), self.lemma)
        self.assertEqual(self.lemma.form_representation[0].spellingVariant,
                         var)

    def test_get_spelling_variants(self):
        var1 = "var1"
        var2 = "var2"
        # There is no FormRepresentation
        self.assertListEqual(self.lemma.get_spelling_variants(), [])
        # Create a FormRepresentation instance
        repr1 = FormRepresentation()
        repr1.spellingVariant = var1
        self.lemma.form_representation.append(repr1)
        self.assertEqual(self.lemma.get_spelling_variants(), [var1])
        repr2 = FormRepresentation()
        repr2.spellingVariant = var2
        self.lemma.form_representation.append(repr2)
        self.assertEqual(self.lemma.get_spelling_variants(), [var1, var2])
        # Release FormRepresentation instances
        del self.lemma.form_representation[:]
        del repr1, repr2

    def test_set_citation_form(self):
        form = "form"
        self.assertIs(self.lemma.set_citation_form(form), self.lemma)
        self.assertEqual(self.lemma.form_representation[0].citationForm, form)

    def test_get_citation_forms(self):
        form1 = "form1"
        form2 = "form2"
        # There is no FormRepresentation
        self.assertListEqual(self.lemma.get_citation_forms(), [])
        # Create a FormRepresentation instance
        repr1 = FormRepresentation()
        repr1.citationForm = form1
        self.lemma.form_representation.append(repr1)
        self.assertEqual(self.lemma.get_citation_forms(), [form1])
        repr2 = FormRepresentation()
        repr2.citationForm = form2
        self.lemma.form_representation.append(repr2)
        self.assertEqual(self.lemma.get_citation_forms(), [form1, form2])
        # Release FormRepresentation instances
        del self.lemma.form_representation[:]
        del repr1, repr2

    def test_set_dialect(self):
        dial = "dial"
        self.assertIs(self.lemma.set_dialect(dial), self.lemma)
        self.assertEqual(self.lemma.form_representation[0].dialect, dial)

    def test_set_transliteration(self):
        trans = "trans"
        self.assertIs(self.lemma.set_transliteration(trans), self.lemma)
        self.assertEqual(self.lemma.form_representation[0].transliteration,
                         trans)

    def test_get_transliterations(self):
        trans1 = "trans1"
        trans2 = "trans2"
        # There is no FormRepresentation
        self.assertListEqual(self.lemma.get_transliterations(), [])
        # Create a FormRepresentation instance
        repr1 = FormRepresentation()
        repr1.transliteration = trans1
        self.lemma.form_representation.append(repr1)
        self.assertEqual(self.lemma.get_transliterations(), [trans1])
        repr2 = FormRepresentation()
        repr2.transliteration = trans2
        self.lemma.form_representation.append(repr2)
        self.assertEqual(self.lemma.get_transliterations(), [trans1, trans2])
        # Release FormRepresentation instances
        del self.lemma.form_representation[:]
        del repr1, repr2

    def test_set_script_name(self):
        script = "script"
        self.assertIs(self.lemma.set_script_name(script), self.lemma)
        self.assertEqual(self.lemma.form_representation[0].scriptName, script)

    def test_set_audio(self):
        media_type = "audio"
        file_name = "name"
        author = "author"
        quality = "low"
        start_position = "T01:23:45"
        duration = "PT12H34M56S"
        external_reference = "ref"
        audio_file_format = "mp3"
        self.assertEqual(
            self.lemma.set_audio(media_type, file_name, author, quality,
                                 start_position, duration, external_reference,
                                 audio_file_format), self.lemma)
        self.assertEqual(self.lemma.form_representation[0].audio.mediaType,
                         media_type)
        self.assertEqual(self.lemma.form_representation[0].audio.fileName,
                         file_name)
        self.assertEqual(self.lemma.form_representation[0].audio.author,
                         author)
        self.assertEqual(self.lemma.form_representation[0].audio.quality,
                         quality)
        self.assertEqual(self.lemma.form_representation[0].audio.startPosition,
                         start_position)
        self.assertEqual(
            self.lemma.form_representation[0].audio.durationOfEffectiveSpeech,
            duration)
        self.assertEqual(
            self.lemma.form_representation[0].audio.externalReference,
            external_reference)
        self.assertEqual(
            self.lemma.form_representation[0].audio.audioFileFormat,
            audio_file_format)
Exemplo n.º 21
0
class LexicalEntry():
    """! "Lexical Entry is a class representing a lexeme in a given language and is a container for managing the Form and Sense classes. A Lexical Entry instance can contain one to many different forms and can have from zero to many different senses." (LMF)
    """
    def __init__(self, id='0'):
        """! @brief Constructor.
        LexicalEntry instances are owned by Lexicon.
        @param id Unique IDentifier. If not provided, default value is 0.
        @return A LexicalEntry instance.
        """
        self.homonymNumber = None
        self.status = None
        self.date = None
        self.partOfSpeech = None
        self.independentWord = None
        self.bibliography = None
        ## UID is managed at the Lexicon level
        self.id = id
        ## Sense instances are owned by LexicalEntry
        # There is zero to many Sense instances per LexicalEntry
        self.sense = []
        ## Lemma instance is owned by LexicalEntry
        # There is one Lemma instance by LexicalEntry instance
        self.lemma = None # lemmatized form
        ## RelatedForm instances are owned by LexicalEntry
        # There is zero to many RelatedForm instances per LexicalEntry
        self.related_form = []
        ## WordForm instances are owned by LexicalEntry
        # There is zero to many WordForm instances per LexicalEntry
        self.word_form = []
        ## Stem instances are owned by LexicalEntry
        # There is zero to many Stem instances per LexicalEntry
        self.stem = [] # ordered list
        ## ListOfComponents instance is owned by LexicalEntry
        # There is zero or one ListOfComponents instance per LexicalEntry
        self.list_of_components = None
        # Speaker id
        self.targets = None
        ## Pointer to an existing Speaker
        # There is one Speaker pointer per LexicalEntry instance
        self.__speaker = None

    def __del__(self):
        """! @brief Destructor.
        Release Sense, Lemma, RelatedForm, WordForm, Stem, ListOfComponents instances.
        """
        for sense in self.sense:
            del sense
        del self.sense[:]
        for related_form in self.related_form:
            del related_form
        del self.related_form[:]
        for word_form in self.word_form:
            del word_form
        del self.word_form[:]
        for stem in self.stem:
            del stem
        del self.stem[:]
        if self.lemma is not None:
            del self.lemma
        if self.list_of_components is not None:
            del self.list_of_components
        # Decrement the reference count on pointed objects
        self.__speaker = None

    def set_partOfSpeech(self, part_of_speech, range=partOfSpeech_range, mapping=ps_partOfSpeech):
        """! @brief Set grammatical category.
        @param part_of_speech The grammatical category to set.
        @param range A Python set giving all possible values of part of speech LMF attribute.
        @param mapping A Python dictionary giving the mapping between MDF and LMF values.
        @return LexicalEntry instance.
        """
        error_msg = "Part of speech value '%s' encountered for lexeme '%s' is not allowed" % (part_of_speech.encode('utf8'), self.get_lexeme().encode('utf8'))
        # Check part of speech type
        check_attr_type(part_of_speech, [str, unicode], error_msg)
        # Check range of part of speech value (also try with converted value from MDF to LMF)
        value = check_attr_range(part_of_speech.encode('utf8'), range, error_msg, mapping)
        self.partOfSpeech = value
        return self

    def get_partOfSpeech(self):
        """! @brief Get grammatical category.
        @return LexicalEntry attribute 'partOfSpeech'.
        """
        return self.partOfSpeech

    def set_status(self, status):
        """! @brief Set lexical entry status.
        @param status The status to set.
        @return LexicalEntry instance.
        """
        self.status = status
        return self

    def get_status(self):
        """! @brief Get lexical entry status.
        @return LexicalEntry attribute 'status'.
        """
        return self.status

    def set_date(self, date):
        """! @brief Set lexical entry date.
        @param status The date to set.
        @return LexicalEntry instance.
        """
        self.date = date
        return self

    def get_date(self):
        """! @brief Get lexical entry date.
        @return LexicalEntry attribute 'date'.
        """
        return self.date

    def set_homonymNumber(self, homonym_number):
        """! @brief Set lexical entry homonym number.
        @param homonym_number The homonym number to set.
        @return LexicalEntry instance.
        """
        self.homonymNumber = homonym_number
        return self

    def get_homonymNumber(self):
        """! @brief Get lexical entry homonym number.
        @return LexicalEntry attribute 'homonymNumber'.
        """
        return self.homonymNumber

    def set_bibliography(self, bibliography):
        """! @brief Set lexical entry bibliography.
        @param bibliography The bibliography to set.
        @return LexicalEntry instance.
        """
        self.bibliography = bibliography
        return self

    def get_bibliography(self):
        """! @brief Get lexical entry bibliography.
        @return LexicalEntry attribute 'bibliography'.
        """
        return self.bibliography

    def set_independentWord(self, independent_word):
        """! @brief Set lexical entry independent word indication.
        @param independent_word The independent word indication to set.
        @return LexicalEntry instance.
        """
        error_msg = "Independent word '%s' encountered for lexeme '%s' is not allowed" % (str(independent_word), self.get_lexeme())
        check_attr_type(independent_word, bool, error_msg)
        self.independentWord = independent_word
        return self

    def get_independentWord(self):
        """! @brief Get lexical entry independent word indication.
        @return LexicalEntry attribute 'independentWord'.
        """
        return self.independentWord

    def get_id(self):
        """! @brief Get Unique IDentifier.
        @return LexicalEntry attribute 'id' followed by the homonym number.
        """
        homonymNumber = self.get_homonymNumber()
        if homonymNumber is None:
            homonymNumber = 1
        return self.id + str(homonymNumber)

    def set_lexeme(self, lexeme):
        """! @brief Set lexeme.
        Attribute 'lexeme' is owned by Lemma.
        @param lexeme The lexeme to set.
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_lexeme(lexeme)
        return self

    def get_lexeme(self):
        """! @brief Get lexeme.
        Attribute 'lexeme' is owned by Lemma.
        @return Lemma attribute 'lexeme' if any.
        """
        if self.lemma is not None:
            return self.lemma.get_lexeme()

    def create_related_form(self, lexeme, semantic_relation):
        """! @brief Create a related form.
        @param lexeme Related lexeme.
        @param semantic_relation The semantic relation existing between this lexical entry and the related lexeme to create.
        @return RelatedForm instance.
        """
        return RelatedForm(lexeme).set_semanticRelation(semantic_relation)

    def add_related_form(self, related_form):
        """! @brief Add a related form to the lexical entry.
        @param related_form The RelatedForm instance to add to the lexical entry.
        @return LexicalEntry instance.
        """
        self.related_form.append(related_form)
        return self

    def create_and_add_related_form(self, lexeme, semantic_relation):
        """! @brief Create and add a related form to the lexical entry.
        @param lexeme Related lexeme.
        @param semantic_relation The semantic relation existing between this lexical entry and the related lexeme to create.
        @return LexicalEntry instance.
        """
        # Check if this related form already exists
        for related_form in self.get_related_forms():
            if related_form.get_lexeme() == lexeme:
                return self
        self.related_form.append(RelatedForm(lexeme).set_semanticRelation(semantic_relation))
        return self

    def find_related_forms(self, semantic_relation):
        """! @brief Find related lexemes.
        This attribute is owned by RelatedForm.
        @param semantic_relation The semantic relation to consider to retrieve the related form.
        @return A Python list of found RelatedForm attributes 'targets'.
        """
        found_lexemes = []
        for related_form in self.get_related_forms():
            if related_form.get_semanticRelation() == semantic_relation:
                found_lexemes.append(related_form.get_lexeme())
        return found_lexemes

    def get_related_forms(self, semantic_relation=None):
        """! @brief Get all related forms maintained by the lexical entry.
        @param semantic_relation The semantic relation to consider to retrieve the related forms.
        @return A Python set of related forms.
        """
        if semantic_relation is None:
            return self.related_form
        found_forms = []
        for related_form in self.related_form:
            if related_form.get_semanticRelation() == semantic_relation:
                found_forms.append(related_form)
        return found_forms

    def get_last_related_form(self, semantic_relation=None):
        """! @brief Get the previously registered related form.
        @param semantic_relation The semantic relation to consider to retrieve the last related form.
        @return The last element of LexicalEntry attribute 'related_form' that matches with semantic relation if provided.
        """
        if len(self.get_related_forms(semantic_relation)) >= 1:
            return self.get_related_forms()[-1]

    def get_form_representations(self):
        """! @brief Get all form representations maintained by the lemma.
        Attribute 'form_representation' is owned by Lemma.
        @return Lemma attribute 'form_representation' if any.
        """
        if self.lemma is not None:
            return self.lemma.get_form_representations()

    def set_variant_form(self, variant_form, type="unspecified"):
        """! @brief Set variant form and type.
        Attributes 'variantForm' and 'type' are owned by FormRepresentation, which is owned by Lemma.
        @param variant_form Variant form.
        @param type Type of variant, in range 'type_variant_range' defined in 'common/range.py'.
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_variant_form(variant_form, type)
        return self

    def get_variant_forms(self, type="unspecified"):
        """! @brief Get all variant forms of specified type.
        Attribute 'variantForm' is owned by FormRepresentation, which is owned by Lemma.
        @return A Python list of FormRepresentation attributes 'variantForm' if type matches.
        """
        if self.lemma is not None:
            return self.lemma.get_variant_forms(type)

    def set_variant_comment(self, comment, language=None):
        """! @brief Set variant comment and language.
        Attributes 'comment' and 'language' are owned by FormRepresentation, which is owned by Lemma.
        @param comment Variant comment.
        @param language Language of comment.
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_variant_comment(comment, language)
        return self

    def set_tone(self, tone):
        """! @brief Set tone.
        Attribute 'tone' is owned by FormRepresentation, which is owned by Lemma.
        @param tone The tone to set.
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_tone(tone)
        return self

    def get_tones(self):
        """! @brief Get all tones.
        Attribute 'tone' is owned by FormRepresentation, which is owned by Lemma.
        @return A Python list of FormRepresentation attributes 'tone' if any.
        """
        if self.lemma is not None:
            return self.lemma.get_tones()

    def set_geographical_variant(self, geographical_variant):
        """! @brief Set geographical variant.
        Attribute 'geographicalVariant' is owned by FormRepresentation, which is owned by Lemma.
        @param geographical_variant The geographical variant to set.
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_geographical_variant(geographical_variant)
        return self

    def set_phonetic_form(self, phonetic_form, script_name=None):
        """! @brief Set phonetic form.
        Attribute 'phoneticForm' is owned by FormRepresentation, which is owned by Lemma.
        @param phonetic_form The phonetic form to set.
        @param script_name The name of the script used to write the phonetic form, e.g. pinyin.
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_phonetic_form(phonetic_form, script_name)
        return self

    def get_phonetic_forms(self, script_name=None):
        """! @brief Get all phonetic forms.
        Attribute 'phoneticForm' is owned by FormRepresentation, which is owned by Lemma.
        @param script_name If provided, get only phonetic forms that are written using this script.
        @return A Python list of FormRepresentation attributes 'phoneticForm' if any.
        """
        if self.lemma is not None:
            return self.lemma.get_phonetic_forms(script_name)

    def set_contextual_variation(self, contextual_variation):
        """! @brief Set contextual variation.
        Attribute 'contextualVariation' is owned by FormRepresentation, which is owned by Lemma.
        @param contextual_variation The contextual variation to set.
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_contextual_variation(contextual_variation)
        return self

    def get_contextual_variations(self):
        """! @brief Get all contextual variations.
        Attribute 'contextualVariation' is owned by FormRepresentation, which is owned by Lemma.
        @return A Python list of FormRepresentation attributes 'contextualVariation' if any.
        """
        if self.lemma is not None:
            return self.lemma.get_contextual_variations()

    def set_spelling_variant(self, spelling_variant):
        """! @brief Set spelling variant.
        Attribute 'spellingVariant' is owned by FormRepresentation, which is owned by Lemma.
        @param spelling_variant The spelling variant to set.
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_spelling_variant(spelling_variant)
        return self

    def get_spelling_variants(self):
        """! @brief Get all spelling variants.
        Attribute 'spellingVariant' is owned by FormRepresentation, which is owned by Lemma.
        @return A Python list of FormRepresentation attributes 'spellingVariant' if any.
        """
        if self.lemma is not None:
            return self.lemma.get_spelling_variants()

    def set_citation_form(self, citation_form, script_name=None):
        """! @brief Set citation form.
        Attribute 'citationForm' is owned by FormRepresentation, which is owned by Lemma.
        @param citation_form The citation form to set.
        @param script_name The name of the script used to write the citation form, e.g. devanagari.
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_citation_form(citation_form, script_name)
        return self

    def get_citation_forms(self, script_name=None):
        """! @brief Get all citation forms.
        Attribute 'citationForm' is owned by FormRepresentation, which is owned by Lemma.
        @param script_name If provided, get only citation forms that are written using this script.
        @return A Python list of FormRepresentation attributes 'citationForm' if any.
        """
        if self.lemma is not None:
            return self.lemma.get_citation_forms(script_name)

    def set_dialect(self, dialect):
        """! @brief Set dialect.
        Attribute 'dialect' is owned by FormRepresentation, which is owned by Lemma.
        @param dialect The dialect to set.
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_dialect(dialect)
        return self

    def set_transliteration(self, transliteration):
        """! @brief Set transliteration.
        Attribute 'transliteration' is owned by FormRepresentation, which is owned by Lemma.
        @param transliteration The transliteration to set.
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_transliteration(transliteration)
        return self

    def get_transliterations(self):
        """! @brief Get all transliterations.
        Attribute 'transliteration' is owned by FormRepresentation, which is owned by Lemma.
        @return A Python list of FormRepresentation attributes 'transliteration' if any.
        """
        if self.lemma is not None:
            return self.lemma.get_transliterations()

    def set_script_name(self, script_name):
        """! @brief Set script name.
        Attribute 'scriptName' is owned by FormRepresentation, which is owned by Lemma.
        @param script_name The script name to set.
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_script_name(script_name)
        return self

    def create_sense(self, id=0):
        """! @brief Create a sense.
        @param id Identifier.
        @return Sense instance.
        """
        return Sense(id)

    def add_sense(self, sense):
        """! @brief Add a sense to the lexical entry.
        @param sense The Sense instance to add to the lexical entry.
        @return LexicalEntry instance.
        """
        self.sense.append(sense)
        return self

    def create_and_add_sense(self, sense_number):
        """! @brief Create and add a sense to the lexical entry.
        @param sense_number Number of the sense to add.
        @return LexicalEntry instance.
        """
        id = self.get_id() + "_" + str(sense_number)
        self.add_sense(self.create_sense(id).set_senseNumber(sense_number))
        return self

    def get_senses(self):
        """! @brief Get all senses maintained by the lexical entry.
        @return LexicalEntry attribute 'sense'.
        """
        return self.sense

    def get_last_sense(self):
        """! @brief Get the previously registered sense.
        @return The last element of LexicalEntry attribute 'sense'.
        """
        if len(self.get_senses()) >= 1:
            return self.get_senses()[-1]

    def set_definition(self, definition, language=None):
        """! @brief Set definition and language.
        Attributes 'definition' and 'language' are owned by Definition, which is owned by Sense.
        @param definition Definition.
        @param language Language of definition.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_definition(definition, language)
        return self

    def set_gloss(self, gloss, language=None):
        """! @brief Set gloss and language.
        Attributes 'gloss' and 'language' are owned by Definition, which is owned by Sense.
        @param gloss Gloss.
        @param language Language of gloss.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instances, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_gloss(gloss, language)
        return self

    def set_note(self, note, type=None, language=None):
        """! @brief Set note, type and language.
        Attributes 'note', 'noteType' and 'language' are owned by Statement, which owned by Definition, itself owned by Sense.
        @param note Note to set.
        @param type Type of the note.
        @param language Language of the note.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instances, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_note(note, type, language)
        return self

    def find_notes(self, type, language=None):
        """! @brief Find notes.
        This attribute is owned by Statement, which owned by Definition, itself owned by Sense.
        @param type Type of the note to consider to retrieve the note.
        @param language If this argument is given, find note only if written in this language.
        @return A Python list of found Statement attributes 'notes'.
        """
        found_notes = []
        for sense in self.get_senses():
            found_notes += sense.find_notes(type, language)
        return found_notes

    def set_usage_note(self, usage_note, language=None):
        """! @brief Set usage note and language.
        Attributes 'usageNote' and 'language' are owned by Statement, which owned by Definition, itself owned by Sense.
        @param usage_note Usage note to set.
        @param language Language of the usage note.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instances, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_usage_note(usage_note, language)
        return self

    def set_encyclopedic_information(self, encyclopedic_information, language=None):
        """! @brief Set encyclopedic information and language.
        Attributes 'encyclopedicInformation' and 'language' are owned by Statement, which owned by Definition, itself owned by Sense.
        @param encyclopedic_information Encyclopedic information to set.
        @param language Language of the encyclopedic information.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instances, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_encyclopedic_information(encyclopedic_information, language)
        return self

    def set_restriction(self, restriction, language=None):
        """! @brief Set restriction and language.
        Attributes 'restriction' and 'language' are owned by Statement, which owned by Definition, itself owned by Sense.
        @param restriction Restriction to set.
        @param language Language of the restriction.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instances, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_restriction(restriction, language)
        return self

    def set_borrowed_word(self, borrowed_word):
        """! @brief Set source language (in English).
        Attribute 'borrowedWord' is owned by Statement, which is owned by Definition, itself owned by Sense.
        @param borrowed_word Source language.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_borrowed_word(borrowed_word)
        return self

    def get_borrowed_word(self):
        """! @brief Get source language (in English).
        This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
        @return Statement attribute 'borrowedWord'.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is a Sense instance, get source language
        if sense is not None:
            return sense.get_borrowed_word()

    def set_written_form(self, written_form):
        """! @brief Set loan word.
        Attribute 'writtenForm' is owned by Statement, which is owned by Definition, itself owned by Sense.
        @param written_form Loan word.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_written_form(written_form)
        return self

    def get_written_form(self):
        """! @brief Get loan word.
        This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
        @return Statement attribute 'writtenForm'.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is a Sense instance, get loan word
        if sense is not None:
            return sense.get_written_form()

    def set_etymology(self, etymology):
        """! @brief Set etymology.
        Attribute 'etymology' is owned by Statement, which is owned by Definition, itself owned by Sense.
        @param etymology Etymology.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_etymology(etymology)
        return self

    def get_etymology(self):
        """! @brief Get etymology.
        This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
        @return The first found Statement attribute 'etymology'.
        """
        for sense in self.get_senses():
            if sense.get_etymology() is not None:
                return sense.get_etymology()

    def set_etymology_comment(self, etymology_comment, term_source_language=None):
        """! @brief Set etymology comment and language.
        Attributes 'etymologyComment' and 'termSourceLanguage' are owned by Statement, which is owned by Definition, itself owned by Sense.
        @param etymology_comment Etymology comment.
        @param term_source_language Language of the comment.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_etymology_comment(etymology_comment, term_source_language)
        return self

    def get_etymology_comment(self, term_source_language=None):
        """! @brief Get etymology comment.
        This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
        @param term_source_language The language of the etymology comment to retrieve.
        @return The first found Statement attribute 'etymologyComment'.
        """
        for sense in self.get_senses():
            if sense.get_etymology_comment(term_source_language) is not None:
                return sense.get_etymology_comment(term_source_language)

    def get_term_source_language(self):
        """! @brief Get language used for the etymology comment.
        This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
        @return Statement attribute 'termSourceLanguage'.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is a Sense instance, get etymology comment language
        if sense is not None:
            return sense.get_term_source_language()

    def set_etymology_gloss(self, etymology_gloss):
        """! @brief Set etymology gloss.
        Attribute 'etymologyGloss' is owned by Statement, which is owned by Definition, itself owned by Sense.
        @param etymology_gloss Etymology gloss.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_etymology_gloss(etymology_gloss)
        return self

    def get_etymology_gloss(self):
        """! @brief Get etymology gloss.
        This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
        @return Statement attribute 'etymologyGloss'.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is a Sense instance, get etymology gloss
        if sense is not None:
            return sense.get_etymology_gloss()

    def set_etymology_source(self, etymology_source):
        """! @brief Set etymology source.
        Attribute 'etymologySource' is owned by Statement, which is owned by Definition, itself owned by Sense.
        @param etymology_source Etymology source.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_etymology_source(etymology_source)
        return self

    def get_etymology_source(self):
        """! @brief Get etymology source.
        This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
        @return Statement attribute 'etymologySource'.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is a Sense instance, get etymology source
        if sense is not None:
            return sense.get_etymology_source()

    def set_scientific_name(self, scientific_name):
        """! @brief Set scientific_name.
        Attribute 'scientificName' is owned by Statement, which is owned by Definition, itself owned by Sense.
        @param scientific_name Scientific name.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_scientific_name(scientific_name)
        return self

    def get_scientific_name(self):
        """! @brief Get scientific name.
        This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
        @return Statement attribute 'scientificName'.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is a Sense instance, get scientific name
        if sense is not None:
            return sense.get_scientific_name()

    def create_word_form(self):
        """! @brief Create a word form.
        @return WordForm instance.
        """
        return WordForm()

    def add_word_form(self, word_form):
        """! @brief Add a word form to the lexical entry.
        @param word_form The WordForm instance to add to the lexical entry.
        @return LexicalEntry instance.
        """
        self.word_form.append(word_form)
        return self

    def get_word_forms(self):
        """! @brief Get all word forms maintained by the lexical entry.
        @return A Python list of word forms.
        """
        return self.word_form

    def set_paradigm(self, written_form, script_name=None, person=None, anymacy=None, grammatical_number=None, clusivity=None):
        """! @brief Set paradigm.
        Attributes 'writtenForm' and 'scriptName' are owned by FormRepresentation, wich is owned by WordForm.
        Attributes 'person', 'anymacy', 'grammaticalNumber' and 'clusivity' are owned by WordForm.
        @param written_form The paradigm to set.
        @param script_name Script used for the written form.
        @param person Person, e.g. first person.
        @param anymacy Anymacy, e.g. animate or inanimate.
        @param grammatical_number Grammatical number, e.g. singular or plural.
        @param clusivity Clusivity, e.g. inclusive or exclusive.
        @return LexicalEntry instance.
        """
        word_form = None
        # Find corresponding word form
        for form in self.get_word_forms():
            if form.get_person() == person and form.get_anymacy() == anymacy and form.get_grammaticalNumber() == grammatical_number and form.get_clusivity() == clusivity:
                # Add a paradigm as a written form to an existing word form
                word_form = form
                break
        if word_form is None:
            # Create a WordForm instance
            word_form = self.create_word_form()
            self.add_word_form(word_form)
            if person is not None:
                word_form.set_person(person)
            if anymacy is not None:
                word_form.set_anymacy(anymacy)
            if grammatical_number is not None:
                word_form.set_grammaticalNumber(grammatical_number)
            if clusivity is not None:
                word_form.set_clusivity(clusivity)
        word_form.set_written_form(written_form, script_name)
        return self

    def find_paradigms(self, script_name=None, person=None, anymacy=None, grammatical_number=None, clusivity=None):
        """! @brief Find paradigms.
        Attribute 'scriptName' is owned by FormRepresentation, wich is owned by WordForm.
        Attributes 'person', 'anymacy', 'grammaticalNumber' and 'clusivity' are owned by WordForm.
        Attribute 'writtenForm' to retrieve is owned by FormRepresentation, wich is owned by WordForm.
        @param script_name If this argument is given, get paradigm written form only if written using this script.
        @param person Person, e.g. first person.
        @param anymacy Anymacy, e.g. animate or inanimate.
        @param grammatical_number Grammatical number, e.g. singular or plural.
        @param clusivity Clusivity, e.g. inclusive or exclusive.
        @return A Python list of FormRepresentation attributes 'writtenForm'.
        """
        written_forms = []
        # Find corresponding word form
        for form in self.get_word_forms():
            if form.get_person() == person and form.get_anymacy() == anymacy and form.get_grammaticalNumber() == grammatical_number and form.get_clusivity() == clusivity:
                written_forms += form.get_written_forms(script_name)
        return written_forms

    def set_paradigm_label(self, paradigm_label):
        """! @brief Set paradigm label.
        Attribute 'paradigmLabel' is owned by Paradigm, which is owned by Sense.
        @param paradigm_label Paradigm label.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_paradigm_label(paradigm_label)
        return self

    def set_paradigm_form(self, paradigm, language=None):
        """! @brief Set paradigm form.
        Attribute 'paradigm' is owned by Paradigm, which is owned by Sense.
        @param paradigm Paradigm form.
        @param language Language of the paradigm form.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_paradigm_form(paradigm, language)
        return self

    def set_morphology(self, morphology):
        """! @brief Set morphology.
        Attribute 'morphology' is owned by Paradigm, which is owned by Sense.
        @param morphology Morphology.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_morphology(morphology)
        return self

    def get_paradigms(self):
        """! @brief Get all paradigms.
        This attribute is owned by Sense.
        @return Sense attribute 'paradigm'.
        """
        paradigms = []
        for sense in self.get_senses():
            paradigms += sense.get_paradigms()
        return paradigms

    def get_morphologies(self):
        """! @brief Get all morphologies.
        This attribute is owned by Paradigm, which is owned by Sense.
        @return A Python list of Paradigm attributes 'morphology'.
        """
        morphologies = []
        for sense in self.get_senses():
            for paradigm in sense.get_paradigms():
                if paradigm.get_morphology() is not None:
                    morphologies.append(paradigm.get_morphology())
        return morphologies

    def create_example(self, reference=None):
        """! @brief Create a context.
        Attribute 'targets' is owned by Context, itself owend by Sense.
        @param reference The example reference to set. If not provided, default value is None.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.create_example(reference)
        return self

    def create_and_add_example(self, written_form, language=None, script_name=None):
        """! @brief Add an example to a new context and set its written form, language and script.
        Attributes 'writtenForm', 'language' and 'scriptName' are owned by TextRepresentation, which is owned by Context, itself owend by Sense.
        @param written_form The written form to set.
        @param language Language used for the written form.
        @param script_name The name of the script used to write the example, e.g. devanagari.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.create_and_add_example(written_form, language, script_name)
        return self

    def add_example(self, written_form, language=None, script_name=None):
        """! @brief Add an example to an existing context and set its written form, language and script.
        Attributes 'writtenForm', 'language' and 'scriptName' are owned by TextRepresentation, which is owned by Context, itself owend by Sense.
        @param written_form The written form to set.
        @param language Language used for the written form.
        @param script_name The name of the script used to write the example, e.g. devanagari.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.add_example(written_form, language, script_name)
        return self

    def set_example_comment(self, comment):
        """! @brief Set comment of an existing example.
        Attribute 'comment' is owned by TextRepresentation, which is owned by Context, itself owend by Sense.
        @param comment The comment to set.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_example_comment(comment)
        return self

    def set_semantic_domain(self, semantic_domain, language=None):
        """! @brief Set semantic domain and language.
        Attributes 'semanticDomain' and 'language' are owned by SubjectField, which is owned by Sense.
        @param semantic_domain The semantic domain to set.
        @param language Language used to describe the semantic domain.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_semantic_domain(semantic_domain, language)
        return self

    def get_semantic_domains(self, language=None):
        """! @brief Get all semantic domains.
        This attribute is owned by SubjectField, which is owned by Sense.
        @param language If this argument is given, get only semantic domains that are described using this language.
        @return A Python list of filtered SubjectField attributes 'semanticDomain'.
        """
        semantic_domains = []
        for sense in self.get_senses():
            for subject_field in sense.get_subject_fields():
                if subject_field.get_semanticDomain(language) is not None:
                    semantic_domains.append(subject_field.get_semanticDomain(language))
                semantic_domains += subject_field.get_sub_domains(language)
        return semantic_domains

    def set_translation(self, translation, language=None):
        """! @brief Set translation and language.
        Attributes 'translation' and 'language' are owned by Equivalent, which is owned by Sense.
        @param translation The translation to set.
        @param language Language used for the translation.
        @return LexicalEntry instance.
        """
        # Get the last Sense instance if any
        sense = self.get_last_sense()
        # If there is no Sense instance, create and add one
        if sense is None:
            sense = self.create_sense()
            self.add_sense(sense)
        sense.set_translation(translation, language)
        return self

    def set_audio(self, media_type="audio", file_name=None, author=None, quality=None, start_position="T00:00:00", duration=None, external_reference=None, audio_file_format=None):
        """! @brief Set audio resource.
        Attributes 'mediaType', 'fileName', 'author', 'quality', 'startPosition', 'durationOfEffectiveSpeech', 'externalReference', 'audioFileFormat' are owned by Material/Audio, which is owned by FormRepresentation, itself owend by Lemma.
        @param media_type The media type to set.
        @param file_name Name of the audio file.
        @param author Author of the recording.
        @param quality Quality of the recording, in range 'quality_range' defined in 'common/range.py'.
        @param start_position Start position of the form in the recording, in format 'Thh:mm:ss,msms', e.g. "T00:05:00".
        @param duration Duration of the effcetive speech, in format 'PThhHmmMssS', e.g. "PT00:05:00".
        @param external_reference Reference of the audio file, if not directly provided.
        @param audio_file_format Format of the audio file, e.g. "wav".
        @return LexicalEntry instance.
        """
        # Create a Lemma instance if not yet created
        if self.lemma is None:
            self.lemma = Lemma()
        self.lemma.set_audio(media_type, file_name, author, quality, start_position, duration, external_reference, audio_file_format)
        return self

    def is_subentry(self):
        """! @brief Check if this lexical entry is a subentry.
        @return 'True' if it is a subentry, 'False' otherwise.
        """
        for related_form in self.get_related_forms():
            # If one of the related form is a main entry, it means that the current lexical entry is a subentry
            if related_form.get_semanticRelation() == "main entry":
                return True
        return False

    def has_subentries(self):
        """! @brief Check if this lexical entry has subentries.
        @return 'True' if it has subentries, 'False' otherwise.
        """
        for related_form in self.get_related_forms():
            # If one of the related form is a subentry, it means that the current lexical entry is a main entry
            if related_form.get_semanticRelation() == "subentry":
                return True
        return False

    def get_subentries(self):
        """! @brief Get subentries of this lexical entry.
        @return A Python list of LexicalEntry.
        """
        subentries = []
        for related_form in self.get_related_forms():
            if related_form.get_semanticRelation() == "subentry":
                subentries.append(related_form.get_lexical_entry())
        return subentries

    def get_main_entry(self):
        """! @brief If this lexical entry is a subentry, get its main entry.
        @return A LexicalEntry if it exists, 'None' otherwise.
        """
        for related_form in self.get_related_forms():
            if related_form.get_semanticRelation() == "main entry":
                return related_form.get_lexical_entry()

    def create_and_add_component(self, position, lexeme):
        """! @brief Create and add a component to the lexical entry.
        @param position The position of the component in the multiword expression.
        @param lexeme Related lexeme.
        @return LexicalEntry instance.
        """
        if self.list_of_components is None:
            self.list_of_components = ListOfComponents()
        self.list_of_components.create_and_add_component(position, lexeme)
        return self

    def get_components(self):
        """! @brief If this lexical entry is a multiword expression, get its components.
        @return A list of components if any, an empty list otherwise.
        """
        if self.list_of_components is None:
            return []
        return self.list_of_components.get_components()

    def is_component(self):
        """! @brief Check if this lexical entry is a component.
        @return 'True' if it is a component, 'False' otherwise.
        """
        for related_form in self.get_related_forms():
            # If one of the related form is a complex predicate, it means that the current lexical entry is a component
            if related_form.get_semanticRelation() == "complex predicate":
                return True
        return False

    def get_speaker(self):
        """! @brief Get speaker.
        @return LexicalEntry private attribute '__speaker'.
        """
        return self.__speaker