当前位置: 首页>>代码示例>>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;未经允许,请勿转载。