本文整理匯總了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();
}