下面列出了java.util.TreeMap#containsValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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;
}
/** 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;
}
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;
}
/** 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;
}
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;
}
@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;
}
/**
* 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;
}
/**
* @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;
}