Refactorización código


Former-commit-id: 73562da16e35b7dedf91127fa65a32be92b2f31a [formerly 8e04240b]
Former-commit-id: 3b9226729775b6badfc5c73d2fbb17708cde48db
parent 2b26aa34
This diff is collapsed.
......@@ -163,7 +163,6 @@ public class MorphologyProcessor extends simplenlg.morphology.MorphologyProcesso
if (root.getFeatureAsBoolean(Feature.PASSIVE) && root.hasFeature(Feature.INTERROGATIVE_TYPE)) {
realisedElements.remove(realisedElements.size() - 1);
} else {
//StringElement prevString = (StringElement) realisedElements.get(realisedElements.size() - 1);
String secondPart = "";
if (currentElement.getRealisation().contains(" ")) {
secondPart = currentElement.getRealisation().substring(currentElement.getRealisation().indexOf(" "));
......@@ -249,18 +248,25 @@ public class MorphologyProcessor extends simplenlg.morphology.MorphologyProcesso
}
}
if (prevElement.getFeatureAsBoolean(Feature.VERB_PRONOUN) != null) {
//linking resulting word to the verb
if (prevElement.getFeatureAsBoolean(Feature.PRONOUN_AFTER)) {
if (prevElement.getFeatureAsString(Feature.VERB_PRONOUN) == null) {
prevString.setRealisation(doAccentuation(prevElement.getFeatureAsString(LexicalFeature.BASE_FORM), result));
} else {
prevString.setRealisation(doAccentuation(prevElement.getFeatureAsString(Feature.VERB_PRONOUN), result));
}
currentElement.setRealisation("");
} else {
prevString.setRealisation(result);
currentElement.setRealisation("");
}
//setting new word
else {
try {
StringElement prevPronoun = (StringElement) realisedElements.get(realisedElements.size() - 3);
prevPronoun.setRealisation(result);
currentElement.setRealisation("");
} catch (Exception e) {
currentElement.setRealisation(result);
}
}
}
//impersonal phrase
......@@ -378,6 +384,12 @@ public class MorphologyProcessor extends simplenlg.morphology.MorphologyProcesso
//monosílabas: si lleva tilde se mantiene
if (syllables.size() == 1) {
}
//aguda no acentuada
else if ((Arrays.asList(VOWELS).contains(String.valueOf(conjugated.charAt(conjugated.length() - 1))) == false) ||
(Arrays.asList(VOWELS).contains(String.valueOf(conjugated.charAt(conjugated.length() - 2))) == false && Arrays.asList(VOWELS).contains(String.valueOf(conjugated.charAt(conjugated.length() - 1))) == false) ||
(Arrays.asList(VOWELS).contains(String.valueOf(conjugated.charAt(conjugated.length() - 2))) && Arrays.asList(SOFT_VOWELS).contains(String.valueOf(conjugated.charAt(conjugated.length() - 1))))) {
//do nothing
}
//aguda acentuada
else if (Arrays.asList(ACCENTUATED_VOWELS).contains(conjugated.substring(conjugated.length() - 1)) || (Arrays.asList(VOWELS).contains(String.valueOf(conjugated.charAt(conjugated.length() - 2))) && (conjugated.substring(conjugated.length() - 1).equals("n")) || conjugated.substring(conjugated.length() - 1).equals("s")) || ((Arrays.asList(VOWELS).contains(String.valueOf(conjugated.charAt(conjugated.length() - 3))) && conjugated.charAt(conjugated.length() - 2) == 'n' && conjugated.charAt(conjugated.length() - 1) == 's'))) {
letter = conjugated.charAt(accentIndex);
......
......@@ -139,7 +139,7 @@ public abstract class Realiser extends NLGModule {
}
//////////////////////////////verb + pronoun colocation/////////////////////////////////////////////////
//negated and interrogative sentences: verb+pronoun
if(postSyntax.getCategory().equals(DocumentCategory.SENTENCE)) {
if(postSyntax.getCategory() != null && postSyntax.getCategory().equals(DocumentCategory.SENTENCE)) {
if (postSyntax.getFeatureAsBoolean(Feature.NEGATED) == false && postSyntax.getFeatureAsBoolean(Feature.INTERROGATIVE_TYPE) == false) {
pronoun_after = true;
}
......@@ -161,20 +161,24 @@ public abstract class Realiser extends NLGModule {
} catch (Exception ex) {
}
if (Arrays.asList(SUBORDINATES).contains(e.getRealisation())) {
indexSubordinate = elements.indexOf(e);
}
if (Arrays.asList(ADVERBS).contains(e.getRealisation()) || e.getCategory().equals(LexicalCategory.ADVERB)) {
indexAdverb = elements.indexOf(e);
}
if (Arrays.asList(INDEFINITES).contains(e.getRealisation())) {
indexIndefinite = elements.indexOf(e);
}
if (Arrays.asList(INTERROGATIVES).contains(e.getRealisation())) {
indexInterrogative = elements.indexOf(e);
}
if (Arrays.asList(DESIDERATIVES).contains(e.getRealisation())) {
indexDesiderative = elements.indexOf(e);
try {
if (Arrays.asList(SUBORDINATES).contains(e.getRealisation())) {
indexSubordinate = elements.indexOf(e);
}
if (Arrays.asList(ADVERBS).contains(e.getRealisation()) || e.getCategory().equals(LexicalCategory.ADVERB)) {
indexAdverb = elements.indexOf(e);
}
if (Arrays.asList(INDEFINITES).contains(e.getRealisation())) {
indexIndefinite = elements.indexOf(e);
}
if (Arrays.asList(INTERROGATIVES).contains(e.getRealisation())) {
indexInterrogative = elements.indexOf(e);
}
if (Arrays.asList(DESIDERATIVES).contains(e.getRealisation())) {
indexDesiderative = elements.indexOf(e);
}
} catch (Exception ex) {
}
}
if (indexVerb >= 0) {
......
......@@ -19,17 +19,19 @@
package simplenlg.syntax.galician;
import gov.nih.nlm.nls.lvg.Lib.Category;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import simplenlg.features.*;
import simplenlg.framework.CoordinatedPhraseElement;
import simplenlg.framework.LexicalCategory;
import simplenlg.framework.PhraseElement;
import simplenlg.framework.*;
import simplenlg.phrasespec.*;
import javax.swing.text.Document;
import java.util.Locale;
// TODO: Auto-generated Javadoc
/**
......@@ -515,16 +517,16 @@ public class ClauseTest extends SimpleNLG4Test {
"eu quero a Mary", this.realiser.realise(_s2).getRealisation()); //$NON-NLS-1$
// test recognition of pronoun for correct form
PhraseElement subject = this.phraseFactory.createNounPhrase("can"); //$NON-NLS-1$
PhraseElement subject = this.phraseFactory.createNounPhrase("can");
subject.setFeature(InternalFeature.SPECIFIER, "un"); //$NON-NLS-1$
subject.addPostModifier("de ao lado"); //$NON-NLS-1$
PhraseElement object = this.phraseFactory.createNounPhrase("eu"); //$NON-NLS-1$
PhraseElement s = this.phraseFactory.createClause(subject,
"perseguir", object); //$NON-NLS-1$
s.setFeature(Feature.PROGRESSIVE, true);
realiser.setDebugMode(true);
Assert.assertEquals("un can de ao lado está perseguíndome", //$NON-NLS-1$
this.realiser.realise(s).getRealisation());
//realiser.setDebugMode(true);
Assert.assertEquals("Un can de ao lado está perseguíndome.", //$NON-NLS-1$
this.realiser.realiseSentence(s));
}
/**
......@@ -640,8 +642,7 @@ public class ClauseTest extends SimpleNLG4Test {
PhraseElement _s4 = this.phraseFactory.createClause(this.phraseFactory
.createNounPhrase("el"), "perseguir", //$NON-NLS-1$ //$NON-NLS-2$
this.phraseFactory.createNounPhrase("eu")); //$NON-NLS-1$
Assert.assertEquals("el perségueme", this.realiser.realise(_s4) //$NON-NLS-1$
.getRealisation());
Assert.assertEquals("El perségueme.", this.realiser.realiseSentence(_s4));
_s4 = this.phraseFactory
.createClause(
this.phraseFactory.createNounPhrase("el"), "perseguir", this.phraseFactory.createNounPhrase("me")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
......@@ -655,8 +656,10 @@ public class ClauseTest extends SimpleNLG4Test {
// anyway
PhraseElement _s5 = this.phraseFactory
.createClause("el", "perseguir", "eu"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
DocumentElement sentence = new DocumentElement(DocumentCategory.SENTENCE, null);
sentence.addComponent(_s5);
Assert.assertEquals(
"el perségueme", this.realiser.realise(_s5).getRealisation()); //$NON-NLS-1$
"El perségueme.", this.realiser.realise(sentence).getRealisation()); //$NON-NLS-1$
_s5 = this.phraseFactory.createClause("el", "perseguir", "eu"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
_s5.setFeature(Feature.PASSIVE, true);
......
......@@ -132,10 +132,10 @@ public class ContractionsTest extends SimpleNLG4Test {
}
/**
* Preposition + article tests
* Contractions between atonic pronouns
*/
@Test
public void testPronouns() {
public void testPronounsContractions() {
SPhraseSpec p = phraseFactory.createClause();
p.setSubject("María");
p.setIndirectObject("me");
......@@ -168,13 +168,25 @@ public class ContractionsTest extends SimpleNLG4Test {
p.setObject("o");
Assert.assertEquals("María dínolo.", this.realiser //$NON-NLS-1$
.realiseSentence(p));
SPhraseSpec p1 = phraseFactory.createClause();
p1.setSubject("María");
VPPhraseSpec vPhrase = phraseFactory.createVerbPhrase("dicir");
vPhrase.setIndirectObject("vos");
NLGElement object = phraseFactory.createNLGElement("as", LexicalCategory.PRONOUN);
object.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
object.setPlural(true);
vPhrase.setObject(object);
p1.setVerb(vPhrase);
Assert.assertEquals("María dívolas.", this.realiser //$NON-NLS-1$
.realiseSentence(p1));
}
/**
* Atonic pronoun collocation with the verb
*/
@Test
public void testVerbs() {
public void testPronounsCollocation() {
SPhraseSpec p = phraseFactory.createClause();
p.setSubject("María");
......@@ -191,13 +203,12 @@ public class ContractionsTest extends SimpleNLG4Test {
Assert.assertEquals("María dime.", this.realiser //$NON-NLS-1$
.realiseSentence(p));
vPhrase.setIndirectObject("vos");
NLGElement object = phraseFactory.createNLGElement("as", LexicalCategory.PRONOUN);
object.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
object.setPlural(true);
vPhrase.setObject(object);
p.setVerb(vPhrase);
Assert.assertEquals("María dívolas.", this.realiser //$NON-NLS-1$
.realiseSentence(p));
SPhraseSpec s = this.phraseFactory.createClause("María", "dicir");
s.setFeature(Feature.TENSE, Tense.PAST);
s.setIndirectObject("che");
s.setObject("o");
s.addPreModifier(this.lexicon.getWord("quizais", LexicalCategory.ADVERB));
Assert.assertEquals("María quizais cho dixo.", this.realiser.realiseSentence(s));
}
}
......@@ -78,37 +78,37 @@ public class CoordinationTest extends SimpleNLG4Test {
CoordinatedPhraseElement coord = this.phraseFactory
.createCoordinatedPhrase(this.getUp, this.fallDown);
coord.setFeature(Feature.TENSE, Tense.PAST);
Assert.assertEquals("levantouse e caeuse", this.realiser
.realise(coord).getRealisation());
Assert.assertEquals("Levantouse e caeuse.", this.realiser
.realiseSentence(coord));
// add a premodifier
coord.addPreModifier("despacio");
Assert.assertEquals("despacio levantouse e caeuse", this.realiser
.realise(coord).getRealisation());
Assert.assertEquals("Despacio levantouse e caeuse.", this.realiser
.realiseSentence(coord));
// adda postmodifier
coord.addPostModifier(this.behindTheCurtain);
Assert.assertEquals("despacio levantouse e caeuse trala cortina",
this.realiser.realise(coord).getRealisation());
Assert.assertEquals("Despacio levantouse e caeuse trala cortina.",
this.realiser.realiseSentence(coord));
// put within the context of a sentence
SPhraseSpec s = this.phraseFactory.createClause("Jake", coord);
s.setFeature(Feature.TENSE, Tense.PAST);
Assert.assertEquals(
"Jake despacio levantouse e caeuse trala cortina",
this.realiser.realise(s).getRealisation());
"Jake despacio levantouse e caeuse trala cortina.",
this.realiser.realiseSentence(s));
// add premod to the sentence
s.addPreModifier(this.lexicon.getWord("sen embargo", LexicalCategory.ADVERB));
Assert.assertEquals(
"Jake sen embargo despacio levantouse e caeuse trala cortina",
this.realiser.realise(s).getRealisation());
"Jake sen embargo despacio levantouse e caeuse trala cortina.",
this.realiser.realiseSentence(s));
// add postmod to the sentence
s.addPostModifier(this.inTheRoom);
Assert.assertEquals(
"Jake sen embargo despacio levantouse e caeuse trala cortina na habitación",
this.realiser.realise(s).getRealisation());
"Jake sen embargo despacio levantouse e caeuse trala cortina na habitación.",
this.realiser.realiseSentence(s));
}
/**
......
......@@ -85,19 +85,17 @@ public class PhraseSpecTest extends SimpleNLG4Test {
// test modifier placement
SPhraseSpec c2 = (SPhraseSpec) phraseFactory.createClause();
SPhraseSpec c2 = phraseFactory.createClause();
c2.setVerb("ver");
//c2.setFeature(Feature.);
c2.setSubject("o home");
c2.setObject("eu");
c2.addFrontModifier("afortunadamente");
c2.addModifier("rápidamente");
c2.addModifier("no parque");
//c2.setFeature(Feature.NEGATED, true);
// try setting tense directly as a feature
c2.setFeature(Feature.TENSE, Tense.PAST);
Assert.assertEquals("afortunadamente o home viume rápidamente no parque", this.realiser //$NON-NLS-1$
.realise(c2).getRealisation());
Assert.assertEquals("Afortunadamente o home viume rápidamente no parque.", this.realiser //$NON-NLS-1$
.realiseSentence(c2));
}
......
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