• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NamedEntity类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: exportToNif

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
public static void exportToNif(A2WDataset ds, String baseUri, WikipediaInterface wikiApi, OutputStream outputStream) {
	List<org.aksw.gerbil.transfer.nif.Document> documents = new Vector<>();

	for (int i = 0; i < ds.getSize(); i++) {
		String text = ds.getTextInstanceList().get(i);
		org.aksw.gerbil.transfer.nif.Document d = new DocumentImpl(text, baseUri + "/doc" + i);

		for (it.unipi.di.acube.batframework.data.Annotation a : ds.getA2WGoldStandardList().get(i)) {
			String title;
			try {
				title = wikiApi.getTitlebyId(a.getConcept());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			d.addMarking(new NamedEntity(a.getPosition(), a.getLength(), getDBPediaURI(title)));
		}
		documents.add(d);
	}
	NIFWriter writer = new TurtleNIFWriter();
	writer.writeNIF(documents, outputStream);
}
 
开发者ID:marcocor,项目名称:smaph,代码行数:22,代码来源:SmaphUtils.java


示例2: annotateDocument

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
private boolean annotateDocument(final Document document, final Resource resource) {
	final String label = getEnglishLabel(resource.getURI());
	if (label == null) {
		LOGGER.info("Couldn't find an English label for " + resource.toString() + ". Returning null.");
		return false;
	}
	final String text = document.getText();
	final int pos = text.indexOf(label);
	if (pos < 0) {
		LOGGER.info("Couldn't find the label \"{}\" inside the given text \"{}\". Returning false.", label, text);
		// return false;
	} else {
		document.addMarking(new NamedEntity(pos, label.length(), resource.getURI()));
	}
	return true;
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:17,代码来源:SemWeb2NLVerbalizer.java


示例3: performTypeExtraction

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
public Document performTypeExtraction(Document document) {
    // extract the surface forms
    // List<List<NamedEntity>> types =
    // surfaceFormExtractor.extractTypeSurfaceForms(document);
    // TypingInfoImpl typingInfo = new TypingInfoImpl();
    // // TODO find a type for every type surface form that has been found
    // List<NamedEntity> typesFound = linkTypes(types, typingInfo);
    // return new TypeExtractionResult(typesFound, typingInfo);
    Map<NamedEntity, List<ExtendedTypedNamedEntity>> extractedTypes = surfaceFormExtractor
            .extractTypeSurfaceForms(document);
    Document resultDoc = new DocumentImpl(document.getText(), document.getDocumentURI());
    List<ExtendedTypedNamedEntity> surfaceForms;
    for (NamedEntity ne : extractedTypes.keySet()) {
        surfaceForms = extractedTypes.get(ne);
        resultDoc.addMarking(typeSearcher.getAllTypes(document, ne, surfaceForms));
        resultDoc.getMarkings().addAll(surfaceForms);
    }
    return resultDoc;
}
 
开发者ID:dice-group,项目名称:Cetus,代码行数:20,代码来源:CetusAnnotator.java


示例4: endElement

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
@Override
public void endElement(String uri, String localName, String qName)
		throws SAXException {
	if (qName.equalsIgnoreCase(SENTENCE_ELEMENT)) {
		i++;
		documents.add(new DocumentImpl(sentence.toString(),
				"http://senseval" + i, markings));
		sentence = new StringBuilder();
	} else if (qName.equalsIgnoreCase(INSTANCE_ELEMENT)) {
		markings.add(new NamedEntity(start, length, instanceUri));
		start = sentence.length();
	} else if (qName.equalsIgnoreCase(WF_ELEMENT)) {
		start = sentence.length();

	}
	this.field = 0;
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:18,代码来源:SensevalSAXHandler.java


示例5: parseJsonStream

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
private List<MeaningSpan> parseJsonStream(InputStream in) throws IOException, ParseException {
    List<MeaningSpan> annotations = new ArrayList<>();

    JSONArray namedEntities = (JSONArray) this.jsonParser.parse(new InputStreamReader(in, "UTF-8"));
    JSONObject namedEntity;
    String url;
    long start, length;
    for (Object obj : namedEntities) {
        namedEntity = (JSONObject) obj;

        start = (long) namedEntity.get("start");
        length = (long) namedEntity.get("offset");

        url = (String) namedEntity.get("disambiguatedURL");
        if (url == null) {
            annotations.add(new NamedEntity((int) start, (int) length, new HashSet<String>()));
        } else {
            annotations.add(new NamedEntity((int) start, (int) length, URLDecoder.decode(url, "UTF-8")));
        }
    }

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


示例6: test

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
@Test
public void test() throws GerbilException, IOException {
	SensevalDataset data = new SensevalDataset(this.file);
	data.init();
	List<Document> documents = data.getInstances();
	Document doc = documents.get(docIndex);
	assertEquals(expectedSentence, doc.getText());
	List<Marking> markings = doc.getMarkings();
	String[] marks = new String[markings.size()];
	for(int i=0; i<markings.size();i++){
		NamedEntity entity = ((NamedEntity)markings.get(i));
		marks[i]=doc.getText().substring(entity.getStartPosition(), 
				entity.getStartPosition()+entity.getLength());
	}
	assertArrayEquals(expectedMarkings, 
			marks);
	data.close();

}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:20,代码来源:SensevalDatasetTest.java


示例7: test

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
@Test
public void test() {
    ConfidenceScoreEvaluatorDecorator<NamedEntity> decorator = new ConfidenceScoreEvaluatorDecorator<NamedEntity>(
            this, EVALUTION_RESULT_NAME, this);
    EvaluationResultContainer results = new EvaluationResultContainer();
    decorator.evaluate(annotatorResults, new ArrayList<List<NamedEntity>>(), results);
    boolean evalationResultFound = false;
    boolean scoreThresholdFound = false;
    for (EvaluationResult result : results.getResults()) {
        if (EVALUTION_RESULT_NAME.equals(result.getName())) {
            evalationResultFound = true;
            Assert.assertEquals(expectedScore, result.getValue());
        }
        if (ConfidenceScoreEvaluatorDecorator.CONFIDENCE_SCORE_THRESHOLD_RESULT_NAME.equals(result.getName())) {
            scoreThresholdFound = true;
            Assert.assertEquals(expectedThreshold, result.getValue());
        }
    }
    Assert.assertTrue(evalationResultFound);
    if (expectedThreshold != null) {
        Assert.assertTrue(scoreThresholdFound);
    }
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:24,代码来源:ConfidenceScoreEvaluatorDecoratorTest.java


示例8: evaluate

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
@Override
public void evaluate(List<List<NamedEntity>> annotatorResults, List<List<NamedEntity>> goldStandard,
        EvaluationResultContainer results) {
    // all gold standards in this test are empty
    Assert.assertEquals(0, goldStandard.size());
    // simply count all correct named entities
    int score = 0, sum = 0;
    for (List<NamedEntity> nes : annotatorResults) {
        for (NamedEntity ne : nes) {
            if (ne.containsUri(CORRECT_MARKING)) {
                ++score;
            }
            ++sum;
        }
    }
    if (sum == 0) {
        results.addResult(new DoubleEvaluationResult(EVALUTION_RESULT_NAME, 0));
    } else {
        results.addResult(new DoubleEvaluationResult(EVALUTION_RESULT_NAME, (double) score / (double) sum));
    }
}
 
开发者ID:dice-group,项目名称:gerbil,代码行数:22,代码来源:ConfidenceScoreEvaluatorDecoratorTest.java


示例9: compare

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
@Override
public int compare(final NamedEntity n1, final NamedEntity n2) {
	final int diff = n1.getLength() - n2.getLength();
	if (diff < 0) {
		// n1 is shorter
		return 1;
	} else if (diff > 0) {
		return -1;
	} else {
		return 0;
	}
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:13,代码来源:SemWeb2NLVerbalizer.java


示例10: compare

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
@Override
public int compare(NamedEntity n1, NamedEntity n2) {
	int diff = n1.getLength() - n2.getLength();
	if (diff < 0) {
		// n1 is shorter
		return 1;
	} else if (diff > 0) {
		return -1;
	} else {
		return 0;
	}
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:13,代码来源:Paraphrasing.java


示例11: compare

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
/**
 * Sorts Named entities descending by their length.
 */
@Override
public int compare(NamedEntity n1, NamedEntity n2) {
	int diff = n1.getLength() - n2.getLength();
	if (diff < 0) {
		// n1 is shorter
		return 1;
	} else if (diff > 0) {
		return -1;
	} else {
		return 0;
	}
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:16,代码来源:ParaphraserImpl.java


示例12: test

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的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


示例13: getAllTypes

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
@Override
public TypedNamedEntity getAllTypes(Document document, NamedEntity ne, List<ExtendedTypedNamedEntity> surfaceForms) {
    TypedNamedEntity tne = new TypedNamedEntity(ne.getStartPosition(), ne.getLength(), ne.getUris(),
            new HashSet<String>());
    for(ExtendedTypedNamedEntity surfaceForm : surfaceForms) {
        tne.getTypes().addAll(surfaceForm.getUris());
    }

    try {
        // request FOX
        Response response = Request
                .Post(FOX_SERVICE)
                .addHeader("Content-type", "application/json")
                .addHeader("Accept-Charset", "UTF-8")
                .body(new StringEntity(new JSONObject().put("input", document.getText()).put("type", "text")
                        .put("task", "ner").put("output", "JSON-LD").toString(), ContentType.APPLICATION_JSON))
                .execute();

        HttpResponse httpResponse = response.returnResponse();
        HttpEntity entry = httpResponse.getEntity();

        String content = IOUtils.toString(entry.getContent(), "UTF-8");
        EntityUtils.consume(entry);

        // parse results
        JSONObject outObj = new JSONObject(content);
        if (outObj.has("@graph")) {

            JSONArray graph = outObj.getJSONArray("@graph");
            for (int i = 0; i < graph.length(); i++) {
                parseType(graph.getJSONObject(i), tne, surfaceForms);
            }
        } else {
            parseType(outObj, tne, surfaceForms);
        }
    } catch (Exception e) {
        LOGGER.error("Got an exception while communicating with the FOX web service.", e);
    }
    return tne;
}
 
开发者ID:dice-group,项目名称:Cetus,代码行数:41,代码来源:FoxBasedTypeSearcher.java


示例14: extractTypeSurfaceForms

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
/**
 * 
 * 
 * @param document
 * @return
 */
public synchronized Map<NamedEntity, List<ExtendedTypedNamedEntity>> extractTypeSurfaceForms(Document nifDocument) {
    // Document tmDocument = createDocument(nifDocument);
    // tmDocument = preprocessor.processDocument(tmDocument);
    // return tmDocument.getProperty(TypeSurfaceForms.class).get();
    Annotation document = new Annotation(nifDocument.getText());
    preprocessDocument(document);
    return getTypeSurfaceForms(document, nifDocument.getMarkings(NamedEntity.class));
}
 
开发者ID:dice-group,项目名称:Cetus,代码行数:15,代码来源:CetusSurfaceFormExtractor.java


示例15: getTypeSurfaceForms

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
private Map<NamedEntity, List<ExtendedTypedNamedEntity>> getTypeSurfaceForms(Annotation document,
        List<NamedEntity> list) {
    Map<NamedEntity, List<ExtendedTypedNamedEntity>> results = new HashMap<NamedEntity, List<ExtendedTypedNamedEntity>>();
    for (NamedEntity ne : list) {
        results.put(ne, getTypeSurfaceForms(document, ne));
    }
    return results;
}
 
开发者ID:dice-group,项目名称:Cetus,代码行数:9,代码来源:CetusSurfaceFormExtractor.java


示例16: test

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
@Test
public void test() {
    Map<NamedEntity, List<ExtendedTypedNamedEntity>> result = EXTRACTOR.extractTypeSurfaceForms(nifDocument);
    List<ExtendedTypedNamedEntity> resultTypes;
    for (NamedEntity ne : nifDocument.getMarkings(NamedEntity.class)) {
        Assert.assertTrue(result.containsKey(ne));
        resultTypes = result.get(ne);
        for (ExtendedTypedNamedEntity types : resultTypes) {
            Assert.assertTrue("Couldn't find " + types + " inside the list of expected types "
                    + expectedTypes.toString() + ".", expectedTypes.contains(types));
        }
        Assert.assertEquals(expectedTypes.size(), resultTypes.size());
    }
}
 
开发者ID:dice-group,项目名称:Cetus,代码行数:15,代码来源:CetusSurfaceFormExtractorTest.java


示例17: test

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
@Test
    public void test() {
        Map<NamedEntity, List<ExtendedTypedNamedEntity>> result = EXTRACTOR.extractTypeSurfaceForms(nifDocument);
        List<ExtendedTypedNamedEntity> resultTypes;
        ExtendedTypedNamedEntity matchingEntity;
        int expectedStartPos, expectedEndPos, startPos, endPos;
        for (NamedEntity ne : nifDocument.getMarkings(NamedEntity.class)) {
            Assert.assertTrue(result.containsKey(ne));
            resultTypes = result.get(ne);
            for (TypedNamedEntity expectedType : expectedTypes) {
                matchingEntity = null;
                expectedStartPos = expectedType.getStartPosition();
                expectedEndPos = expectedStartPos + expectedType.getLength();
                // search for a matching entity
                for (ExtendedTypedNamedEntity type : resultTypes) {
                    startPos = type.getStartPosition();
                    endPos = startPos + type.getLength();
                    if ((expectedStartPos >= startPos) && (expectedEndPos <= endPos)) {
                        matchingEntity = type;
                    }
                }
                Assert.assertNotNull("Couldn't find " + expectedType + " inside the list of expected types.",
                        matchingEntity);
            }
//            if (resultTypes.size() > 0) {
//                LOGGER.warn("Got more types than expected: " + Arrays.toString(resultTypes.toArray()));
//            }
        }
    }
 
开发者ID:dice-group,项目名称:Cetus,代码行数:30,代码来源:ExtendedCetusSurfaceFormExtractorTest.java


示例18: reduceToTextAndEntities

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
public static Document reduceToTextAndEntities(Document document) {
    MarkingFilter<TypedNamedEntity> filter = new TypeBasedMarkingFilter<TypedNamedEntity>(false,
            RDFS.Class.getURI(), OWL.Class.getURI());
    List<TypedNamedEntity> namedEntities = document.getMarkings(TypedNamedEntity.class);
    List<Marking> markings = new ArrayList<Marking>(namedEntities.size());
    for (TypedNamedEntity tne : namedEntities) {
        if (filter.isMarkingGood(tne)) {
            markings.add(new NamedEntity(tne.getStartPosition(), tne.getLength(), tne.getUris()));
        }
    }
    return new DocumentImpl(document.getText(), document.getDocumentURI(), markings);
}
 
开发者ID:dice-group,项目名称:Cetus,代码行数:13,代码来源:ExtendedCetusSurfaceFormExtractorTest.java


示例19: ExtendedYagoBasedTypeSearcherTest

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
public ExtendedYagoBasedTypeSearcherTest(Document nifDocument, NamedEntity namedEntity,
        List<ExtendedTypedNamedEntity> surfaceForms, Set<String> expectedTypes) {
    this.nifDocument = nifDocument;
    this.namedEntity = namedEntity;
    this.surfaceForms = surfaceForms;
    this.expectedTypes = expectedTypes;
}
 
开发者ID:dice-group,项目名称:Cetus,代码行数:8,代码来源:ExtendedYagoBasedTypeSearcherTest.java


示例20: extractNamedEntity

import org.aksw.gerbil.transfer.nif.data.NamedEntity; //导入依赖的package包/类
public static NamedEntity extractNamedEntity(Document document) {
    MarkingFilter<TypedNamedEntity> filter = new TypeBasedMarkingFilter<TypedNamedEntity>(false,
            RDFS.Class.getURI(), OWL.Class.getURI());
    List<TypedNamedEntity> namedEntities = document.getMarkings(TypedNamedEntity.class);
    for (TypedNamedEntity tne : namedEntities) {
        if (filter.isMarkingGood(tne)) {
            return new NamedEntity(tne.getStartPosition(), tne.getLength(), tne.getUris());
        }
    }
    return null;
}
 
开发者ID:dice-group,项目名称:Cetus,代码行数:12,代码来源:ExtendedYagoBasedTypeSearcherTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PdfGState类代码示例发布时间:2022-05-23
下一篇:
Java Node类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap