本文整理了Java中opennlp.tools.util.Span.toString()
方法的一些代码示例,展示了Span.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Span.toString()
方法的具体详情如下:
包路径:opennlp.tools.util.Span
类名称:Span
方法名:toString
[英]Generates a human readable string.
[中]生成人类可读的字符串。
代码示例来源:origin: apache/opennlp
/**
* Retrieves the string covered by the current span of the specified text.
*
* @param text
*
* @return the substring covered by the current span
*/
public CharSequence getCoveredText(CharSequence text) {
if (getEnd() > text.length()) {
throw new IllegalArgumentException("The span " + toString()
+ " is outside the given text which has length " + text.length() + "!");
}
return text.subSequence(getStart(), getEnd());
}
代码示例来源:origin: apache/opennlp
/**
* Initializes the current instance.
*
* @param text the text which contains the tokens.
* @param tokenSpans the spans which mark the begin and end of the tokens.
*/
public TokenSample(String text, Span[] tokenSpans) {
Objects.requireNonNull(tokenSpans, "tokenSpans must not be null");
this.text = Objects.requireNonNull(text, "text must not be null");
this.tokenSpans = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(tokenSpans)));
for (Span tokenSpan : tokenSpans) {
if (tokenSpan.getStart() < 0 || tokenSpan.getStart() > text.length() ||
tokenSpan.getEnd() > text.length() || tokenSpan.getEnd() < 0) {
throw new IllegalArgumentException("Span " + tokenSpan.toString() +
" is out of bounds, text length: " + text.length() + "!");
}
}
}
代码示例来源:origin: apache/opennlp
/**
* Test for {@link Span#toString()}.
*/
@Test
public void testToString() {
Assert.assertEquals("[50..100)", new Span(50, 100).toString());
Assert.assertEquals("[50..100) myType", new Span(50, 100, "myType").toString());
}
代码示例来源:origin: stackoverflow.com
for(Span s: nameSpans){
String a = s.toString().replace("[", "").replace(")", "");
String[] b = a.split("\\s");
String[] c = b[0].split("\\..");
int first = Integer.parseInt(c[0]);
int second = Integer.parseInt(c[1]);
String[] word = input.split("\\s");
int n;
for(n=first;n<second;n++){
names.add(word[n]);
System.out.println(word[n]);
}
}
代码示例来源:origin: ai.idylnlp/idylnlp-opennlp-tools-1.8.3
/**
* Retrieves the string covered by the current span of the specified text.
*
* @param text
*
* @return the substring covered by the current span
*/
public CharSequence getCoveredText(CharSequence text) {
if (getEnd() > text.length()) {
throw new IllegalArgumentException("The span " + toString()
+ " is outside the given text which has length " + text.length() + "!");
}
return text.subSequence(getStart(), getEnd());
}
代码示例来源:origin: org.apache.opennlp/opennlp-tools
/**
* Retrieves the string covered by the current span of the specified text.
*
* @param text
*
* @return the substring covered by the current span
*/
public CharSequence getCoveredText(CharSequence text) {
if (getEnd() > text.length()) {
throw new IllegalArgumentException("The span " + toString()
+ " is outside the given text which has length " + text.length() + "!");
}
return text.subSequence(getStart(), getEnd());
}
代码示例来源:origin: org.apache.opennlp/opennlp-tools
/**
* Initializes the current instance.
*
* @param text the text which contains the tokens.
* @param tokenSpans the spans which mark the begin and end of the tokens.
*/
public TokenSample(String text, Span[] tokenSpans) {
Objects.requireNonNull(tokenSpans, "tokenSpans must not be null");
this.text = Objects.requireNonNull(text, "text must not be null");
this.tokenSpans = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(tokenSpans)));
for (Span tokenSpan : tokenSpans) {
if (tokenSpan.getStart() < 0 || tokenSpan.getStart() > text.length() ||
tokenSpan.getEnd() > text.length() || tokenSpan.getEnd() < 0) {
throw new IllegalArgumentException("Span " + tokenSpan.toString() +
" is out of bounds, text length: " + text.length() + "!");
}
}
}
代码示例来源:origin: ai.idylnlp/idylnlp-opennlp-tools-1.8.3
/**
* Initializes the current instance.
*
* @param text the text which contains the tokens.
* @param tokenSpans the spans which mark the begin and end of the tokens.
*/
public TokenSample(String text, Span[] tokenSpans) {
Objects.requireNonNull(tokenSpans, "tokenSpans must not be null");
this.text = Objects.requireNonNull(text, "text must not be null");
this.tokenSpans = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(tokenSpans)));
for (Span tokenSpan : tokenSpans) {
if (tokenSpan.getStart() < 0 || tokenSpan.getStart() > text.length() ||
tokenSpan.getEnd() > text.length() || tokenSpan.getEnd() < 0) {
throw new IllegalArgumentException("Span " + tokenSpan.toString() +
" is out of bounds, text length: " + text.length() + "!");
}
}
}
代码示例来源:origin: stackoverflow.com
for(Span s: nameSpans)
System.out.print(s.toString());
System.out.print(" ");
for(int index = s.getStart();index < s.getEnd();index++)
代码示例来源:origin: Texera/texera
System.out.println(s.toString());
for(int i = s.getStart(); i < s.getEnd(); i++) {
代码示例来源:origin: armenak/DataDefender
log.debug("Span: " + nameSpans[i].toString());
log.debug("Covered text is: " + tokens[nameSpans[i].getStart()]);
log.debug("Probability is: " + spanProbs[i]);
代码示例来源:origin: armenak/DataDefender
final String span = nameSpans[i].toString();
内容来源于网络,如有侵权,请联系作者删除!