Example #1
0
def comment_analyse(bv):
    url = 'https://www.bilibili.com/video/' + bv
    comments = get_comment(url)
    title = get_video_info(bv)['data']['title']
    comment_words = get_words(comments)
    comment_words_img_url, word_counts_top10 = word_cloud(comment_words, title)
    return render_template('comment_analyse.html', url=url, title='分析',
                           comment_words_img_url=comment_words_img_url,
                           word_counts_top10=word_counts_top10, video_title=title,bv=bv)
Example #2
0
def bullet_analyse(bv):
    url = 'https://www.bilibili.com/video/' + bv
    bullets = get_bullet_chat(url)
    title = get_video_info(bv)['data']['title']
    bullet_words = get_words(bullets)
    bullet_words_img_url, word_counts_top10 = word_cloud(bullet_words, title)
    bullets_img_url, bullet_counts_top10 = word_cloud(bullets, title)
    return render_template('bullet_analyse.html', url=url, title='分析',
                           bullet_words_img_url=bullet_words_img_url,
                           word_counts_top10=word_counts_top10, bullet_counts_top10=bullet_counts_top10,
                           bullets_img_url=bullets_img_url, video_title=title,bv=bv)
Example #3
0
def get_rhymes(word):
    word = prepare_string(word).strip()
    assert type(word) == str
    assert len(word) >= 1
    words = get_words()

    rhymes = []
    max_ending_size = min(4, len(word))
    max_ending = word[-max_ending_size:]
    smaller_ending_size = max(1, max_ending_size - 1)
    smaller_ending = word[-smaller_ending_size:]
    for candidate_word in words:
        candidate_word_lower = prepare_string(candidate_word)
        if candidate_word_lower == word:
            # Discard, because we don't want to include the search word in the results
            continue

        if candidate_word_lower.endswith(smaller_ending):
            rhyme = {"word": candidate_word, "score": 100}

            if candidate_word_lower.endswith(max_ending):
                rhyme["score"] *= 2

            if candidate_word.lower().endswith(word):
                rhyme["score"] *= 0.3

            rhymes.append(rhyme)

    rhymes.sort(key=lambda rhyme: rhyme["score"], reverse=True)

    # Limit the number of words in the result
    rhymes = rhymes[0:500]

    for rhyme in rhymes:
        rhyme["num_syllables"] = count_syllables(rhyme["word"])
        if rhyme["word"][0] == rhyme["word"][0].upper():
            # If the first letter is uppercase, it's probably an "egennamn". In that
            # case, we link to Wikipedia
            rhyme["url"] = "https://no.wikipedia.org/wiki/" + quote(
                rhyme["word"])
        else:
            rhyme["url"] = ("https://ordbok.uib.no/perl/ordbok.cgi?OPP=" +
                            quote(rhyme["word"]) +
                            "&ant_nynorsk=5&nynorsk=+&ordbok=nynorsk")

    return rhymes
Example #4
0
def get_random_word():
    words = get_words()
    chosen_word = random.choice(words)
    return chosen_word
 def test_get_words(self):
     words = get_words()
     self.assertGreater(len(words), 400000)