本文整理汇总了Java中org.aksw.gerbil.transfer.nif.data.StartPosBasedComparator类的典型用法代码示例。如果您正苦于以下问题:Java StartPosBasedComparator类的具体用法?Java StartPosBasedComparator怎么用?Java StartPosBasedComparator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StartPosBasedComparator类属于org.aksw.gerbil.transfer.nif.data包,在下文中一共展示了StartPosBasedComparator类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.aksw.gerbil.transfer.nif.data.StartPosBasedComparator; //导入依赖的package包/类
@Test
public void test() {
ParaphraserImpl paraphraser = new ParaphraserImpl(this);
Document newDocument = paraphraser.getParaphrase(document);
Assert.assertEquals(expectedDocument.getDocumentURI(), newDocument.getDocumentURI());
Assert.assertEquals(expectedDocument.getText(), newDocument.getText());
StartPosBasedComparator comparator = new StartPosBasedComparator();
List<NamedEntity> expectedNes = expectedDocument.getMarkings(NamedEntity.class);
List<NamedEntity> nes = newDocument.getMarkings(NamedEntity.class);
Collections.sort(expectedNes, comparator);
Collections.sort(nes, comparator);
Assert.assertArrayEquals(nes.toArray(), expectedNes.toArray());
}
示例2: test
import org.aksw.gerbil.transfer.nif.data.StartPosBasedComparator; //导入依赖的package包/类
@Test
public void test() {
SpanMergingEvaluatorDecorator<Span> merger = new SpanMergingEvaluatorDecorator<>(null);
markings = merger.merge(markings);
Span results[] = markings.toArray(new Span[markings.size()]);
StartPosBasedComparator comparator = new StartPosBasedComparator();
Arrays.sort(results, comparator);
Arrays.sort(expectedMarkings, comparator);
Assert.assertArrayEquals(expectedMarkings, results);
}
示例3: createTextWithMentions
import org.aksw.gerbil.transfer.nif.data.StartPosBasedComparator; //导入依赖的package包/类
static String createTextWithMentions(String text, List<Span> mentions) {
// Example: 'The <entity>University of Leipzig</entity> in
// <entity>Barack Obama</entity>.'
Collections.sort(mentions, new StartPosBasedComparator());
StringBuilder textBuilder = new StringBuilder();
int lastPos = 0;
for (int i = 0; i < mentions.size(); i++) {
Span span = mentions.get(i);
int begin = span.getStartPosition();
int end = begin + span.getLength();
if (begin < lastPos) {
// we have two overlapping mentions --> take the larger one
Span prev = mentions.get(i - 1);
LOGGER.warn("\"{}\" at pos {} overlaps with \"{}\" at pos {}",
text.substring(span.getStartPosition(), span.getStartPosition() + span.getLength()),
span.getStartPosition(),
text.substring(prev.getStartPosition(), prev.getStartPosition() + prev.getLength()),
prev.getStartPosition());
if (span.getLength() > prev.getLength()) {
// current is larger --> replace previous with current
textBuilder.delete(textBuilder.length() - prev.getLength(), textBuilder.length());
lastPos -= prev.getLength();
} else
// previous is larger or equal --> skip current
continue;
}
String before = text.substring(lastPos, begin);
String label = text.substring(begin, end);
lastPos = end;
textBuilder.append(before).append("<entity>" + label + "</entity>");
}
String lastSnippet = text.substring(lastPos, text.length());
textBuilder.append(lastSnippet);
return textBuilder.toString();
}
示例4: createTextWithMentions
import org.aksw.gerbil.transfer.nif.data.StartPosBasedComparator; //导入依赖的package包/类
public String createTextWithMentions(String text, List<Span> mentions) {
// Example: 'The <entity>University of Leipzig</entity> in
// <entity>Barack Obama</entity>.'
Collections.sort(mentions, new StartPosBasedComparator());
StringBuilder textBuilder = new StringBuilder();
int lastPos = 0;
for (int i = 0; i < mentions.size(); i++) {
Span span = mentions.get(i);
int begin = span.getStartPosition();
int end = begin + span.getLength();
if (begin < lastPos) {
// we have two overlapping mentions --> take the larger one
Span prev = mentions.get(i - 1);
LOGGER.warn("\"{}\" at pos {} overlaps with \"{}\" at pos {}",
text.substring(span.getStartPosition(), span.getStartPosition() + span.getLength()),
span.getStartPosition(),
text.substring(prev.getStartPosition(), prev.getStartPosition() + prev.getLength()),
prev.getStartPosition());
if (span.getLength() > prev.getLength()) {
// current is larger --> replace previous with current
textBuilder.delete(textBuilder.length() - prev.getLength(), textBuilder.length());
lastPos -= prev.getLength();
} else // previous is larger or equal --> skip current
{
continue;
}
}
String before = text.substring(lastPos, begin);
String label = text.substring(begin, end);
lastPos = end;
textBuilder.append(before).append("<entity>" + label + "</entity>");
}
String lastSnippet = text.substring(lastPos, text.length());
textBuilder.append(lastSnippet);
return textBuilder.toString();
}