Add a few fixes

parent 2646380e
......@@ -71,7 +71,7 @@ Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret
<fileset dir="${res.dir}" includes="*.properties"/>
</copy>
<copy todir="${classes.dir}/simplenlg/lexicon">
<fileset dir="${res.dir}" includes="default-lexicon.xml" />
<fileset dir="${res.dir}" includes="*.xml"/>
</copy>
</target>
......@@ -83,7 +83,7 @@ Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret
<compilerarg value="-XDignore.symbol.file" />
</javac>
<copy todir="${classes.dir}/simplenlg/lexicon">
<fileset dir="${res.dir}" includes="default-lexicon.xml" />
<fileset dir="${res.dir}" includes="*.xml"/>
</copy>
</target>
......
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
......
......@@ -149,12 +149,11 @@ public abstract class XMLLexicon extends Lexicon {
try {
URL defaultLexicon = this.getClass().getClassLoader().getResource(resourceName);
if (null != defaultLexicon) {
createLexicon(defaultLexicon.toURI());
} else {
createLexicon(this.getClass().getResource(
"/simplenlg/lexicon/default-lexicon.xml").toURI());
defaultLexicon = this.getClass().getClassLoader().getResource("simplenlg/lexicon/" + resourceName);
createLexicon(defaultLexicon.toURI());
}
} catch (URISyntaxException ex) {
......
......@@ -121,8 +121,14 @@ public class MorphologyProcessor extends simplenlg.morphology.MorphologyProcesso
}
}
if (prevElement != null && LexicalCategory.VERB.equals(prevElement.getCategory()) && LexicalCategory.PRONOUN.equals(eachElement.getCategory())) {
realisedElements.add(0, currentElement);
if (prevElement != null && (LexicalCategory.VERB.equals(prevElement.getCategory()) || LexicalCategory.MODAL.equals(prevElement.getCategory())) && LexicalCategory.PRONOUN.equals(eachElement.getCategory())) {
int i;
for (i = 0; i < elements.size(); i++) {
if (LexicalCategory.VERB.equals(elements.get(i).getCategory())) {
break;
}
}
realisedElements.add(i, currentElement);
} else {
realisedElements.add(currentElement);
}
......
......@@ -1498,14 +1498,22 @@ public class MorphologyRules extends simplenlg.morphology.MorphologyRules {
private String buildRegularAdjective(String baseForm, Gender gender, NumberAgreement number) {
String morphology = null;
if (baseForm != null) {
morphology = baseForm.substring(0, baseForm.length() - 1);
if (Gender.FEMININE.equals(gender)) {
morphology = morphology + "a";
} else if (Gender.MASCULINE.equals(gender)) {
morphology = morphology + "o";
}
if (NumberAgreement.PLURAL.equals(number)) {
morphology = morphology + "s";
Character lastChar = baseForm.charAt(baseForm.length() - 1);
if (lastChar.equals('a') || lastChar.equals('o')) {
morphology = baseForm.substring(0, baseForm.length() - 1);
if (Gender.FEMININE.equals(gender)) {
morphology = morphology + "a";
} else if (Gender.MASCULINE.equals(gender)) {
morphology = morphology + "o";
}
if (NumberAgreement.PLURAL.equals(number)) {
morphology = morphology + "s";
}
} else {
morphology = baseForm;
if (NumberAgreement.PLURAL.equals(number)) {
morphology = morphology + "es";
}
}
}
return morphology;
......
......@@ -185,7 +185,6 @@ public abstract class OrthographyProcessor extends NLGModule {
if (postmod.getFeatureAsBoolean(Feature.APPOSITIVE)) {
buffer.append(", ");
buffer.append(realise(postmod));
if (i < len - 1) {
buffer.append(", ");
}
......@@ -281,6 +280,10 @@ public abstract class OrthographyProcessor extends NLGModule {
*/
protected void terminateSentence(StringBuffer realisation, boolean interrogative) {
char character = realisation.charAt(realisation.length() - 1);
// if (character == ','){
// realisation.deleteCharAt(realisation.length() - 1);
// character = realisation.charAt(realisation.length() - 1);
// }
if (character != '.' && character != '?') {
if (interrogative) {
realisation.append('?');
......
......@@ -220,16 +220,15 @@ class VerbPhraseHelper extends simplenlg.syntax.VerbPhraseHelper {
frontVG = addHave(frontVG, vgComponents, modal, tenseValue);
}
frontVG = pushIfModal(actualModal != null, phrase, frontVG,
vgComponents);
frontVG = pushIfModal(actualModal != null, phrase, frontVG, vgComponents);
pushModal(actualModal, phrase, vgComponents);
frontVG = addReflexivePronoun(phrase, vgComponents, frontVG);
frontVG = createNot(phrase, vgComponents, frontVG, modal != null);
if (frontVG != null) {
pushFrontVerb(phrase, vgComponents, frontVG, formValue, interrogative);
frontVG.setFeature(Feature.FORM, formValue);
}
pushModal(actualModal, phrase, vgComponents);
return vgComponents;
}
......@@ -287,6 +286,48 @@ class VerbPhraseHelper extends simplenlg.syntax.VerbPhraseHelper {
return frontVG;
}
private NLGElement addReflexivePronoun(PhraseElement phrase, Stack<NLGElement> vgComponents, NLGElement frontVG) {
if (phrase.getFeatureAsBoolean(LexicalFeature.REFLEXIVE)) {
Person p = (Person) phrase.getFeature(Feature.PERSON);
NumberAgreement n = (NumberAgreement) phrase.getFeature(Feature.NUMBER);
InflectedWordElement pronoun;
switch (p) {
case FIRST:
switch (n) {
case PLURAL:
pronoun = new InflectedWordElement("nosotros", LexicalCategory.PRONOUN);
break;
default:
pronoun = new InflectedWordElement("yo", LexicalCategory.PRONOUN);
}
break;
case SECOND:
switch (n) {
case PLURAL:
pronoun = new InflectedWordElement("vosotros", LexicalCategory.PRONOUN);
break;
default:
pronoun = new InflectedWordElement("tú", LexicalCategory.PRONOUN);
}
break;
default:
switch (n) {
case PLURAL:
pronoun = new InflectedWordElement("ellos", LexicalCategory.PRONOUN);
break;
default:
pronoun = new InflectedWordElement("él", LexicalCategory.PRONOUN);
}
}
vgComponents.push(frontVG);
pronoun.setParent(phrase);
vgComponents.push(pronoun);
return null;
}
return frontVG;
}
/**
* Adds <em>have</em> to the stack.
*
......@@ -418,6 +459,22 @@ class VerbPhraseHelper extends simplenlg.syntax.VerbPhraseHelper {
}
}
/**
* Checks to see if the phrase is in imperative, infinitive or bare
* infinitive form. If it is then no morphology is done on the main verb.
*
* @param formValue the <code>Form</code> of the phrase.
* @param frontVG the first verb in the verb group.
*/
@Override
protected void checkImperativeInfinitive(Object formValue,
NLGElement frontVG) {
if (frontVG != null && !frontVG.getParent().getFeatureAsBoolean(Feature.PERFECT)) {
super.checkImperativeInfinitive(formValue, frontVG);
}
}
/**
* Determines the number agreement for the phrase ensuring that any number
* agreement on the parent element is inherited by the phrase.
......
......@@ -20,18 +20,9 @@
package simplenlg.syntax.english;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Test;
import simplenlg.features.DiscourseFunction;
import simplenlg.features.Feature;
import simplenlg.features.Tense;
import simplenlg.features.Gender;
import simplenlg.features.InternalFeature;
import simplenlg.features.LexicalFeature;
import simplenlg.features.NumberAgreement;
import simplenlg.features.Person;
import simplenlg.features.*;
import simplenlg.framework.CoordinatedPhraseElement;
import simplenlg.framework.LexicalCategory;
import simplenlg.framework.NLGElement;
......@@ -611,7 +602,7 @@ public class NounPhraseTest extends SimpleNLG4Test {
PhraseElement _rott = this.phraseFactory.createNounPhrase("a", "rottweiler");
_rott.setFeature(Feature.APPOSITIVE, true);
_dog.addPostModifier(_rott);
SPhraseSpec _sent = this.phraseFactory.createClause(_dog, "ran");
SPhraseSpec _sent = this.phraseFactory.createClause(_dog, "ran");
Assert.assertEquals("The dog, a rottweiler, runs.", this.realiser.realiseSentence(_sent));
}
}
......@@ -604,6 +604,6 @@ public class NounPhraseTest extends SimpleNLG4Test {
_rott.setFeature(Feature.APPOSITIVE, true);
_dog.addPostModifier(_rott);
SPhraseSpec _sent = this.phraseFactory.createClause(_dog, "correr");
Assert.assertEquals("El perro, un rottweiler corre.", this.realiser.realiseSentence(_sent));
Assert.assertEquals("El perro, un rottweiler, corre.", this.realiser.realiseSentence(_sent));
}
}
......@@ -433,19 +433,19 @@ public class VerbPhraseTest extends SimpleNLG4Test {
// set a modal
coord1.setFeature(Feature.MODAL, "poder"); //$NON-NLS-1$
assertEquals(
"puede no haber besado el perro y puede no haber golpeado el niño", //$NON-NLS-1$
"no puede haber besado el perro y no puede haber golpeado el niño", //$NON-NLS-1$
this.realiser.realise(coord1).getRealisation());
// set perfect and progressive
coord1.setFeature(Feature.PERFECT, true);
coord1.setFeature(Feature.PROGRESSIVE, true);
assertEquals("puede no haber estado besando el perro y puede no haber estado golpeando el niño", this.realiser.realise( //$NON-NLS-1$
assertEquals("no puede haber estado besando el perro y no puede haber estado golpeando el niño", this.realiser.realise( //$NON-NLS-1$
coord1).getRealisation());
// now aggregate
coord1.setFeature(Feature.AGGREGATE_AUXILIARY, true);
assertEquals(
"puede no haber estado besando el perro y golpeando el niño", //$NON-NLS-1$
"no puede haber estado besando el perro y golpeando el niño", //$NON-NLS-1$
this.realiser.realise(coord1).getRealisation());
}
}
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