Java Code Examples for java.util.TreeMap#containsValue()

The following examples show how to use java.util.TreeMap#containsValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Classifier.java    From LAML with Apache License 2.0 6 votes vote down vote up
/**
 * Get an ID to integer label mapping array. IDs start from 0.
 * 
 * @param labels any integer array holding the original
 *               integer labels
 *               
 * @return ID to integer label mapping array
 * 
 */
public static int[] getIDLabelMap(int[] labels) {
	TreeMap<Integer, Integer> IDLabelMap = new TreeMap<Integer, Integer>();
	int ID = 0;
	int label = -1;
	for (int i = 0; i < labels.length; i++) {
		label = labels[i];
		if (!IDLabelMap.containsValue(label)) {
			IDLabelMap.put(ID++, label);
		}
	}
	int nClass = IDLabelMap.size();
	int[] IDLabelArray = new int[nClass];
	for (int idx : IDLabelMap.keySet()) {
		IDLabelArray[idx] = IDLabelMap.get(idx);
	}
	return IDLabelArray;
}
 
Example 2
Source File: EntropyChunker.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
/** Returns a sorted map of candidate delimiters for a given string and a given
 * n-gram size.
 *@param sStr The string to analyse to identify the candidate delimiters.
 *@param iNGramSize The n-gram size of the delimiters to extract.
 *@return The sorted map of delimiters, sorted by their entropy of next character.
 */
private final SortedMap identifyCandidateDelimiters(String sStr, int iNGramSize) {
    String sSubStr = null;
    Integer[] iRes = null;
    ArrayList alRes = new ArrayList();
    TreeMap tmRes = new TreeMap();
    
    for (int iCnt = 0; iCnt <= sStr.length() - iNGramSize; iCnt++) {
        if (iCnt + iNGramSize > sStr.length())
            continue;
        // Get n-gram
        sSubStr = sStr.substring(iCnt, iCnt + iNGramSize);
        if (tmRes.containsValue(sSubStr))   // Ignore duplicates
            continue;
        
        // Look-up current n-gram
        Vertex vStrNode = clLocator.locateVertexInGraph(sgOverallGraph, new VertexImpl(sSubStr));
        if (vStrNode == null)
            continue; // Ignore inexistent symbols
        // double dNormEntropy = getEntropyOfNextChar(sSubStr, true);
        double dEntropy = getEntropyOfNextChar(sSubStr, false);
        // tmRes.put(dNormEntropy, sSubStr);
        tmRes.put(dEntropy, sSubStr);
        
    }
    
    return tmRes;
}
 
Example 3
Source File: NGramCorrelationForm.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
private TreeMap identifyCandidateDelimiters(String sStr, int iNGramSize) {
    String sSubStr;
    Integer[] iRes;
    ArrayList alRes = new ArrayList();
    TreeMap tmRes = new TreeMap();
    
    for (int iCnt = 0; iCnt <= sStr.length() - iNGramSize; iCnt++) {
        if (iCnt + iNGramSize > sStr.length())
            continue;
        // Get n-gram
        sSubStr = sStr.substring(iCnt, iCnt + iNGramSize);
        if (tmRes.containsValue(sSubStr))   // Ignore duplicates
            continue;
        
        // Look-up current n-gram
        Vertex vStrNode = gr.demokritos.iit.jinsect.utils.locateVertexInGraph(sgOverallGraph, sSubStr);
        if (vStrNode == null)
            continue; // Ignore inexistent symbols
        // double dNormEntropy = getEntropyOfNextChar(sSubStr, true);
        double dEntropy = getEntropyOfNextChar(sSubStr, false);
        // tmRes.put(dNormEntropy, sSubStr);
        tmRes.put(dEntropy, sSubStr);
            
    }
    
    return tmRes;
}
 
Example 4
Source File: EntropyChunker.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
/** Returns a sorted map of candidate delimiters for a given string and a given
 * n-gram size.
 *@param sStr The string to analyse to identify the candidate delimiters.
 *@param iNGramSize The n-gram size of the delimiters to extract.
 *@return The sorted map of delimiters, sorted by their entropy of next character.
 */
private final SortedMap identifyCandidateDelimiters(String sStr, int iNGramSize) {
    String sSubStr = null;
    Integer[] iRes = null;
    ArrayList alRes = new ArrayList();
    TreeMap tmRes = new TreeMap();
    
    for (int iCnt = 0; iCnt <= sStr.length() - iNGramSize; iCnt++) {
        if (iCnt + iNGramSize > sStr.length())
            continue;
        // Get n-gram
        sSubStr = sStr.substring(iCnt, iCnt + iNGramSize);
        if (tmRes.containsValue(sSubStr))   // Ignore duplicates
            continue;
        
        // Look-up current n-gram
        Vertex vStrNode = clLocator.locateVertexInGraph(sgOverallGraph, new VertexImpl(sSubStr));
        if (vStrNode == null)
            continue; // Ignore inexistent symbols
        // double dNormEntropy = getEntropyOfNextChar(sSubStr, true);
        double dEntropy = getEntropyOfNextChar(sSubStr, false);
        // tmRes.put(dNormEntropy, sSubStr);
        tmRes.put(dEntropy, sSubStr);
        
    }
    
    return tmRes;
}
 
Example 5
Source File: NGramCorrelationForm.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
private TreeMap identifyCandidateDelimiters(String sStr, int iNGramSize) {
    String sSubStr;
    Integer[] iRes;
    ArrayList alRes = new ArrayList();
    TreeMap tmRes = new TreeMap();
    
    for (int iCnt = 0; iCnt <= sStr.length() - iNGramSize; iCnt++) {
        if (iCnt + iNGramSize > sStr.length())
            continue;
        // Get n-gram
        sSubStr = sStr.substring(iCnt, iCnt + iNGramSize);
        if (tmRes.containsValue(sSubStr))   // Ignore duplicates
            continue;
        
        // Look-up current n-gram
        Vertex vStrNode = gr.demokritos.iit.jinsect.utils.locateVertexInGraph(sgOverallGraph, sSubStr);
        if (vStrNode == null)
            continue; // Ignore inexistent symbols
        // double dNormEntropy = getEntropyOfNextChar(sSubStr, true);
        double dEntropy = getEntropyOfNextChar(sSubStr, false);
        // tmRes.put(dNormEntropy, sSubStr);
        tmRes.put(dEntropy, sSubStr);
            
    }
    
    return tmRes;
}
 
Example 6
Source File: AdeConfigPropertiesImpl.java    From ade with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SortedMap<String, String> create(String propVal) {
    final String[] parts = propVal.trim().split(",");
    final TreeMap<String, String> res = new TreeMap<String, String>();

    if (parts == null || parts.length == 0) {
        return res;
    }
    for (String part : parts) {
        String src;
        String dst;
        if (part.contains("->")) {
            final String[] pp = part.split("->");
            if (pp.length != MAX_PP_LENGTH) {
                throw new InvalidParameterException("Invalid usage of -> in result mapping \"" + part + "\"");
            }
            src = pp[0];
            dst = pp[1];
        } else {
            src = dst = part;
        }
        if (src == null || src.length() == 0 || dst == null || dst.length() == 0) {
            throw new InvalidParameterException("Invalding result mapping \"" + part + "\"");
        }
        if (res.containsKey(src) || res.containsValue(dst)) {
            throw new InvalidParameterException("Duplicate mapping \"" + part + "\"");
        }
        res.put(src, dst);
    }
    return res;
}
 
Example 7
Source File: Classifier.java    From LAML with Apache License 2.0 5 votes vote down vote up
/**
 * Infer the number of classes from a given label sequence.
 * 
 * @param labels any integer array holding the original
 *               integer labels
 *               
 * @return number of classes
 * 
 */
public static int calcNumClass(int[] labels) {
	TreeMap<Integer, Integer> IDLabelMap = new TreeMap<Integer, Integer>();
	int ID = 0;
	int label = -1;
	for (int i = 0; i < labels.length; i++) {
		label = labels[i];
		if (!IDLabelMap.containsValue(label)) {
			IDLabelMap.put(ID++, label);
		}
	}
	int nClass = IDLabelMap.size();
	return nClass;
}
 
Example 8
Source File: SectionCursorAdapter.java    From SectionCursorAdapter with Apache License 2.0 5 votes vote down vote up
/**
 * @param cursor a non-null cursor at position -1.
 * @return A map whose keys are the position at which a section is and values are an object
 * which will be passed to newSectionView and bindSectionView
 */
protected SortedMap<Integer, Object> buildSections(Cursor cursor) {
    TreeMap<Integer, Object> sections = new TreeMap<Integer, Object>();
    int cursorPosition = 0;
    while (hasOpenCursor() && cursor.moveToNext()) {
        Object section = getSectionFromCursor(cursor);
        if (cursor.getPosition() != cursorPosition)
            throw new IllegalStateException("Do no move the cursor's position in getSectionFromCursor.");
        if (!sections.containsValue(section))
            sections.put(cursorPosition + sections.size(), section);
        cursorPosition++;
    }
    return sections;
}