How to use the ngram.write_to_file function in ngram

To help you get started, we’ve selected a few ngram examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stanfordnlp / cocoa / src / analysis / negotiation / get_data_statistics.py View on Github external
if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    top_ngrams_by_agent = []
    for agent_type in args.agent_types:
        grouped_utterances = grouping_fn(transcripts, agent_type)
        analyzer = ngram.NgramAnalyzer(grouped_utterances, n=n, agent_type=agent_type)

        top_ngrams_by_cat = analyzer.analyze()
        top_ngrams_by_agent.append(top_ngrams_by_cat)

    ngram.plot_top_ngrams(top_ngrams_by_agent, agents=args.agent_types,
                          output_dir=output_dir,
                          suffix="_{:d}grams".format(n))
    ngram.write_to_file(top_ngrams_by_agent, agents=args.agent_types,
                        output_dir=output_dir,
                        suffix="_{:d}grams".format(n))