本文整理汇总了Java中org.aksw.gerbil.transfer.nif.MeaningSpan类的典型用法代码示例。如果您正苦于以下问题:Java MeaningSpan类的具体用法?Java MeaningSpan怎么用?Java MeaningSpan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MeaningSpan类属于org.aksw.gerbil.transfer.nif包,在下文中一共展示了MeaningSpan类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: parseJsonStream
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的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
示例2: performD2KBTask
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
protected static List<MeaningSpan> performD2KBTask(SingleInstanceSecuringAnnotatorDecorator decorator,
Document document) throws GerbilException {
List<MeaningSpan> 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 = ((D2KBAnnotator) decorator.getDecoratedAnnotator()).performD2KBTask(document);
} finally {
decorator.semaphore.release();
}
return result;
}
开发者ID:dice-group,项目名称:gerbil,代码行数:18,代码来源:SingleInstanceSecuringAnnotatorDecorator.java
示例3: performExtraction
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
protected static List<MeaningSpan> performExtraction(SingleInstanceSecuringAnnotatorDecorator decorator,
Document document) throws GerbilException {
List<MeaningSpan> 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 = ((A2KBAnnotator) decorator.getDecoratedAnnotator()).performA2KBTask(document);
} finally {
decorator.semaphore.release();
}
return result;
}
开发者ID:dice-group,项目名称:gerbil,代码行数:18,代码来源:SingleInstanceSecuringAnnotatorDecorator.java
示例4: performD2KBTask
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
protected static List<MeaningSpan> performD2KBTask(ErrorCountingAnnotatorDecorator errorCounter, Document document)
throws GerbilException {
List<MeaningSpan> result = null;
try {
result = ((D2KBAnnotator) errorCounter.getDecoratedAnnotator()).performD2KBTask(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<MeaningSpan>(0);
}
if (printDebugMsg && LOGGER.isDebugEnabled()) {
logResult(result, errorCounter.getName(), "MeaningSpan");
}
return result;
}
开发者ID:dice-group,项目名称:gerbil,代码行数:23,代码来源:ErrorCountingAnnotatorDecorator.java
示例5: performExtraction
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
protected static List<MeaningSpan> performExtraction(ErrorCountingAnnotatorDecorator errorCounter, Document document)
throws GerbilException {
List<MeaningSpan> result = null;
try {
result = ((A2KBAnnotator) errorCounter.getDecoratedAnnotator()).performA2KBTask(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<MeaningSpan>(0);
}
if (printDebugMsg && LOGGER.isDebugEnabled()) {
logResult(result, errorCounter.getName(), "MeaningSpan");
}
return result;
}
开发者ID:dice-group,项目名称:gerbil,代码行数:23,代码来源:ErrorCountingAnnotatorDecorator.java
示例6: searchFirstOccurrence
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
/**
* Searches the {@link MeaningSpan} that a) occurs first inside the document
* and b) has the given URI as meaning.
*
* @param uri
* the meaning the searched marking should have
* @param document
* the document in which the marking should be searched
* @return the first occurrence of a meaning with the given URI in the text
* or null if such a marking couldn't be found.
*/
public static MeaningSpan searchFirstOccurrence(String uri, Document document) {
List<MeaningSpan> entities = document.getMarkings(MeaningSpan.class);
MeaningSpan result = null;
for (MeaningSpan marking : entities) {
if (marking.containsUri(uri)) {
if ((result == null) || (marking.getStartPosition() < result.getStartPosition())) {
result = marking;
}
}
}
return result;
}
开发者ID:dice-group,项目名称:BENGAL,代码行数:24,代码来源:DocumentHelper.java
示例7: translateAnnotations
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
public List<MeaningSpan> translateAnnotations(Set<it.unipi.di.acube.batframework.data.Annotation> annotations) {
List<MeaningSpan> markings = new ArrayList<MeaningSpan>();
if (annotations != null) {
for (it.unipi.di.acube.batframework.data.Annotation a : annotations) {
if (a instanceof it.unipi.di.acube.batframework.data.ScoredAnnotation) {
markings.add(translate((it.unipi.di.acube.batframework.data.ScoredAnnotation) a));
} else {
markings.add(translate(a));
}
}
}
return markings;
}
开发者ID:dice-group,项目名称:gerbil,代码行数:14,代码来源:BAT2NIF_TranslationHelper.java
示例8: performD2KBTask
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
protected static List<MeaningSpan> performD2KBTask(TimeMeasuringAnnotatorDecorator timeMeasurer, Document document)
throws GerbilException {
long startTime = System.currentTimeMillis();
List<MeaningSpan> result = null;
result = ((D2KBAnnotator) timeMeasurer.getDecoratedAnnotator()).performD2KBTask(document);
timeMeasurer.addCallRuntime(System.currentTimeMillis() - startTime);
return result;
}
开发者ID:dice-group,项目名称:gerbil,代码行数:9,代码来源:TimeMeasuringAnnotatorDecorator.java
示例9: performExtraction
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
protected static List<MeaningSpan> performExtraction(TimeMeasuringAnnotatorDecorator timeMeasurer, Document document)
throws GerbilException {
long startTime = System.currentTimeMillis();
List<MeaningSpan> result = null;
result = ((A2KBAnnotator) timeMeasurer.getDecoratedAnnotator()).performA2KBTask(document);
timeMeasurer.addCallRuntime(System.currentTimeMillis() - startTime);
return result;
}
开发者ID:dice-group,项目名称:gerbil,代码行数:9,代码来源:TimeMeasuringAnnotatorDecorator.java
示例10: createClassifiedMeaning
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
public static ClassifiedMarking createClassifiedMeaning(Marking marking) {
if (marking instanceof ScoredNamedEntity) {
ScoredNamedEntity sne = (ScoredNamedEntity) marking;
return new ClassifiedScoredNamedEntity(sne.getStartPosition(), sne.getLength(), sne.getUris(),
sne.getConfidence());
} else if (marking instanceof MeaningSpan) {
MeaningSpan ne = (MeaningSpan) marking;
return new ClassifiedNamedEntity(ne.getStartPosition(), ne.getLength(), ne.getUris());
} else if (marking instanceof Meaning) {
return new ClassifiedAnnotation(((Meaning) marking).getUris());
}
return null;
}
开发者ID:dice-group,项目名称:gerbil,代码行数:14,代码来源:ClassifiedMarkingFactory.java
示例11: printDatasetUris
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
private static void printDatasetUris(Dataset dataset, PrintStream pout) {
for (Document document : dataset.getInstances()) {
String text = document.getText();
for (MeaningSpan meaning : document.getMarkings(MeaningSpan.class)) {
for (String uri : meaning.getUris()) {
pout.print(uri);
pout.print('\t');
pout.print(text.substring(meaning.getStartPosition(),
meaning.getStartPosition() + meaning.getLength()));
pout.println();
}
}
}
}
开发者ID:dice-group,项目名称:gerbil,代码行数:15,代码来源:UriExport.java
示例12: createEvaluator
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "deprecation", "rawtypes" })
public Evaluator createEvaluator(ExperimentType type, ExperimentTaskConfiguration configuration, Dataset dataset,
UriKBClassifier globalClassifier, SubClassInferencer inferencer) {
switch (type) {
case D2KB: {
return new SearcherBasedNotMatchingMarkingFilter<MeaningSpan>(
new StrongSpanMatchingsSearcher<MeaningSpan>(),
new ClassifyingEvaluatorDecorator<MeaningSpan, ClassifiedSpanMeaning>(
new GSInKBClassifyingEvaluatorDecorator<ClassifiedSpanMeaning>(
new ClassConsideringFMeasureCalculator<ClassifiedSpanMeaning>(
new MatchingsCounterImpl<ClassifiedSpanMeaning>(
new CompoundMatchingsSearcher<ClassifiedSpanMeaning>(
(MatchingsSearcher<ClassifiedSpanMeaning>) MatchingsSearcherFactory
.createSpanMatchingsSearcher(
configuration.matching),
new ClassifiedMeaningMatchingsSearcher<ClassifiedSpanMeaning>())),
MarkingClasses.IN_KB, MarkingClasses.EE, MarkingClasses.GS_IN_KB),
new StrongSpanMatchingsSearcher<ClassifiedSpanMeaning>()),
new UriBasedMeaningClassifier<ClassifiedSpanMeaning>(globalClassifier, MarkingClasses.IN_KB),
new EmergingEntityMeaningClassifier<ClassifiedSpanMeaning>()),
true);
}
case Sa2KB:
case A2KB:
case C2KB:
case ERec:
case ETyping:
case OKE_Task1:
case OKE_Task2:
default: {
throw new IllegalArgumentException("Got an unknown Experiment Type.");
}
}
}
开发者ID:dice-group,项目名称:gerbil,代码行数:36,代码来源:SimpleSingleD2KBRun.java
示例13: test
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void test() {
Evaluator<MeaningSpan> evaluator = new ClassifyingEvaluatorDecorator<MeaningSpan, ClassifiedSpanMeaning>(this,
new UriBasedMeaningClassifier<ClassifiedSpanMeaning>(CLASSIFIER, MarkingClasses.IN_KB));
evaluator.evaluate(Arrays.asList(Arrays.asList(annotatorResponse)), Arrays.asList(Arrays.asList(goldStandard)),
null);
}
开发者ID:dice-group,项目名称:gerbil,代码行数:9,代码来源:InKBClassifyingEvaluatorDecoratorTest.java
示例14: test
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void test() {
Evaluator<MeaningSpan> evaluator = new ClassifyingEvaluatorDecorator<MeaningSpan, ClassifiedSpanMeaning>(
new GSInKBClassifyingEvaluatorDecorator<ClassifiedSpanMeaning>(this,
new StrongSpanMatchingsSearcher<ClassifiedSpanMeaning>()),
new UriBasedMeaningClassifier<ClassifiedSpanMeaning>(CLASSIFIER, MarkingClasses.IN_KB),
new EmergingEntityMeaningClassifier<ClassifiedSpanMeaning>());
evaluator.evaluate(Arrays.asList(Arrays.asList(annotatorResponse)), Arrays.asList(Arrays.asList(goldStandard)),
null);
}
开发者ID:dice-group,项目名称:gerbil,代码行数:12,代码来源:GSInKBClassifyingEvaluatorDecoratorTest.java
示例15: test
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void test() {
Evaluator<MeaningSpan> evaluator = new ClassifyingEvaluatorDecorator<MeaningSpan, ClassifiedSpanMeaning>(this,
new UriBasedMeaningClassifier<ClassifiedSpanMeaning>(CLASSIFIER, MarkingClasses.IN_KB),
new EmergingEntityMeaningClassifier<ClassifiedSpanMeaning>());
evaluator.evaluate(Arrays.asList(Arrays.asList(annotatorResponse)), Arrays.asList(Arrays.asList(goldStandard)),
null);
}
开发者ID:dice-group,项目名称:gerbil,代码行数:10,代码来源:EEClassifyingEvaluatorDecoratorTest.java
示例16: NIFGerbil
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
public String NIFGerbil(InputStream input, NEDAlgo_HITS agdistis) throws IOException {
org.aksw.gerbil.transfer.nif.Document document;
String nifDocument = "";
String textWithMentions = "";
List<MeaningSpan> annotations = new ArrayList<>();
try {
document = parser.getDocumentFromNIFStream(input);
log.info("NIF file coming from GERBIL");
textWithMentions = nifParser.createTextWithMentions(document.getText(), document.getMarkings(Span.class));
Document d = textToDocument(textWithMentions);
agdistis.run(d, null);
for (NamedEntityInText namedEntity : d.getNamedEntitiesInText()) {
String disambiguatedURL = namedEntity.getNamedEntityUri();
if (disambiguatedURL == null) {
annotations.add(new NamedEntity(namedEntity.getStartPos(), namedEntity.getLength(), URLDecoder
.decode("http://aksw.org/notInWiki/" + namedEntity.getSingleWordLabel(), "UTF-8")));
} else {
annotations.add(new NamedEntity(namedEntity.getStartPos(), namedEntity.getLength(),
URLDecoder.decode(namedEntity.getNamedEntityUri(), "UTF-8")));
}
}
document.setMarkings(new ArrayList<Marking>(annotations));
log.debug("Result: " + document.toString());
nifDocument = creator.getDocumentAsNIFString(document);
log.debug(nifDocument);
} catch (Exception e) {
log.error("Exception while reading request.", e);
return "";
}
return nifDocument;
}
开发者ID:dice-group,项目名称:AGDISTIS,代码行数:35,代码来源:GetDisambiguation.java
示例17: NIFType
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
public String NIFType(String text, NEDAlgo_HITS agdistis) throws IOException {
org.aksw.gerbil.transfer.nif.Document document = null;
String nifDocument = "";
NIFParser nifParser = new NIFParser();
String textWithMentions = "";
List<MeaningSpan> annotations = new ArrayList<>();
try {
document = parser.getDocumentFromNIFString(text);
log.debug("Request: " + document.toString());
textWithMentions = nifParser.createTextWithMentions(document.getText(), document.getMarkings(Span.class));
Document d = textToDocument(textWithMentions);
agdistis.run(d, null);
for (NamedEntityInText namedEntity : d.getNamedEntitiesInText()) {
String disambiguatedURL = namedEntity.getNamedEntityUri();
if (disambiguatedURL == null) {
annotations.add(new NamedEntity(namedEntity.getStartPos(), namedEntity.getLength(), URLDecoder
.decode("http://aksw.org/notInWiki/" + namedEntity.getSingleWordLabel(), "UTF-8")));
} else {
annotations.add(new NamedEntity(namedEntity.getStartPos(), namedEntity.getLength(),
URLDecoder.decode(disambiguatedURL, "UTF-8")));
}
}
document.setMarkings(new ArrayList<Marking>(annotations));
log.debug("Result: " + document.toString());
nifDocument = creator.getDocumentAsNIFString(document);
} catch (Exception e) {
log.error("Exception while reading request.", e);
return "";
}
return nifDocument;
}
开发者ID:dice-group,项目名称:AGDISTIS,代码行数:34,代码来源:GetDisambiguation.java
示例18: replaceSubjectWithPronoun
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
/**
* Replaces the first occurrence of the statements subject with a pronoun.
*
* @param document
* @param s
*/
public void replaceSubjectWithPronoun(final Document document, final String subjectUri) {
final MeaningSpan marking = DocumentHelper.searchFirstOccurrence(subjectUri, document);
if (marking == null) {
return;
}
final String documentText = document.getText();
String pronoun = null;
final int start = marking.getStartPosition();
int length = marking.getLength();
final int end = start + length;
// FIXME check whether the entity is preceded by an article
// Check whether we have to add a possessive pronoun (check whether it
// has a trailing "'s")
boolean possessiveForm = false;
if ((documentText.charAt(end - 2) == '\'') && (documentText.charAt(end - 1) == 's')) {
possessiveForm = true;
} else if (((end + 1) < documentText.length()) && (documentText.charAt(end) == '\'')) {
possessiveForm = true;
// Check whether we have "<entity>'" or "<entity>'s"
if (documentText.charAt(end + 1) == 's') {
length += 2;
} else {
length += 1;
}
}
// Choose a pronoun based on the type of the entity
final String type = getType(subjectUri);
if (type != null) {
if (type.equals("http://dbpedia.org/ontology/Person")) {
// Get the comment text
final String commentString = getGender(subjectUri);
// Search for a pronoun that identifies the person as man
if (commentString.contains(" he ") || commentString.contains("He ")
|| commentString.contains(" his ")) {
if (possessiveForm) {
pronoun = (start == 0) ? "His" : "his";
} else {
pronoun = (start == 0) ? "He" : "he";
}
// Ok, than search for a woman
} else if (commentString.contains(" she ") || commentString.contains("She ")
|| commentString.contains(" her ")) {
if (possessiveForm) {
pronoun = (start == 0) ? "Her" : "her";
} else {
pronoun = (start == 0) ? "She" : "she";
}
}
// If we can not decide the gender we shouldn't insert a pronoun
// (let it be null)
} else {
if (possessiveForm) {
pronoun = (start == 0) ? "Its" : "its";
} else {
pronoun = (start == 0) ? "It" : "it";
}
}
}
// If we couldn't find a pronoun
if (pronoun == null) {
return;
}
// Remove the marking from the document
document.getMarkings().remove(marking);
// Replace the text
DocumentHelper.replaceText(document, start, length, pronoun);
}
开发者ID:dice-group,项目名称:BENGAL,代码行数:80,代码来源:SemWeb2NLVerbalizer.java
示例19: replaceSubjectWithPronoun
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
public void replaceSubjectWithPronoun(Document document, String subjectUri) {
MeaningSpan marking = DocumentHelper.searchFirstOccurrence(subjectUri, document);
if (marking == null) {
return;
}
String documentText = document.getText();
String pronoun = null;
int start = marking.getStartPosition();
int length = marking.getLength();
int end = start + length;
// FIXME check whether the entity is preceded by an article
// Check whether we have to add a possessive pronoun (check whether it
// has a trailing "'s")
boolean possessiveForm = false;
if ((documentText.charAt(end - 2) == '\'') && (documentText.charAt(end - 1) == 's')) {
possessiveForm = true;
} else if (((end + 1) < documentText.length()) && (documentText.charAt(end) == '\'')) {
possessiveForm = true;
// Check whether we have "<entity>'" or "<entity>'s"
if (documentText.charAt(end + 1) == 's') {
length += 2;
} else {
length += 1;
}
}
// Choose a pronoun based on the type of the entity
String type = getType(subjectUri);
if (type != null) {
if (type.equals("http://dbpedia.org/ontology/Person")) {
// Get the comment text
String commentString = getGender(subjectUri);
// Search for a pronoun that identifies the person as man
if (commentString.contains(" he ") || commentString.contains("He ")
|| commentString.contains(" his ")) {
if (possessiveForm) {
pronoun = (start == 0) ? "His" : "his";
} else {
pronoun = (start == 0) ? "He" : "he";
}
// Ok, than search for a woman
} else if (commentString.contains(" she ") || commentString.contains("She ")
|| commentString.contains(" her ")) {
if (possessiveForm) {
pronoun = (start == 0) ? "Her" : "her";
} else {
pronoun = (start == 0) ? "She" : "she";
}
}
// If we can not decide the gender we shouldn't insert a pronoun
// (let it be null)
} else {
if (possessiveForm) {
pronoun = (start == 0) ? "Its" : "its";
} else {
pronoun = (start == 0) ? "It" : "it";
}
}
}
// If we couldn't find a pronoun
if (pronoun == null) {
return;
}
// Remove the marking from the document
document.getMarkings().remove(marking);
// Replace the text
DocumentHelper.replaceText(document, start, length, pronoun);
}
开发者ID:dice-group,项目名称:BENGAL,代码行数:74,代码来源:ParaphasingNIF.java
示例20: performD2KBTask
import org.aksw.gerbil.transfer.nif.MeaningSpan; //导入依赖的package包/类
@Override
public List<MeaningSpan> performD2KBTask(Document document) throws GerbilException {
return getNERDAnnotations(document).getMarkings(MeaningSpan.class);
}
开发者ID:dice-group,项目名称:gerbil,代码行数:5,代码来源:NERDAnnotator.java
注:本文中的org.aksw.gerbil.transfer.nif.MeaningSpan类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论