如何将表情符号插入词云?

时间:2019-05-06 16:55:09

标签: python-3.x emoji word-cloud

我有表情符号图像列表。我想生成这些表情符号的词云。类似于:https://twitter.com/mattlingard/status/1019351150607421440

如何生成,需要帮助吗?基于文本的词云的python代码如下:

insertVideo() {
  var filestream;
  var reader  = new FileReader();

  // Gets Blob data from the video url
  this.galleryService.getVideo(this.videoUrl)
    .subscribe(data => {
      reader.readAsDataURL(data);
  });

  reader.onloadend = function () {
    filestream = reader.result;

    gapi.client.youtube.videos
      .insert({
        part: 'snippet,status',
        resource : {
          snippet: {
            title: 'Test video',
            description: 'Testing the YouTube API',
          },
          status: {
            privacyStatus: 'private'
          }
        },

      }, filestream) // This is where it's supposed to be?
      .then(response => {
        console.log(response);
      })
      .catch(err => console.log(err));
  }
}

运行以下代码行以调用上面的generate_wordcloud函数。

from wordcloud import WordCloud, STOPWORDS
from PIL import Image
import urllib
import requests
import numpy as np
import matplotlib.pyplot as plt

words = 'access guest guest apartment area area bathroom bed bed bed bed bed 
bedroom block coffee coffee coffee coffee entrance entry francisco free 
garden guest home house kettle kettle kitchen kitchen kitchen kitchen 
kitchen kitchenliving located microwave neighborhood new park parking place 
privacy private queen room san separate seperate shared space space space 
street suite time welcome'

mask = np.array(Image.open(requests.get(
'http://www.clker.com/cliparts/O/i/x/Y/q/P/yellow-house-hi.png', 
stream=True).raw))

# This function takes in your text and your mask and generates a wordcloud. 
def generate_wordcloud(words, mask):
    word_cloud = WordCloud(width = 512, height = 512, 
    background_color='white', stopwords=STOPWORDS, 
    mask=mask).generate(words)
    plt.figure(figsize=(10,8),facecolor = 'white', edgecolor='blue')
    plt.imshow(word_cloud)
    plt.axis('off')
    plt.tight_layout(pad=0)
    plt.show()

对于表情符号,我得到以下链接:      https://github.com/amueller/word_cloud/commit/ae3b133be7156e37de852eaedecd2f3add32a2cd

需要下载:symbola.ttf

休息,我不知道如何解决这个问题

0 个答案:

没有答案