Commit 1de6ba8c authored by Andrea Cascallar Fuentes's avatar Andrea Cascallar Fuentes

Refactorización código

parent 8e04240b
Pipeline #1639 passed with stage
in 1 minute and 25 seconds
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -18,6 +18,7 @@
*/
package simplenlg.morphology.galician;
import simplenlg.features.DiscourseFunction;
import simplenlg.features.Feature;
import simplenlg.features.InternalFeature;
import simplenlg.features.LexicalFeature;
......
......@@ -1803,6 +1803,13 @@ public class MorphologyRules extends simplenlg.morphology.MorphologyRules {
String realised = null;
if(element.getFeature(InternalFeature.DISCOURSE_FUNCTION) != null && element.getFeature(InternalFeature.DISCOURSE_FUNCTION).equals(DiscourseFunction.COMPLEMENT)) {
NLGElement parent = element.getParent();
if(parent != null && (parent.getFeature(InternalFeature.DISCOURSE_FUNCTION).equals(DiscourseFunction.INDIRECT_OBJECT))) {
element.setFeature(InternalFeature.DISCOURSE_FUNCTION, parent.getFeature(InternalFeature.DISCOURSE_FUNCTION));
}
}
if (!element.getFeatureAsBoolean(InternalFeature.NON_MORPH).booleanValue() && !isWHPronoun(element)) {
Object genderValue = element.getFeature(LexicalFeature.GENDER);
Object personValue = element.getFeature(Feature.PERSON);
......
......@@ -18,7 +18,9 @@
*/
package simplenlg.realiser;
import simplenlg.features.DiscourseFunction;
import simplenlg.features.Feature;
import simplenlg.features.InternalFeature;
import simplenlg.framework.*;
import simplenlg.lexicon.Lexicon;
import simplenlg.morphology.MorphologyProcessor;
......
......@@ -64,6 +64,7 @@ public abstract class SyntaxProcessor extends NLGModule {
@Override
public NLGElement realise(NLGElement element) {
NLGElement realisedElement = null;
List<NLGElement> subjects;
if (element != null
&& !element.getFeatureAsBoolean(Feature.ELIDED).booleanValue()) {
......@@ -86,6 +87,18 @@ public abstract class SyntaxProcessor extends NLGModule {
String baseForm = ((InflectedWordElement) element)
.getBaseForm();
ElementCategory category = element.getCategory();
if(category.equalTo(LexicalCategory.VERB) && element.getFeatureAsString(Feature.PERSON) == null) {
if(element.getParent() != null) {
subjects = element.getParent().getFeatureAsElementList(InternalFeature.SUBJECTS);
if(subjects.size() == 0 && element.getParent().getParent() != null) {
subjects = element.getParent().getParent().getFeatureAsElementList(InternalFeature.SUBJECTS);
}
if(subjects.size() == 1) {
element.setFeature(Feature.PERSON, subjects.get(0).getFeature(Feature.PERSON));
}
}
}
if (this.lexicon != null && baseForm != null) {
WordElement word = ((InflectedWordElement) element)
......
......@@ -292316,7 +292316,7 @@
<base>quen</base>
<category>pronoun</category>
<gender>neuter</gender>
<number>both</number>
<number>singular</number>
<person>none</person>
</word>
<word>
......@@ -210,5 +210,18 @@ public class ContractionsTest extends SimpleNLG4Test {
s.addPreModifier(this.lexicon.getWord("quizais", LexicalCategory.ADVERB));
Assert.assertEquals("María quizais cho dixo.", this.realiser.realiseSentence(s));
SPhraseSpec p1 = phraseFactory.createClause("eu", "saber");
p1.setFeature(Feature.NEGATED, true);
SPhraseSpec q = phraseFactory.createClause("María", "dicir");
q.setIndirectObject("ti");
q.setFeature(Feature.COMPLEMENTISER, "se");
q.setFeature(Feature.TENSE, Tense.PAST);
p1.addComplement(q);
Assert.assertEquals("eu non sei se María che dixo", this.realiser //$NON-NLS-1$
.realise(p1).getRealisation());
}
}
......@@ -298,83 +298,6 @@ public class InterrogativeTest extends SimpleNLG4Test {
.realise(s).getRealisation());
}
/**
* Test for wh questions.
*/
/* @Test
public void testWHQuestions() {
// subject interrogative
setUp();
this.realiser.setLexicon(this.lexicon);
this.s4.setFeature(Feature.INTERROGATIVE_TYPE,
InterrogativeType.WHO_SUBJECT);
Assert.assertEquals(
"sen embargo quen collerán as pelotas na tenda mañán", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// subject interrogative in passive
setUp();
this.s4.setFeature(Feature.PASSIVE, true);
this.s4.setFeature(Feature.INTERROGATIVE_TYPE,
InterrogativeType.WHO_SUBJECT);
Assert.assertEquals(
"sen embargo por quen serán as pelotas collidas na tenda mañán", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// object interrogative
setUp();
this.s4.setFeature(Feature.INTERROGATIVE_TYPE,
InterrogativeType.WHAT_OBJECT);
Assert.assertEquals(
"sen embargo que collerán Jane e Andrew na tenda mañán", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// object interrogative with passive
setUp();
this.s4.setFeature(Feature.INTERROGATIVE_TYPE,
InterrogativeType.WHAT_OBJECT);
this.s4.setFeature(Feature.PASSIVE, true);
Assert.assertEquals(
"sen embargo que serán collidas na tenda por Jane e Andrew mañán", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// how-question + passive
setUp();
this.s4.setFeature(Feature.PASSIVE, true);
this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.HOW);
Assert.assertEquals(
"sen embargo como serán collidas as pelotas na tenda por Jane e Andrew mañán", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// // why-question + passive
setUp();
this.s4.setFeature(Feature.PASSIVE, true);
this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
Assert.assertEquals(
"sen embargo por que serán collidas as pelotas na tenda por Jane e Andrew mañán", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// how question with modal
setUp();
this.s4.setFeature(Feature.PASSIVE, true);
this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.HOW);
this.s4.setFeature(Feature.MODAL, "deber"); //$NON-NLS-1$
Assert.assertEquals(
"sen embargo como deberán ser collidas as pelotas na tenda por Jane e Andrew mañán", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// indirect object
setUp();
this.realiser.setLexicon(this.lexicon);
this.s3.setFeature(Feature.INTERROGATIVE_TYPE,
InterrogativeType.WHO_INDIRECT_OBJECT);
Assert.assertEquals("a quen dá o home a flor de John", //$NON-NLS-1$
this.realiser.realise(this.s3).getRealisation());
}*/
/**
* WH movement in the progressive
*/
......@@ -573,43 +496,6 @@ public class InterrogativeTest extends SimpleNLG4Test {
}
/**
* Test for questions with "be"
*/
/* @Test
public void testBeQuestions() {
SPhraseSpec p = this.phraseFactory.createClause(
this.phraseFactory.createNounPhrase("unha", "pelota"),
this.phraseFactory.createWord("ser", LexicalCategory.VERB),
this.phraseFactory.createNounPhrase("un", "xoguete"));
p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
Assert.assertEquals("que é unha pelota", this.realiser.realise(p)
.getRealisation());
p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
Assert.assertEquals("é unha pelota un xoguete", this.realiser.realise(p)
.getRealisation());
p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
Assert.assertEquals("que é un xoguete", this.realiser.realise(p)
.getRealisation());
SPhraseSpec p2 = this.phraseFactory.createClause("Mary", "ser",
"bonita");
p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
Assert.assertEquals("por que é Mary bonita", this.realiser.realise(p2)
.getRealisation());
p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHERE);
Assert.assertEquals("onde é Mary bonita", this.realiser.realise(p2)
.getRealisation());
p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
Assert.assertEquals("quen é bonita", this.realiser.realise(p2)
.getRealisation());
}*/
/**
* Test for questions with "be" in future tense
*/
......
......@@ -82,7 +82,7 @@ public class InterrogativeTest2 extends SimpleNLG4Test {
this.s4.getObject().setFeature(LexicalFeature.GENDER, Gender.FEMININE);
this.s4.addPostModifier("na tenda"); //$NON-NLS-1$
this.s4.setFeature(Feature.CUE_PHRASE, "sen embargo"); //$NON-NLS-1$
this.s4.addFrontModifier("mañán"); //$NON-NLS-1$
this.s4.addFrontModifier("mañá"); //$NON-NLS-1$
this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
// this.s5 = new SPhraseSpec();
// this.s5.setSubject(new NPPhraseSpec("the", "dog"));
......@@ -97,6 +97,7 @@ public class InterrogativeTest2 extends SimpleNLG4Test {
*/
@Test
public void testWHQuestions() {
//todo
// subject interrogative
setUp();
......@@ -104,7 +105,7 @@ public class InterrogativeTest2 extends SimpleNLG4Test {
this.s4.setFeature(Feature.INTERROGATIVE_TYPE,
InterrogativeType.WHO_SUBJECT);
Assert.assertEquals(
"sen embargo quen collerán as pelotas na tenda mañán", //$NON-NLS-1$
"sen embargo quen collerán as pelotas na tenda mañá", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// subject interrogative in passive
......@@ -114,7 +115,7 @@ public class InterrogativeTest2 extends SimpleNLG4Test {
InterrogativeType.WHO_SUBJECT);
Assert.assertEquals(
"sen embargo por quen serán as pelotas collidas na tenda mañán", //$NON-NLS-1$
"sen embargo por quen serán as pelotas collidas na tenda mañá", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// object interrogative
......@@ -122,7 +123,7 @@ public class InterrogativeTest2 extends SimpleNLG4Test {
this.s4.setFeature(Feature.INTERROGATIVE_TYPE,
InterrogativeType.WHAT_OBJECT);
Assert.assertEquals(
"sen embargo que collerán Jane e Andrew na tenda mañán", //$NON-NLS-1$
"sen embargo que collerán Jane e Andrew na tenda mañá", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// object interrogative with passive
......@@ -132,7 +133,7 @@ public class InterrogativeTest2 extends SimpleNLG4Test {
this.s4.setFeature(Feature.PASSIVE, true);
Assert.assertEquals(
"sen embargo que serán collidas na tenda por Jane e Andrew mañán", //$NON-NLS-1$
"sen embargo que serán collidas na tenda por Jane e Andrew mañá", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// how-question + passive
......@@ -140,7 +141,7 @@ public class InterrogativeTest2 extends SimpleNLG4Test {
this.s4.setFeature(Feature.PASSIVE, true);
this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.HOW);
Assert.assertEquals(
"sen embargo como serán collidas as pelotas na tenda por Jane e Andrew mañán", //$NON-NLS-1$
"sen embargo como serán collidas as pelotas na tenda por Jane e Andrew mañá", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// // why-question + passive
......@@ -148,7 +149,7 @@ public class InterrogativeTest2 extends SimpleNLG4Test {
this.s4.setFeature(Feature.PASSIVE, true);
this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
Assert.assertEquals(
"sen embargo por que serán collidas as pelotas na tenda por Jane e Andrew mañán", //$NON-NLS-1$
"sen embargo por que serán collidas as pelotas na tenda por Jane e Andrew mañá", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// how question with modal
......@@ -157,7 +158,7 @@ public class InterrogativeTest2 extends SimpleNLG4Test {
this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.HOW);
this.s4.setFeature(Feature.MODAL, "deber"); //$NON-NLS-1$
Assert.assertEquals(
"sen embargo como deberán ser collidas as pelotas na tenda por Jane e Andrew mañán", //$NON-NLS-1$
"sen embargo como deberán ser collidas as pelotas na tenda por Jane e Andrew mañá", //$NON-NLS-1$
this.realiser.realise(this.s4).getRealisation());
// indirect object
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment