本文整理汇总了Java中org.aksw.gerbil.transfer.nif.MeaningSpan.getStartPosition方法的典型用法代码示例。如果您正苦于以下问题:Java MeaningSpan.getStartPosition方法的具体用法?Java MeaningSpan.getStartPosition怎么用?Java MeaningSpan.getStartPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.aksw.gerbil.transfer.nif.MeaningSpan
的用法示例。
在下文中一共展示了MeaningSpan.getStartPosition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
示例4: 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);
}