本文整理汇总了Java中edu.stanford.nlp.util.ArrayUtils类的典型用法代码示例。如果您正苦于以下问题:Java ArrayUtils类的具体用法?Java ArrayUtils怎么用?Java ArrayUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArrayUtils类属于edu.stanford.nlp.util包,在下文中一共展示了ArrayUtils类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: expandByAlias
import edu.stanford.nlp.util.ArrayUtils; //导入依赖的package包/类
public List<EntityLexicalEntry> expandByAlias(String query, int topk) {
List<EntityLexicalEntry> res= new ArrayList<>();
query = query.toUpperCase();
List<EntityInfo> entityInfos = entityAlias.getEntityInfo(query, topk);
if (entityInfos == null)
return res;
for (EntityInfo info:entityInfos) {
String[] fbDescriptions = new String[1];
fbDescriptions[0] = info.name;
Formula formula = Formula.fromString(info.id);
String ID = info.id;
int IDLevel = 0;
if (opts.useIDLevel && ID.startsWith("fb:en"))
IDLevel = 1;
Set<String> types = new HashSet<>();
if (opts.domainLimit) {
for (String token: info.types) {
if (validDomain(token)) {
types.add(token);
}
}
} else {
Collections.addAll(types, info.types);
}
double popularity = info.popularity;
int distance = 0;
Counter<String> tokenEditDistanceFeatures = TokenLevelMatchFeatures.extractFeatures(query.toLowerCase(), fbDescriptions[0]);
res.add(new EntityLexicalEntry(query.toLowerCase(), query.toLowerCase(), ArrayUtils.asSet(fbDescriptions), formula, EntrySource.ENTITYALIAS, popularity, distance, types, tokenEditDistanceFeatures, IDLevel));
}
return res;
}
开发者ID:cgraywang,项目名称:TextHIN,代码行数:33,代码来源:EntityLexicon.java
示例2: getMangledTree
import edu.stanford.nlp.util.ArrayUtils; //导入依赖的package包/类
private Tree getMangledTree(Tree t) {
Collocation matchingColl = null;
for (Tree child : t.children()) {
child = getMangledTree(child);
}
//boolean additionalCollocationsExist = false;
for (Collocation c : collocationCollector) {
// if there are multiple collocations with the same parent node,
// this will take the longer one
if (t.equals(c.parentNode)) {
if (matchingColl == null ||
(c.span.first() <= matchingColl.span.first() &&
c.span.second() >= matchingColl.span.second())) {
matchingColl = c;
if (DEBUG) {
err.println("Found matching collocation for tree:");
t.pennPrint();
err.print(" head label: " + c.headLabel);
err.println("; collocation string: " + c.collocationString);
err.println(" Constituents: "+ c.indicesOfConstituentChildren);
}
}
}
}
if (matchingColl == null) {
return t;
} else {
if (DEBUG) {
err.println("Collapsing " + matchingColl);
}
Tree[] allChildren = t.children();
// get the earliest child in the collocation and store it as first child.
// delete the rest.
StringBuffer mutatedString = new StringBuffer(160);
for (int i : matchingColl.indicesOfConstituentChildren) {
String strToAppend = mergeLeavesIntoCollocatedString(allChildren[i]);
mutatedString.append(strToAppend);
mutatedString.append("_");
}
mutatedString = mutatedString.deleteCharAt(mutatedString.length() - 1);
// Starting with the latest constituent, delete all the "pruned" children
if (DEBUG) { err.println("allChildren is: " + Arrays.toString(allChildren)); }
for (int index = matchingColl.indicesOfConstituentChildren.size() - 1; index > 0; index--) {
int thisConstituent = matchingColl.indicesOfConstituentChildren.get(index);
allChildren = (Tree[]) ArrayUtils.removeAt(allChildren, thisConstituent);
if (DEBUG) { err.println(" deleted " + thisConstituent + "; allChildren is: " + Arrays.toString(allChildren)); }
}
//name for the leaf string of our new collocation
String newNodeString = mutatedString.toString();
int firstChildIndex = matchingColl.indicesOfConstituentChildren.get(0);
//now we mutate the earliest constituent
Tree newCollocationChild = allChildren[firstChildIndex];
if (DEBUG) err.println("Manipulating: " + newCollocationChild);
newCollocationChild.setValue(matchingColl.headLabel.value());
Tree newCollocationLeaf = newCollocationChild.treeFactory().newLeaf(newNodeString);
newCollocationChild.setChildren(Collections.singletonList(newCollocationLeaf));
if (DEBUG) err.println(" changed to: " + newCollocationChild);
allChildren[firstChildIndex] = newCollocationChild;
t.setChildren(allChildren);
if (DEBUG) {
err.println("Restructured tree is:");
t.pennPrint();
err.println();
}
return t;
}
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:73,代码来源:CollocationFinder.java
示例3: valueOf
import edu.stanford.nlp.util.ArrayUtils; //导入依赖的package包/类
/** Make a clique over the provided relativeIndices.
* relativeIndices should be sorted. */
public static Clique valueOf(int[] relativeIndices) {
checkSorted(relativeIndices);
// copy the array so as to be safe
return valueOfHelper(ArrayUtils.copy(relativeIndices));
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:8,代码来源:Clique.java
示例4: calculateProbs
import edu.stanford.nlp.util.ArrayUtils; //导入依赖的package包/类
/** calculateProbs puts log probs of taggings in the probabilities array.
*
* @param probabilities Array with indices sent size, k best size, numTags
*/
protected void calculateProbs(double[][][] probabilities) {
ArrayUtils.fill(probabilities, Double.NEGATIVE_INFINITY);
for (int hyp = 0; hyp < kBestSize; hyp++) {
// put the whole thing in pairs, give its beginning and end
pairs.setSize(size);
for (int i = 0; i < size; i++) {
pairs.setWord(i,sent.get(i));
pairs.setTag(i,finalTags[i]);
//pairs.add(new WordTag(sent.get(i),finalTags[i]));
// TODO: if kBestSize > 1, use KBestSequenceFinder and save
// k-best hypotheses into finalTags:
//pairs.setTag(i,finalTags[i]);
}
int start = endSizePairs;
int end = endSizePairs + size - 1;
endSizePairs = endSizePairs + size;
// iterate over the sentence
for (int current = 0; current < size; current++) {
History h = new History(start, end, current + start, pairs, maxentTagger.extractors);
String[] tags = stringTagsAt(h.current - h.start + leftWindow());
double[] probs = getHistories(tags, h);
ArrayMath.logNormalize(probs);
// System.err.println("word: " + pairs.getWord(current));
// System.err.println("tags: " + Arrays.asList(tags));
// System.err.println("probs: " + ArrayMath.toString(probs));
for (int j = 0; j < tags.length; j++) {
// score the j-th tag
String tag = tags[j];
boolean approximate = maxentTagger.defaultScore > 0.0;
int tagindex = approximate ? maxentTagger.tags.getIndex(tag) : j;
// System.err.println("Mapped from j="+ j + " " + tag + " to " + tagindex);
probabilities[current][hyp][tagindex] = probs[j];
}
} // for current
} // for hyp
// clean up the stuff in PairsHolder (added by cdm in Aug 2008)
revert(0);
}
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:45,代码来源:TestSentence.java
示例5: calculateProbs
import edu.stanford.nlp.util.ArrayUtils; //导入依赖的package包/类
/** calculateProbs puts log probs of taggings in the probabilities array.
*
* @param probabilities Array with indices sent size, k best size, numTags
*/
protected void calculateProbs(double[][][] probabilities) {
ArrayUtils.fill(probabilities, Double.NEGATIVE_INFINITY);
for (int hyp = 0; hyp < kBestSize; hyp++) {
// put the whole thing in pairs, give its beginning and end
pairs.setSize(size);
for (int i = 0; i < size; i++) {
pairs.setWord(i,sent.get(i));
pairs.setTag(i,finalTags[i]);
//pairs.add(new WordTag(sent.get(i),finalTags[i]));
// TODO: if kBestSize > 1, use KBestSequenceFinder and save
// k-best hypotheses into finalTags:
//pairs.setTag(i,finalTags[i]);
}
int start = endSizePairs;
int end = endSizePairs + size - 1;
endSizePairs = endSizePairs + size;
// iterate over the sentence
for (int current = 0; current < size; current++) {
History h = new History(start, end, current + start, pairs, maxentTagger.extractors);
String[] tags = stringTagsAt(h.current - h.start + leftWindow());
double[] probs = getHistories(tags, h);
ArrayMath.logNormalize(probs);
// System.err.println("word: " + pairs.getWord(current));
// System.err.println("tags: " + Arrays.asList(tags));
// System.err.println("probs: " + ArrayMath.toString(probs));
for (int j = 0; j < tags.length; j++) {
// score the j-th tag
String tag = tags[j];
boolean approximate = maxentTagger.hasApproximateScoring();
int tagindex = approximate ? maxentTagger.tags.getIndex(tag) : j;
// System.err.println("Mapped from j="+ j + " " + tag + " to " + tagindex);
probabilities[current][hyp][tagindex] = probs[j];
}
} // for current
} // for hyp
// clean up the stuff in PairsHolder (added by cdm in Aug 2008)
revert(0);
}
开发者ID:jaimeguzman,项目名称:data_mining,代码行数:45,代码来源:TestSentence.java
注:本文中的edu.stanford.nlp.util.ArrayUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论