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


Java MeaningSpan.getLength方法代码示例

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


在下文中一共展示了MeaningSpan.getLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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


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