本文整理汇总了Java中simplenlg.phrasespec.NPPhraseSpec类的典型用法代码示例。如果您正苦于以下问题:Java NPPhraseSpec类的具体用法?Java NPPhraseSpec怎么用?Java NPPhraseSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NPPhraseSpec类属于simplenlg.phrasespec包,在下文中一共展示了NPPhraseSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processObject
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
private NPPhraseSpec processObject(Node object, boolean isClass) throws IOException {
NPPhraseSpec element;
if (object.isVariable()) {
element = processVarNode(object);
} else if (object.isLiteral()) {
element = processLiteralNode(object);
} else if (object.isURI()) {
if (isClass) {
element = processClassNode(object, false);
} else {
element = processResourceNode(object);
}
} else {
throw new IllegalArgumentException("Can not convert blank node " + object + ".");
}
return element;
}
示例2: testEx02
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
/**
* This example shows: a) preposition contraction: em + uma = numa b) no
* preposition contraction: de + São João = de + São João d) preposition
* contraction: em + o = no e) preposition contraction: de + a = da
*/
@Test
public void testEx02() {
NPPhraseSpec subject = this.phraseFactory.createNounPhrase("meus", "amigo");
subject.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
VPPhraseSpec verb = this.phraseFactory.createVerbPhrase("estar");
NPPhraseSpec place = this.phraseFactory.createNounPhrase("uma", "festa");
PPPhraseSpec placePhrase = this.phraseFactory.createPrepositionPhrase("em", place);
NPPhraseSpec type = this.phraseFactory.createNounPhrase("São João");
PPPhraseSpec typePhrase = this.phraseFactory.createPrepositionPhrase("de", type);
place.addComplement(typePhrase);
SPhraseSpec s = this.phraseFactory.createClause(subject, verb, placePhrase);
Assert.assertEquals("Meus amigos estão numa festa de São João.", getResult(s, "02a"));
NPPhraseSpec subject2 = this.phraseFactory.createNounPhrase("eu");
VPPhraseSpec verb2 = this.phraseFactory.createVerbPhrase("estar");
NPPhraseSpec place2 = this.phraseFactory.createNounPhrase("o", "quarto");
PPPhraseSpec place2Phrase = this.phraseFactory.createPrepositionPhrase("em", place2);
NPPhraseSpec place3 = this.phraseFactory.createNounPhrase("a", "minha casa");
PPPhraseSpec place3Phrase = this.phraseFactory.createPrepositionPhrase("de", place3);
place2.addComplement(place3Phrase);
SPhraseSpec s2 = this.phraseFactory.createClause(subject2, verb2, place2Phrase);
Assert.assertEquals("Eu estou no quarto da minha casa.", getResult(s2, "02b"));
}
示例3: testEx03
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
/**
* This example shows a long verb periphrasis.
*
*/
@Test
public void testEx03() {
NPPhraseSpec subject = this.phraseFactory.createNounPhrase("você");
VPPhraseSpec verb = this.phraseFactory.createVerbPhrase("criar");
verb.setFeature(Feature.NEGATED, true);
verb.setFeature(Feature.PROSPECTIVE, true);
verb.setFeature(Feature.PROGRESSIVE, "ficar");
NPPhraseSpec object = this.phraseFactory.createNounPhrase("exemplo");
object.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
SPhraseSpec s = this.phraseFactory.createClause(subject, verb, object);
NPPhraseSpec subject2 = this.phraseFactory.createNounPhrase("a", "festa");
VPPhraseSpec verb2 = this.phraseFactory.createVerbPhrase("acabar");
verb2.setFeature(Feature.TENSE, Tense.IMPERSONAL_INFINITIVE);
SPhraseSpec s2 = this.phraseFactory.createClause(subject2, verb2);
s.addPostModifier("até");
s.addPostModifier(s2);
Assert.assertEquals("Você não vai ficar criando exemplos até a festa acabar.", getResult(s, "03"));
}
示例4: testEx17
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
@Test
public void testEx17() {
NPPhraseSpec np = this.phraseFactory.createNounPhrase("que");
VPPhraseSpec vp = this.phraseFactory.createVerbPhrase("instalar");
np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
vp.setFeature(Feature.TENSE, Tense.PAST);
vp.setFeature(Feature.PASSIVE, true);
PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("ao longo de");
NPPhraseSpec np2 = this.phraseFactory.createNounPhrase("calçadão");
np2.setSpecifier("o");
pp.addComplement(np2);
vp.addPostModifier(pp);
SPhraseSpec s = this.phraseFactory.createClause(np, vp);
Assert.assertEquals("Que foram instalados ao longo do calçadão.", getResult(s));
}
示例5: testEx17b
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
@Test
public void testEx17b() {
NPPhraseSpec np = this.phraseFactory.createNounPhrase("que");
VPPhraseSpec vp = this.phraseFactory.createVerbPhrase("instalar");
np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
vp.setFeature(Feature.TENSE, Tense.IMPERFECT);
vp.setFeature(Feature.PERFECT, true);
PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("ao longo de");
NPPhraseSpec np2 = this.phraseFactory.createNounPhrase("calçadão");
np2.setSpecifier("o");
pp.addComplement(np2);
vp.addPostModifier(pp);
SPhraseSpec s = this.phraseFactory.createClause(np, vp);
Assert.assertEquals("Que tinham instalado ao longo do calçadão.", getResult(s));
}
示例6: testEx17c
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
@Test
public void testEx17c() {
NPPhraseSpec np = this.phraseFactory.createNounPhrase("que");
VPPhraseSpec vp = this.phraseFactory.createVerbPhrase("instalar");
np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
vp.setFeature(Feature.TENSE, Tense.PAST);
vp.setFeature(Feature.PROGRESSIVE, true);
PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("ao longo de");
NPPhraseSpec np2 = this.phraseFactory.createNounPhrase("calçadão");
np2.setSpecifier("o");
pp.addComplement(np2);
vp.addPostModifier(pp);
SPhraseSpec s = this.phraseFactory.createClause(np, vp);
Assert.assertEquals("Que estiveram instalando ao longo do calçadão.", getResult(s));
}
示例7: testEx27
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
@Test
public void testEx27() {
VPPhraseSpec vp = this.phraseFactory.createVerbPhrase("dar");
PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("para");
VPPhraseSpec vp2 = this.phraseFactory.createVerbPhrase("ir");
vp2.setFeature(Feature.TENSE, Tense.IMPERSONAL_INFINITIVE);
PPPhraseSpec pp2 = this.phraseFactory.createPrepositionPhrase("de");
NPPhraseSpec np = this.phraseFactory.createNounPhrase("bar");
pp2.addComplement(np);
PPPhraseSpec pp3 = this.phraseFactory.createPrepositionPhrase("em");
pp3.addComplement(np);
vp2.addComplement(pp2);
vp2.addComplement(pp3);
pp.addComplement(vp2);
SPhraseSpec s = this.phraseFactory.createClause(vp, pp);
Assert.assertEquals("Dá para ir de bar em bar.", getResult(s));
}
示例8: testEx32
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
@Test
public void testEx32() {
VPPhraseSpec vp = this.phraseFactory.createVerbPhrase("chegar"); // chegar
vp.setFeature(Feature.MODAL, "dar"); // da para chegar
PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("perto de"); // perto
// de
pp.addPreModifier("bem"); // bem perto de
NPPhraseSpec np = this.phraseFactory.createNounPhrase("as", "quedas"); // as
// quedas
pp.addComplement(np); // bem perto das quedas
AdvPhraseSpec ap = this.phraseFactory.createAdverbPhrase("em"); // em
NPPhraseSpec np2 = this.phraseFactory.createNounPhrase("botes"); // botes
ap.addComplement(np2); // em botes
SPhraseSpec s = this.phraseFactory.createClause(vp, pp, ap);
Assert.assertEquals("Dá para chegar bem perto das quedas em botes.", getResult(s));
}
示例9: testEx35
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
@Test
public void testEx35() {
NPPhraseSpec np = this.phraseFactory.createNounPhrase("você");
VPPhraseSpec vp = this.phraseFactory.createVerbPhrase("passar");
vp.setFeature(Feature.PROSPECTIVE, true);
PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("por");
NPPhraseSpec np2 = this.phraseFactory.createNounPhrase("o", "bairro");
PPPhraseSpec pp2 = this.phraseFactory.createPrepositionPhrase("entre");
NPPhraseSpec np3 = this.phraseFactory.createNounPhrase("as", "parada");
np3.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
np3.addPostModifier("3 e 4");
pp2.addComplement(np3);
np2.addComplement(pp2);
pp.addComplement(np2);
vp.addComplement(pp);
SPhraseSpec s = this.phraseFactory.createClause(np, vp);
Assert.assertEquals("Você vai passar pelo bairro entre as paradas 3 e 4.", getResult(s));
}
示例10: testEx58
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
@Test
public void testEx58() {
NPPhraseSpec np = this.phraseFactory.createNounPhrase("o", "local");
np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
VPPhraseSpec vp = this.phraseFactory.createVerbPhrase("estar");
AdvPhraseSpec ap = this.phraseFactory.createAdverbPhrase("espalhado");
ap.addPreModifier("um pouco");
SPhraseSpec s = this.phraseFactory.createClause(np, vp, ap);
// TODO this example generates an ill-formed clause but, in the way
// the grammar currently is, neither (a) determiner-noun agreement
// happens, nor (b) subject-predicate agreement of copula clauses.
// commented out is the realisation one wishes to get.
Assert.assertEquals(
// "os locais estão um pouco espalhados",
"O locais estão um pouco espalhado.", getResult(s));
}
示例11: generateSubjects
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
/**
* Returns a list of synonymous expressions as subject for the given
* resource.
*
* @param resource
* the resource
* @param resourceType
* the type of the resource
* @param resourceGender
* the gender of the resource
* @return list of synonymous expressions
*/
public List<NPPhraseSpec> generateSubjects(Resource resource, OWLClass resourceType, Gender resourceGender) {
List<NPPhraseSpec> result = new ArrayList<NPPhraseSpec>();
// the textual representation of the resource itself
result.add(nlg.getNPPhrase(resource.getURI(), false, false));
// the class, e.g. 'this book'
NPPhraseSpec np = nlg.getNPPhrase(resourceType.toStringID(), false);
np.addPreModifier("This");
result.add(np);
// the pronoun depending on the gender of the resource
if (resourceGender.equals(Gender.MALE)) {
result.add(nlg.nlgFactory.createNounPhrase("he"));
} else if (resourceGender.equals(Gender.FEMALE)) {
result.add(nlg.nlgFactory.createNounPhrase("she"));
} else {
result.add(nlg.nlgFactory.createNounPhrase("it"));
}
return result;
}
示例12: processResourceNode
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
public NPPhraseSpec processResourceNode(Node node) {
// get string from URI
String s = uriConverter.convert(node.getURI());
// create word
NLGElement word = nlgFactory.createWord(s, LexicalCategory.NOUN);
// add gender information if enabled
if (useGenderInformation) {
Gender gender = genderDetector.getGender(s);
if (gender == Gender.FEMALE) {
word.setFeature(LexicalFeature.GENDER, simplenlg.features.Gender.FEMININE);
} else if (gender == Gender.MALE) {
word.setFeature(LexicalFeature.GENDER, simplenlg.features.Gender.MASCULINE);
}
}
// should be a proper noun, thus, will not be pluralized by morphology
word.setFeature(LexicalFeature.PROPER, true);
// wrap in NP
NPPhraseSpec np = nlgFactory.createNounPhrase(word);
return np;
}
示例13: processObject
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
private NPPhraseSpec processObject(Node object, boolean isClass) {
NPPhraseSpec element;
if (object.isVariable()) {
element = processVarNode(object);
} else if (object.isLiteral()) {
element = processLiteralNode(object);
} else if (object.isURI()) {
if (isClass) {
element = processClassNode(object, false);
} else {
element = processResourceNode(object);
}
} else {
throw new IllegalArgumentException("Can not convert blank node " + object + ".");
}
return element;
}
示例14: processClassNode
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
/**
* Converts the node that is supposed to represent a class in the knowledge
* base into an NL phrase.
*
* @param node
* the node
* @param plural
* whether the plural form should be used
* @return the NL phrase
*/
public NPPhraseSpec processClassNode(Node node, boolean plural) {
NPPhraseSpec object;
if (node.equals(OWL.Thing.asNode())) {
object = nlgFactory.createNounPhrase(GenericType.ENTITY.getNlr());
} else if (node.equals(RDFS.Literal.asNode())) {
object = nlgFactory.createNounPhrase(GenericType.VALUE.getNlr());
} else if (node.equals(RDF.Property.asNode())) {
object = nlgFactory.createNounPhrase(GenericType.RELATION.getNlr());
} else if (node.equals(RDF.type.asNode())) {
object = nlgFactory.createNounPhrase(GenericType.TYPE.getNlr());
} else {
String label = uriConverter.convert(node.getURI());
if (label != null) {
// get the singular form
// label = PlingStemmer.stem(label);
// we assume that classes are always used in lower case format
label = label.toLowerCase();
object = nlgFactory.createNounPhrase(nlgFactory.createWord(label, LexicalCategory.NOUN));
} else {
object = nlgFactory.createNounPhrase(GenericType.ENTITY.getNlr());
}
}
// set plural form
object.setPlural(plural);
return object;
}
示例15: getNPPhrase
import simplenlg.phrasespec.NPPhraseSpec; //导入依赖的package包/类
/**
* Takes a URI and returns a noun phrase for it
*
* @param uri
* the URI to convert
* @param plural
* whether it is in plural form
* @param isClass
* if URI is supposed to be a class
* @return the noun phrase
*/
public NPPhraseSpec getNPPhrase(String uri, boolean plural, boolean isClass) {
NPPhraseSpec object;
if (uri.equals(OWL.Thing.getURI())) {
object = nlgFactory.createNounPhrase(GenericType.ENTITY.getNlr());
} else if (uri.equals(RDFS.Literal.getURI())) {
object = nlgFactory.createNounPhrase(GenericType.VALUE.getNlr());
} else if (uri.equals(RDF.Property.getURI())) {
object = nlgFactory.createNounPhrase(GenericType.RELATION.getNlr());
} else if (uri.equals(RDF.type.getURI())) {
object = nlgFactory.createNounPhrase(GenericType.TYPE.getNlr());
} else {
String label = uriConverter.convert(uri);
if (label != null) {
if (isClass) {
// get the singular form
label = PlingStemmer.stem(label);
// we assume that classes are always used in lower case
// format
label = label.toLowerCase();
}
object = nlgFactory.createNounPhrase(nlgFactory.createWord(label, LexicalCategory.NOUN));
} else {
object = nlgFactory.createNounPhrase(GenericType.ENTITY.getNlr());
}
}
object.setPlural(plural);
return object;
}