word_processing.py 文件源码

python
阅读 43 收藏 0 点赞 0 评论 0

项目:Hacker_News_Article_Topics 作者: reeddunkle 项目源码 文件源码
def display_collocations(articles):
    '''
    Given list of article tuples (title, text, url), generates and
    PRINTS collocations (no return).
    '''

    def clear_screen():
        os.system('cls' if os.name == 'nt' else 'clear')

    total = len(articles)

    for i, article in enumerate(articles):

        title, text, url = article
        article_number = i + 1

        if title != '':

            try:
                clear_screen()

                colls = generate_collocations(text)

                print("Article {}/{}".format(article_number, total))
                print('---------------')
                print("{}\n".format(title))
                print("Link: {}\n".format(url))
                print("Topics:")



                output = ""
                for tup in colls:
                    word1, word2 = tup
                    output += "{} {}; ".format(word1, word2)

                print(output[:-2])
                print('---------------\n')

                print("Press ENTER for next article or any key to exit.")
                user_input = raw_input("> ")
                if user_input:
                    exit(0)

            except TypeError:
                continue

        else:
            continue

        clear_screen()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号