示例#1
0
    def test_get_synonyms_long_short_equal(self):
        # arrange
        word = 'München'

        # act
        instance = OpenThesaurusWeb()
        synonyms_short = instance.get_synonyms(word=word)
        synonyms_long = instance.get_synonyms(word=word, form='long')

        # assert
        synonyms_long_len = len(".".join(synonyms_long))
        synonyms_short_len = len(".".join(synonyms_short))

        self.assertLessEqual(synonyms_short_len, synonyms_long_len)
示例#2
0
def main():
    logger = log.setup_custom_logger(__name__)

    parser = argparse.ArgumentParser(
        description='Get synonyms of German words from www.openthesaurus.de')

    parser.add_argument(
        '--form',
        required=False,
        action='store',
        choices=['long', 'short'],
        type=str,
        default='short',
        help=
        "Defaults to form=short which means that short versions of synonyms will be returned, "
        "without nach/zu prefixes/suffixes."
        "On the other hand, form=long returns the full versions of synonyms including nach/zu, "
        "sich prefixes/suffixes")

    required = parser.add_argument_group('required arguments')

    required.add_argument('--word',
                          type=str,
                          action='store',
                          required=True,
                          help="A word from which synonyms will be obtained")

    args = parser.parse_args()

    open_thesaurus = OpenThesaurusWeb()

    synonyms = open_thesaurus.get_synonyms(word=args.word, form=args.form)

    logger.info(synonyms)
示例#3
0
    def test_get_synonyms_empty_wrong_input_word_special_characters(self):
        # arrange
        word = None

        # act
        instance = OpenThesaurusWeb()
        synonyms = instance.get_synonyms(word=word)

        # assert
        self.assertFalse(synonyms)
示例#4
0
    def test_get_synonyms_empty_wrong_input_word(self):
        # arrange
        word = ''

        # act
        instance = OpenThesaurusWeb()
        synonyms = instance.get_synonyms(word=word)

        # assert
        self.assertFalse(synonyms)
示例#5
0
    def test_get_synonyms_empty_no_word_in_dictionary(self):
        # arrange
        word = 'Taking'

        # act
        instance = OpenThesaurusWeb()
        synonyms = instance.get_synonyms(word=word)

        # assert
        self.assertFalse(synonyms)
示例#6
0
    def test_get_synonyms_short_not_empty(self):
        # arrange
        word = 'gehen'

        # act
        instance = OpenThesaurusWeb()
        synonyms = instance.get_synonyms(word=word)

        # assert
        self.assertTrue(synonyms)
示例#7
0
    def test_runtime_error_wrong_type(self):
        # arrange
        word = 'München'

        # act
        instance = OpenThesaurusWeb()
        synonyms = instance.get_synonyms(word=word, form='sadsa')

        # assert
        self.assertRaises(RuntimeError)
        self.assertFalse(synonyms)