Я пытаюсь определить частоту эмодзи и слов. После импорта библиотек
import emoji
import regex
я использовал следующую функцию, чтобы подсчитать, сколько смайликов и слов в текстах.
def split_count(text):
emoji_counter = 0
data = regex.findall(r'\X', text)
for word in data:
if any(char in emoji.UNICODE_EMOJI for char in word):
emoji_counter += 1
# Remove from the given text the emojis
text = text.replace(word, '')
words_counter = len(text.split())
return emoji_counter, words_counter
Приведенный выше код был предложен в качестве ответа другому пользователю в этом сообществе. Поскольку у меня есть список строк, мне нужно было бы l oop через них:
sent=["I know it's possible to match a word and then reverse the matches using other tools (e.g. grep -v)?. However, is it possible to match lines that do not contain a specific word, e.g. hede, using a regular expression?","?I'm trying to iterate over the words of a string. The string can be assumed to be composed of words separated by whitespace?. Note that I'm not interested in C string functions or that kind of character manipulation/access?","I currently have a list of words within a text file, all the words within the document are on a separate line.?",...]
Я пробовал следующее:
for line in sent:
counter = split_count(line)
print("Emojis - {}, Words - {}".format(counter[0], counter[1]))
он работает довольно хорошо, но Я не умею отображать эти результаты (смайлики и слова) в двух отдельных диаграммах (гистограммах), где по оси Y - частота, а по оси X - метка для каждого текста (например, первого слова). Я надеюсь в вашу помощь и советы.