本文整理汇总了Java中edu.stanford.nlp.util.CollectionUtils.sorted方法的典型用法代码示例。如果您正苦于以下问题:Java CollectionUtils.sorted方法的具体用法?Java CollectionUtils.sorted怎么用?Java CollectionUtils.sorted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.util.CollectionUtils
的用法示例。
在下文中一共展示了CollectionUtils.sorted方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hIndex
import edu.stanford.nlp.util.CollectionUtils; //导入方法依赖的package包/类
/**
* Calculate h-Index (Hirsch, 2005) of an author.
*
* A scientist has index h if h of their Np papers have at least h citations each,
* and the other (Np − h) papers have at most h citations each.
*
* @param citationCounts Citation counts for each of the articles written by the
* author. The keys can be anything, but the values should
* be integers.
* @return The h-Index of the author.
*/
public static <E> int hIndex(Counter<E> citationCounts) {
Counter<Integer> countCounts = new ClassicCounter<Integer>();
for (double value: citationCounts.values()) {
for (int i = 0; i <= value; ++i) {
countCounts.incrementCount(i);
}
}
List<Integer> citationCountValues = CollectionUtils.sorted(countCounts.keySet());
Collections.reverse(citationCountValues);
for (int citationCount: citationCountValues) {
double occurrences = countCounts.getCount(citationCount);
if (occurrences >= citationCount) {
return citationCount;
}
}
return 0;
}
示例2: hIndex
import edu.stanford.nlp.util.CollectionUtils; //导入方法依赖的package包/类
/**
* Calculate h-Index (Hirsch, 2005) of an author.
*
* A scientist has index h if h of their Np papers have at least h citations
* each, and the other (Np − h) papers have at most h citations each.
*
* @param citationCounts
* Citation counts for each of the articles written by the author.
* The keys can be anything, but the values should be integers.
* @return The h-Index of the author.
*/
public static <E> int hIndex(Counter<E> citationCounts) {
Counter<Integer> countCounts = new ClassicCounter<Integer>();
for (double value : citationCounts.values()) {
for (int i = 0; i <= value; ++i) {
countCounts.incrementCount(i);
}
}
List<Integer> citationCountValues = CollectionUtils.sorted(countCounts.keySet());
Collections.reverse(citationCountValues);
for (int citationCount : citationCountValues) {
double occurrences = countCounts.getCount(citationCount);
if (occurrences >= citationCount) {
return citationCount;
}
}
return 0;
}
示例3: toStringSorted
import edu.stanford.nlp.util.CollectionUtils; //导入方法依赖的package包/类
/**
* Write the features in text order.
*/
public String toStringSorted() {
StringBuffer sb = new StringBuffer(_docSource + "\t" + _relation.toString());
for (String key : CollectionUtils.sorted(_featureCounts.keySet())) {
sb.append("\t");
sb.append(key);
// sb.append("\t");
// sb.append((int)_featureCounts.getCount(key));
}
// sb.append(Counters.toSortedByKeysString(_featureCounts, "%1$s %2$f", "\t", "HAPPY"));
return sb.toString();
}
示例4: toSortedByKeysString
import edu.stanford.nlp.util.CollectionUtils; //导入方法依赖的package包/类
/**
* Returns a string representation of a Counter, where (key, value) pairs are
* sorted by key, and formatted as specified.
*
* @param counter The Counter.
* @param itemFormat The format string for key/count pairs, where the key is
* first and the value is second. To display the value first,
* use argument indices, e.g. "%2$f %1$s".
* @param joiner The string used between pairs of key/value strings.
* @param wrapperFormat The format string for wrapping text around the joined items,
* where the joined item string value is "%s".
* @return The Counter, formatted as specified.
*/
public static <T extends Comparable<T>> String toSortedByKeysString(
Counter<T> counter, String itemFormat, String joiner, String wrapperFormat) {
List<String> strings = new ArrayList<String>();
for (T key: CollectionUtils.sorted(counter.keySet())) {
strings.add(String.format(itemFormat, key, counter.getCount(key)));
}
return String.format(wrapperFormat, StringUtils.join(strings, joiner));
}
示例5: toSortedByKeysString
import edu.stanford.nlp.util.CollectionUtils; //导入方法依赖的package包/类
/**
* Returns a string representation of a Counter, where (key, value) pairs are
* sorted by key, and formatted as specified.
*
* @param counter
* The Counter.
* @param itemFormat
* The format string for key/count pairs, where the key is first and
* the value is second. To display the value first, use argument
* indices, e.g. "%2$f %1$s".
* @param joiner
* The string used between pairs of key/value strings.
* @param wrapperFormat
* The format string for wrapping text around the joined items, where
* the joined item string value is "%s".
* @return The Counter, formatted as specified.
*/
public static <T extends Comparable<T>> String toSortedByKeysString(Counter<T> counter, String itemFormat, String joiner, String wrapperFormat) {
List<String> strings = new ArrayList<String>();
for (T key : CollectionUtils.sorted(counter.keySet())) {
strings.add(String.format(itemFormat, key, counter.getCount(key)));
}
return String.format(wrapperFormat, StringUtils.join(strings, joiner));
}