當前位置: 首頁>>代碼示例>>Java>>正文


Java StartPosBasedComparator類代碼示例

本文整理匯總了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());
}
 
開發者ID:dice-group,項目名稱:BENGAL,代碼行數:15,代碼來源:ParaphraserImplTest.java

示例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);
}
 
開發者ID:dice-group,項目名稱:gerbil,代碼行數:12,代碼來源:SpanMergingEvaluatorDecoratorTest.java

示例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();
}
 
開發者ID:dice-group,項目名稱:gerbil,代碼行數:42,代碼來源:AgdistisAnnotator.java

示例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();
}
 
開發者ID:dice-group,項目名稱:AGDISTIS,代碼行數:43,代碼來源:NIFParser.java


注:本文中的org.aksw.gerbil.transfer.nif.data.StartPosBasedComparator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。