本文整理汇总了Java中edu.stanford.nlp.util.CollectionUtils类的典型用法代码示例。如果您正苦于以下问题:Java CollectionUtils类的具体用法?Java CollectionUtils怎么用?Java CollectionUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CollectionUtils类属于edu.stanford.nlp.util包,在下文中一共展示了CollectionUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getMergedList
import edu.stanford.nlp.util.CollectionUtils; //导入依赖的package包/类
public List<CoreMap> getMergedList(int... groups)
{
List<CoreMap> res = new ArrayList<CoreMap>();
int last = 0;
List<Integer> orderedGroups = CollectionUtils.asList(groups);
Collections.sort(orderedGroups);
for (int group:orderedGroups) {
int groupStart = start(group);
if (groupStart >= last) {
res.addAll(elements.subList(last,groupStart));
int groupEnd = end(group);
if (groupEnd - groupStart >= 1) {
CoreMap merged = createMergedChunk(groupStart, groupEnd);
res.add(merged);
last = groupEnd;
}
}
}
res.addAll(elements.subList(last, elements.size()));
return res;
}
示例4: 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();
}
示例5: getConnectedComponents
import edu.stanford.nlp.util.CollectionUtils; //导入依赖的package包/类
public static <V, E> List<Set<V>> getConnectedComponents(DirectedMultiGraph<V, E> graph) {
List<Set<V>> ccs = new ArrayList<Set<V>>();
LinkedList<V> todo = new LinkedList<V>();
// TODO: why not a set?
List<V> verticesLeft = CollectionUtils.toList(graph.getAllVertices());
while (verticesLeft.size() > 0) {
todo.add(verticesLeft.get(0));
verticesLeft.remove(0);
ccs.add(bfs(todo, graph, verticesLeft));
}
return ccs;
}
示例6: maxInPlace
import edu.stanford.nlp.util.CollectionUtils; //导入依赖的package包/类
/**
* Places the maximum of first and second keys values in the first counter.
* @param <E>
*/
public static <E> void maxInPlace(Counter<E> target, Counter<E> other) {
for(E e: CollectionUtils.union(other.keySet(), target.keySet())){
target.setCount(e, Math.max(target.getCount(e), other.getCount(e)));
}
}
示例7: minInPlace
import edu.stanford.nlp.util.CollectionUtils; //导入依赖的package包/类
/**
* Places the minimum of first and second keys values in the first counter.
* @param <E>
*/
public static <E> void minInPlace(Counter<E> target, Counter<E> other){
for(E e: CollectionUtils.union(other.keySet(), target.keySet())){
target.setCount(e, Math.min(target.getCount(e), other.getCount(e)));
}
}
示例8: ExplicitTemporalSet
import edu.stanford.nlp.util.CollectionUtils; //导入依赖的package包/类
public ExplicitTemporalSet(Temporal... temporals) {
this.temporals = CollectionUtils.asSet(temporals);
}
示例9: AttributesEqualMatchChecker
import edu.stanford.nlp.util.CollectionUtils; //导入依赖的package包/类
public AttributesEqualMatchChecker(Class... classes) {
keys = CollectionUtils.asSet(classes);
}
示例10: apply
import edu.stanford.nlp.util.CollectionUtils; //导入依赖的package包/类
public SequenceMatchResult<CoreMap> apply(SequenceMatchResult<CoreMap> matchResult, int... groups)
{
BasicSequenceMatchResult<CoreMap> res = matchResult.toBasicSequenceMatchResult();
List<? extends CoreMap> elements = matchResult.elements();
List<CoreMap> mergedElements = new ArrayList<CoreMap>();
res.elements = mergedElements;
int last = 0;
int mergedGroup = 0;
int offset = 0;
List<Integer> orderedGroups = CollectionUtils.asList(groups);
Collections.sort(orderedGroups);
for (int group:orderedGroups) {
int groupStart = matchResult.start(group);
if (groupStart >= last) {
// Add elements from last to start of group to merged elements
mergedElements.addAll(elements.subList(last,groupStart));
// Fiddle with matched group indices
for (; mergedGroup < group; mergedGroup++) {
if (res.matchedGroups[mergedGroup] != null) {
res.matchedGroups[mergedGroup].matchBegin -= offset;
res.matchedGroups[mergedGroup].matchEnd -= offset;
}
}
// Get merged element
int groupEnd = matchResult.end(group);
if (groupEnd - groupStart >= 1) {
CoreMap merged = aggregator.merge(elements, groupStart, groupEnd);
mergedElements.add(merged);
last = groupEnd;
// Fiddle with matched group indices
res.matchedGroups[mergedGroup].matchBegin = mergedElements.size()-1;
res.matchedGroups[mergedGroup].matchEnd = mergedElements.size();
mergedGroup++;
while (mergedGroup < res.matchedGroups.length) {
if (res.matchedGroups[mergedGroup] != null) {
if (res.matchedGroups[mergedGroup].matchBegin == matchResult.start(group) &&
res.matchedGroups[mergedGroup].matchEnd == matchResult.end(group)) {
res.matchedGroups[mergedGroup].matchBegin = res.matchedGroups[group].matchBegin;
res.matchedGroups[mergedGroup].matchEnd = res.matchedGroups[group].matchEnd;
} else if (res.matchedGroups[mergedGroup].matchEnd <= matchResult.end(group)) {
res.matchedGroups[mergedGroup] = null;
} else {
break;
}
}
mergedGroup++;
}
offset = matchResult.end(group) - res.matchedGroups[group].matchEnd;
}
}
}
// Add rest of elements
mergedElements.addAll(elements.subList(last, elements.size()));
// Fiddle with matched group indices
for (; mergedGroup < res.matchedGroups.length; mergedGroup++) {
if (res.matchedGroups[mergedGroup] != null) {
res.matchedGroups[mergedGroup].matchBegin -= offset;
res.matchedGroups[mergedGroup].matchEnd -= offset;
}
}
return res;
}
示例11: getOutgoingEdges
import edu.stanford.nlp.util.CollectionUtils; //导入依赖的package包/类
public List<E> getOutgoingEdges(V v) {
return CollectionUtils.flatten(outgoingEdges.get(v).values());
}
示例12: getIncomingEdges
import edu.stanford.nlp.util.CollectionUtils; //导入依赖的package包/类
public List<E> getIncomingEdges(V v) {
return CollectionUtils.flatten(incomingEdges.get(v).values());
}
示例13: 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));
}
示例14: 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));
}
示例15: compareArrays
import edu.stanford.nlp.util.CollectionUtils; //导入依赖的package包/类
/**
* Provides a consistent ordering over arrays. First compares by the
* first element. If that element is equal, the next element is
* considered, and so on. This is the array version of
* {@link edu.stanford.nlp.util.CollectionUtils#compareLists}
* and uses the same logic when the arrays are of different lengths.
*/
public static <T extends Comparable<T>> int compareArrays(T[] first, T[] second) {
List<T> firstAsList = Arrays.asList(first);
List<T> secondAsList = Arrays.asList(second);
return CollectionUtils.compareLists(firstAsList, secondAsList);
}