#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Count the number of emojis in a tweet

Created on Mon Oct 11 19:01:20 2021

@author: laura
"""

from code.feature_extraction.feature_extractor import FeatureExtractor
import emoji
import numpy as np

class EmojiCount(FeatureExtractor):
    """Class for extracting the number of emojis within a tweet"""
    
    # constructor
    def __init__(self, input_column):
        """Initialize EmojiCount with the given input and output column."""
        
        super().__init__([input_column], "{0}_emojicount".format(input_column))
        
    # don't need to fit, so don't overwrite _set_variables()
    
    def _get_values(self, inputs):
        """Compute the number of emojis in the tweet"""
        
        emoji_count = []
        for tweet in inputs[0]:
            # extract the emojis from the tweet
            extracted_emojis = ''.join(character for character in tweet if character in emoji.UNICODE_EMOJI['en'])
            # count how many emojis were extracted
            count = len(extracted_emojis)
            # save the number of emojis in list emoji_count
            emoji_count.append(count)
            
        result = np.array(emoji_count).reshape(-1, 1)
        return result
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Count the number of emojis in a tweet

Created on Mon Oct 11 19:01:20 2021

@author: laura
"""

from code.feature_extraction.feature_extractor import FeatureExtractor
import emoji
import numpy as np

class EmojiCount(FeatureExtractor):
    """Class for extracting the number of emojis within a tweet"""
    
    # constructor
    def __init__(self, input_column):
        """Initialize EmojiCount with the given input and output column."""
        
        super().__init__([input_column], "{0}_emojicount".format(input_column))
        
    # don't need to fit, so don't overwrite _set_variables()
    
    def _get_values(self, inputs):
        """Compute the number of emojis in the tweet"""
        
        emoji_count = []
        for tweet in inputs[0]:
            # extract the emojis from the tweet
            extracted_emojis = ''.join(character for character in tweet if character in emoji.UNICODE_EMOJI['en'])
            # count how many emojis were extracted
            count = len(extracted_emojis)
            # save the number of emojis in list emoji_count
            emoji_count.append(count)
            
        result = np.array(emoji_count).reshape(-1, 1)
        return result
#!/usr/bin/env python3 # -*- coding: utf-8 -*- Count the number of emojis in a tweet  Created on Mon Oct 11 19:01:20 2021  @author: laura Class for extracting the number of emojis within a tweet # constructor Initialize EmojiCount with the given input and output column. # don't need to fit, so don't overwrite _set_variables() Compute the number of emojis in the tweet # extract the emojis from the tweet # count how many emojis were extracted # save the number of emojis in list emoji_count