Beispiel #1
0
 def __init__(self, dtd_version=16):
     """! @brief Constructor.
     @return A LexicalResource instance.
     """
     self.dtdVersion = dtd_version
     ## GlobalInformation instance is owned by LexicalResource
     # There is one GlobalInformation for one LexicalResource
     self.global_information = GlobalInformation()
     ## Lexicon instances are owned by LexicalResource
     # There is one or more Lexicon instances for one unique LexicalResource
     self.lexicon = []
     ## Speaker instances are owned by LexicalResource
     # There is zero to many Speaker instances for one unique LexicalResource
     self.speaker = []
Beispiel #2
0
class LexicalResource():
    """! "Lexical Resource is a class representing the entire resource and is a container for one or more lexicons. There is only one Lexical Resource instance." (LMF)
    """
    def __init__(self, dtd_version=16):
        """! @brief Constructor.
        @return A LexicalResource instance.
        """
        self.dtdVersion = dtd_version
        ## GlobalInformation instance is owned by LexicalResource
        # There is one GlobalInformation for one LexicalResource
        self.global_information = GlobalInformation()
        ## Lexicon instances are owned by LexicalResource
        # There is one or more Lexicon instances for one unique LexicalResource
        self.lexicon = []
        ## Speaker instances are owned by LexicalResource
        # There is zero to many Speaker instances for one unique LexicalResource
        self.speaker = []

    def __del__(self):
        """! @brief Destructor.
        Release GlobalInformation, Lexicon, Speaker instances.
        """
        for lexicon in self.lexicon:
            del lexicon
        del self.lexicon[:]
        for speaker in self.speaker:
            del speaker
        del self.speaker[:]
        if self.global_information is not None:
            del self.global_information

    def get_lexicons(self):
        """! @brief Get all lexicons maintained by the lexical resource.
        @return A Python list of lexicons.
        """
        return self.lexicon

    def add_lexicon(self, lexicon):
        """! @brief Add a lexicon to the lexical resource.
        @param lexicon A Lexicon instance to add to the Lexical Resource.
        @return Lexical Resource instance.
        """
        self.lexicon.append(lexicon)
        return self

    def remove_lexicon(self, lexicon):
        """! @brief Remove a lexicon from the lexical resource.
        @param lexicon The Lexicon instance to remove from the Lexical Resource.
        @return Lexical Resource instance.
        """
        self.lexicon.remove(lexicon)
        return self

    def get_lexicon(self, id):
        """Retrieve a lexicon from its identifier.
        @param id The identifier of the lexicon to retrieve.
        @result A Lexicon instance, or None if not found.
        """
        for lexicon in self.get_lexicons():
            if lexicon.id == id:
                return lexicon

    def set_dtdVersion(self, dtd_version):
        """! @brief Set DTD version.
        @param dtd_version The DTD version to use.
        @return LexicalResource instance.
        """
        self.dtdVersion = dtd_version
        return self

    def get_dtdVersion(self):
        """! @brief Get DTD version.
        @return LexicalResource attribute 'dtdVersion'.
        """
        return self.dtdVersion

    def set_language_code(self, language_code):
        """! @brief Set language code.
        Attribute 'languageCode' is owned by GlobalInformation.
        @param language_code The language code to use.
        @return LexicalResource instance.
        """
        self.global_information.set_languageCode(language_code)
        return self

    def get_language_code(self):
        """! @brief Get language code.
        Attribute 'languageCode' is owned by GlobalInformation.
        @return GlobalInformation attribute 'languageCode'.
        """
        return self.global_information.get_languageCode()

    def set_version(self, version):
        """! @brief Set version.
        Attribute 'version' is owned by GlobalInformation.
        @param version The version to set.
        @return LexicalResource instance.
        """
        self.global_information.set_version(version)
        return self

    def get_version(self):
        """! @brief Get version.
        Attribute 'version' is owned by GlobalInformation.
        @return GlobalInformation attribute 'version'.
        """
        return self.global_information.get_version()

    def set_license(self, license):
        """! @brief Set license.
        Attribute 'license' is owned by GlobalInformation.
        @param license The license to set.
        @return LexicalResource instance.
        """
        self.global_information.set_license(license)
        return self

    def get_license(self):
        """! @brief Get license.
        Attribute 'license' is owned by GlobalInformation.
        @return GlobalInformation attribute 'license'.
        """
        return self.global_information.get_license()

    def set_character_encoding(self, character_encoding):
        """! @brief Set character encoding.
        Attribute 'characterEncoding' is owned by GlobalInformation.
        @param character_encoding The character encoding to use.
        @return LexicalResource instance.
        """
        self.global_information.set_characterEncoding(character_encoding)
        return self

    def get_character_encoding(self):
        """! @brief Get character encoding.
        Attribute 'characterEncoding' is owned by GlobalInformation.
        @return GlobalInformation attribute 'characterEncoding'.
        """
        return self.global_information.get_characterEncoding()

    def set_date_coding(self, date_coding):
        """! @brief Set date coding.
        Attribute 'dateCoding' is owned by GlobalInformation.
        @param date_coding The date coding to use.
        @return LexicalResource instance.
        """
        self.global_information.set_dateCoding(date_coding)
        return self

    def get_date_coding(self):
        """! @brief Get date coding.
        Attribute 'dateCoding' is owned by GlobalInformation.
        @return GlobalInformation attribute 'dateCoding'.
        """
        return self.global_information.get_dateCoding()

    def set_project_name(self, project_name):
        """! @brief Set project name.
        Attribute 'projectName' is owned by GlobalInformation.
        @param project_name The project's name to set.
        @return LexicalResource instance.
        """
        self.global_information.set_projectName(project_name)
        return self

    def get_project_name(self):
        """! @brief Get project name.
        Attribute 'projectName' is owned by GlobalInformation.
        @return GlobalInformation attribute 'projectName'.
        """
        return self.global_information.get_projectName()

    def set_creation_date(self, date):
        """! @brief Set creation date.
        Attribute 'creationDate' is owned by GlobalInformation.
        @param date The date to set, in format YYYY-MM-DD.
        @return LexicalResource instance.
        """
        self.global_information.set_creationDate(date)
        return self

    def get_creation_date(self):
        """! @brief Get creation date.
        Attribute 'creationDate' is owned by GlobalInformation.
        @return GlobalInformation attribute 'creationdDate'.
        """
        return self.global_information.get_creationDate()

    def set_last_update(self, date):
        """! @brief Set last update.
        Attribute 'lastUpdate' is owned by GlobalInformation.
        @param date The date to set, in format YYYY-MM-DD.
        @return LexicalResource instance.
        """
        self.global_information.set_lastUpdate(date)
        return self

    def get_last_update(self):
        """! @brief Get last update.
        Attribute 'lastUpdate' is owned by GlobalInformation.
        @return GlobalInformation attribute 'lastUpdate'.
        """
        return self.global_information.get_lastUpdate()

    def set_author(self, author):
        """! @brief Set author.
        Attribute 'author' is owned by GlobalInformation.
        @param author The author's name to set.
        @return LexicalResource instance.
        """
        self.global_information.set_author(author)
        return self

    def get_author(self):
        """! @brief Get author.
        Attribute 'author' is owned by GlobalInformation.
        @return GlobalInformation attribute 'author'.
        """
        return self.global_information.get_author()

    def set_description(self, description):
        """! @brief Set description.
        Attribute 'description' is owned by GlobalInformation.
        @param description The description to set.
        @return LexicalResource instance.
        """
        self.global_information.set_description(description)
        return self

    def get_description(self):
        """! @brief Get description.
        Attribute 'description' is owned by GlobalInformation.
        @return GlobalInformation attribute 'description'.
        """
        return self.global_information.get_description()

    def get_bibliographic_citation(self):
        """! @brief Get bibliographic citation.
        Attribute 'bibliographicCitation' is owned by GlobalInformation.
        @return GlobalInformation attribute 'bibliographicCitation'.
        """
        return self.global_information.get_bibliographicCitation()
 def setUp(self):
     # Instantiate a GlobalInformation object
     self.global_information = GlobalInformation()
class TestGlobalInformationFunctions(unittest.TestCase):

    def setUp(self):
        # Instantiate a GlobalInformation object
        self.global_information = GlobalInformation()

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

    def test_init(self):
        self.assertIsNone(self.global_information.languageCode)
        self.assertIsNone(self.global_information.author)
        self.assertIsNone(self.global_information.version)
        self.assertIsNone(self.global_information.lastUpdate)
        self.assertIsNone(self.global_information.license)
        self.assertIsNone(self.global_information.characterEncoding)
        self.assertIsNone(self.global_information.dateCoding)
        self.assertIsNone(self.global_information.creationDate)
        self.assertIsNone(self.global_information.projectName)
        self.assertIsNone(self.global_information.description)
        self.assertIsNone(self.global_information.bibliographicCitation)

    def test_set_languageCode(self):
        code = "iso"
        self.assertEqual(self.global_information.set_languageCode(code), self.global_information)
        self.assertEqual(self.global_information.languageCode, code)

    def test_get_languageCode(self):
        self.assertIs(self.global_information.get_languageCode(), self.global_information.languageCode)

    def test_set_version(self):
        version = "0"
        self.assertEqual(self.global_information.set_version(version), self.global_information)
        self.assertEqual(self.global_information.version, version)

    def test_get_version(self):
        self.assertIs(self.global_information.get_version(), self.global_information.version)

    def test_set_license(self):
        license = "free"
        self.assertEqual(self.global_information.set_license(license), self.global_information)
        self.assertEqual(self.global_information.license, license)

    def test_get_license(self):
        self.assertIs(self.global_information.get_license(), self.global_information.license)

    def test_set_characterEncoding(self):
        coding = "iso"
        self.assertEqual(self.global_information.set_characterEncoding(coding), self.global_information)
        self.assertEqual(self.global_information.characterEncoding, coding)

    def test_get_characterEncoding(self):
        self.assertIs(self.global_information.get_characterEncoding(), self.global_information.characterEncoding)

    def test_set_dateCoding(self):
        coding = "iso"
        self.assertEqual(self.global_information.set_dateCoding(coding), self.global_information)
        self.assertEqual(self.global_information.dateCoding, coding)

    def test_get_dateCoding(self):
        self.assertIs(self.global_information.get_dateCoding(), self.global_information.dateCoding)

    def test_set_projectName(self):
        name = "project"
        self.assertEqual(self.global_information.set_projectName(name), self.global_information)
        self.assertEqual(self.global_information.projectName, name)

    def test_get_projectName(self):
        self.assertIs(self.global_information.get_projectName(), self.global_information.projectName)

    def test_set_creationDate(self):
        date = "2014-10-08"
        self.assertEqual(self.global_information.set_creationDate(date), self.global_information)
        self.assertEqual(self.global_information.creationDate, date)
        
    def test_get_creationDate(self):
        self.assertIs(self.global_information.get_creationDate(), self.global_information.creationDate)

    def test_set_lastUpdate(self):
        date = "2014-10-08"
        self.assertEqual(self.global_information.set_lastUpdate(date), self.global_information)
        self.assertEqual(self.global_information.lastUpdate, date)

    def test_get_lastUpdate(self):
        self.assertIs(self.global_information.get_lastUpdate(), self.global_information.lastUpdate)

    def test_set_author(self):
        author = "My Name"
        self.assertEqual(self.global_information.set_author(author), self.global_information)
        self.assertEqual(self.global_information.author, author)

    def test_get_author(self):
        self.assertIs(self.global_information.get_author(), self.global_information.author)

    def test_set_description(self):
        descr = "This is a short description of the lexical resource."
        self.assertEqual(self.global_information.set_description(descr), self.global_information)
        self.assertEqual(self.global_information.description, descr)

    def test_get_description(self):
        self.assertIs(self.global_information.get_description(), self.global_information.description)

    def test_compute_bibliographicCitation(self):
        self.global_information.author = "CNRS"
        self.global_information.lastUpdate = "2014"
        # Test compute bibliographic citation
        self.global_information.compute_bibliographicCitation()
        self.assertEqual(self.global_information.bibliographicCitation, "Online dictionaries, CNRS, 2014")

    def test_get_bibliographicCitation(self):
        self.assertIs(self.global_information.get_bibliographicCitation(), self.global_information.bibliographicCitation)