Ejemplo n.º 1
0
def main(args):
    '''
    The main function that takes input sentence as parameter and
    visualize the scene based on the input.

    :param args:
    :return:
    '''
    # Tokenize the input sentence to Main_Noun, Dependent_Noun, and Preposition
    failed = "FAILED"
    word_dict = InputSentenceTokenizer.tokenize(args[1])
    if word_dict == failed:
        return failed

    # Create a dictionary with wordnet id for noun objects
    nouns = [word_dict.get('Dependent_Noun'), word_dict.get('Main_Noun')]
    word_net_id_dict = WordNetIdGetter.get_word_net_ids(nouns)
    for key, value in word_net_id_dict.items():
        if not value:
            print(failed)
            return failed

    # Fetch images of the noun objects
    ImageFetcher.fetchImages(word_net_id_dict)

    # Randomly pick images to generate an image that describes the input sentence
    image_path_list_to_process = []
    image_path = getRandomImagePath(
        word_net_id_dict.get(word_dict.get('Main_Noun')))
    image_path_list_to_process.append(image_path)
    image_path = getRandomImagePath(
        word_net_id_dict.get(word_dict.get('Dependent_Noun')))
    image_path_list_to_process.append(image_path)

    # Generate the image
    processed_image_path_list = ImageProcessor.process_images(
        image_path_list_to_process)
    created_image_path = ImageProcessor.generateImage(
        processed_image_path_list, word_dict.get('Preposition'))
    if created_image_path:
        print(created_image_path)
        return created_image_path
    else:
        print(failed)
        return failed
Ejemplo n.º 2
0
 def processImages(self,sourceSite,images,maxFetch,perEmailLimit):
     '''
     This function processes the image locations, building the actual files and calling for email
     '''
     overallCount = 1
     attachmentList = []
     emailCount = 0
     for image in images:
         if overallCount <= maxFetch or maxFetch == -1:
             imageLocation = ImageFetcher.tidyUpFileLocationForSite(image,sourceSite)
             picture = ImageFetcher.fetchFile(imageLocation)
             if picture:
                 name = 'image'+str(overallCount)+ImageFetcher.getExtension(image)
                 pictureAndName = (name,picture)
                 attachmentList.append(pictureAndName)
                 overallCount += 1
                 emailCount += 1
                 if emailCount == perEmailLimit:
                     ResultsPage.sendMail(self,attachmentList)
                     attachmentList = []
                     emailCount = 0
Ejemplo n.º 3
0
 def post(self):
     '''
     A rather bland page that just lets the user know the email is on its way.
     '''
     sourceSite = ""+cgi.escape(self.request.get('SourceSite'))
     if not sourceSite.startswith('http://'):
         sourceSite = 'http://'+sourceSite
     try:
         limit = int(""+self.request.get('MaxFetchSize'))
     except ValueError:
         limit = -1
     try:
         attachSize = int(""+self.request.get('AttachSize'))
     except ValueError:
         attachSize = 5
         
     source = ImageFetcher.returnSource(sourceSite)
     images = ImageFetcher.findImages(source)
     ResultsPage.processImages(self,sourceSite,images,limit,attachSize)
     self.response.out.write('<html><body>Your images are being collected, and will be emailed to you momentarily.  Please wait...')
     self.response.out.write('</body></html>')