Beispiel #1
0
    def test_generate_phrases_with_length_limit(self):
        sentences = [
            "Red apples, are good in flavour.",
            "Keywords, which we define as a sequence of one or more words, "
            + "provide a compact representation of a document's content",
            "Criteria of compatibility of a system of linear Diophantine "
            + "equations",
            "whose gloomy beams transfigured the village into a lunar "
            + "encampment of glowing houses and streets of volcanic deserts "
            + "every fifteen seconds ",
        ]

        # Consider phrases which have minimum of 2 words and max of 4
        r = Rake(min_length=2, max_length=4)
        phrase_list = {
            ("red", "apples"),
            ("compact", "representation"),
            ("linear", "diophantine", "equations"),
            ("whose", "gloomy", "beams", "transfigured"),
            ("lunar", "encampment"),
            ("glowing", "houses"),
        }
        self.assertEqual(r._generate_phrases(sentences), phrase_list)

        # Consider phrases which have minimum of 5 words and max of 5
        r = Rake(min_length=5, max_length=5)
        phrase_list = {("volcanic", "deserts", "every", "fifteen", "seconds")}
        self.assertEqual(r._generate_phrases(sentences), phrase_list)
Beispiel #2
0
def test_generate_phrases_with_length_limit():
    sentences = [
        'Red apples, are good in flavour.',
        'Keywords, which we define as a sequence of one or more words, ' +
        "provide a compact representation of a document's content",
        'Criteria of compatibility of a system of linear Diophantine ' +
        'equations',
        'whose gloomy beams transfigured the village into a lunar ' +
        'encampment of glowing houses and streets of volcanic deserts ' +
        'every fifteen seconds ',
    ]

    # Consider phrases which have minimum of 2 words and max of 4
    r = Rake(min_length=2, max_length=4)
    phrase_list = [
        ('red', 'apples'),
        ('compact', 'representation'),
        ('linear', 'diophantine', 'equations'),
        ('whose', 'gloomy', 'beams', 'transfigured'),
        ('lunar', 'encampment'),
        ('glowing', 'houses'),
    ]
    assert r._generate_phrases(sentences) == phrase_list

    # Consider phrases which have minimum of 5 words and max of 5
    r = Rake(min_length=5, max_length=5)
    phrase_list = [('volcanic', 'deserts', 'every', 'fifteen', 'seconds')]
    assert r._generate_phrases(sentences) == phrase_list
Beispiel #3
0
def test_allow_repeated_phrases():
    sentences = [
        'Magic systems is a company.', 'Magic systems was built in a garage'
    ]
    expected_phrase_list_with_repetitions = [
        (
            'magic',
            'systems',
        ),
        ('company', ),
        ('magic', 'systems'),
        ('built', ),
        ('garage', ),
    ]
    expected_phrase_list_without_repetitions = [
        (
            'magic',
            'systems',
        ),
        ('company', ),
        ('built', ),
        ('garage', ),
    ]

    r = Rake()
    assert r._generate_phrases(
        sentences) == expected_phrase_list_with_repetitions

    r = Rake(include_repeated_phrases=True)
    assert r._generate_phrases(
        sentences) == expected_phrase_list_with_repetitions

    r = Rake(include_repeated_phrases=False)
    assert r._generate_phrases(
        sentences) == expected_phrase_list_without_repetitions
Beispiel #4
0
    def test_generate_phrases(self):
        r = Rake()

        sentences = [
            'Red apples, are good in flavour.',
            'Keywords, which we define as a sequence of one or more words, ' +
            'provide a compact representation of a document\'s content'
        ]
        phrase_list = {('red', 'apples'), ('good', ), ('flavour', ),
                       ('keywords', ), ('define', ), ('sequence', ), ('one', ),
                       ('words', ), ('provide', ),
                       ('compact', 'representation'), ('document', ),
                       ('content', )}
        self.assertEqual(r._generate_phrases(sentences), phrase_list)
Beispiel #5
0
    def test_generate_phrases(self):
        r = Rake()

        sentences = [
            "Red apples, are good in flavour.",
            "Keywords, which we define as a sequence of one or more words, "
            + "provide a compact representation of a document's content",
            "Criteria of compatibility of a system of linear Diophantine "
            + "equations",
            "whose gloomy beams transfigured the village into a lunar "
            + "encampment of glowing houses and streets of volcanic deserts "
            + "every fifteen seconds ",
        ]
        phrase_list = {
            ("red", "apples"),
            ("good",),
            ("flavour",),
            ("keywords",),
            ("define",),
            ("sequence",),
            ("one",),
            ("words",),
            ("provide",),
            ("compact", "representation"),
            ("document",),
            ("content",),
            ("criteria",),
            ("compatibility",),
            ("system",),
            ("linear", "diophantine", "equations"),
            ("whose", "gloomy", "beams", "transfigured"),
            ("volcanic", "deserts", "every", "fifteen", "seconds"),
            ("lunar", "encampment"),
            ("glowing", "houses"),
            ("village",),
            ("streets",),
        }
        self.assertEqual(r._generate_phrases(sentences), phrase_list)
Beispiel #6
0
def test_generate_phrases():
    r = Rake()

    sentences = [
        'Red apples, are good in flavour.',
        'Keywords, which we define as a sequence of one or more words, ' +
        "provide a compact representation of a document's content",
        'Criteria of compatibility of a system of linear Diophantine ' +
        'equations',
        'whose gloomy beams transfigured the village into a lunar ' +
        'encampment of glowing houses and streets of volcanic deserts ' +
        'every fifteen seconds ',
    ]
    phrase_list = [
        ('red', 'apples'),
        ('good', ),
        ('flavour', ),
        ('keywords', ),
        ('define', ),
        ('sequence', ),
        ('one', ),
        ('words', ),
        ('provide', ),
        ('compact', 'representation'),
        ('document', ),
        ('content', ),
        ('criteria', ),
        ('compatibility', ),
        ('system', ),
        ('linear', 'diophantine', 'equations'),
        ('whose', 'gloomy', 'beams', 'transfigured'),
        ('village', ),
        ('lunar', 'encampment'),
        ('glowing', 'houses'),
        ('streets', ),
        ('volcanic', 'deserts', 'every', 'fifteen', 'seconds'),
    ]
    assert r._generate_phrases(sentences) == phrase_list
Beispiel #7
0
if os.path.exists("downloads"):
    shutil.rmtree("downloads")
if os.path.exists("final_save"):
    shutil.rmtree("final_save")


r = Rake(min_length=1, max_length=1) # Uses stopwords for english from NLTK, and all punctuation characters.

text = input("Hello!\nI will find images for your keywords and translate your sentence(s) for you.\nTo look up an image for every word, seperate with periods.\n\nWrite your sentence(s) below please:\n")
lang = input("\nWhat language do you want to translate the sentence(s) to?\n")

translator= Translator(from_lang="english",to_lang=lang)

text_sentences=list(text.split("."))

usr=r._generate_phrases(text_sentences)

print(usr)

response = google_images_download.googleimagesdownload()  

search_queries = (usr)
  
  
# download the images using the key words
def downloadimages(query,picture_counter): 
    # keywords is the search query 
    # format is the image file format 
    # limit is the number of images to be downloaded 
    # print urls is to print the image file url 
    # size is the image size which can