本文整理了Java中opennlp.tools.util.Span.length()
方法的一些代码示例,展示了Span.length()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Span.length()
方法的具体详情如下:
包路径:opennlp.tools.util.Span
类名称:Span
方法名:length
[英]Returns the length of this span.
[中]返回此跨度的长度。
代码示例来源:origin: apache/opennlp
if (i - start > 0) {
Span span = new Span(start, i).trim(s);
if (span.length() > 0) {
sentences.add(span);
if (span.length() > 0) {
sentences.add(span);
代码示例来源:origin: apache/opennlp
public Span[] find(String[] textTokenized) {
List<Span> namesFound = new LinkedList<>();
for (int offsetFrom = 0; offsetFrom < textTokenized.length; offsetFrom++) {
Span nameFound = null;
String[] tokensSearching;
for (int offsetTo = offsetFrom; offsetTo < textTokenized.length; offsetTo++) {
int lengthSearching = offsetTo - offsetFrom + 1;
if (lengthSearching > mDictionary.getMaxTokenCount()) {
break;
} else {
tokensSearching = new String[lengthSearching];
System.arraycopy(textTokenized, offsetFrom, tokensSearching, 0,
lengthSearching);
StringList entryForSearch = new StringList(tokensSearching);
if (mDictionary.contains(entryForSearch)) {
nameFound = new Span(offsetFrom, offsetTo + 1, type);
}
}
}
if (nameFound != null) {
namesFound.add(nameFound);
// skip over the found tokens for the next search
offsetFrom += nameFound.length() - 1;
}
}
return namesFound.toArray(new Span[namesFound.size()]);
}
代码示例来源:origin: apache/opennlp
/**
* Returns an array of probabilities for each of the specified spans which is
* the arithmetic mean of the probabilities for each of the outcomes which
* make up the span.
*
* @param spans The spans of the names for which probabilities are desired.
*
* @return an array of probabilities for each of the specified spans.
*/
public double[] probs(Span[] spans) {
double[] sprobs = new double[spans.length];
double[] probs = bestSequence.getProbs();
for (int si = 0; si < spans.length; si++) {
double p = 0;
for (int oi = spans[si].getStart(); oi < spans[si].getEnd(); oi++) {
p += probs[oi];
}
p /= spans[si].length();
sprobs[si] = p;
}
return sprobs;
}
代码示例来源:origin: apache/opennlp
if (span.length() > 0) {
spans[si] = span;
if (span.length() > 0) {
spans[spans.length - 1] = span;
sentProbs.add(1d);
代码示例来源:origin: apache/opennlp
/**
* Test for {@link Span#length()}.
*/
@Test
public void testLength() {
Assert.assertEquals(11, new Span(10, 21).length());
}
代码示例来源:origin: apache/opennlp
@Test
public void testCaseLongerEntry() {
String[] sentence = {"a", "b", "michael", "jordan"};
Span[] names = mNameFinder.find(sentence);
Assert.assertTrue(names.length == 1);
Assert.assertTrue(names[0].length() == 2);
}
}
代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.commons.opennlp
public int getSize(){
return chunkSpan.length();
}
/**
代码示例来源:origin: apache/stanbol
public int getSize(){
return chunkSpan.length();
}
/**
代码示例来源:origin: apache/opennlp
String[] toks = sample.getSentence();
for (Span name : names) {
String[] nameToks = new String[name.length()];
System.arraycopy(toks, name.getStart(), nameToks, 0, name.length());
entries.add(nameToks);
代码示例来源:origin: apache/opennlp
if (name.length() > 1) {
if (name.getType() == null) {
outcomes[name.getStart()] = "default" + "-" + BilouCodec.START;
代码示例来源:origin: ai.idylnlp/idylnlp-opennlp-tools-1.8.3
if (i - start > 0) {
Span span = new Span(start, i).trim(s);
if (span.length() > 0) {
sentences.add(span);
if (span.length() > 0) {
sentences.add(span);
代码示例来源:origin: org.apache.opennlp/opennlp-tools
if (i - start > 0) {
Span span = new Span(start, i).trim(s);
if (span.length() > 0) {
sentences.add(span);
if (span.length() > 0) {
sentences.add(span);
代码示例来源:origin: eus.ixa/ixa-pipe-pos
offsetFrom += multiwordFound.length() - 1;
代码示例来源:origin: org.apache.opennlp/opennlp-tools
public Span[] find(String[] textTokenized) {
List<Span> namesFound = new LinkedList<>();
for (int offsetFrom = 0; offsetFrom < textTokenized.length; offsetFrom++) {
Span nameFound = null;
String[] tokensSearching;
for (int offsetTo = offsetFrom; offsetTo < textTokenized.length; offsetTo++) {
int lengthSearching = offsetTo - offsetFrom + 1;
if (lengthSearching > mDictionary.getMaxTokenCount()) {
break;
} else {
tokensSearching = new String[lengthSearching];
System.arraycopy(textTokenized, offsetFrom, tokensSearching, 0,
lengthSearching);
StringList entryForSearch = new StringList(tokensSearching);
if (mDictionary.contains(entryForSearch)) {
nameFound = new Span(offsetFrom, offsetTo + 1, type);
}
}
}
if (nameFound != null) {
namesFound.add(nameFound);
// skip over the found tokens for the next search
offsetFrom += nameFound.length() - 1;
}
}
return namesFound.toArray(new Span[namesFound.size()]);
}
代码示例来源:origin: ai.idylnlp/idylnlp-opennlp-tools-1.8.3
public Span[] find(String[] textTokenized) {
List<Span> namesFound = new LinkedList<>();
for (int offsetFrom = 0; offsetFrom < textTokenized.length; offsetFrom++) {
Span nameFound = null;
String[] tokensSearching;
for (int offsetTo = offsetFrom; offsetTo < textTokenized.length; offsetTo++) {
int lengthSearching = offsetTo - offsetFrom + 1;
if (lengthSearching > mDictionary.getMaxTokenCount()) {
break;
} else {
tokensSearching = new String[lengthSearching];
System.arraycopy(textTokenized, offsetFrom, tokensSearching, 0,
lengthSearching);
StringList entryForSearch = new StringList(tokensSearching);
if (mDictionary.contains(entryForSearch)) {
nameFound = new Span(offsetFrom, offsetTo + 1, type);
}
}
}
if (nameFound != null) {
namesFound.add(nameFound);
// skip over the found tokens for the next search
offsetFrom += nameFound.length() - 1;
}
}
return namesFound.toArray(new Span[namesFound.size()]);
}
代码示例来源:origin: org.cogroo/cogroo-ann
public static List<Token> groupTokens(String text, List<Token> toks,
List<? extends Span> spans, String additionalContext) {
for (int i = spans.size() - 1; i >= 0; i--) {
Span span = spans.get(i);
if (span.length() > 0) {
int s = toks.get(span.getStart()).getStart();
int e = toks.get(span.getEnd() - 1).getEnd();
String lexeme = text.substring(s, e).replace(" ", "_");
List<Token> removeToks = new ArrayList<Token>();
for (int j = span.getEnd() - 1; j >= span.getStart(); j--) {
removeToks.add(toks.remove(j));
}
Token t = new TokenImpl(s, e, lexeme);
t.setPOSTag(span.getType());
// if(additionalContext != null) {
// t.addContext(analyzer, additionalContext);
// t.setAdditionalContext(additionalContext);
// }
toks.add(span.getStart(), t);
}
}
return toks;
}
代码示例来源:origin: cogroo/cogroo4
public static List<Token> groupTokens(String text, List<Token> toks,
List<? extends Span> spans, String additionalContext) {
for (int i = spans.size() - 1; i >= 0; i--) {
Span span = spans.get(i);
if (span.length() > 0) {
int s = toks.get(span.getStart()).getStart();
int e = toks.get(span.getEnd() - 1).getEnd();
String lexeme = text.substring(s, e).replace(" ", "_");
List<Token> removeToks = new ArrayList<Token>();
for (int j = span.getEnd() - 1; j >= span.getStart(); j--) {
removeToks.add(toks.remove(j));
}
Token t = new TokenImpl(s, e, lexeme);
t.setPOSTag(span.getType());
// if(additionalContext != null) {
// t.addContext(analyzer, additionalContext);
// t.setAdditionalContext(additionalContext);
// }
toks.add(span.getStart(), t);
}
}
return toks;
}
代码示例来源:origin: org.apache.opennlp/opennlp-tools
/**
* Returns an array of probabilities for each of the specified spans which is
* the arithmetic mean of the probabilities for each of the outcomes which
* make up the span.
*
* @param spans The spans of the names for which probabilities are desired.
*
* @return an array of probabilities for each of the specified spans.
*/
public double[] probs(Span[] spans) {
double[] sprobs = new double[spans.length];
double[] probs = bestSequence.getProbs();
for (int si = 0; si < spans.length; si++) {
double p = 0;
for (int oi = spans[si].getStart(); oi < spans[si].getEnd(); oi++) {
p += probs[oi];
}
p /= spans[si].length();
sprobs[si] = p;
}
return sprobs;
}
代码示例来源:origin: ai.idylnlp/idylnlp-opennlp-tools-1.8.3
/**
* Returns an array of probabilities for each of the specified spans which is
* the arithmetic mean of the probabilities for each of the outcomes which
* make up the span.
*
* @param spans The spans of the names for which probabilities are desired.
*
* @return an array of probabilities for each of the specified spans.
*/
public double[] probs(Span[] spans) {
double[] sprobs = new double[spans.length];
double[] probs = bestSequence.getProbs();
for (int si = 0; si < spans.length; si++) {
double p = 0;
for (int oi = spans[si].getStart(); oi < spans[si].getEnd(); oi++) {
p += probs[oi];
}
p /= spans[si].length();
sprobs[si] = p;
}
return sprobs;
}
代码示例来源:origin: org.apache.opennlp/opennlp-tools
if (name.length() > 1) {
if (name.getType() == null) {
outcomes[name.getStart()] = "default" + "-" + BilouCodec.START;
内容来源于网络,如有侵权,请联系作者删除!