当前位置: 首页>>代码示例>>Java>>正文


Java Span类代码示例

本文整理汇总了Java中org.aksw.gerbil.transfer.nif.Span的典型用法代码示例。如果您正苦于以下问题:Java Span类的具体用法?Java Span怎么用?Java Span使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Span类属于org.aksw.gerbil.transfer.nif包,在下文中一共展示了Span类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTextWithSpans

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
protected String createTextWithSpans(Document document) {
    String text = document.getText();
    List<Span> spans = document.getMarkings(Span.class);
    Collections.sort(spans, spanComparator);
    int pos = 0;
    StringBuilder textBuilder = new StringBuilder();
    for (Span span : spans) {
        textBuilder.append(text.substring(pos, span.getStartPosition()));
        textBuilder.append("[[");
        pos = span.getStartPosition() + span.getLength();
        textBuilder.append(text.substring(span.getStartPosition(), pos));
        textBuilder.append("]]");
    }
    if (pos < text.length()) {
        textBuilder.append(text.substring(pos, text.length()));
    }
    return textBuilder.toString();
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:19,代码来源:AidaAnnotator.java

示例2: performRecognition

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
protected static List<Span> performRecognition(SingleInstanceSecuringAnnotatorDecorator decorator, Document document)
        throws GerbilException {
    List<Span> result = null;
    try {
        decorator.semaphore.acquire();
    } catch (InterruptedException e) {
        LOGGER.error("Interrupted while waiting for the Annotator's semaphore.", e);
        throw new GerbilException("Interrupted while waiting for the Annotator's semaphore.", e,
                ErrorTypes.UNEXPECTED_EXCEPTION);
    }
    try {
        result = ((EntityRecognizer) decorator.getDecoratedAnnotator()).performRecognition(document);
    } finally {
        decorator.semaphore.release();
    }
    return result;
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:18,代码来源:SingleInstanceSecuringAnnotatorDecorator.java

示例3: performRecognition

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
protected static List<Span> performRecognition(ErrorCountingAnnotatorDecorator errorCounter, Document document)
        throws GerbilException {
    List<Span> result = null;
    try {
        result = ((EntityRecognizer) errorCounter.getDecoratedAnnotator()).performRecognition(document);
    } catch (Exception e) {
        if (errorCounter.getErrorCount() == 0) {
            // Log only the first exception completely
            LOGGER.error("Got an Exception from the annotator (" + errorCounter.getName() + ")", e);
        } else {
            // Log only the Exception message without the stack trace
            LOGGER.error("Got an Exception from the annotator (" + errorCounter.getName() + "): "
                    + e.getLocalizedMessage());
        }
        errorCounter.increaseErrorCount();
        return new ArrayList<Span>(0);
    }
    if (printDebugMsg && LOGGER.isDebugEnabled()) {
        logResult(result, errorCounter.getName(), "Span");
    }
    return result;
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:23,代码来源:ErrorCountingAnnotatorDecorator.java

示例4: test

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
@Test
public void test() {
    ScoredMatchingsCounterImpl<Span> counterImpl = new ScoredMatchingsCounterImpl<Span>(
            new MatchingsCounterImpl<Span>(new WeakSpanMatchingsSearcher<Span>()));
    ScoredEvaluationCounts counts[] = counterImpl.countMatchings(Arrays.asList(annotatorResult),
            Arrays.asList(goldStandard));
    int expectedCounts[];
    for (int i = 0; i < counts.length; ++i) {
        Assert.assertTrue("Didn't expected the threshold " + counts[i].confidenceThreshould + ".",
                expectedResults.containsKey(counts[i].confidenceThreshould));
        expectedCounts = expectedResults.get(counts[i].confidenceThreshould);
        Assert.assertEquals(expectedCounts[TRUE_POSITIVE_COUNT_ID], counts[i].truePositives);
        Assert.assertEquals(expectedCounts[FALSE_POSITIVE_COUNT_ID], counts[i].falsePositives);
        Assert.assertEquals(expectedCounts[FALSE_NEGATIVE_COUNT_ID], counts[i].falseNegatives);
    }
    Assert.assertEquals(expectedResults.size(), counts.length);
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:18,代码来源:ScoredMatchingsCounterImplTest.java

示例5: replaceText

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
/**
 * This method replaces the part with the given start position and the given
 * length inside the text of the given document with the given replacement.
 * It updates the positions of markings that occur in the text behind the
 * replaced part. <b>Note</b> that this method does not take care of
 * markings that overlap with the replaced part!
 * 
 * @param document
 *            the document that should be updated
 * @param start
 *            the start position of the part that should be replaced
 * @param length
 *            the length of the part that should be replaced
 * @param replacement
 *            the replacement that should be inserted at the position of the
 *            deleted part
 */
public static void replaceText(Document document, int start, int length, String replacement) {
	if (start < 0) {
		throw new IllegalArgumentException("Negative start position (s=" + start + ").");
	}
	if (length < 0) {
		throw new IllegalArgumentException("Negative length (l=" + length + ").");
	}
	// Calculate the difference between the old part of the text and the
	// replacement
	int diff = replacement.length() - length;
	int end = start + length;

	String text = document.getText();
	if (end > text.length()) {
		throw new IllegalArgumentException("The given Span(s=" + start + ",l=" + length
				+ ") is outside of the bounds of the document text (l=" + text.length() + ").");
	}

	if (diff != 0) {
		// Update all spans
		List<Span> spans = document.getMarkings(Span.class);
		for (Span span : spans) {
			if (span.getStartPosition() >= end) {
				span.setStartPosition(span.getStartPosition() + diff);
			}
		}
	}

	// Create the new text
	StringBuilder builder = new StringBuilder(text.length() + diff);
	builder.append(text.substring(0, start));
	builder.append(replacement);
	builder.append(text.substring(end));
	document.setText(builder.toString());
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:53,代码来源:DocumentHelper.java

示例6: compare

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
@Override
public int compare(Span s1, Span s2) {
    // sort them based on their length
    int diff = s1.getLength() - s2.getLength();
    if (diff == 0) {
        return 0;
    } else if (diff < 0) {
        return -1;
    } else {
        return 1;
    }
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:13,代码来源:MSNBCDataset.java

示例7: translateMentions

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
public List<Span> translateMentions(Set<Mention> mentions) {
    List<Span> markings = new ArrayList<Span>();
    if (mentions != null) {
        for (Mention mention : mentions) {
            markings.add(translate(mention));
        }
    }
    return markings;
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:10,代码来源:BAT2NIF_TranslationHelper.java

示例8: createSpanMatchingsSearcher

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
public static MatchingsSearcher<? extends Span> createSpanMatchingsSearcher(Matching matching) {
    switch (matching) {
    case WEAK_ANNOTATION_MATCH: {
        return new WeakSpanMatchingsSearcher<>();
    }
    case STRONG_ENTITY_MATCH:
    case STRONG_ANNOTATION_MATCH: {
        return new StrongSpanMatchingsSearcher<>();
    }
    default: {
        throw new IllegalArgumentException("Got an unknown Matching \"" + matching.toString() + "\".");
    }
    }
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:15,代码来源:MatchingsSearcherFactory.java

示例9: getUri

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
protected String getUri(Marking ne) {
    StringBuilder builder = new StringBuilder();
    if (ne instanceof Span) {
        builder.append(((Span) ne).getStartPosition());
        builder.append('|');
        builder.append(((Span) ne).getLength());
        builder.append('|');
    } else {
        builder.append("||");
    }
    if (ne instanceof Meaning) {
        if (((Meaning) ne).getUris().size() == 0) {
            builder.append("null");
        } else {
            boolean uriFound = false;
            for (String uri : ((Meaning) ne).getUris()) {
                if (uri.startsWith("http://dbpedia.org") && !uriFound) {
                    builder.append(uri);
                    uriFound = true;
                }
            }
            if (!uriFound) {
                builder.append(((Meaning) ne).getUris().iterator().next());
            }
        }
    }
    return builder.toString();
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:29,代码来源:ClassConsideringMatchingsCounter.java

示例10: merge

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected List<T> merge(List<T> spans) {
    Span spanArray[] = spans.toArray(new Span[spans.size()]);
    Arrays.sort(spanArray, this);
    IntIntOpenHashMap enclosedByMap = new IntIntOpenHashMap();
    boolean isEnclosed;
    for (int i = 0; i < spanArray.length; ++i) {
        isEnclosed = false;
        for (int j = spanArray.length - 1; (j > i) && (!isEnclosed); --j) {
            // if spanArray[i] is enclosed by spanArray[j]
            if ((spanArray[i].getStartPosition() >= spanArray[j].getStartPosition())
                    && ((spanArray[i].getStartPosition() + spanArray[i].getLength()) <= (spanArray[j]
                            .getStartPosition() + spanArray[j].getLength()))) {
                enclosedByMap.put(i, j);
                isEnclosed = true;
            }
        }
    }
    // if no match could be found
    if (enclosedByMap.size() == 0) {
        return spans;
    }

    List<T> mergedMarkings = new ArrayList<T>(spans.size());
    // starting with the smallest span, check if a span is enclosed by
    // another
    int largerSpanId;
    for (int i = 0; i < spanArray.length; ++i) {
        if (enclosedByMap.containsKey(i)) {
            largerSpanId = enclosedByMap.lget();
            spanArray[largerSpanId] = merge(spanArray[i], spanArray[largerSpanId]);
        } else {
            mergedMarkings.add((T) spanArray[i]);
        }
    }
    return mergedMarkings;
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:38,代码来源:SpanMergingEvaluatorDecorator.java

示例11: updateNewSpan

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
private void updateNewSpan(Span newSpan, Span oldSpan) {
    // FIXME Scoring is missing!
    if (oldSpan instanceof Meaning) {
        for (String uri : ((Meaning) oldSpan).getUris()) {
            ((Meaning) newSpan).addUri(uri);
        }
    }
    if (oldSpan instanceof TypedMarking) {
        ((TypedMarking) newSpan).getTypes().addAll(((TypedMarking) oldSpan).getTypes());
    }
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:12,代码来源:SpanMergingEvaluatorDecorator.java

示例12: compare

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
/**
 * Sorts the spans ascending by their length.
 */
@Override
public int compare(Span a1, Span a2) {
    int diff = a1.getLength() - a2.getLength();
    if (diff < 0) {
        return -1;
    } else if (diff > 0) {
        return 1;
    } else {
        return 0;
    }
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:15,代码来源:SpanMergingEvaluatorDecorator.java

示例13: spotSavely

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
public List<Span> spotSavely(Document document) {
    try {
        return spot(document);
    } catch (GerbilException e) {
        LOGGER.error("Error while requesting DBpedia Spotlight to spot text. Returning null.", e);
        return null;
    }
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:9,代码来源:SpotlightClient.java

示例14: parseSpottingResponse

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
protected List<Span> parseSpottingResponse(String response) {
    List<Span> markings = new ArrayList<Span>();

    JSONParser parser = new JSONParser();
    JSONObject jsonObject = null;
    try {
        jsonObject = (JSONObject) parser.parse(response);
    } catch (ParseException e) {
        LOGGER.error("Error while parsing DBpedia Spotlight response. Returning null.", e);
        return null;
    }

    jsonObject = (JSONObject) jsonObject.get("annotation");
    // If there are surface forms
    if (jsonObject.containsKey("surfaceForm")) {
        Object surfaceFormContainer = jsonObject.get("surfaceForm");
        // If there is an array of surface forms
        if (surfaceFormContainer instanceof JSONArray) {
            JSONArray resources = (JSONArray) jsonObject.get("surfaceForm");
            JSONObject resource;
            if (resources != null) {
                for (Object res : resources.toArray()) {
                    resource = (JSONObject) res;
                    addSpan(resource, markings);
                }
            }
        } else {
            // If there is only one surface form
            addSpan((JSONObject) surfaceFormContainer, markings);
        }
    }

    return markings;
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:35,代码来源:SpotlightClient.java

示例15: performRecognition

import org.aksw.gerbil.transfer.nif.Span; //导入依赖的package包/类
protected static List<Span> performRecognition(TimeMeasuringAnnotatorDecorator timeMeasurer, Document document)
        throws GerbilException {
    long startTime = System.currentTimeMillis();
    List<Span> result = null;
    result = ((EntityRecognizer) timeMeasurer.getDecoratedAnnotator()).performRecognition(document);
    timeMeasurer.addCallRuntime(System.currentTimeMillis() - startTime);
    return result;
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:9,代码来源:TimeMeasuringAnnotatorDecorator.java


注:本文中的org.aksw.gerbil.transfer.nif.Span类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。