All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hankcs.hanlp.classification.collections.FrequencyMap Maven / Gradle / Ivy

There is a newer version: portable-1.8.5
Show newest version
/*
 * 
 * He Han
 * [email protected]
 * 16/2/13 PM3:48
 *
 * 
 * Copyright (c) 2008-2016, 码农场. All Right Reserved, http://www.hankcs.com/
 * This source is subject to Hankcs. Please contact Hankcs to get more information.
 * 
 */
package com.hankcs.hanlp.classification.collections;

import java.util.TreeMap;

/**
 * 统计词频的Map
 * @author hankcs
 */
public class FrequencyMap extends TreeMap
{
    /**
     * 增加一个词的词频
     * @param key
     * @return
     */
    public int add(K key)
    {
        int[] f = get(key);
        if (f == null)
        {
            f = new int[]{1};
            put(key, f);
        }
        else ++f[0];

        return f[0];
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy