From c86cbc9d1c638b6bf22cb3bc46bf1e795fd14ea1 Mon Sep 17 00:00:00 2001
From: Arash Sabet
Date: Fri, 7 Jul 2017 08:36:46 -0400
Subject: [PATCH 01/10] Fixed test projects' warning messages.
---
SharpSimpleNLGTests/syntax/ClauseAggregationTest.cs | 4 ++--
SharpSimpleNLGTests/syntax/DocumentElementTest.cs | 2 +-
SharpSimpleNLGTests/syntax/InterrogativeTest.cs | 3 +--
SharpSimpleNLGTests/syntax/OrthographyFormatTest.cs | 2 +-
SharpSimpleNLGTests/syntax/SimpleNLG4Test.cs | 2 +-
5 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/SharpSimpleNLGTests/syntax/ClauseAggregationTest.cs b/SharpSimpleNLGTests/syntax/ClauseAggregationTest.cs
index 14e87ff..98e8388 100644
--- a/SharpSimpleNLGTests/syntax/ClauseAggregationTest.cs
+++ b/SharpSimpleNLGTests/syntax/ClauseAggregationTest.cs
@@ -42,7 +42,7 @@ public class ClauseAggregationTest : SimpleNLG4TestBase
{
// set up a few more fixtures
/** The s4. */
- public SPhraseSpec s1, s2, s3, s4, s5, s6;
+ public SPhraseSpec s5, s6;
public Aggregator aggregator = new Aggregator();
public ClauseCoordinationRule coord = new ClauseCoordinationRule();
public ForwardConjunctionReductionRule fcr = new ForwardConjunctionReductionRule();
@@ -56,7 +56,7 @@ public class ClauseAggregationTest : SimpleNLG4TestBase
*/
[SetUp]
- protected void setUp()
+ protected override void setUp()
{
aggregator.initialise();
diff --git a/SharpSimpleNLGTests/syntax/DocumentElementTest.cs b/SharpSimpleNLGTests/syntax/DocumentElementTest.cs
index 03e2945..6d526f5 100644
--- a/SharpSimpleNLGTests/syntax/DocumentElementTest.cs
+++ b/SharpSimpleNLGTests/syntax/DocumentElementTest.cs
@@ -50,7 +50,7 @@ public class DocumentElementTest : SimpleNLG4TestBase
*/
[SetUp]
- protected void setUp()
+ protected override void setUp()
{
p1 = this.phraseFactory.createClause("you", "be", "happy");
p2 = this.phraseFactory.createClause("I", "be", "sad");
diff --git a/SharpSimpleNLGTests/syntax/InterrogativeTest.cs b/SharpSimpleNLGTests/syntax/InterrogativeTest.cs
index 1fcdeb4..38190b2 100644
--- a/SharpSimpleNLGTests/syntax/InterrogativeTest.cs
+++ b/SharpSimpleNLGTests/syntax/InterrogativeTest.cs
@@ -40,11 +40,10 @@ public class InterrogativeTest : SimpleNLG4TestBase
// set up a few more fixtures
/** The s5. */
- SPhraseSpec s1, s2, s3, s4;
[SetUp]
- protected void setUp()
+ protected override void setUp()
{
// // the man gives the woman John's flower
diff --git a/SharpSimpleNLGTests/syntax/OrthographyFormatTest.cs b/SharpSimpleNLGTests/syntax/OrthographyFormatTest.cs
index 1b2a8cb..29df4c5 100644
--- a/SharpSimpleNLGTests/syntax/OrthographyFormatTest.cs
+++ b/SharpSimpleNLGTests/syntax/OrthographyFormatTest.cs
@@ -42,7 +42,7 @@ public class OrthographyFormatTest : SimpleNLG4TestBase
public string list2Realisation;
[SetUp]
- public void setUp()
+ public new void setUp()
{
list2Realisation = new StringBuilder("* in the room").append("\n* ").append(list1Realisation).append("\n").ToString();
diff --git a/SharpSimpleNLGTests/syntax/SimpleNLG4Test.cs b/SharpSimpleNLGTests/syntax/SimpleNLG4Test.cs
index f6cdee7..99f8453 100644
--- a/SharpSimpleNLGTests/syntax/SimpleNLG4Test.cs
+++ b/SharpSimpleNLGTests/syntax/SimpleNLG4Test.cs
@@ -68,7 +68,7 @@ public class SimpleNLG4TestBase
*/
[SetUp]
- protected void setUp()
+ protected virtual void setUp()
{
this.lexicon = Lexicon.getDefaultLexicon();
From 98653f75cef9842526ab1d5943291456076aa20b Mon Sep 17 00:00:00 2001
From: Arash Sabet
Date: Fri, 7 Jul 2017 10:33:43 -0400
Subject: [PATCH 02/10] Added a test library project by targetting .net
standard 1.6.
---
SharpSimpleNLG.sln | 8 +-
.../SharpSimpleNLGUnitTests.csproj | 35 +
.../external/ExternalTest.cs | 562 ++++++++
.../format/EnumeratedListTest.cs | 101 ++
.../format/NumberedPrefixTest.cs | 111 ++
.../format/TextFormatterTest.cs | 161 +++
.../format/english/EnumeratedListTest.java | 98 ++
.../format/english/NumberedPrefixTest.java | 75 ++
.../format/english/TextFormatterTest.java | 157 +++
.../helpers/ExtensionHelpersTest.cs | 336 +++++
.../helpers/RegexExercises.cs | 151 +++
.../lexicon/LexicalVariantsTest.java | 285 ++++
.../lexicon/MultipleLexiconTest.java | 103 ++
.../lexicon/NIHDBLexiconTest.java | 251 ++++
.../lexicon/SharedLexiconTests.java | 137 ++
.../lexicon/XMLLexiconTest.cs | 155 +++
.../lexicon/english/LexicalVariantsTest.java | 285 ++++
.../lexicon/english/MultipleLexiconTest.java | 103 ++
.../lexicon/english/NIHDBLexiconTest.java | 251 ++++
.../lexicon/english/SharedLexiconTests.java | 137 ++
.../lexicon/english/XMLLexiconTest.java | 108 ++
.../morphology/DeterminerAgrHelper.cs | 244 ++++
.../morphology/DeterminerAgrHelperTest.cs | 103 ++
.../morphology/MorphologyProcessor.cs | 302 +++++
.../morphology/MorphologyRules.cs | 1148 +++++++++++++++++
.../english/DeterminerAgrHelperTest.java | 75 ++
.../realiser/RealiserTest.cs | 173 +++
.../realiser/english/RealiserTest.java | 173 +++
.../syntax/AdjectivePhraseTest.cs | 160 +++
.../syntax/ClauseAggregationTest.cs | 259 ++++
SharpSimpleNLGUnitTests/syntax/ClauseTest.cs | 886 +++++++++++++
.../syntax/CoordinationTest.cs | 200 +++
.../syntax/DeterminerTest.cs | 400 ++++++
.../syntax/DocumentElementTest.cs | 209 +++
SharpSimpleNLGUnitTests/syntax/ElisionTest.cs | 97 ++
SharpSimpleNLGUnitTests/syntax/FeatureTest.cs | 346 +++++
.../syntax/HTMLFormatterTest.cs | 138 ++
.../syntax/InterrogativeTest.cs | 847 ++++++++++++
.../syntax/NounPhraseTest.cs | 643 +++++++++
.../syntax/OrthographyFormatTest.cs | 195 +++
.../syntax/PhraseSpecTest.cs | 92 ++
.../syntax/PremodifierTest.cs | 101 ++
.../syntax/PrepositionalPhraseTest.cs | 105 ++
.../syntax/SimpleNLG4Test.cs | 245 ++++
.../syntax/StandAloneExample.cs | 117 ++
.../syntax/StringElementTest.cs | 413 ++++++
.../syntax/TutorialTest.cs | 465 +++++++
.../syntax/VerbPhraseTest.cs | 472 +++++++
.../syntax/english/AdjectivePhraseTest.java | 168 +++
.../syntax/english/ClauseAggregationTest.java | 273 ++++
.../syntax/english/ClauseTest.java | 926 +++++++++++++
.../syntax/english/CoordinationTest.java | 201 +++
.../syntax/english/DeterminerTest.java | 388 ++++++
.../syntax/english/DocumentElementTest.java | 209 +++
.../syntax/english/ElisionTest.java | 105 ++
.../syntax/english/FeatureTest.java | 368 ++++++
.../syntax/english/HTMLFormatterTest.java | 138 ++
.../syntax/english/InterrogativeTest.java | 836 ++++++++++++
.../syntax/english/NounPhraseTest.java | 617 +++++++++
.../syntax/english/OrthographyFormatTest.java | 205 +++
.../syntax/english/PhraseSpecTest.java | 120 ++
.../syntax/english/PremodifierTest.java | 114 ++
.../english/PrepositionalPhraseTest.java | 113 ++
.../syntax/english/SimpleNLG4Test.java | 145 +++
.../syntax/english/StandAloneExample.java | 123 ++
.../syntax/english/StringElementTest.java | 407 ++++++
.../syntax/english/TutorialTest.java | 450 +++++++
.../syntax/english/VerbPhraseTest.java | 461 +++++++
68 files changed, 18584 insertions(+), 1 deletion(-)
create mode 100644 SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj
create mode 100644 SharpSimpleNLGUnitTests/external/ExternalTest.cs
create mode 100644 SharpSimpleNLGUnitTests/format/EnumeratedListTest.cs
create mode 100644 SharpSimpleNLGUnitTests/format/NumberedPrefixTest.cs
create mode 100644 SharpSimpleNLGUnitTests/format/TextFormatterTest.cs
create mode 100644 SharpSimpleNLGUnitTests/format/english/EnumeratedListTest.java
create mode 100644 SharpSimpleNLGUnitTests/format/english/NumberedPrefixTest.java
create mode 100644 SharpSimpleNLGUnitTests/format/english/TextFormatterTest.java
create mode 100644 SharpSimpleNLGUnitTests/helpers/ExtensionHelpersTest.cs
create mode 100644 SharpSimpleNLGUnitTests/helpers/RegexExercises.cs
create mode 100644 SharpSimpleNLGUnitTests/lexicon/LexicalVariantsTest.java
create mode 100644 SharpSimpleNLGUnitTests/lexicon/MultipleLexiconTest.java
create mode 100644 SharpSimpleNLGUnitTests/lexicon/NIHDBLexiconTest.java
create mode 100644 SharpSimpleNLGUnitTests/lexicon/SharedLexiconTests.java
create mode 100644 SharpSimpleNLGUnitTests/lexicon/XMLLexiconTest.cs
create mode 100644 SharpSimpleNLGUnitTests/lexicon/english/LexicalVariantsTest.java
create mode 100644 SharpSimpleNLGUnitTests/lexicon/english/MultipleLexiconTest.java
create mode 100644 SharpSimpleNLGUnitTests/lexicon/english/NIHDBLexiconTest.java
create mode 100644 SharpSimpleNLGUnitTests/lexicon/english/SharedLexiconTests.java
create mode 100644 SharpSimpleNLGUnitTests/lexicon/english/XMLLexiconTest.java
create mode 100644 SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelper.cs
create mode 100644 SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelperTest.cs
create mode 100644 SharpSimpleNLGUnitTests/morphology/MorphologyProcessor.cs
create mode 100644 SharpSimpleNLGUnitTests/morphology/MorphologyRules.cs
create mode 100644 SharpSimpleNLGUnitTests/morphology/english/DeterminerAgrHelperTest.java
create mode 100644 SharpSimpleNLGUnitTests/realiser/RealiserTest.cs
create mode 100644 SharpSimpleNLGUnitTests/realiser/english/RealiserTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/AdjectivePhraseTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/ClauseAggregationTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/ClauseTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/CoordinationTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/DeterminerTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/DocumentElementTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/ElisionTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/FeatureTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/HTMLFormatterTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/InterrogativeTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/NounPhraseTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/OrthographyFormatTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/PhraseSpecTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/PremodifierTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/PrepositionalPhraseTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/SimpleNLG4Test.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/StandAloneExample.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/StringElementTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/TutorialTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/VerbPhraseTest.cs
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/AdjectivePhraseTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/ClauseAggregationTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/ClauseTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/CoordinationTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/DeterminerTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/DocumentElementTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/ElisionTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/FeatureTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/HTMLFormatterTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/InterrogativeTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/NounPhraseTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/OrthographyFormatTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/PhraseSpecTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/PremodifierTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/PrepositionalPhraseTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/SimpleNLG4Test.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/StandAloneExample.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/StringElementTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/TutorialTest.java
create mode 100644 SharpSimpleNLGUnitTests/syntax/english/VerbPhraseTest.java
diff --git a/SharpSimpleNLG.sln b/SharpSimpleNLG.sln
index 66eb67a..4c75c7a 100644
--- a/SharpSimpleNLG.sln
+++ b/SharpSimpleNLG.sln
@@ -18,7 +18,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpSimpleNLGDotNet45", "S
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpSimpleNLG", "SharpSimpleNLG\SharpSimpleNLG.csproj", "{16F344A8-B688-4D95-8DA6-2E207D47AECB}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpSimpleNLGConsoleNetCore", "SharpSimpleNLGConsoleNetCore\SharpSimpleNLGConsoleNetCore.csproj", "{3E619416-20EC-429F-A467-9F7BFE8BACB1}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpSimpleNLGConsoleNetCore", "SharpSimpleNLGConsoleNetCore\SharpSimpleNLGConsoleNetCore.csproj", "{3E619416-20EC-429F-A467-9F7BFE8BACB1}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpSimpleNLGUnitTests", "SharpSimpleNLGUnitTests\SharpSimpleNLGUnitTests.csproj", "{F4C4C12D-F50D-46F4-9F53-F7C997AD97B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -46,6 +48,10 @@ Global
{3E619416-20EC-429F-A467-9F7BFE8BACB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E619416-20EC-429F-A467-9F7BFE8BACB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E619416-20EC-429F-A467-9F7BFE8BACB1}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F4C4C12D-F50D-46F4-9F53-F7C997AD97B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F4C4C12D-F50D-46F4-9F53-F7C997AD97B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F4C4C12D-F50D-46F4-9F53-F7C997AD97B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F4C4C12D-F50D-46F4-9F53-F7C997AD97B8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj b/SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj
new file mode 100644
index 0000000..31598bd
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj
@@ -0,0 +1,35 @@
+
+
+
+ netstandard1.6
+
+
+
+
+ 1.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/external/ExternalTest.cs b/SharpSimpleNLGUnitTests/external/ExternalTest.cs
new file mode 100644
index 0000000..f4624d1
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/external/ExternalTest.cs
@@ -0,0 +1,562 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+using SimpleNLG;
+using SimpleNLG.Extensions;
+
+namespace SimpleNLGTests.external
+{
+ /**
+ * Tests from third parties
+ * @author ereiter
+ *
+ */
+
+
+ public class ExternalTest
+ {
+ [SetUpFixture]
+ public class SetupForExternalTest
+ {
+ public static Lexicon lexicon = Lexicon.getDefaultLexicon();
+ public static NLGFactory phraseFactory = new NLGFactory(lexicon);
+ public static Realiser realiser = new Realiser(lexicon);
+ }
+
+ [Test]
+ public void forcherTest()
+ {
+ // Bjorn Forcher's tests
+ SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);
+ SPhraseSpec s1 = SetupForExternalTest.phraseFactory.createClause(null, "associate", "Marie");
+ s1.setFeature(Feature.PASSIVE.ToString(), true);
+ PPPhraseSpec pp1 = SetupForExternalTest.phraseFactory.createPrepositionPhrase("with");
+ pp1.addComplement("Peter");
+ pp1.addComplement("Paul");
+ s1.addPostModifier(pp1);
+
+
+ SetupForExternalTest.realiser.setDebugMode(true);
+ var r = SetupForExternalTest.realiser.realise(s1).getRealisation();
+
+ Assert.AreEqual("Marie is associated with Peter and Paul", r);
+
+
+ SPhraseSpec s2 = SetupForExternalTest.phraseFactory.createClause();
+ s2.setSubject((NPPhraseSpec)SetupForExternalTest.phraseFactory.createNounPhrase("Peter"));
+ s2.setVerb("have");
+ s2.setObject("something to do");
+ s2.addPostModifier((PPPhraseSpec)SetupForExternalTest.phraseFactory.createPrepositionPhrase(
+ "with", "Paul"));
+
+
+ Assert.AreEqual("Peter has something to do with Paul",
+ SetupForExternalTest.realiser.realise(s2).getRealisation());
+ }
+
+ [Test]
+ public void luTest()
+ {
+ // Xin Lu's test
+ SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);
+ SPhraseSpec s1 = SetupForExternalTest.phraseFactory.createClause("we",
+ "consider",
+ "John");
+ s1.addPostModifier("a friend");
+
+ Assert.AreEqual("we consider John a friend", SetupForExternalTest.realiser
+ .realise(s1).getRealisation());
+ }
+
+
+ [Test]
+ public void dwightTest()
+ {
+ // Rachel Dwight's test
+ SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);
+
+ NPPhraseSpec noun4 = SetupForExternalTest.phraseFactory
+ .createNounPhrase("FGFR3 gene in every cell");
+
+ noun4.setSpecifier("the");
+
+ PPPhraseSpec prep1 = SetupForExternalTest.phraseFactory.createPrepositionPhrase(
+ "of", noun4);
+
+ NPPhraseSpec noun1 = SetupForExternalTest.phraseFactory.createNounPhrase(
+ "the", "patient's mother");
+
+ NPPhraseSpec noun2 = SetupForExternalTest.phraseFactory.createNounPhrase(
+ "the", "patient's father");
+
+ NPPhraseSpec noun3 = SetupForExternalTest.phraseFactory
+ .createNounPhrase("changed copy");
+ noun3.addPreModifier("one");
+ noun3.addComplement(prep1);
+
+ var coordNoun1 = new CoordinatedPhraseElement(
+ noun1, noun2);
+ coordNoun1.setConjunction("or");
+
+ VPPhraseSpec verbPhrase1 = SetupForExternalTest.phraseFactory.createVerbPhrase("have");
+ verbPhrase1.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
+
+ SPhraseSpec sentence1 = SetupForExternalTest.phraseFactory.createClause(coordNoun1,
+ verbPhrase1, noun3);
+
+ Assert
+ .AreEqual(
+ "the patient's mother or the patient's father has one changed copy of the FGFR3 gene in every cell",
+
+ SetupForExternalTest.realiser.realise(sentence1).getRealisation());
+
+ // Rachel's second test
+ noun3 = SetupForExternalTest.phraseFactory.createNounPhrase("a", "gene test");
+ noun2 = SetupForExternalTest.phraseFactory.createNounPhrase("an", "LDL test");
+ noun1 = SetupForExternalTest.phraseFactory.createNounPhrase("the", "clinic");
+ verbPhrase1 = SetupForExternalTest.phraseFactory.createVerbPhrase("perform");
+
+ var coord1 = new CoordinatedPhraseElement(noun2,
+ noun3);
+ sentence1 = SetupForExternalTest.phraseFactory.createClause(noun1, verbPhrase1, coord1);
+ sentence1.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+
+ Assert
+ .AreEqual(
+ "the clinic performed an LDL test and a gene test", SetupForExternalTest.realiser
+ .realise(sentence1).getRealisation());
+ }
+
+
+ [Test]
+ public void novelliTest()
+ {
+ // Nicole Novelli's test
+ SPhraseSpec p = SetupForExternalTest.phraseFactory.createClause(
+ "Mary", "chase", "George");
+
+ PPPhraseSpec pp = SetupForExternalTest.phraseFactory.createPrepositionPhrase(
+ "in", "the park");
+ p.addPostModifier(pp);
+
+ Assert.AreEqual("Mary chases George in the park", SetupForExternalTest.realiser
+ .realise(p).getRealisation());
+
+ // another question from Nicole
+ SPhraseSpec run = SetupForExternalTest.phraseFactory.createClause(
+ "you", "go", "running");
+ run.setFeature(Feature.MODAL.ToString(), "should");
+ run.addPreModifier("really");
+ SPhraseSpec think = SetupForExternalTest.phraseFactory.createClause("I", "think");
+ think.setObject(run);
+ run.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true);
+
+ var text = SetupForExternalTest.realiser.realise(think).getRealisation();
+ Assert.AreEqual("I think you should really go running", text);
+ }
+
+
+ [Test]
+ public void piotrekTest()
+ {
+ // Piotrek Smulikowski's test
+ SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);
+ SPhraseSpec sent = SetupForExternalTest.phraseFactory.createClause(
+ "I", "shoot", "the duck");
+ sent.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+
+ PPPhraseSpec loc = SetupForExternalTest.phraseFactory.createPrepositionPhrase(
+ "at", "the Shooting Range");
+ sent.addPostModifier(loc);
+ sent.setFeature(Feature.CUE_PHRASE.ToString(), "then");
+
+ Assert.AreEqual("then I shot the duck at the Shooting Range",
+ SetupForExternalTest.realiser.realise(sent).getRealisation());
+ }
+
+
+ [Test]
+ public void prescottTest()
+ {
+ // Michael Prescott's test
+ SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);
+ var embedded = SetupForExternalTest.phraseFactory.createClause(
+ "Jill", "prod", "Spot");
+ var sent = SetupForExternalTest.phraseFactory.createClause(
+ "Jack", "see", embedded);
+ embedded.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true);
+ embedded.setFeature(Feature.FORM.ToString(), Form.BARE_INFINITIVE.ToString());
+
+ Assert.AreEqual("Jack sees Jill prod Spot", SetupForExternalTest.realiser
+ .realise(sent).getRealisation());
+ }
+
+
+ [Test]
+ public void wissnerTest()
+ {
+ // Michael Wissner's text
+ var p = SetupForExternalTest.phraseFactory.createClause("a wolf", "eat");
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
+ Assert.AreEqual("what does a wolf eat", SetupForExternalTest.realiser.realise(p)
+ .getRealisation());
+
+ }
+
+
+ [Test]
+ public void phanTest()
+ {
+ // Thomas Phan's text
+ var subjectElement = SetupForExternalTest.phraseFactory.createNounPhrase("I");
+ var verbElement = SetupForExternalTest.phraseFactory.createVerbPhrase("run");
+
+ var prepPhrase = SetupForExternalTest.phraseFactory.createPrepositionPhrase("from");
+ prepPhrase.addComplement("home");
+
+ verbElement.addComplement(prepPhrase);
+ var newSentence = SetupForExternalTest.phraseFactory.createClause();
+ newSentence.setSubject(subjectElement);
+ newSentence.setVerbPhrase(verbElement);
+
+ Assert.AreEqual("I run from home", SetupForExternalTest.realiser.realise(newSentence)
+ .getRealisation());
+
+ }
+
+
+ [Test]
+ public void kerberTest()
+ {
+ // Frederic Kerber's tests
+ var sp = SetupForExternalTest.phraseFactory.createClause("he", "need");
+ var secondSp = SetupForExternalTest.phraseFactory.createClause();
+ secondSp.setVerb("build");
+ secondSp.setObject("a house");
+ secondSp.setFeature(Feature.FORM.ToString(), Form.INFINITIVE);
+ sp.setObject("stone");
+ sp.addComplement(secondSp);
+ Assert.AreEqual("he needs stone to build a house", SetupForExternalTest.realiser.realise(sp).getRealisation());
+
+ var sp2 = SetupForExternalTest.phraseFactory.createClause("he", "give");
+ sp2.setIndirectObject("I");
+ sp2.setObject("the book");
+ Assert.AreEqual("he gives me the book", SetupForExternalTest.realiser.realise(sp2).getRealisation());
+
+ }
+
+
+ [Test]
+ public void stephensonTest()
+ {
+ // Bruce Stephenson's test
+ var qs2 = SetupForExternalTest.phraseFactory.createClause();
+ qs2 = SetupForExternalTest.phraseFactory.createClause();
+ qs2.setSubject("moles of Gold");
+ qs2.setVerb("are");
+ qs2.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+ qs2.setFeature(Feature.PASSIVE.ToString(), false);
+ qs2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.HOW_MANY);
+ qs2.setObject("in a 2.50 g sample of pure Gold");
+ var sentence = SetupForExternalTest.phraseFactory.createSentence(qs2);
+ Assert.AreEqual("How many moles of Gold are in a 2.50 g sample of pure Gold?",
+ SetupForExternalTest.realiser.realise(sentence).getRealisation());
+ }
+
+
+ [Test]
+ public void pierreTest()
+ {
+ // John Pierre's test
+ var p = SetupForExternalTest.phraseFactory.createClause("Mary", "chase", "George");
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
+ Assert.AreEqual("What does Mary chase?", SetupForExternalTest.realiser.realiseSentence(p));
+
+ p = SetupForExternalTest.phraseFactory.createClause("Mary", "chase", "George");
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ Assert.AreEqual("Does Mary chase George?", SetupForExternalTest.realiser.realiseSentence(p));
+
+ p = SetupForExternalTest.phraseFactory.createClause("Mary", "chase", "George");
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHERE);
+ Assert.AreEqual("Where does Mary chase George?", SetupForExternalTest.realiser.realiseSentence(p));
+
+ p = SetupForExternalTest.phraseFactory.createClause("Mary", "chase", "George");
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
+ Assert.AreEqual("Why does Mary chase George?", SetupForExternalTest.realiser.realiseSentence(p));
+
+ p = SetupForExternalTest.phraseFactory.createClause("Mary", "chase", "George");
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.HOW);
+ Assert.AreEqual("How does Mary chase George?", SetupForExternalTest.realiser.realiseSentence(p));
+
+
+ }
+
+ [Test]
+ public void data2TextTest()
+ {
+ // Data2Text tests
+ // test OK to have number at end of sentence
+ SPhraseSpec p = SetupForExternalTest.phraseFactory.createClause("the dog", "weigh", "12");
+ Assert.AreEqual("The dog weighs 12.", SetupForExternalTest.realiser.realiseSentence(p));
+
+ // test OK to have "there be" sentence with "there" as a StringElement
+ var dataDropout2 = SetupForExternalTest.phraseFactory.createNLGElement("data dropouts");
+ dataDropout2.setPlural(true);
+ var sentence2 = SetupForExternalTest.phraseFactory.createClause();
+ sentence2.setSubject(SetupForExternalTest.phraseFactory.createStringElement("there"));
+ sentence2.setVerb("be");
+ sentence2.setObject(dataDropout2);
+ Assert.AreEqual("There are data dropouts.", SetupForExternalTest.realiser.realiseSentence(sentence2));
+
+ // test OK to have gerund form verb
+ SPhraseSpec weather1 = SetupForExternalTest.phraseFactory.createClause("SE 10-15", "veer", "S 15-20");
+ weather1.setFeature(Feature.FORM.ToString(), Form.GERUND);
+ Assert.AreEqual("SE 10-15 veering S 15-20.", SetupForExternalTest.realiser.realiseSentence(weather1));
+
+ // test OK to have subject only
+ SPhraseSpec weather2 = SetupForExternalTest.phraseFactory.createClause("cloudy and misty", "be", "XXX");
+ weather2.getVerbPhrase().setFeature(Feature.ELIDED.ToString(), true);
+ Assert.AreEqual("Cloudy and misty.", SetupForExternalTest.realiser.realiseSentence(weather2));
+
+ // test OK to have VP only
+ SPhraseSpec weather3 = SetupForExternalTest.phraseFactory.createClause("S 15-20", "increase", "20-25");
+ weather3.setFeature(Feature.FORM.ToString(), Form.GERUND);
+ weather3.getSubject().setFeature(Feature.ELIDED.ToString(), true);
+ Assert.AreEqual("Increasing 20-25.", SetupForExternalTest.realiser.realiseSentence(weather3));
+
+ // conjoined test
+ SPhraseSpec weather4 = SetupForExternalTest.phraseFactory.createClause("S 20-25", "back", "SSE");
+ weather4.setFeature(Feature.FORM.ToString(), Form.GERUND);
+ weather4.getSubject().setFeature(Feature.ELIDED.ToString(), true);
+
+ var coord = new CoordinatedPhraseElement();
+ coord.addCoordinate(weather1);
+ coord.addCoordinate(weather3);
+ coord.addCoordinate(weather4);
+ coord.setConjunction("then");
+ Assert.AreEqual("SE 10-15 veering S 15-20, increasing 20-25 then backing SSE.",
+ SetupForExternalTest.realiser.realiseSentence(coord));
+
+
+ // no verb
+ SPhraseSpec weather5 = SetupForExternalTest.phraseFactory.createClause("rain", null, "likely");
+ Assert.AreEqual("Rain likely.", SetupForExternalTest.realiser.realiseSentence(weather5));
+
+ }
+
+
+ /*[Test]
+ public void rafaelTest()
+ {
+ // Rafael Valle's tests
+ List ss = new List();
+ ClauseCoordinationRule coord = new ClauseCoordinationRule();
+ coord.setFactory(SetupForPassive.phraseFactory);
+
+ ss.add(SetupForPassive.agreePhrase("John Lennon")); // john lennon agreed with it
+ ss.add(SetupForPassive.disagreePhrase("Geri Halliwell")); // Geri Halliwell disagreed with it
+ ss.add(SetupForPassive.commentPhrase("Melanie B")); // Mealnie B commented on it
+ ss.add(SetupForPassive.agreePhrase("you")); // you agreed with it
+ ss.add(SetupForPassive.commentPhrase("Emma Bunton")); //Emma Bunton commented on it
+
+ List results = coord.apply(ss);
+ List ret = SetupForPassive.realizeAll(results);
+ Assert.AreEqual(
+ "[John Lennon and you agreed with it, Geri Halliwell disagreed with it, Melanie B and Emma Bunton commented on it]",
+ ret.toString());
+ }
+ */
+ private NLGElement commentPhrase(String name)
+ {
+ // used by testRafael
+ var s = SetupForExternalTest.phraseFactory.createClause();
+ s.setSubject(SetupForExternalTest.phraseFactory.createNounPhrase(name));
+ s.setVerbPhrase(SetupForExternalTest.phraseFactory.createVerbPhrase("comment on"));
+ s.setObject("it");
+ s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ return s;
+ }
+
+ private NLGElement agreePhrase(String name)
+ {
+ // used by testRafael
+ var s = SetupForExternalTest.phraseFactory.createClause();
+ s.setSubject(SetupForExternalTest.phraseFactory.createNounPhrase(name));
+ s.setVerbPhrase(SetupForExternalTest.phraseFactory.createVerbPhrase("agree with"));
+ s.setObject("it");
+ s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ return s;
+ }
+
+ private NLGElement disagreePhrase(String name)
+ {
+ // used by testRafael
+ var s = SetupForExternalTest.phraseFactory.createClause();
+ s.setSubject(SetupForExternalTest.phraseFactory.createNounPhrase(name));
+ s.setVerbPhrase(SetupForExternalTest.phraseFactory.createVerbPhrase("disagree with"));
+ s.setObject("it");
+ s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ return s;
+ }
+
+ private List realizeAll(List results)
+ {
+ // used by testRafael
+ var ret = new List();
+ foreach (var e in results)
+ {
+ var r = SetupForExternalTest.realiser.realise(e).getRealisation();
+ ret.add(r);
+ }
+ return ret;
+ }
+
+ [Test]
+ public void wikipediaTest()
+ {
+ // test code fragments in wikipedia
+ // realisation
+ var subject = SetupForExternalTest.phraseFactory.createNounPhrase("the", "woman");
+ subject.setPlural(true);
+ var sentence = SetupForExternalTest.phraseFactory.createClause(subject, "smoke");
+ sentence.setFeature(Feature.NEGATED.ToString(), true);
+ Assert.AreEqual("The women do not smoke.", SetupForExternalTest.realiser.realiseSentence(sentence));
+
+ // aggregation
+ var s1 = SetupForExternalTest.phraseFactory.createClause("the man", "be", "hungry");
+ var s2 = SetupForExternalTest.phraseFactory.createClause("the man", "buy", "an apple");
+ var subject2 = SetupForExternalTest.phraseFactory.createCoordinatedPhrase(s1, s2);
+ Assert.AreEqual("The man is hungry and buys an apple.", SetupForExternalTest.realiser.realiseSentence(subject2));
+
+ }
+
+ [Test]
+ public void leanTest()
+ {
+ // A Lean's test
+ var sentence = SetupForExternalTest.phraseFactory.createClause();
+ sentence.setVerb("be");
+ sentence.setObject("a ball");
+ sentence.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
+ Assert.AreEqual("What is a ball?", SetupForExternalTest.realiser.realiseSentence(sentence));
+
+ sentence = SetupForExternalTest.phraseFactory.createClause();
+ sentence.setVerb("be");
+ var o = SetupForExternalTest.phraseFactory.createNounPhrase("example");
+ o.setPlural(true);
+ o.addModifier("of jobs");
+ sentence.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
+ sentence.setObject(o);
+ Assert.AreEqual("What are examples of jobs?", SetupForExternalTest.realiser.realiseSentence(sentence));
+
+ var p = SetupForExternalTest.phraseFactory.createClause();
+ var sub1 = SetupForExternalTest.phraseFactory.createNounPhrase("Mary");
+
+ sub1.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
+ sub1.setFeature(Feature.PRONOMINAL.ToString(), true);
+ sub1.setFeature(Feature.PERSON.ToString(), Person.FIRST);
+ p.setSubject(sub1);
+ p.setVerb("chase");
+ p.setObject("the monkey");
+
+
+ var output2 = SetupForExternalTest.realiser.realiseSentence(p); // Realiser created earlier.
+ Assert.AreEqual("I chase the monkey.", output2);
+
+ var test = SetupForExternalTest.phraseFactory.createClause();
+ var subject = SetupForExternalTest.phraseFactory.createNounPhrase("Mary");
+
+ subject.setFeature(Feature.PRONOMINAL.ToString(), true);
+ subject.setFeature(Feature.PERSON.ToString(), Person.SECOND);
+ test.setSubject(subject);
+ test.setVerb("cry");
+
+ test.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
+ test.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
+ Assert.AreEqual("Why do you cry?", SetupForExternalTest.realiser.realiseSentence(test));
+
+ test = SetupForExternalTest.phraseFactory.createClause();
+ subject = SetupForExternalTest.phraseFactory.createNounPhrase("Mary");
+
+ subject.setFeature(Feature.PRONOMINAL.ToString(), true);
+ subject.setFeature(Feature.PERSON.ToString(), Person.SECOND);
+ test.setSubject(subject);
+ test.setVerb("be");
+ test.setObject("crying");
+
+ test.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
+ test.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
+ Assert.AreEqual("Why are you crying?", SetupForExternalTest.realiser.realiseSentence(test));
+
+
+ }
+
+ [Test]
+ public void kalijurandTest()
+ {
+ // K Kalijurand's test
+ var lemma = "walk";
+
+
+ var word = SetupForExternalTest.lexicon.lookupWord(lemma, new LexicalCategory_VERB());
+ var inflectedWord = new InflectedWordElement(word);
+
+ inflectedWord.setFeature(Feature.FORM.ToString(), Form.PAST_PARTICIPLE);
+ var form = SetupForExternalTest.realiser.realise(inflectedWord).getRealisation();
+ Assert.AreEqual("walked", form);
+
+
+ inflectedWord = new InflectedWordElement(word);
+
+ inflectedWord.setFeature(Feature.PERSON.ToString(), Person.THIRD);
+ form = SetupForExternalTest.realiser.realise(inflectedWord).getRealisation();
+ Assert.AreEqual("walks", form);
+
+ }
+
+ [Test]
+ public void layTest()
+ {
+ // Richard Lay's test
+ var lemma = "slap";
+
+ var word = SetupForExternalTest.lexicon.lookupWord(lemma,new LexicalCategory_VERB());
+ var inflectedWord = new InflectedWordElement(word);
+ inflectedWord.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE);
+ var form = SetupForExternalTest.realiser.realise(inflectedWord).getRealisation();
+ Assert.AreEqual("slapping", form);
+
+
+ var v = SetupForExternalTest.phraseFactory.createVerbPhrase("slap");
+ v.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ var progressive = SetupForExternalTest.realiser.realise(v).getRealisation();
+ Assert.AreEqual("is slapping", progressive);
+ }
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/format/EnumeratedListTest.cs b/SharpSimpleNLGUnitTests/format/EnumeratedListTest.cs
new file mode 100644
index 0000000..110a0e8
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/format/EnumeratedListTest.cs
@@ -0,0 +1,101 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.morphology
+{
+
+ /**
+ * This tests that two sentences are realised as a list.
+ * @author Rodrigo de Oliveira - Data2Text Ltd
+ *
+ */
+
+ public class EnumeratedListTest
+ {
+
+ [Test]
+ public void bulletList()
+ {
+ var lexicon = Lexicon.getDefaultLexicon();
+ var nlgFactory = new NLGFactory(lexicon);
+ var realiser = new Realiser(lexicon);
+ realiser.setFormatter(new HTMLFormatter());
+ var document = nlgFactory.createDocument("Document");
+ var paragraph = nlgFactory.createParagraph();
+ var list = nlgFactory.createList();
+ var item1 = nlgFactory.createListItem();
+ var item2 = nlgFactory.createListItem();
+ // NB: a list item employs orthographical operations only until sentence level;
+ // nest clauses within a sentence to generate more than 1 clause per list item.
+ var sentence1 = nlgFactory.createSentence("this", "be", "the first sentence");
+ var sentence2 = nlgFactory.createSentence("this", "be", "the second sentence");
+ item1.addComponent(sentence1);
+ item2.addComponent(sentence2);
+ list.addComponent(item1);
+ list.addComponent(item2);
+ paragraph.addComponent(list);
+ document.addComponent(paragraph);
+ var expectedOutput = "Document " + "" + "
" + "This is the first sentence. "
+ + "This is the second sentence. " + " " + "
";
+
+ var realisedOutput = realiser.realise(document).getRealisation();
+ Assert.AreEqual(expectedOutput, realisedOutput);
+ }
+
+ [Test]
+ public void enumeratedList()
+ {
+ var lexicon = Lexicon.getDefaultLexicon();
+ var nlgFactory = new NLGFactory(lexicon);
+ var realiser = new Realiser(lexicon);
+ realiser.setFormatter(new HTMLFormatter());
+ var document = nlgFactory.createDocument("Document");
+ var paragraph = nlgFactory.createParagraph();
+ var list = nlgFactory.createEnumeratedList();
+ var item1 = nlgFactory.createListItem();
+ var item2 = nlgFactory.createListItem();
+ // NB: a list item employs orthographical operations only until sentence level;
+ // nest clauses within a sentence to generate more than 1 clause per list item.
+ var sentence1 = nlgFactory.createSentence("this", "be", "the first sentence");
+ var sentence2 = nlgFactory.createSentence("this", "be", "the second sentence");
+ item1.addComponent(sentence1);
+ item2.addComponent(sentence2);
+ list.addComponent(item1);
+ list.addComponent(item2);
+ paragraph.addComponent(list);
+ document.addComponent(paragraph);
+ var expectedOutput = "Document " + "" + "
" + "This is the first sentence. "
+ + "This is the second sentence. " + " " + "";
+
+ var realisedOutput = realiser.realise(document).getRealisation();
+ Assert.AreEqual(expectedOutput, realisedOutput);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/format/NumberedPrefixTest.cs b/SharpSimpleNLGUnitTests/format/NumberedPrefixTest.cs
new file mode 100644
index 0000000..adb7be2
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/format/NumberedPrefixTest.cs
@@ -0,0 +1,111 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.morphology
+{
+ public class NumberedPrefixTest
+ {
+
+ [Test]
+ public void testNewInstancePrefixIsZero()
+ {
+ NumberedPrefix prefix = new NumberedPrefix();
+ Assert.AreEqual("0", prefix.getPrefix());
+ }
+
+ [Test]
+ public void testIncrementFromNewInstanceIsOne()
+ {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.increment();
+ Assert.AreEqual("1", prefix.getPrefix());
+ }
+
+ [Test]
+ public void testIncrementForTwoPointTwoIsTwoPointThree()
+ {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.setPrefix("2.2");
+ prefix.increment();
+ Assert.AreEqual("2.3", prefix.getPrefix());
+ }
+
+ [Test]
+ public void testIncrementForThreePointFourPointThreeIsThreePointFourPointFour()
+ {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.setPrefix("3.4.3");
+ prefix.increment();
+ Assert.AreEqual("3.4.4", prefix.getPrefix());
+ }
+
+ [Test]
+ public void testUpALevelForNewInstanceIsOne()
+ {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.upALevel();
+ Assert.AreEqual("1", prefix.getPrefix());
+ }
+
+ [Test]
+ public void testDownALevelForNewInstanceIsZero()
+ {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.downALevel();
+ Assert.AreEqual("0", prefix.getPrefix());
+ }
+
+ [Test]
+ public void testDownALevelForSevenIsZero()
+ {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.setPrefix("7");
+ prefix.downALevel();
+ Assert.AreEqual("0", prefix.getPrefix());
+ }
+
+ [Test]
+ public void testDownALevelForTwoPointSevenIsTwo()
+ {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.setPrefix("2.7");
+ prefix.downALevel();
+ Assert.AreEqual("2", prefix.getPrefix());
+ }
+
+ [Test]
+ public void testDownALevelForThreePointFourPointThreeIsThreePointFour()
+ {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.setPrefix("3.4.3");
+ prefix.downALevel();
+ Assert.AreEqual("3.4", prefix.getPrefix());
+ }
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/format/TextFormatterTest.cs b/SharpSimpleNLGUnitTests/format/TextFormatterTest.cs
new file mode 100644
index 0000000..617304f
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/format/TextFormatterTest.cs
@@ -0,0 +1,161 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.morphology
+{
+ /**
+ * TextFormatterTest -- Test's the TextFormatter.
+ * @author Daniel Paiva -- Arria NLG plc.
+ */
+ public class TextFormatterTest {
+
+ [Test]
+ public void testEnumeratedList() {
+ var lexicon = Lexicon.getDefaultLexicon();
+ var nlgFactory = new NLGFactory(lexicon);
+ var realiser = new Realiser(lexicon);
+ realiser.setFormatter(new TextFormatter());
+ var document = nlgFactory.createDocument("Document");
+ var paragraph = nlgFactory.createParagraph();
+
+
+ var subListItem1 = nlgFactory.createListItem();
+ var subListSentence1 = nlgFactory.createSentence("this", "be", "sub-list sentence 1");
+ subListItem1.addComponent(subListSentence1);
+
+ var subListItem2 = nlgFactory.createListItem();
+ var subListSentence2 = nlgFactory.createSentence("this", "be", "sub-list sentence 2");
+ subListItem2.addComponent(subListSentence2);
+
+ var subList = nlgFactory.createEnumeratedList();
+ subList.addComponent(subListItem1);
+ subList.addComponent(subListItem2);
+
+ var item1 = nlgFactory.createListItem();
+ var sentence1 = nlgFactory.createSentence("this", "be", "the first sentence");
+ item1.addComponent(sentence1);
+
+ var item2 = nlgFactory.createListItem();
+ var sentence2 = nlgFactory.createSentence("this", "be", "the second sentence");
+ item2.addComponent(sentence2);
+
+ var list = nlgFactory.createEnumeratedList();
+ list.addComponent(subList);
+ list.addComponent(item1);
+ list.addComponent(item2);
+ paragraph.addComponent(list);
+ document.addComponent(paragraph);
+ var expectedOutput = "Document\n" +
+ "\n" +
+ "1.1 - This is sub-list sentence 1.\n" +
+ "1.2 - This is sub-list sentence 2.\n"+
+ "2 - This is the first sentence.\n" +
+ "3 - This is the second sentence.\n" +
+ "\n\n"; // for the end of a paragraph
+
+ var realisedOutput = realiser.realise(document).getRealisation();
+ Assert.AreEqual(expectedOutput, realisedOutput);
+ }
+
+ [Test]
+ public void testEnumeratedListWithSeveralLevelsOfNesting() {
+ var lexicon = Lexicon.getDefaultLexicon();
+ var nlgFactory = new NLGFactory(lexicon);
+ var realiser = new Realiser(lexicon);
+ realiser.setFormatter(new TextFormatter());
+ var document = nlgFactory.createDocument("Document");
+ var paragraph = nlgFactory.createParagraph();
+
+ // sub item 1
+ var subList1Item1 = nlgFactory.createListItem();
+ var subList1Sentence1 = nlgFactory.createSentence("sub-list item 1");
+ subList1Item1.addComponent(subList1Sentence1);
+
+ // sub sub item 1
+ var subSubList1Item1 = nlgFactory.createListItem();
+ var subSubList1Sentence1 = nlgFactory.createSentence("sub-sub-list item 1");
+ subSubList1Item1.addComponent(subSubList1Sentence1);
+
+ // sub sub item 2
+ var subSubList1Item2 = nlgFactory.createListItem();
+ var subSubList1Sentence2 = nlgFactory.createSentence("sub-sub-list item 2");
+ subSubList1Item2.addComponent(subSubList1Sentence2);
+
+ // sub sub list
+ var subSubList1 = nlgFactory.createEnumeratedList();
+ subSubList1.addComponent(subSubList1Item1);
+ subSubList1.addComponent(subSubList1Item2);
+
+ // sub item 2
+ var subList1Item2 = nlgFactory.createListItem();
+ var subList1Sentence2 = nlgFactory.createSentence("sub-list item 3");
+ subList1Item2.addComponent(subList1Sentence2);
+
+ // sub list 1
+ var subList1 = nlgFactory.createEnumeratedList();
+ subList1.addComponent(subList1Item1);
+ subList1.addComponent(subSubList1);
+ subList1.addComponent(subList1Item2);
+
+ // item 2
+ var item2 = nlgFactory.createListItem();
+ var sentence2 = nlgFactory.createSentence("item 2");
+ item2.addComponent(sentence2);
+
+ // item 3
+ var item3 = nlgFactory.createListItem();
+ var sentence3 = nlgFactory.createSentence("item 3");
+ item3.addComponent(sentence3);
+
+ // list
+ var list = nlgFactory.createEnumeratedList();
+ list.addComponent(subList1);
+ list.addComponent(item2);
+ list.addComponent(item3);
+
+ paragraph.addComponent(list);
+
+ document.addComponent(paragraph);
+
+ var expectedOutput = "Document\n" +
+ "\n" +
+ "1.1 - Sub-list item 1.\n" +
+ "1.2.1 - Sub-sub-list item 1.\n" +
+ "1.2.2 - Sub-sub-list item 2.\n" +
+ "1.3 - Sub-list item 3.\n"+
+ "2 - Item 2.\n" +
+ "3 - Item 3.\n" +
+ "\n\n";
+
+ var realisedOutput = realiser.realise(document).getRealisation();
+ Assert.AreEqual(expectedOutput, realisedOutput);
+ }
+
+}
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/format/english/EnumeratedListTest.java b/SharpSimpleNLGUnitTests/format/english/EnumeratedListTest.java
new file mode 100644
index 0000000..e88dd9e
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/format/english/EnumeratedListTest.java
@@ -0,0 +1,98 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.format.english;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+import simplenlg.framework.DocumentElement;
+import simplenlg.framework.NLGFactory;
+import simplenlg.lexicon.Lexicon;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * This tests that two sentences are realised as a list.
+ * @author Rodrigo de Oliveira - Data2Text Ltd
+ *
+ */
+public class EnumeratedListTest {
+
+ @Test
+ public void bulletList() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon();
+ NLGFactory nlgFactory = new NLGFactory(lexicon);
+ Realiser realiser = new Realiser(lexicon);
+ realiser.setFormatter(new HTMLFormatter());
+ DocumentElement document = nlgFactory.createDocument("Document");
+ DocumentElement paragraph = nlgFactory.createParagraph();
+ DocumentElement list = nlgFactory.createList();
+ DocumentElement item1 = nlgFactory.createListItem();
+ DocumentElement item2 = nlgFactory.createListItem();
+ // NB: a list item employs orthographical operations only until sentence level;
+ // nest clauses within a sentence to generate more than 1 clause per list item.
+ DocumentElement sentence1 = nlgFactory.createSentence("this", "be", "the first sentence");
+ DocumentElement sentence2 = nlgFactory.createSentence("this", "be", "the second sentence");
+ item1.addComponent(sentence1);
+ item2.addComponent(sentence2);
+ list.addComponent(item1);
+ list.addComponent(item2);
+ paragraph.addComponent(list);
+ document.addComponent(paragraph);
+ String expectedOutput = "Document " + "" + "
" + "This is the first sentence. "
+ + "This is the second sentence. " + " " + "";
+
+ String realisedOutput = realiser.realise(document).getRealisation();
+ // System.out.println(expectedOutput);
+ // System.out.println(realisedOutput);
+ Assert.assertEquals(expectedOutput, realisedOutput);
+ }
+
+ @Test
+ public void enumeratedList() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon();
+ NLGFactory nlgFactory = new NLGFactory(lexicon);
+ Realiser realiser = new Realiser(lexicon);
+ realiser.setFormatter(new HTMLFormatter());
+ DocumentElement document = nlgFactory.createDocument("Document");
+ DocumentElement paragraph = nlgFactory.createParagraph();
+ DocumentElement list = nlgFactory.createEnumeratedList();
+ DocumentElement item1 = nlgFactory.createListItem();
+ DocumentElement item2 = nlgFactory.createListItem();
+ // NB: a list item employs orthographical operations only until sentence level;
+ // nest clauses within a sentence to generate more than 1 clause per list item.
+ DocumentElement sentence1 = nlgFactory.createSentence("this", "be", "the first sentence");
+ DocumentElement sentence2 = nlgFactory.createSentence("this", "be", "the second sentence");
+ item1.addComponent(sentence1);
+ item2.addComponent(sentence2);
+ list.addComponent(item1);
+ list.addComponent(item2);
+ paragraph.addComponent(list);
+ document.addComponent(paragraph);
+ String expectedOutput = "Document " + "" + "
" + "This is the first sentence. "
+ + "This is the second sentence. " + " " + "";
+
+ String realisedOutput = realiser.realise(document).getRealisation();
+ // System.out.println(expectedOutput);
+ // System.out.println(realisedOutput);
+ Assert.assertEquals(expectedOutput, realisedOutput);
+ }
+
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/format/english/NumberedPrefixTest.java b/SharpSimpleNLGUnitTests/format/english/NumberedPrefixTest.java
new file mode 100644
index 0000000..85d3912
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/format/english/NumberedPrefixTest.java
@@ -0,0 +1,75 @@
+package simplenlg.format.english;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+
+public class NumberedPrefixTest {
+
+ @Test
+ public void testNewInstancePrefixIsZero() {
+ NumberedPrefix prefix = new NumberedPrefix();
+ Assert.assertEquals("0", prefix.getPrefix());
+ }
+
+ @Test
+ public void testIncrementFromNewInstanceIsOne() {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.increment();
+ Assert.assertEquals("1", prefix.getPrefix());
+ }
+
+ @Test
+ public void testIncrementForTwoPointTwoIsTwoPointThree() {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.setPrefix("2.2");
+ prefix.increment();
+ Assert.assertEquals("2.3", prefix.getPrefix());
+ }
+
+ @Test
+ public void testIncrementForThreePointFourPointThreeIsThreePointFourPointFour() {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.setPrefix("3.4.3");
+ prefix.increment();
+ Assert.assertEquals("3.4.4", prefix.getPrefix());
+ }
+
+ @Test
+ public void testUpALevelForNewInstanceIsOne() {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.upALevel();
+ Assert.assertEquals("1", prefix.getPrefix());
+ }
+
+ @Test
+ public void testDownALevelForNewInstanceIsZero() {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.downALevel();
+ Assert.assertEquals("0", prefix.getPrefix());
+ }
+
+ @Test
+ public void testDownALevelForSevenIsZero() {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.setPrefix("7");
+ prefix.downALevel();
+ Assert.assertEquals("0", prefix.getPrefix());
+ }
+
+ @Test
+ public void testDownALevelForTwoPointSevenIsTwo() {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.setPrefix("2.7");
+ prefix.downALevel();
+ Assert.assertEquals("2", prefix.getPrefix());
+ }
+
+ @Test
+ public void testDownALevelForThreePointFourPointThreeIsThreePointFour() {
+ NumberedPrefix prefix = new NumberedPrefix();
+ prefix.setPrefix("3.4.3");
+ prefix.downALevel();
+ Assert.assertEquals("3.4", prefix.getPrefix());
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/format/english/TextFormatterTest.java b/SharpSimpleNLGUnitTests/format/english/TextFormatterTest.java
new file mode 100644
index 0000000..42c036d
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/format/english/TextFormatterTest.java
@@ -0,0 +1,157 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.format.english;
+
+import junit.framework.Assert;
+import org.junit.Test;
+import simplenlg.framework.DocumentElement;
+import simplenlg.framework.NLGFactory;
+import simplenlg.lexicon.Lexicon;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * TextFormatterTest -- Test's the TextFormatter.
+ * @author Daniel Paiva -- Arria NLG plc.
+ */
+public class TextFormatterTest {
+
+ @Test
+ public void testEnumeratedList() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon();
+ NLGFactory nlgFactory = new NLGFactory(lexicon);
+ Realiser realiser = new Realiser(lexicon);
+ realiser.setFormatter(new TextFormatter());
+ DocumentElement document = nlgFactory.createDocument("Document");
+ DocumentElement paragraph = nlgFactory.createParagraph();
+
+
+ DocumentElement subListItem1 = nlgFactory.createListItem();
+ DocumentElement subListSentence1 = nlgFactory.createSentence("this", "be", "sub-list sentence 1");
+ subListItem1.addComponent(subListSentence1);
+
+ DocumentElement subListItem2 = nlgFactory.createListItem();
+ DocumentElement subListSentence2 = nlgFactory.createSentence("this", "be", "sub-list sentence 2");
+ subListItem2.addComponent(subListSentence2);
+
+ DocumentElement subList = nlgFactory.createEnumeratedList();
+ subList.addComponent(subListItem1);
+ subList.addComponent(subListItem2);
+
+ DocumentElement item1 = nlgFactory.createListItem();
+ DocumentElement sentence1 = nlgFactory.createSentence("this", "be", "the first sentence");
+ item1.addComponent(sentence1);
+
+ DocumentElement item2 = nlgFactory.createListItem();
+ DocumentElement sentence2 = nlgFactory.createSentence("this", "be", "the second sentence");
+ item2.addComponent(sentence2);
+
+ DocumentElement list = nlgFactory.createEnumeratedList();
+ list.addComponent(subList);
+ list.addComponent(item1);
+ list.addComponent(item2);
+ paragraph.addComponent(list);
+ document.addComponent(paragraph);
+ String expectedOutput = "Document\n" +
+ "\n" +
+ "1.1 - This is sub-list sentence 1.\n" +
+ "1.2 - This is sub-list sentence 2.\n"+
+ "2 - This is the first sentence.\n" +
+ "3 - This is the second sentence.\n" +
+ "\n\n"; // for the end of a paragraph
+
+ String realisedOutput = realiser.realise(document).getRealisation();
+ Assert.assertEquals(expectedOutput, realisedOutput);
+ }
+
+ @Test
+ public void testEnumeratedListWithSeveralLevelsOfNesting() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon();
+ NLGFactory nlgFactory = new NLGFactory(lexicon);
+ Realiser realiser = new Realiser(lexicon);
+ realiser.setFormatter(new TextFormatter());
+ DocumentElement document = nlgFactory.createDocument("Document");
+ DocumentElement paragraph = nlgFactory.createParagraph();
+
+ // sub item 1
+ DocumentElement subList1Item1 = nlgFactory.createListItem();
+ DocumentElement subList1Sentence1 = nlgFactory.createSentence("sub-list item 1");
+ subList1Item1.addComponent(subList1Sentence1);
+
+ // sub sub item 1
+ DocumentElement subSubList1Item1 = nlgFactory.createListItem();
+ DocumentElement subSubList1Sentence1 = nlgFactory.createSentence("sub-sub-list item 1");
+ subSubList1Item1.addComponent(subSubList1Sentence1);
+
+ // sub sub item 2
+ DocumentElement subSubList1Item2 = nlgFactory.createListItem();
+ DocumentElement subSubList1Sentence2 = nlgFactory.createSentence("sub-sub-list item 2");
+ subSubList1Item2.addComponent(subSubList1Sentence2);
+
+ // sub sub list
+ DocumentElement subSubList1 = nlgFactory.createEnumeratedList();
+ subSubList1.addComponent(subSubList1Item1);
+ subSubList1.addComponent(subSubList1Item2);
+
+ // sub item 2
+ DocumentElement subList1Item2 = nlgFactory.createListItem();
+ DocumentElement subList1Sentence2 = nlgFactory.createSentence("sub-list item 3");
+ subList1Item2.addComponent(subList1Sentence2);
+
+ // sub list 1
+ DocumentElement subList1 = nlgFactory.createEnumeratedList();
+ subList1.addComponent(subList1Item1);
+ subList1.addComponent(subSubList1);
+ subList1.addComponent(subList1Item2);
+
+ // item 2
+ DocumentElement item2 = nlgFactory.createListItem();
+ DocumentElement sentence2 = nlgFactory.createSentence("item 2");
+ item2.addComponent(sentence2);
+
+ // item 3
+ DocumentElement item3 = nlgFactory.createListItem();
+ DocumentElement sentence3 = nlgFactory.createSentence("item 3");
+ item3.addComponent(sentence3);
+
+ // list
+ DocumentElement list = nlgFactory.createEnumeratedList();
+ list.addComponent(subList1);
+ list.addComponent(item2);
+ list.addComponent(item3);
+
+ paragraph.addComponent(list);
+
+ document.addComponent(paragraph);
+
+ String expectedOutput = "Document\n" +
+ "\n" +
+ "1.1 - Sub-list item 1.\n" +
+ "1.2.1 - Sub-sub-list item 1.\n" +
+ "1.2.2 - Sub-sub-list item 2.\n" +
+ "1.3 - Sub-list item 3.\n"+
+ "2 - Item 2.\n" +
+ "3 - Item 3.\n" +
+ "\n\n";
+
+ String realisedOutput = realiser.realise(document).getRealisation();
+ Assert.assertEquals(expectedOutput, realisedOutput);
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/helpers/ExtensionHelpersTest.cs b/SharpSimpleNLGUnitTests/helpers/ExtensionHelpersTest.cs
new file mode 100644
index 0000000..da0523c
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/helpers/ExtensionHelpersTest.cs
@@ -0,0 +1,336 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using System.Collections.Generic;
+using NUnit.Framework;
+using Shouldly;
+using SimpleNLG.Extensions;
+
+namespace SimpleNLGTests.helpers
+{
+
+ /**
+ * @author Nick Hodge, nhodge@mungr.com
+ *
+ */
+
+ public class ExtensionHelpersTests
+ {
+ // String and Char ones first
+
+
+ //ref: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isDigit(char)
+ [TestCase(' ', ExpectedResult = false, TestName = "isDigit: space case")]
+ [TestCase('a', ExpectedResult = false, TestName = "isDigit: single char a")]
+ [TestCase('0', ExpectedResult = true, TestName = "isDigit: single char 0")]
+ [TestCase('1', ExpectedResult = true, TestName = "isDigit: single char 1")]
+ [TestCase('2', ExpectedResult = true, TestName = "isDigit: single char 2")]
+ [TestCase('3', ExpectedResult = true, TestName = "isDigit: single char 3")]
+ [TestCase('4', ExpectedResult = true, TestName = "isDigit: single char 4")]
+ [TestCase('5', ExpectedResult = true, TestName = "isDigit: single char 5")]
+ [TestCase('6', ExpectedResult = true, TestName = "isDigit: single char 6")]
+ [TestCase('7', ExpectedResult = true, TestName = "isDigit: single char 7")]
+ [TestCase('8', ExpectedResult = true, TestName = "isDigit: single char 8")]
+ [TestCase('9', ExpectedResult = true, TestName = "isDigit: single char 9")]
+ [TestCase('\u0660', ExpectedResult = true, TestName = "isDigit: arabic/indic start")]
+ [TestCase('\u0669', ExpectedResult = true, TestName = "isDigit: arabic/indic end")]
+ [TestCase('\u06F0', ExpectedResult = true, TestName = "isDigit: arabic extended start")]
+ [TestCase('\u06F9', ExpectedResult = true, TestName = "isDigit: arabic extended end")]
+ [TestCase('\u0966', ExpectedResult = true, TestName = "isDigit: Devanagari extended start")]
+ [TestCase('\u096F', ExpectedResult = true, TestName = "isDigit: Devanagari extended end")]
+ [TestCase('\uFF10', ExpectedResult = true, TestName = "isDigit: Fullwidth extended start")]
+ [TestCase('\uFF19', ExpectedResult = true, TestName = "isDigit: Fullwidth extended end")]
+ public bool isDigit_ToCsharp(char c)
+ {
+ return c.isDigit();
+ }
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#length()
+ [TestCase("", ExpectedResult = 0, TestName = "length: null case")]
+ [TestCase(" ", ExpectedResult = 1, TestName = "length: 1")]
+ [TestCase(" ", ExpectedResult = 2, TestName = "length: 2")]
+ [TestCase("cat", ExpectedResult = 3, TestName = "length: 3")]
+ [TestCase("\uFF19cat", ExpectedResult = 4, TestName = "length: 4 with Unicode")]
+ public int length_ToCsharp(string s)
+ {
+ return s.length();
+ }
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#trim()
+ [TestCase("", ExpectedResult = "", TestName = "trim: null case")]
+ [TestCase("cat", ExpectedResult = "cat", TestName = "trim: 3 chars")]
+ [TestCase(" \uFF19cat", ExpectedResult = "\uFF19cat", TestName = "trim: 4 chars with Unicode, leading only")]
+ [TestCase(" cat", ExpectedResult = "cat", TestName = "trim: 4 chars with leading space")]
+ [TestCase("cat ", ExpectedResult = "cat", TestName = "trim: 4 chars with trailing space")]
+ [TestCase(" cat ", ExpectedResult = "cat", TestName = "trim: 4 chars leading and trailing space")]
+ [TestCase("\uFF19cat", ExpectedResult = "\uFF19cat", TestName = "trim: 4 chars with Unicode, leading spcae")]
+ [TestCase(" \uFF19cat", ExpectedResult = "\uFF19cat",
+ TestName = "trim: 4 chars with Unicode, leading")]
+ [TestCase("\uFF19cat ", ExpectedResult = "\uFF19cat",
+ TestName = "trim: 4 chars with Unicode, leading and trailing")]
+ [TestCase(" \uFF19cat ", ExpectedResult = "\uFF19cat", TestName = "trim: 4 chars with Unicode")]
+ [TestCase("\r\uFF19cat ", ExpectedResult = "\uFF19cat",
+ TestName = "trim: 4 chars with Unicode, return char at start")]
+ [TestCase("\r\uFF19cat \n", ExpectedResult = "\uFF19cat",
+ TestName = "trim: 4 chars with Unicode, return at start, new line char at end")]
+ public string trim_ToCsharp(string s)
+ {
+ return s.trim();
+ }
+
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#toLowerCase()
+ [TestCase("", ExpectedResult = "", TestName = "toLower: null")]
+ [TestCase("cat", ExpectedResult = "cat", TestName = "toLower: simple")]
+ [TestCase("CAT", ExpectedResult = "cat", TestName = "toLower: all caps")]
+ [TestCase("cAt", ExpectedResult = "cat", TestName = "toLower: mixed caps")]
+ public string tolower_ToCsharp(string s)
+ {
+ return s.toLowerCase();
+ }
+
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#toUpperCase()
+ [TestCase("", ExpectedResult = "", TestName = "toUpper: null")]
+ [TestCase("cat", ExpectedResult = "CAT", TestName = "toUpper: simple")]
+ [TestCase("CAT", ExpectedResult = "CAT", TestName = "toUpper: all caps")]
+ [TestCase("cAt", ExpectedResult = "CAT", TestName = "toUpper: mixed caps")]
+ public string toupper_ToCsharp(string s)
+ {
+ return s.toUpperCase();
+ }
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#equalsIgnoreCase(java.lang.String)
+ [TestCase("cat", ExpectedResult = true, TestName = "equalsIgnoreCase: lower, true")]
+ [TestCase("dog", ExpectedResult = false, TestName = "equalsIgnoreCase: lower, false")]
+ [TestCase("Cat", ExpectedResult = true, TestName = "equalsIgnoreCase: mixed 1, true")]
+ [TestCase("Dog", ExpectedResult = false, TestName = "equalsIgnoreCase: mixed, false")]
+ [TestCase("CAT", ExpectedResult = true, TestName = "equalsIgnoreCase: tupper, rue")]
+ [TestCase("CaT", ExpectedResult = true, TestName = "equalsIgnoreCase: mixed 2,true")]
+ public bool equalsIgnoreCase_ToCsharp(string s)
+ {
+ return s.equalsIgnoreCase("cat");
+ }
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(int)
+ [TestCase("", ExpectedResult = -1, TestName = "indexOf string: null is negative")]
+ [TestCase("CaT", ExpectedResult = 1, TestName = "indexOf string: in cat 1")]
+ [TestCase("dog", ExpectedResult = -1, TestName = "indexOf string: in dog negative")]
+ [TestCase("cta", ExpectedResult = 2, TestName = "indexOf string: in cat end")]
+ [TestCase("atac", ExpectedResult = 0, TestName = "indexOf string: in cat beginning")]
+ public int indexOf_string_ToCsharp(string s)
+ {
+ return s.indexOf("a");
+ }
+
+ [TestCase("", ExpectedResult = -1, TestName = "indexOf char: null is negative")]
+ [TestCase("CaT", ExpectedResult = 1, TestName = "indexOf char: in cat 1")]
+ public int indexOf_char_ToCsharp(string s)
+ {
+ return s.indexOf('a');
+ }
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#charAt(int)
+ [TestCase(0, ExpectedResult = 'c', TestName = "charAt: in cat 1")]
+ [TestCase(1, ExpectedResult = 'a', TestName = "charAt: in cat 2")]
+ [TestCase(2, ExpectedResult = 't', TestName = "charAt: in cat 3")]
+ [TestCase(3, ExpectedResult = '\uFF19', TestName = "charAt: in cat 4")]
+ public char charAt_ToCsharp(int i)
+ {
+ return "cat\uFF19".charAt(i);
+ }
+
+ [TestCase("\uFF19", ExpectedResult = true, TestName = "endsWith: 1 in cat Unicode")]
+ [TestCase("t\uFF19", ExpectedResult = true, TestName = "endsWith: 2 in cat Unicode")]
+ [TestCase("at\uFF19", ExpectedResult = true, TestName = "endsWith: 3 in cat Unicode")]
+ [TestCase("cat\uFF19", ExpectedResult = true, TestName = "endsWith: 4 in cat Unicode")]
+ [TestCase("dog", ExpectedResult = false, TestName = "endsWith: false")]
+ public bool endsWith_ToCsharp(string s)
+ {
+ return "cat\uFF19".endsWith(s);
+ }
+
+
+ [TestCase("dog", ExpectedResult = false, TestName = "contains: false")]
+ [TestCase("cat", ExpectedResult = true, TestName = "contains: true cat")]
+ [TestCase("\uFF19", ExpectedResult = true, TestName = "contains: true Unicode")]
+ public bool contains_ToCsharp(string s)
+ {
+ return "cat\uFF19".contains(s);
+ }
+
+
+ [TestCase("c", ExpectedResult = true, TestName = "startsWith: 1 in cat Unicode")]
+ [TestCase("ca", ExpectedResult = true, TestName = "startsWith: 2 in cat Unicode")]
+ [TestCase("cat", ExpectedResult = true, TestName = "startsWith: 3 in cat Unicode")]
+ [TestCase("cat\uFF19", ExpectedResult = true, TestName = "startsWith: 4 in cat Unicode")]
+ [TestCase("dog", ExpectedResult = false, TestName = "startsWith: false")]
+ public bool startsWith_ToCsharp(string s)
+ {
+ return "cat\uFF19".startsWith(s);
+ }
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#substring(int,%20int)
+ // and contrast: https://msdn.microsoft.com/en-us/library/aka44szs(v=vs.110).aspx
+ [Test]
+ public void substring_ToCsharp()
+ {
+ // NOTE Java semantics: public String substring(int beginIndex, int endIndex) base 1
+ // NOTE C# semantics:
+
+ "hamburger".substring(4, 8).ShouldBe("urge");
+ "smiles".substring(1, 5).ShouldBe("mile");
+
+ var s = "the cat sat on the matz";
+ s.substring(0, 1).ShouldBe("t");
+ s.substring(0, 2).ShouldBe("th");
+ s.substring((s.Length - 1), (s.Length)).ShouldBe("z"); // just the last char
+ s.substring(0, (s.Length - 1)).ShouldBe("the cat sat on the mat"); // all except last char
+ }
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#isEmpty()
+ [TestCase("", ExpectedResult = true, TestName = "isEmpty: true")]
+ [TestCase(" ", ExpectedResult = false, TestName = "isEmpty: false")]
+ [TestCase("\uFF19", ExpectedResult = false, TestName = "isEmpty: with Unicode false")]
+ public bool isEmpty_ToCsharp(string s)
+ {
+ return s.isEmpty();
+ }
+
+
+ [TestCase("", ExpectedResult = false, TestName = "matches: false")]
+ [TestCase("word", ExpectedResult = true, TestName = "matches: true")]
+ public bool matches_ToCsharp(string s)
+ {
+ return s.matches(@"[\w]+");
+ }
+
+ [TestCase("word", ExpectedResult = "nerd", TestName = "replaceAll: nerd")]
+ [TestCase("wordwo", ExpectedResult = "nerdne", TestName = "replaceAll: nerdier")]
+ [TestCase("rd", ExpectedResult = "rd", TestName = "replaceAll: rd")]
+ public string replaceAll_ToCsharp(string s)
+ {
+ return s.replaceAll(@"wo", "ne");
+ }
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html
+ [Test]
+ public void Lists_ToCsharp()
+ {
+ var one = new List();
+ var two = new List() {"cat", "dog"};
+ var three = new List() {"cat", "dog", "cat"};
+
+ one.isEmpty().ShouldBe(true);
+ two.isEmpty().ShouldBe(false);
+
+ one.size().ShouldBe(0);
+ two.size().ShouldBe(2);
+
+ two.get(0).ShouldBe(two[0]);
+ two.get(0).ShouldBe("cat");
+
+ two.get(1).ShouldBe(two[1]);
+ two.get(1).ShouldBe("dog");
+
+ three.indexOf("cat").ShouldBe(0);
+
+ one.contains("cat").ShouldBe(false);
+ two.contains("dog").ShouldBe(true);
+ two.contains("tree").ShouldBe(false);
+
+ three.remove("cat").ShouldBe(true); // remove first
+ three.remove("cat").ShouldBe(true); // remove second
+ three.remove("cat").ShouldBe(false); // no more to remove, so should return false
+
+ three = new List() {"cat", "dog", "cat"};
+ three.removeAll(new List {"cat"}).ShouldBe(true); // remove second
+ three.remove("cat").ShouldBe(false); // no more to remove, so should return false
+
+
+ two.clear();
+ two.size().ShouldBe(0);
+ two.isEmpty().ShouldBe(true);
+
+ // now two is empty, let's continue
+ two.add("horse").ShouldBe(true);
+ two.size().ShouldBe(1);
+
+ two.addAll(new List {"cat", "dog"}).ShouldBe(true);
+ two.size().ShouldBe(3);
+
+ two.set(0, "cow").ShouldBe("cow");
+ two[0].ShouldBe("cow");
+ two[1].ShouldBe("cat");
+
+ }
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html
+ [Test]
+ public void Hashset_ToCsharp()
+ {
+ var two = new HashSet() {"cat", "dog"};
+ two.add("horse").ShouldBe(true);
+ two.add("cat").ShouldBe(false);
+ }
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/util/Stack.html
+ [Test]
+ public void Stack_ToCsharp()
+ {
+ var two = new Stack();
+ two.push("cat").ShouldBe("cat");
+ two.push("dog").ShouldBe("dog");
+ two.isEmpty().ShouldBe(false);
+ two.pop().ShouldBe("dog"); // LIFO
+ two.pop().ShouldBe("cat");
+ two.isEmpty().ShouldBe(true);
+ }
+
+
+ // Dictionary ones
+
+ // ref: https://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html
+ [Test]
+ public void HashMap_ToCsharp_Dictionary()
+ {
+ var two = new Dictionary();
+ two.put("cat","lucy").ShouldBe("lucy");
+ two.put("dog", "benny").ShouldBe("benny");
+
+ two.Keys.Count.ShouldBe(2);
+ two["cat"].ShouldBe("lucy");
+
+ two.put("cat", "emi").ShouldBe("emi");
+ two["cat"].ShouldBe("emi");
+
+ two.containsKey("dog").ShouldBe(true);
+ two.containsKey("camel").ShouldBe(false);
+
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/helpers/RegexExercises.cs b/SharpSimpleNLGUnitTests/helpers/RegexExercises.cs
new file mode 100644
index 0000000..a12dcec
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/helpers/RegexExercises.cs
@@ -0,0 +1,151 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using Shouldly;
+
+namespace SimpleNLG.Extensions
+{
+ /**
+ * @author Nick Hodge, nhodge@mungr.com
+ */
+
+ public class RegexExercises
+ {
+ // The Regex engine in Java is different to .NET, and there are a couple of
+ // idioms/semantic difference "exercised" and tested here.
+ // ref: MorphologyRules.cs
+
+ // this checks the "matches" and "replaceAll" extension methods as found
+ [Test]
+ public void TestDotNetRegex_vsJava_Nouns()
+ {
+ // Firstly, Noun Plural Morpholology
+
+ var baseForm1 = "carry away";
+ if (baseForm1.matches(@".*[b-z-[eiou]]y\\b"))
+ {
+ baseForm1.replaceAll(@"y\b", @"ies").ShouldBe("carried away");
+ }
+
+ var baseForm1a = "cazy away";
+ if (baseForm1a.matches(@".*[b-z-[eiou]]y\\b"))
+ {
+ baseForm1a.replaceAll(@"y\b", @"ies").ShouldBe("cazies away");
+ }
+
+ var baseForm2 = "cash";
+ if (baseForm2.matches(@".*([szx]|[cs]h)\\b"))
+ {
+ (baseForm2 + "es").ShouldBe("cashes");
+ }
+
+ var baseForm2a = "cax";
+ if (baseForm2a.matches(@".*([szx]|[cs]h)\\b"))
+ {
+ (baseForm2a + "es").ShouldBe("caxes");
+ }
+
+ var baseForm3 = "documentus impartum";
+ if (baseForm3.endsWith("us"))
+ {
+ baseForm3.replaceAll(@"us\b", "i").ShouldBe("documenti impartum");
+
+ }
+
+ var baseForm4 = "documentus impartum onton";
+ if (baseForm4.matches(@".*[(um)(on)]\\b"))
+ {
+ baseForm4.replaceAll(@"[(um)(on)]\\b", "a").ShouldBe("documentus imparta onta");
+ }
+
+ var baseForm5 = "sepsis";
+ if (baseForm5.endsWith("sis"))
+ {
+ baseForm5.replaceAll(@"sis\b", "ses").ShouldBe("sepses");
+ }
+
+ var baseForm6 = "markis";
+ if (baseForm6.endsWith("is"))
+ {
+ baseForm6.replaceAll(@"is\b", "ides").ShouldBe("markides");
+ }
+
+ var baseForm7 = "cognomen";
+ if (baseForm7.endsWith("men"))
+ {
+ baseForm7.replaceAll(@"men\b", "mina").ShouldBe("cognomina");
+ }
+
+ var baseForm8 = "index";
+ if (baseForm8.endsWith("ex"))
+ {
+ baseForm8.replaceAll(@"ex\b", "ices").ShouldBe("indices");
+ }
+
+ var baseForm9 = "wax";
+ if (baseForm9.endsWith("x"))
+ {
+ baseForm9.replaceAll(@"x\b", "ces").ShouldBe("waces");
+ }
+
+ }
+
+ [Test]
+ public void TestDotNetRegex_vsJava_Verbs()
+ {
+ var baseForm1 = "come";
+ if (baseForm1.matches(@".*[^iyeo]e\\b"))
+ {
+ baseForm1.replaceAll(@"e\b", "ing").ShouldBe("coming");
+ }
+
+ var baseForm1a = "cooee";
+ if (baseForm1a.matches(@".*[^iyeo]e\\b"))
+ {
+ // actually shouldnt match so want fall through to here
+ baseForm1a.replaceAll(@"e\b", "ing").ShouldBe("banana");
+ }
+
+ var baseForm2 = "carry";
+ if (baseForm2.matches(@".*[b-z-[eiou]]y\\b"))
+ {
+ baseForm2.replaceAll(@"y\b", "ied").ShouldBe("carried");
+ }
+ }
+
+ [Test]
+ public void AN_AGREEMENT_DeterminierAgrHelper()
+ {
+ var AN_AGREEMENT = @"\A(a|e|i|o|u).*";
+ var lowercaseInput = "enormous".toLowerCase();
+
+ lowercaseInput.matches(AN_AGREEMENT).ShouldBeTrue();
+
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/lexicon/LexicalVariantsTest.java b/SharpSimpleNLGUnitTests/lexicon/LexicalVariantsTest.java
new file mode 100644
index 0000000..04ca697
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/lexicon/LexicalVariantsTest.java
@@ -0,0 +1,285 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.lexicon.english;
+
+import java.util.List;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.features.Inflection;
+import simplenlg.features.LexicalFeature;
+import simplenlg.features.NumberAgreement;
+import simplenlg.features.Tense;
+import simplenlg.framework.InflectedWordElement;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.NLGFactory;
+import simplenlg.framework.WordElement;
+import simplenlg.lexicon.NIHDBLexicon;
+import simplenlg.lexicon.XMLLexicon;
+import simplenlg.lexicon.Lexicon;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * Tests on the use of spelling and inflectional variants, using the
+ * NIHDBLexicon.
+ *
+ * @author bertugatt
+ *
+ */
+public class LexicalVariantsTest {
+
+ // lexicon object -- an instance of Lexicon
+ Lexicon lexicon = null;
+
+ // factory for phrases
+ NLGFactory factory;
+
+ // realiser
+ Realiser realiser;
+
+ // DB location -- change this to point to the lex access data dir
+ static String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
+
+ @Before
+ /*
+ * * Sets up the accessor and runs it -- takes ca. 26 sec
+ */
+ public void setUp() {
+ // use property file for the lexicon
+ try {
+ Properties prop = new Properties();
+ prop.load(getClass().getClassLoader().
+ getResourceAsStream("lexicon.properties"));
+
+ String type = prop.getProperty("LexiconType");
+
+ // the XML lexicon is used by default
+ if (type == null)
+ type = "XML";
+
+ if ("NIH".AreEqual(type)) {
+ // NIH lexicon
+ lexicon = new NIHDBLexicon(prop.getProperty("DB_FILENAME"));
+ } else {
+ // XML lexicon
+ lexicon = new XMLLexicon(prop.getProperty("XML_FILENAME"));
+ }
+ } catch (Exception e) {
+ this.lexicon = new NIHDBLexicon(DB_FILENAME);
+ }
+
+ this.factory = new NLGFactory(lexicon);
+ this.realiser = new Realiser(this.lexicon);
+ }
+
+ /**
+ * Close the lexicon
+ */
+ @After
+ public void tearDown() throws Exception {
+
+ if (lexicon != null)
+ lexicon.close();
+ }
+
+ /**
+ * check that spelling variants are properly set
+ */
+ [Test]
+ public void spellingVariantsTest() {
+ WordElement asd = lexicon.getWord("Adams-Stokes disease");
+ List spellVars = asd
+ .getFeatureAsStringList(LexicalFeature.SPELL_VARS);
+ Assert.assertTrue(spellVars.contains("Adams Stokes disease"));
+ Assert.assertTrue(spellVars.contains("Adam-Stokes disease"));
+ Assert.AreEqual(2, spellVars.size());
+ Assert.AreEqual(asd.getBaseForm(), asd
+ .getFeatureAsString(LexicalFeature.DEFAULT_SPELL));
+
+ // default spell variant is baseform
+ Assert.AreEqual("Adams-Stokes disease", asd
+ .getDefaultSpellingVariant());
+
+ // default spell variant changes
+ asd.setDefaultSpellingVariant("Adams Stokes disease");
+ Assert.AreEqual("Adams Stokes disease", asd
+ .getDefaultSpellingVariant());
+ }
+
+ /**
+ * Test spelling/orthographic variants with different inflections
+ */
+ [Test]
+ public void spellingVariantWithInflectionTest() {
+ WordElement word = lexicon.getWord("formalization");
+ List spellVars = word
+ .getFeatureAsStringList(LexicalFeature.SPELL_VARS);
+ Assert.assertTrue(spellVars.contains("formalisation"));
+ Assert.AreEqual(Inflection.REGULAR, word
+ .getDefaultInflectionalVariant());
+
+ // create with default spelling
+ NPPhraseSpec np = factory.createNounPhrase("the", word);
+ np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ Assert.AreEqual("the formalizations", this.realiser.realise(np)
+ .getRealisation());
+
+ // reset spell var
+ word.setDefaultSpellingVariant("formalisation");
+ Assert.AreEqual("the formalisations", this.realiser.realise(np)
+ .getRealisation());
+ }
+
+ /**
+ * Test the inflectional variants for a verb.
+ */
+ [Test]
+ public void verbInflectionalVariantsTest() {
+ WordElement word = lexicon.getWord("lie", LexicalCategory.VERB);
+ Assert.AreEqual(Inflection.REGULAR, word
+ .getDefaultInflectionalVariant());
+
+ // default past is "lied"
+ InflectedWordElement infl = new InflectedWordElement(word);
+ infl.setFeature(Feature.TENSE, Tense.PAST);
+ String past = realiser.realise(infl).getRealisation();
+ Assert.AreEqual("lied", past);
+
+ // switch to irregular
+ word.setDefaultInflectionalVariant(Inflection.IRREGULAR);
+ infl = new InflectedWordElement(word);
+ infl.setFeature(Feature.TENSE, Tense.PAST);
+ past = realiser.realise(infl).getRealisation();
+ Assert.AreEqual("lay", past);
+
+ // switch back to regular
+ word.setDefaultInflectionalVariant(Inflection.REGULAR);
+ Assert.AreEqual(null, word.getFeature(LexicalFeature.PAST));
+ infl = new InflectedWordElement(word);
+ infl.setFeature(Feature.TENSE, Tense.PAST);
+ past = realiser.realise(infl).getRealisation();
+ Assert.AreEqual("lied", past);
+ }
+
+ /**
+ * Test inflectional variants for nouns
+ */
+ [Test]
+ public void nounInflectionalVariantsTest() {
+ WordElement word = lexicon.getWord("sanctum", LexicalCategory.NOUN);
+ Assert.AreEqual(Inflection.REGULAR, word
+ .getDefaultInflectionalVariant());
+
+ // reg plural shouldn't be stored
+ Assert.AreEqual(null, word.getFeature(LexicalFeature.PLURAL));
+ InflectedWordElement infl = new InflectedWordElement(word);
+ infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ String plur = realiser.realise(infl).getRealisation();
+ Assert.AreEqual("sanctums", plur);
+
+ // switch to glreg
+ word.setDefaultInflectionalVariant(Inflection.GRECO_LATIN_REGULAR);
+ infl = new InflectedWordElement(word);
+ infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ plur = realiser.realise(infl).getRealisation();
+ Assert.AreEqual("sancta", plur);
+
+ // and back to reg
+ word.setDefaultInflectionalVariant(Inflection.REGULAR);
+ infl = new InflectedWordElement(word);
+ infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ plur = realiser.realise(infl).getRealisation();
+ Assert.AreEqual("sanctums", plur);
+ }
+
+ /**
+ * Check that spelling variants are preserved during realisation of NPs
+ */
+ [Test]
+ public void spellingVariantsInNPTest() {
+ WordElement asd = lexicon.getWord("Adams-Stokes disease");
+ Assert.AreEqual("Adams-Stokes disease", asd
+ .getDefaultSpellingVariant());
+ NPPhraseSpec np = this.factory.createNounPhrase(asd);
+ np.setSpecifier(lexicon.getWord("the"));
+ Assert.AreEqual("the Adams-Stokes disease", this.realiser.realise(
+ np).getRealisation());
+
+ // change spelling var
+ asd.setDefaultSpellingVariant("Adams Stokes disease");
+ Assert.AreEqual("Adams Stokes disease", asd
+ .getDefaultSpellingVariant());
+ Assert.AreEqual("the Adams Stokes disease", this.realiser.realise(
+ np).getRealisation());
+
+ //default infl for this word is uncount
+ np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ Assert.AreEqual("the Adams Stokes disease", this.realiser.realise(
+ np).getRealisation());
+
+ //change default infl for this word
+ asd.setDefaultInflectionalVariant(Inflection.REGULAR);
+ Assert.AreEqual("the Adams Stokes diseases", this.realiser.realise(
+ np).getRealisation());
+ }
+
+ /**
+ * Check that spelling variants are preserved during realisation of VPs
+ */
+ [Test]
+ public void spellingVariantsInVPTest() {
+ WordElement eth = (WordElement) factory.createWord("etherise",
+ LexicalCategory.VERB);
+ Assert.AreEqual("etherize", eth.getDefaultSpellingVariant());
+ eth.setDefaultSpellingVariant("etherise");
+ Assert.AreEqual("etherise", eth.getDefaultSpellingVariant());
+ SPhraseSpec s = this.factory.createClause(this.factory
+ .createNounPhrase("the", "doctor"), eth, this.factory.createNounPhrase("the patient"));
+ Assert.AreEqual("the doctor etherises the patient", this.realiser.realise(s).getRealisation());
+ }
+
+ /**
+ * Test the difference between an uncount and a count noun
+ */
+ [Test]
+ public void uncountInflectionalVariantTest() {
+ WordElement calc = (WordElement) factory.createWord("calcification", LexicalCategory.NOUN);
+ NPPhraseSpec theCalc = this.factory.createNounPhrase("the", calc);
+ theCalc.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+
+ String r1 = this.realiser.realise(theCalc).getRealisation();
+ Assert.AreEqual("the calcifications", r1);
+
+ calc.setDefaultInflectionalVariant(Inflection.UNCOUNT);
+ NPPhraseSpec theCalc2 = this.factory.createNounPhrase("the", calc);
+ theCalc2.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ String r2 = this.realiser.realise(theCalc2).getRealisation();
+ Assert.AreEqual("the calcification", r2);
+
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/lexicon/MultipleLexiconTest.java b/SharpSimpleNLGUnitTests/lexicon/MultipleLexiconTest.java
new file mode 100644
index 0000000..73425bc
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/lexicon/MultipleLexiconTest.java
@@ -0,0 +1,103 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.lexicon.english;
+
+import java.io.File;
+import java.io.FileReader;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.features.LexicalFeature;
+import simplenlg.framework.WordElement;
+import simplenlg.lexicon.MultipleLexicon;
+import simplenlg.lexicon.NIHDBLexicon;
+import simplenlg.lexicon.XMLLexicon;
+
+/**
+ * @author Dave Westwater, Data2Text Ltd
+ *
+ */
+public class MultipleLexiconTest {
+
+ // NIH, XML lexicon location
+ static String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
+ static String XML_FILENAME = "src/main/resources/default-lexicon.xml";
+
+ // multi lexicon
+ MultipleLexicon lexicon;
+
+
+ @Before
+ public void setUp() throws Exception {
+ try {
+ Properties prop = new Properties();
+ FileReader reader = new FileReader(new File("./src/main/resources/lexicon.properties"));
+ prop.load(reader);
+
+ String xmlFile = prop.getProperty("XML_FILENAME");
+ String dbFile = prop.getProperty("DB_FILENAME");
+
+ this.lexicon = new MultipleLexicon(new XMLLexicon(xmlFile),
+ new NIHDBLexicon(dbFile));
+ } catch (Exception e) {
+ e.printStackTrace();
+ this.lexicon = new MultipleLexicon(new XMLLexicon(XML_FILENAME),
+ new NIHDBLexicon(DB_FILENAME));
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ lexicon.close();
+ }
+
+ [Test]
+ public void basicLexiconTests() {
+ SharedLexiconTests tests = new SharedLexiconTests();
+ tests.doBasicTests(lexicon);
+ }
+
+ [Test]
+ public void multipleSpecificsTests() {
+ // try to get word which is only in NIH lexicon
+ WordElement UK = lexicon.getWord("UK");
+
+ Assert.AreEqual(true, UK.getFeatureAsString(LexicalFeature.ACRONYM_OF).contains("United Kingdom"));
+
+ // test alwaysSearchAll flag
+ boolean alwaysSearchAll = lexicon.isAlwaysSearchAll();
+
+ // tree as noun exists in both, but as verb only in NIH
+ lexicon.setAlwaysSearchAll(true);
+ Assert.AreEqual(3, lexicon.getWords("tree").size()); // 3 = once in XML plus twice in NIH
+
+ lexicon.setAlwaysSearchAll(false);
+ Assert.AreEqual(1, lexicon.getWords("tree").size());
+
+ // restore flag to original state
+ lexicon.setAlwaysSearchAll(alwaysSearchAll);
+ }
+
+
+}
diff --git a/SharpSimpleNLGUnitTests/lexicon/NIHDBLexiconTest.java b/SharpSimpleNLGUnitTests/lexicon/NIHDBLexiconTest.java
new file mode 100644
index 0000000..838e844
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/lexicon/NIHDBLexiconTest.java
@@ -0,0 +1,251 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.lexicon.english;
+
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.features.LexicalFeature;
+import simplenlg.features.NumberAgreement;
+import simplenlg.features.Person;
+import simplenlg.features.Tense;
+import simplenlg.framework.InflectedWordElement;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.NLGElement;
+import simplenlg.framework.WordElement;
+import simplenlg.lexicon.NIHDBLexicon;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * Tests for NIHDBLexicon
+ *
+ * @author Ehud Reiter, Albert Gatt
+ */
+public class NIHDBLexiconTest {
+
+ // lexicon object -- an instance of Lexicon
+ NIHDBLexicon lexicon = null;
+
+ // DB location -- change this to point to the lex access data dir
+ static String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
+
+ @Before
+ /*
+ * * Sets up the accessor and runs it -- takes ca. 26 sec
+ */
+ public void setUp() {
+ // use property file for the lexicon
+ try {
+ Properties prop = new Properties();
+ prop.load(getClass().getClassLoader().
+ getResourceAsStream("lexicon.properties"));
+
+ String lexiconPath = prop.getProperty("DB_FILENAME");
+
+ if (null != lexiconPath)
+ this.lexicon = new NIHDBLexicon(lexiconPath);
+ } catch (Exception e) {
+ this.lexicon = new NIHDBLexicon(DB_FILENAME);
+ }
+ }
+
+ /**
+ * Close the lexicon
+ */
+ @After
+ public void tearDown() throws Exception {
+ if (lexicon != null)
+ lexicon.close();
+ }
+
+ /**
+ * Runs basic Lexicon Tests.
+ */
+ [Test]
+ public void basicLexiconTests() {
+ SharedLexiconTests tests = new SharedLexiconTests();
+ tests.doBasicTests(lexicon);
+ }
+
+ /**
+ * Verb 'be' conjugation tests.
+ */
+ public void beInflectionTest() {
+ Realiser r = new Realiser();
+ WordElement word = lexicon.getWord("be", LexicalCategory.VERB);
+ InflectedWordElement inflWord = new InflectedWordElement(word);
+
+ //1st person sg past
+ inflWord.setFeature(Feature.PERSON, Person.FIRST);
+ inflWord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.AreEqual("was", r.realise(inflWord).toString());
+
+ //2nd person sg past
+ inflWord.setFeature(Feature.PERSON, Person.SECOND);
+ inflWord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.AreEqual("were", r.realise(inflWord).toString());
+
+ //3rd person sg past
+ inflWord.setFeature(Feature.PERSON, Person.THIRD);
+ inflWord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.AreEqual("was", r.realise(inflWord).toString());
+
+ //1st person sg present
+ inflWord.setFeature(Feature.PERSON, Person.FIRST);
+ inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
+ Assert.AreEqual("am", r.realise(inflWord).toString());
+
+ //2nd person sg present
+ inflWord.setFeature(Feature.PERSON, Person.SECOND);
+ inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
+ Assert.AreEqual("are", r.realise(inflWord).toString());
+
+ //3rd person sg present
+ inflWord.setFeature(Feature.PERSON, Person.THIRD);
+ inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
+ Assert.AreEqual("is", r.realise(inflWord).toString());
+
+ inflWord.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+
+ //1st person pl past
+ inflWord.setFeature(Feature.PERSON, Person.FIRST);
+ inflWord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.AreEqual("were", r.realise(inflWord).toString());
+
+ //2nd person pl past
+ inflWord.setFeature(Feature.PERSON, Person.SECOND);
+ inflWord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.AreEqual("were", r.realise(inflWord).toString());
+
+ //3rd person pl past
+ inflWord.setFeature(Feature.PERSON, Person.THIRD);
+ inflWord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.AreEqual("were", r.realise(inflWord).toString());
+
+ //1st person pl present
+ inflWord.setFeature(Feature.PERSON, Person.FIRST);
+ inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
+ Assert.AreEqual("are", r.realise(inflWord).toString());
+
+ //2nd person pl present
+ inflWord.setFeature(Feature.PERSON, Person.SECOND);
+ inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
+ Assert.AreEqual("are", r.realise(inflWord).toString());
+
+ //3rd person pl present
+ inflWord.setFeature(Feature.PERSON, Person.THIRD);
+ inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
+ Assert.AreEqual("are", r.realise(inflWord).toString());
+
+ }
+
+ /**
+ * Tests the lexicon for recall of Acryonms.
+ */
+ [Test]
+ public void acronymsTests() {
+ WordElement uk = lexicon.getWord("UK");
+ WordElement unitedKingdom = lexicon.getWord("United Kingdom");
+ List fullForms = uk
+ .getFeatureAsElementList(LexicalFeature.ACRONYM_OF);
+
+ // "uk" is an acronym of 3 full forms
+ Assert.AreEqual(3, fullForms.size());
+ Assert.assertTrue(fullForms.contains(unitedKingdom));
+ }
+
+ /**
+ * Tests the lexicon for recall of baseforms with their standard inflected forms.
+ */
+ [Test]
+ public void standardInflectionsTest() {
+ // test keepStandardInflection flag
+ boolean keepInflectionsFlag = lexicon.isKeepStandardInflections();
+
+ lexicon.setKeepStandardInflections(true);
+ WordElement dog = lexicon.getWord("dog", LexicalCategory.NOUN);
+ Assert.AreEqual("dogs", dog
+ .getFeatureAsString(LexicalFeature.PLURAL));
+
+ lexicon.setKeepStandardInflections(false);
+ WordElement cat = lexicon.getWord("cat", LexicalCategory.NOUN);
+ Assert
+ .AreEqual(null, cat
+ .getFeatureAsString(LexicalFeature.PLURAL));
+
+ // restore flag to original state
+ lexicon.setKeepStandardInflections(keepInflectionsFlag);
+ }
+
+ /**
+ * Test for NIHDBLexicon functionality when several threads are using the
+ * same Lexicon
+ */
+ @SuppressWarnings("static-access")
+ public void multiThreadAppAccessTest() {
+
+ LexThread runner1 = new LexThread("lie");
+ LexThread runner2 = new LexThread("bark");
+
+ // schedule them and run them
+ ScheduledExecutorService service = Executors.newScheduledThreadPool(2);
+ service.schedule(runner1, 0, TimeUnit.MILLISECONDS);
+ service.schedule(runner2, 0, TimeUnit.MILLISECONDS);
+
+ try {
+ Thread.currentThread().sleep(500);
+ } catch (InterruptedException ie) {
+ ;// do nothing
+ }
+
+ service.shutdownNow();
+
+ // check that the right words have been retrieved
+ Assert.AreEqual("lie", runner1.word.getBaseForm());
+ Assert.AreEqual("bark", runner2.word.getBaseForm());
+ }
+
+ /*
+ * Class that implements a thread from which a lexical item can be retrieved
+ */
+ private class LexThread extends Thread {
+ WordElement word;
+ String base;
+
+ public LexThread(String base) {
+ this.base = base;
+ }
+
+ public void run() {
+ word = lexicon.getWord(base, LexicalCategory.VERB);
+ }
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/lexicon/SharedLexiconTests.java b/SharpSimpleNLGUnitTests/lexicon/SharedLexiconTests.java
new file mode 100644
index 0000000..413b6ce
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/lexicon/SharedLexiconTests.java
@@ -0,0 +1,137 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.lexicon.english;
+
+import junit.framework.Assert;
+import simplenlg.features.Inflection;
+import simplenlg.features.LexicalFeature;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.WordElement;
+import simplenlg.lexicon.Lexicon;
+
+/**
+ * @author Dave Westwater, Data2Text Ltd
+ *
+ */
+public class SharedLexiconTests {
+
+ public void doBasicTests(Lexicon lexicon) {
+ // test getWords. Should be 2 "can" (of any cat), 1 noun tree, 0 adj
+ // trees
+ Assert.AreEqual(3, lexicon.getWords("can").size());
+ Assert.AreEqual(1, lexicon.getWords("can", LexicalCategory.NOUN)
+ .size());
+ Assert.AreEqual(0, lexicon.getWords("can",
+ LexicalCategory.ADJECTIVE).size());
+
+ // below test removed as standard morph variants no longer recorded in
+ // lexicon
+ // WordElement early = lexicon.getWord("early",
+ // LexicalCategory.ADJECTIVE);
+ // Assert.AreEqual("earlier",
+ // early.getFeatureAsString(Feature.COMPARATIVE));
+
+ // test getWord. Comparative of ADJ "good" is "better", superlative is
+ // "best", this is a qualitative and predicative adjective
+ WordElement good = lexicon.getWord("good", LexicalCategory.ADJECTIVE);
+ Assert.AreEqual("better", good
+ .getFeatureAsString(LexicalFeature.COMPARATIVE));
+ Assert.AreEqual("best", good
+ .getFeatureAsString(LexicalFeature.SUPERLATIVE));
+ Assert.AreEqual(true, good.getFeatureAsBoolean(
+ LexicalFeature.QUALITATIVE).booleanValue());
+ Assert.AreEqual(true, good.getFeatureAsBoolean(
+ LexicalFeature.PREDICATIVE).booleanValue());
+ Assert.AreEqual(false, good.getFeatureAsBoolean(
+ LexicalFeature.COLOUR).booleanValue());
+ Assert.AreEqual(false, good.getFeatureAsBoolean(
+ LexicalFeature.CLASSIFYING).booleanValue());
+
+ // test getWord. There is only one "woman", and its plural is "women".
+ // It is not an acronym, not proper, and countable
+ WordElement woman = lexicon.getWord("woman");
+
+ Assert.AreEqual("women", woman
+ .getFeatureAsString(LexicalFeature.PLURAL));
+ Assert.AreEqual(null, woman
+ .getFeatureAsString(LexicalFeature.ACRONYM_OF));
+ Assert.AreEqual(false, woman.getFeatureAsBoolean(
+ LexicalFeature.PROPER).booleanValue());
+ Assert.assertFalse(woman.hasInflectionalVariant(Inflection.UNCOUNT));
+
+ // NB: This fails if the lexicon is XMLLexicon. No idea why.
+ // Assert.AreEqual("irreg",
+ // woman.getFeatureAsString(LexicalFeature.DEFAULT_INFL));
+
+ // test getWord. Noun "sand" is non-count
+ WordElement sand = lexicon.getWord("sand", LexicalCategory.NOUN);
+ Assert.AreEqual(true, sand.hasInflectionalVariant(Inflection.UNCOUNT));
+ Assert.AreEqual(Inflection.UNCOUNT, sand.getDefaultInflectionalVariant());
+
+ // test hasWord
+ Assert.AreEqual(true, lexicon.hasWord("tree")); // "tree" exists
+ Assert.AreEqual(false, lexicon.hasWord("tree",
+ LexicalCategory.ADVERB)); // but not as an adverb
+
+ // test getWordByID; quickly, also check that this is a verb_modifier
+ WordElement quickly = lexicon.getWordByID("E0051632");
+ Assert.AreEqual("quickly", quickly.getBaseForm());
+ Assert.AreEqual(LexicalCategory.ADVERB, quickly.getCategory());
+ Assert.AreEqual(true, quickly.getFeatureAsBoolean(
+ LexicalFeature.VERB_MODIFIER).booleanValue());
+ Assert.AreEqual(false, quickly.getFeatureAsBoolean(
+ LexicalFeature.SENTENCE_MODIFIER).booleanValue());
+ Assert.AreEqual(false, quickly.getFeatureAsBoolean(
+ LexicalFeature.INTENSIFIER).booleanValue());
+
+ // test getWordFromVariant, verb type (tran or intran, not ditran)
+ WordElement eat = lexicon.getWordFromVariant("eating");
+ Assert.AreEqual("eat", eat.getBaseForm());
+ Assert.AreEqual(LexicalCategory.VERB, eat.getCategory());
+ Assert.AreEqual(true, eat.getFeatureAsBoolean(
+ LexicalFeature.INTRANSITIVE).booleanValue());
+ Assert.AreEqual(true, eat.getFeatureAsBoolean(
+ LexicalFeature.TRANSITIVE).booleanValue());
+ Assert.AreEqual(false, eat.getFeatureAsBoolean(
+ LexicalFeature.DITRANSITIVE).booleanValue());
+
+ // test BE is handled OK
+ Assert.AreEqual("been", lexicon.getWordFromVariant("is",
+ LexicalCategory.VERB).getFeatureAsString(
+ LexicalFeature.PAST_PARTICIPLE));
+
+ // test modal
+ WordElement can = lexicon.getWord("can", LexicalCategory.MODAL);
+ Assert.AreEqual("could", can
+ .getFeatureAsString(LexicalFeature.PAST));
+
+ // test non-existent word
+ Assert.AreEqual(0, lexicon.getWords("akjmchsgk").size());
+
+ // test lookup word method
+ Assert.AreEqual(lexicon.lookupWord("say", LexicalCategory.VERB)
+ .getBaseForm(), "say");
+ Assert.AreEqual(lexicon.lookupWord("said", LexicalCategory.VERB)
+ .getBaseForm(), "say");
+ Assert.AreEqual(lexicon
+ .lookupWord("E0054448", LexicalCategory.VERB).getBaseForm(),
+ "say");
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/lexicon/XMLLexiconTest.cs b/SharpSimpleNLGUnitTests/lexicon/XMLLexiconTest.cs
new file mode 100644
index 0000000..fd4267a
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/lexicon/XMLLexiconTest.cs
@@ -0,0 +1,155 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using System;
+using System.Diagnostics;
+using FluentAssertions;
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.lexicon
+{
+
+ /**
+ * @author D. Westwater, Data2Text Ltd
+ *
+ */
+
+ public class XMLLexiconTest
+ {
+
+ // lexicon object -- an instance of Lexicon
+ XMLLexicon lexicon = null;
+
+
+ [Test]
+ public void setUp_from_EmbeddedResource()
+ {
+ var timer = new Stopwatch();
+ timer.Start();
+ this.lexicon = new XMLLexicon();
+ timer.Stop();
+ Console.WriteLine($"Loading Lexicon took: {timer.ElapsedMilliseconds}ms");
+ }
+
+
+ [Test]
+ public void setUp_from_Filepath()
+ {
+ var timer = new Stopwatch();
+ timer.Start();
+ this.lexicon = new XMLLexicon(@"C:\work\SharpSimpleNLG\SharpSimpleNLGDotNetCore\lexicon\default-lexicon.xml");
+ timer.Stop();
+ Console.WriteLine($"Loading Lexicon took: {timer.ElapsedMilliseconds}ms");
+ }
+
+
+ /**
+ * Tests the immutability of the XMLLexicon by checking to make sure features
+ * are not inadvertently propagated to the canonical XMLLexicon WordElement object.
+ */
+
+ [Test]
+ public void xmlLexiconImmutabilityTest()
+ {
+ this.lexicon = new XMLLexicon();
+ NLGFactory factory = new NLGFactory(lexicon);
+ Realiser realiser = new Realiser(lexicon);
+
+ // "wall" is singular.
+ NPPhraseSpec wall = factory.createNounPhrase("the", "wall");
+ Assert.AreEqual(NumberAgreement.SINGULAR, wall.getFeature(Feature.NUMBER.ToString()));
+
+ // Realise a sentence with plural form of "wall"
+ wall.setPlural(true);
+ SPhraseSpec sentence = factory.createClause("motion", "observe");
+ sentence.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ PPPhraseSpec pp = factory.createPrepositionPhrase("in", wall);
+ sentence.addPostModifier(pp);
+ var r = realiser.realiseSentence(sentence);
+
+ Assert.AreEqual(r, "Motion observed in the walls.");
+
+ // Create a new 'the wall' NP and check to make sure that the syntax processor has
+ // not propagated plurality to the canonical XMLLexicon WordElement object.
+ wall = factory.createNounPhrase("the", "wall");
+ Assert.AreEqual(NumberAgreement.SINGULAR, wall.getFeature(Feature.NUMBER.ToString()));
+ }
+
+ [Test]
+ public void xmlLexiconLookupTests()
+ {
+ this.lexicon = new XMLLexicon();
+
+ var w = lexicon.getWords("man");
+ w.Count.ShouldBeEquivalentTo(1);
+ w[0].getBaseForm().ShouldBeEquivalentTo("man");
+ w[0].features.Count.ShouldBeEquivalentTo(2);
+ w[0].getId().ShouldBeEquivalentTo("E0038767");
+ }
+
+ [Test]
+ public void xmlLexiconLookupWord()
+ {
+ this.lexicon = new XMLLexicon();
+ var w = lexicon.lookupWord("man", new LexicalCategory_NOUN());
+ var id = w.getId();
+ Assert.IsNotNull(id);
+ Assert.IsNotEmpty(id);
+ id.ShouldBeEquivalentTo("E0038767");
+ }
+
+ [Test]
+ public void xmlLexiconLookupWord_plurals()
+ {
+ this.lexicon = new XMLLexicon();
+ var w1 = lexicon.lookupWord("man", new LexicalCategory_NOUN());
+ var w2 = w1.getFeature(LexicalFeature.PLURAL.ToString());
+ w2.ShouldBeEquivalentTo("men");
+ }
+
+
+ [Test]
+ public void xmlLexiconGetWordVariants()
+ {
+ this.lexicon = new XMLLexicon();
+ var w = lexicon.getWordsFromVariant("did");
+ var resw = w[0];
+ Assert.IsNotNull(resw);
+ resw.getAllFeatures().Count.ShouldBeEquivalentTo(8);
+ var form1 = resw.getFeature(LexicalFeature.PAST);
+ form1.ShouldBeEquivalentTo("did");
+ var form2 = resw.getFeature(LexicalFeature.PRESENT3S);
+ form2.ShouldBeEquivalentTo("does");
+ var form3 = resw.getFeature(LexicalFeature.PAST_PARTICIPLE);
+ form3.ShouldBeEquivalentTo("done");
+ var form4 = resw.getFeature(LexicalFeature.PRESENT_PARTICIPLE);
+ form4.ShouldBeEquivalentTo("doing");
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/lexicon/english/LexicalVariantsTest.java b/SharpSimpleNLGUnitTests/lexicon/english/LexicalVariantsTest.java
new file mode 100644
index 0000000..e316e16
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/lexicon/english/LexicalVariantsTest.java
@@ -0,0 +1,285 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.lexicon.english;
+
+import java.util.List;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.features.Inflection;
+import simplenlg.features.LexicalFeature;
+import simplenlg.features.NumberAgreement;
+import simplenlg.features.Tense;
+import simplenlg.framework.InflectedWordElement;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.NLGFactory;
+import simplenlg.framework.WordElement;
+import simplenlg.lexicon.NIHDBLexicon;
+import simplenlg.lexicon.XMLLexicon;
+import simplenlg.lexicon.Lexicon;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * Tests on the use of spelling and inflectional variants, using the
+ * NIHDBLexicon.
+ *
+ * @author bertugatt
+ *
+ */
+public class LexicalVariantsTest {
+
+ // lexicon object -- an instance of Lexicon
+ Lexicon lexicon = null;
+
+ // factory for phrases
+ NLGFactory factory;
+
+ // realiser
+ Realiser realiser;
+
+ // DB location -- change this to point to the lex access data dir
+ static String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
+
+ @Before
+ /*
+ * * Sets up the accessor and runs it -- takes ca. 26 sec
+ */
+ public void setUp() {
+ // use property file for the lexicon
+ try {
+ Properties prop = new Properties();
+ prop.load(getClass().getClassLoader().
+ getResourceAsStream("lexicon.properties"));
+
+ String type = prop.getProperty("LexiconType");
+
+ // the XML lexicon is used by default
+ if (type == null)
+ type = "XML";
+
+ if ("NIH".equals(type)) {
+ // NIH lexicon
+ lexicon = new NIHDBLexicon(prop.getProperty("DB_FILENAME"));
+ } else {
+ // XML lexicon
+ lexicon = new XMLLexicon(prop.getProperty("XML_FILENAME"));
+ }
+ } catch (Exception e) {
+ this.lexicon = new NIHDBLexicon(DB_FILENAME);
+ }
+
+ this.factory = new NLGFactory(lexicon);
+ this.realiser = new Realiser(this.lexicon);
+ }
+
+ /**
+ * Close the lexicon
+ */
+ @After
+ public void tearDown() throws Exception {
+
+ if (lexicon != null)
+ lexicon.close();
+ }
+
+ /**
+ * check that spelling variants are properly set
+ */
+ @Test
+ public void spellingVariantsTest() {
+ WordElement asd = lexicon.getWord("Adams-Stokes disease");
+ List spellVars = asd
+ .getFeatureAsStringList(LexicalFeature.SPELL_VARS);
+ Assert.assertTrue(spellVars.contains("Adams Stokes disease"));
+ Assert.assertTrue(spellVars.contains("Adam-Stokes disease"));
+ Assert.assertEquals(2, spellVars.size());
+ Assert.assertEquals(asd.getBaseForm(), asd
+ .getFeatureAsString(LexicalFeature.DEFAULT_SPELL));
+
+ // default spell variant is baseform
+ Assert.assertEquals("Adams-Stokes disease", asd
+ .getDefaultSpellingVariant());
+
+ // default spell variant changes
+ asd.setDefaultSpellingVariant("Adams Stokes disease");
+ Assert.assertEquals("Adams Stokes disease", asd
+ .getDefaultSpellingVariant());
+ }
+
+ /**
+ * Test spelling/orthographic variants with different inflections
+ */
+ @Test
+ public void spellingVariantWithInflectionTest() {
+ WordElement word = lexicon.getWord("formalization");
+ List spellVars = word
+ .getFeatureAsStringList(LexicalFeature.SPELL_VARS);
+ Assert.assertTrue(spellVars.contains("formalisation"));
+ Assert.assertEquals(Inflection.REGULAR, word
+ .getDefaultInflectionalVariant());
+
+ // create with default spelling
+ NPPhraseSpec np = factory.createNounPhrase("the", word);
+ np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ Assert.assertEquals("the formalizations", this.realiser.realise(np)
+ .getRealisation());
+
+ // reset spell var
+ word.setDefaultSpellingVariant("formalisation");
+ Assert.assertEquals("the formalisations", this.realiser.realise(np)
+ .getRealisation());
+ }
+
+ /**
+ * Test the inflectional variants for a verb.
+ */
+ @Test
+ public void verbInflectionalVariantsTest() {
+ WordElement word = lexicon.getWord("lie", LexicalCategory.VERB);
+ Assert.assertEquals(Inflection.REGULAR, word
+ .getDefaultInflectionalVariant());
+
+ // default past is "lied"
+ InflectedWordElement infl = new InflectedWordElement(word);
+ infl.setFeature(Feature.TENSE, Tense.PAST);
+ String past = realiser.realise(infl).getRealisation();
+ Assert.assertEquals("lied", past);
+
+ // switch to irregular
+ word.setDefaultInflectionalVariant(Inflection.IRREGULAR);
+ infl = new InflectedWordElement(word);
+ infl.setFeature(Feature.TENSE, Tense.PAST);
+ past = realiser.realise(infl).getRealisation();
+ Assert.assertEquals("lay", past);
+
+ // switch back to regular
+ word.setDefaultInflectionalVariant(Inflection.REGULAR);
+ Assert.assertEquals(null, word.getFeature(LexicalFeature.PAST));
+ infl = new InflectedWordElement(word);
+ infl.setFeature(Feature.TENSE, Tense.PAST);
+ past = realiser.realise(infl).getRealisation();
+ Assert.assertEquals("lied", past);
+ }
+
+ /**
+ * Test inflectional variants for nouns
+ */
+ @Test
+ public void nounInflectionalVariantsTest() {
+ WordElement word = lexicon.getWord("sanctum", LexicalCategory.NOUN);
+ Assert.assertEquals(Inflection.REGULAR, word
+ .getDefaultInflectionalVariant());
+
+ // reg plural shouldn't be stored
+ Assert.assertEquals(null, word.getFeature(LexicalFeature.PLURAL));
+ InflectedWordElement infl = new InflectedWordElement(word);
+ infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ String plur = realiser.realise(infl).getRealisation();
+ Assert.assertEquals("sanctums", plur);
+
+ // switch to glreg
+ word.setDefaultInflectionalVariant(Inflection.GRECO_LATIN_REGULAR);
+ infl = new InflectedWordElement(word);
+ infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ plur = realiser.realise(infl).getRealisation();
+ Assert.assertEquals("sancta", plur);
+
+ // and back to reg
+ word.setDefaultInflectionalVariant(Inflection.REGULAR);
+ infl = new InflectedWordElement(word);
+ infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ plur = realiser.realise(infl).getRealisation();
+ Assert.assertEquals("sanctums", plur);
+ }
+
+ /**
+ * Check that spelling variants are preserved during realisation of NPs
+ */
+ @Test
+ public void spellingVariantsInNPTest() {
+ WordElement asd = lexicon.getWord("Adams-Stokes disease");
+ Assert.assertEquals("Adams-Stokes disease", asd
+ .getDefaultSpellingVariant());
+ NPPhraseSpec np = this.factory.createNounPhrase(asd);
+ np.setSpecifier(lexicon.getWord("the"));
+ Assert.assertEquals("the Adams-Stokes disease", this.realiser.realise(
+ np).getRealisation());
+
+ // change spelling var
+ asd.setDefaultSpellingVariant("Adams Stokes disease");
+ Assert.assertEquals("Adams Stokes disease", asd
+ .getDefaultSpellingVariant());
+ Assert.assertEquals("the Adams Stokes disease", this.realiser.realise(
+ np).getRealisation());
+
+ //default infl for this word is uncount
+ np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ Assert.assertEquals("the Adams Stokes disease", this.realiser.realise(
+ np).getRealisation());
+
+ //change default infl for this word
+ asd.setDefaultInflectionalVariant(Inflection.REGULAR);
+ Assert.assertEquals("the Adams Stokes diseases", this.realiser.realise(
+ np).getRealisation());
+ }
+
+ /**
+ * Check that spelling variants are preserved during realisation of VPs
+ */
+ @Test
+ public void spellingVariantsInVPTest() {
+ WordElement eth = (WordElement) factory.createWord("etherise",
+ LexicalCategory.VERB);
+ Assert.assertEquals("etherize", eth.getDefaultSpellingVariant());
+ eth.setDefaultSpellingVariant("etherise");
+ Assert.assertEquals("etherise", eth.getDefaultSpellingVariant());
+ SPhraseSpec s = this.factory.createClause(this.factory
+ .createNounPhrase("the", "doctor"), eth, this.factory.createNounPhrase("the patient"));
+ Assert.assertEquals("the doctor etherises the patient", this.realiser.realise(s).getRealisation());
+ }
+
+ /**
+ * Test the difference between an uncount and a count noun
+ */
+ @Test
+ public void uncountInflectionalVariantTest() {
+ WordElement calc = (WordElement) factory.createWord("calcification", LexicalCategory.NOUN);
+ NPPhraseSpec theCalc = this.factory.createNounPhrase("the", calc);
+ theCalc.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+
+ String r1 = this.realiser.realise(theCalc).getRealisation();
+ Assert.assertEquals("the calcifications", r1);
+
+ calc.setDefaultInflectionalVariant(Inflection.UNCOUNT);
+ NPPhraseSpec theCalc2 = this.factory.createNounPhrase("the", calc);
+ theCalc2.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ String r2 = this.realiser.realise(theCalc2).getRealisation();
+ Assert.assertEquals("the calcification", r2);
+
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/lexicon/english/MultipleLexiconTest.java b/SharpSimpleNLGUnitTests/lexicon/english/MultipleLexiconTest.java
new file mode 100644
index 0000000..3b9df74
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/lexicon/english/MultipleLexiconTest.java
@@ -0,0 +1,103 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.lexicon.english;
+
+import java.io.File;
+import java.io.FileReader;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.features.LexicalFeature;
+import simplenlg.framework.WordElement;
+import simplenlg.lexicon.MultipleLexicon;
+import simplenlg.lexicon.NIHDBLexicon;
+import simplenlg.lexicon.XMLLexicon;
+
+/**
+ * @author Dave Westwater, Data2Text Ltd
+ *
+ */
+public class MultipleLexiconTest {
+
+ // NIH, XML lexicon location
+ static String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
+ static String XML_FILENAME = "src/main/resources/default-lexicon.xml";
+
+ // multi lexicon
+ MultipleLexicon lexicon;
+
+
+ @Before
+ public void setUp() throws Exception {
+ try {
+ Properties prop = new Properties();
+ FileReader reader = new FileReader(new File("./src/main/resources/lexicon.properties"));
+ prop.load(reader);
+
+ String xmlFile = prop.getProperty("XML_FILENAME");
+ String dbFile = prop.getProperty("DB_FILENAME");
+
+ this.lexicon = new MultipleLexicon(new XMLLexicon(xmlFile),
+ new NIHDBLexicon(dbFile));
+ } catch (Exception e) {
+ e.printStackTrace();
+ this.lexicon = new MultipleLexicon(new XMLLexicon(XML_FILENAME),
+ new NIHDBLexicon(DB_FILENAME));
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ lexicon.close();
+ }
+
+ @Test
+ public void basicLexiconTests() {
+ SharedLexiconTests tests = new SharedLexiconTests();
+ tests.doBasicTests(lexicon);
+ }
+
+ @Test
+ public void multipleSpecificsTests() {
+ // try to get word which is only in NIH lexicon
+ WordElement UK = lexicon.getWord("UK");
+
+ Assert.assertEquals(true, UK.getFeatureAsString(LexicalFeature.ACRONYM_OF).contains("United Kingdom"));
+
+ // test alwaysSearchAll flag
+ boolean alwaysSearchAll = lexicon.isAlwaysSearchAll();
+
+ // tree as noun exists in both, but as verb only in NIH
+ lexicon.setAlwaysSearchAll(true);
+ Assert.assertEquals(3, lexicon.getWords("tree").size()); // 3 = once in XML plus twice in NIH
+
+ lexicon.setAlwaysSearchAll(false);
+ Assert.assertEquals(1, lexicon.getWords("tree").size());
+
+ // restore flag to original state
+ lexicon.setAlwaysSearchAll(alwaysSearchAll);
+ }
+
+
+}
diff --git a/SharpSimpleNLGUnitTests/lexicon/english/NIHDBLexiconTest.java b/SharpSimpleNLGUnitTests/lexicon/english/NIHDBLexiconTest.java
new file mode 100644
index 0000000..232aba8
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/lexicon/english/NIHDBLexiconTest.java
@@ -0,0 +1,251 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.lexicon.english;
+
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.features.LexicalFeature;
+import simplenlg.features.NumberAgreement;
+import simplenlg.features.Person;
+import simplenlg.features.Tense;
+import simplenlg.framework.InflectedWordElement;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.NLGElement;
+import simplenlg.framework.WordElement;
+import simplenlg.lexicon.NIHDBLexicon;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * Tests for NIHDBLexicon
+ *
+ * @author Ehud Reiter, Albert Gatt
+ */
+public class NIHDBLexiconTest {
+
+ // lexicon object -- an instance of Lexicon
+ NIHDBLexicon lexicon = null;
+
+ // DB location -- change this to point to the lex access data dir
+ static String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
+
+ @Before
+ /*
+ * * Sets up the accessor and runs it -- takes ca. 26 sec
+ */
+ public void setUp() {
+ // use property file for the lexicon
+ try {
+ Properties prop = new Properties();
+ prop.load(getClass().getClassLoader().
+ getResourceAsStream("lexicon.properties"));
+
+ String lexiconPath = prop.getProperty("DB_FILENAME");
+
+ if (null != lexiconPath)
+ this.lexicon = new NIHDBLexicon(lexiconPath);
+ } catch (Exception e) {
+ this.lexicon = new NIHDBLexicon(DB_FILENAME);
+ }
+ }
+
+ /**
+ * Close the lexicon
+ */
+ @After
+ public void tearDown() throws Exception {
+ if (lexicon != null)
+ lexicon.close();
+ }
+
+ /**
+ * Runs basic Lexicon Tests.
+ */
+ @Test
+ public void basicLexiconTests() {
+ SharedLexiconTests tests = new SharedLexiconTests();
+ tests.doBasicTests(lexicon);
+ }
+
+ /**
+ * Verb 'be' conjugation tests.
+ */
+ public void beInflectionTest() {
+ Realiser r = new Realiser();
+ WordElement word = lexicon.getWord("be", LexicalCategory.VERB);
+ InflectedWordElement inflWord = new InflectedWordElement(word);
+
+ //1st person sg past
+ inflWord.setFeature(Feature.PERSON, Person.FIRST);
+ inflWord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals("was", r.realise(inflWord).toString());
+
+ //2nd person sg past
+ inflWord.setFeature(Feature.PERSON, Person.SECOND);
+ inflWord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals("were", r.realise(inflWord).toString());
+
+ //3rd person sg past
+ inflWord.setFeature(Feature.PERSON, Person.THIRD);
+ inflWord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals("was", r.realise(inflWord).toString());
+
+ //1st person sg present
+ inflWord.setFeature(Feature.PERSON, Person.FIRST);
+ inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
+ Assert.assertEquals("am", r.realise(inflWord).toString());
+
+ //2nd person sg present
+ inflWord.setFeature(Feature.PERSON, Person.SECOND);
+ inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
+ Assert.assertEquals("are", r.realise(inflWord).toString());
+
+ //3rd person sg present
+ inflWord.setFeature(Feature.PERSON, Person.THIRD);
+ inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
+ Assert.assertEquals("is", r.realise(inflWord).toString());
+
+ inflWord.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+
+ //1st person pl past
+ inflWord.setFeature(Feature.PERSON, Person.FIRST);
+ inflWord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals("were", r.realise(inflWord).toString());
+
+ //2nd person pl past
+ inflWord.setFeature(Feature.PERSON, Person.SECOND);
+ inflWord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals("were", r.realise(inflWord).toString());
+
+ //3rd person pl past
+ inflWord.setFeature(Feature.PERSON, Person.THIRD);
+ inflWord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals("were", r.realise(inflWord).toString());
+
+ //1st person pl present
+ inflWord.setFeature(Feature.PERSON, Person.FIRST);
+ inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
+ Assert.assertEquals("are", r.realise(inflWord).toString());
+
+ //2nd person pl present
+ inflWord.setFeature(Feature.PERSON, Person.SECOND);
+ inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
+ Assert.assertEquals("are", r.realise(inflWord).toString());
+
+ //3rd person pl present
+ inflWord.setFeature(Feature.PERSON, Person.THIRD);
+ inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
+ Assert.assertEquals("are", r.realise(inflWord).toString());
+
+ }
+
+ /**
+ * Tests the lexicon for recall of Acryonms.
+ */
+ @Test
+ public void acronymsTests() {
+ WordElement uk = lexicon.getWord("UK");
+ WordElement unitedKingdom = lexicon.getWord("United Kingdom");
+ List fullForms = uk
+ .getFeatureAsElementList(LexicalFeature.ACRONYM_OF);
+
+ // "uk" is an acronym of 3 full forms
+ Assert.assertEquals(3, fullForms.size());
+ Assert.assertTrue(fullForms.contains(unitedKingdom));
+ }
+
+ /**
+ * Tests the lexicon for recall of baseforms with their standard inflected forms.
+ */
+ @Test
+ public void standardInflectionsTest() {
+ // test keepStandardInflection flag
+ boolean keepInflectionsFlag = lexicon.isKeepStandardInflections();
+
+ lexicon.setKeepStandardInflections(true);
+ WordElement dog = lexicon.getWord("dog", LexicalCategory.NOUN);
+ Assert.assertEquals("dogs", dog
+ .getFeatureAsString(LexicalFeature.PLURAL));
+
+ lexicon.setKeepStandardInflections(false);
+ WordElement cat = lexicon.getWord("cat", LexicalCategory.NOUN);
+ Assert
+ .assertEquals(null, cat
+ .getFeatureAsString(LexicalFeature.PLURAL));
+
+ // restore flag to original state
+ lexicon.setKeepStandardInflections(keepInflectionsFlag);
+ }
+
+ /**
+ * Test for NIHDBLexicon functionality when several threads are using the
+ * same Lexicon
+ */
+ @SuppressWarnings("static-access")
+ public void multiThreadAppAccessTest() {
+
+ LexThread runner1 = new LexThread("lie");
+ LexThread runner2 = new LexThread("bark");
+
+ // schedule them and run them
+ ScheduledExecutorService service = Executors.newScheduledThreadPool(2);
+ service.schedule(runner1, 0, TimeUnit.MILLISECONDS);
+ service.schedule(runner2, 0, TimeUnit.MILLISECONDS);
+
+ try {
+ Thread.currentThread().sleep(500);
+ } catch (InterruptedException ie) {
+ ;// do nothing
+ }
+
+ service.shutdownNow();
+
+ // check that the right words have been retrieved
+ Assert.assertEquals("lie", runner1.word.getBaseForm());
+ Assert.assertEquals("bark", runner2.word.getBaseForm());
+ }
+
+ /*
+ * Class that implements a thread from which a lexical item can be retrieved
+ */
+ private class LexThread extends Thread {
+ WordElement word;
+ String base;
+
+ public LexThread(String base) {
+ this.base = base;
+ }
+
+ public void run() {
+ word = lexicon.getWord(base, LexicalCategory.VERB);
+ }
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/lexicon/english/SharedLexiconTests.java b/SharpSimpleNLGUnitTests/lexicon/english/SharedLexiconTests.java
new file mode 100644
index 0000000..9ba975b
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/lexicon/english/SharedLexiconTests.java
@@ -0,0 +1,137 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.lexicon.english;
+
+import junit.framework.Assert;
+import simplenlg.features.Inflection;
+import simplenlg.features.LexicalFeature;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.WordElement;
+import simplenlg.lexicon.Lexicon;
+
+/**
+ * @author Dave Westwater, Data2Text Ltd
+ *
+ */
+public class SharedLexiconTests {
+
+ public void doBasicTests(Lexicon lexicon) {
+ // test getWords. Should be 2 "can" (of any cat), 1 noun tree, 0 adj
+ // trees
+ Assert.assertEquals(3, lexicon.getWords("can").size());
+ Assert.assertEquals(1, lexicon.getWords("can", LexicalCategory.NOUN)
+ .size());
+ Assert.assertEquals(0, lexicon.getWords("can",
+ LexicalCategory.ADJECTIVE).size());
+
+ // below test removed as standard morph variants no longer recorded in
+ // lexicon
+ // WordElement early = lexicon.getWord("early",
+ // LexicalCategory.ADJECTIVE);
+ // Assert.assertEquals("earlier",
+ // early.getFeatureAsString(Feature.COMPARATIVE));
+
+ // test getWord. Comparative of ADJ "good" is "better", superlative is
+ // "best", this is a qualitative and predicative adjective
+ WordElement good = lexicon.getWord("good", LexicalCategory.ADJECTIVE);
+ Assert.assertEquals("better", good
+ .getFeatureAsString(LexicalFeature.COMPARATIVE));
+ Assert.assertEquals("best", good
+ .getFeatureAsString(LexicalFeature.SUPERLATIVE));
+ Assert.assertEquals(true, good.getFeatureAsBoolean(
+ LexicalFeature.QUALITATIVE).booleanValue());
+ Assert.assertEquals(true, good.getFeatureAsBoolean(
+ LexicalFeature.PREDICATIVE).booleanValue());
+ Assert.assertEquals(false, good.getFeatureAsBoolean(
+ LexicalFeature.COLOUR).booleanValue());
+ Assert.assertEquals(false, good.getFeatureAsBoolean(
+ LexicalFeature.CLASSIFYING).booleanValue());
+
+ // test getWord. There is only one "woman", and its plural is "women".
+ // It is not an acronym, not proper, and countable
+ WordElement woman = lexicon.getWord("woman");
+
+ Assert.assertEquals("women", woman
+ .getFeatureAsString(LexicalFeature.PLURAL));
+ Assert.assertEquals(null, woman
+ .getFeatureAsString(LexicalFeature.ACRONYM_OF));
+ Assert.assertEquals(false, woman.getFeatureAsBoolean(
+ LexicalFeature.PROPER).booleanValue());
+ Assert.assertFalse(woman.hasInflectionalVariant(Inflection.UNCOUNT));
+
+ // NB: This fails if the lexicon is XMLLexicon. No idea why.
+ // Assert.assertEquals("irreg",
+ // woman.getFeatureAsString(LexicalFeature.DEFAULT_INFL));
+
+ // test getWord. Noun "sand" is non-count
+ WordElement sand = lexicon.getWord("sand", LexicalCategory.NOUN);
+ Assert.assertEquals(true, sand.hasInflectionalVariant(Inflection.UNCOUNT));
+ Assert.assertEquals(Inflection.UNCOUNT, sand.getDefaultInflectionalVariant());
+
+ // test hasWord
+ Assert.assertEquals(true, lexicon.hasWord("tree")); // "tree" exists
+ Assert.assertEquals(false, lexicon.hasWord("tree",
+ LexicalCategory.ADVERB)); // but not as an adverb
+
+ // test getWordByID; quickly, also check that this is a verb_modifier
+ WordElement quickly = lexicon.getWordByID("E0051632");
+ Assert.assertEquals("quickly", quickly.getBaseForm());
+ Assert.assertEquals(LexicalCategory.ADVERB, quickly.getCategory());
+ Assert.assertEquals(true, quickly.getFeatureAsBoolean(
+ LexicalFeature.VERB_MODIFIER).booleanValue());
+ Assert.assertEquals(false, quickly.getFeatureAsBoolean(
+ LexicalFeature.SENTENCE_MODIFIER).booleanValue());
+ Assert.assertEquals(false, quickly.getFeatureAsBoolean(
+ LexicalFeature.INTENSIFIER).booleanValue());
+
+ // test getWordFromVariant, verb type (tran or intran, not ditran)
+ WordElement eat = lexicon.getWordFromVariant("eating");
+ Assert.assertEquals("eat", eat.getBaseForm());
+ Assert.assertEquals(LexicalCategory.VERB, eat.getCategory());
+ Assert.assertEquals(true, eat.getFeatureAsBoolean(
+ LexicalFeature.INTRANSITIVE).booleanValue());
+ Assert.assertEquals(true, eat.getFeatureAsBoolean(
+ LexicalFeature.TRANSITIVE).booleanValue());
+ Assert.assertEquals(false, eat.getFeatureAsBoolean(
+ LexicalFeature.DITRANSITIVE).booleanValue());
+
+ // test BE is handled OK
+ Assert.assertEquals("been", lexicon.getWordFromVariant("is",
+ LexicalCategory.VERB).getFeatureAsString(
+ LexicalFeature.PAST_PARTICIPLE));
+
+ // test modal
+ WordElement can = lexicon.getWord("can", LexicalCategory.MODAL);
+ Assert.assertEquals("could", can
+ .getFeatureAsString(LexicalFeature.PAST));
+
+ // test non-existent word
+ Assert.assertEquals(0, lexicon.getWords("akjmchsgk").size());
+
+ // test lookup word method
+ Assert.assertEquals(lexicon.lookupWord("say", LexicalCategory.VERB)
+ .getBaseForm(), "say");
+ Assert.assertEquals(lexicon.lookupWord("said", LexicalCategory.VERB)
+ .getBaseForm(), "say");
+ Assert.assertEquals(lexicon
+ .lookupWord("E0054448", LexicalCategory.VERB).getBaseForm(),
+ "say");
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/lexicon/english/XMLLexiconTest.java b/SharpSimpleNLGUnitTests/lexicon/english/XMLLexiconTest.java
new file mode 100644
index 0000000..1152bc7
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/lexicon/english/XMLLexiconTest.java
@@ -0,0 +1,108 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.lexicon.english;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.features.NumberAgreement;
+import simplenlg.features.Tense;
+import simplenlg.framework.NLGFactory;
+import simplenlg.lexicon.XMLLexicon;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.PPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * @author D. Westwater, Data2Text Ltd
+ *
+ */
+public class XMLLexiconTest {
+
+ // lexicon object -- an instance of Lexicon
+ XMLLexicon lexicon = null;
+
+
+ @Before
+ /*
+ * * Sets up the accessor and runs it -- takes ca. 26 sec
+ */
+ public void setUp() {
+ long startTime = System.currentTimeMillis();
+ //this.lexicon = new XMLLexicon(XML_FILENAME); // omit, use default
+ // lexicon instead
+ this.lexicon = new XMLLexicon();
+ long stopTime = System.currentTimeMillis();
+
+ System.out.format("Loading XML lexicon took %d ms%n",
+ stopTime - startTime);
+
+ }
+
+ /**
+ * Close the lexicon and cleanup.
+ */
+ @After
+ public void tearDown() throws Exception {
+ if (lexicon != null)
+ lexicon.close();
+ }
+
+ /**
+ * Runs basic Lexicon tests.
+ */
+ @Test
+ public void basicLexiconTests() {
+ SharedLexiconTests tests = new SharedLexiconTests();
+ tests.doBasicTests(lexicon);
+ }
+
+ /**
+ * Tests the immutability of the XMLLexicon by checking to make sure features
+ * are not inadvertently propagated to the canonical XMLLexicon WordElement object.
+ */
+ @Test
+ public void xmlLexiconImmutabilityTest() {
+ NLGFactory factory = new NLGFactory(lexicon);
+ Realiser realiser = new Realiser(lexicon);
+
+ // "wall" is singular.
+ NPPhraseSpec wall = factory.createNounPhrase("the", "wall");
+ Assert.assertEquals(NumberAgreement.SINGULAR, wall.getFeature(Feature.NUMBER));
+
+ // Realise a sentence with plural form of "wall"
+ wall.setPlural(true);
+ SPhraseSpec sentence = factory.createClause("motion", "observe");
+ sentence.setFeature(Feature.TENSE, Tense.PAST);
+ PPPhraseSpec pp = factory.createPrepositionPhrase("in", wall);
+ sentence.addPostModifier(pp);
+ realiser.realiseSentence(sentence);
+
+ // Create a new 'the wall' NP and check to make sure that the syntax processor has
+ // not propagated plurality to the canonical XMLLexicon WordElement object.
+ wall = factory.createNounPhrase("the", "wall");
+ Assert.assertEquals(NumberAgreement.SINGULAR, wall.getFeature(Feature.NUMBER));
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelper.cs b/SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelper.cs
new file mode 100644
index 0000000..8ca707f
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelper.cs
@@ -0,0 +1,244 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using System.Text;
+using SimpleNLG.Extensions;
+
+namespace SharpNLG.Extensions
+{
+/**
+ * This class is used to parse numbers that are passed as figures, to determine
+ * whether they should take "a" or "an" as determiner.
+ *
+ * @author bertugatt
+ *
+ */
+
+ public class DeterminerAgrHelper
+ {
+ /*
+ * An array of strings which are exceptions to the rule that "an" comes
+ * before vowels
+ */
+ private static string[] AN_EXCEPTIONS = {"one", "180", "110"};
+
+ /*
+ * Start of string involving vowels, for use of "an"
+ */
+ private static string AN_AGREEMENT = @"\A(a|e|i|o|u).*";
+
+ /*
+ * Start of string involving numbers, for use of "an" -- courtesy of Chris
+ * Howell, Agfa healthcare corporation
+ */
+ // private static final string AN_NUMERAL_AGREEMENT =
+ // "^(((8((\\d+)|(\\d+(\\.|,)\\d+))?).*)|((11|18)(\\d{3,}|\\D)).*)$";
+
+ /**
+ * Check whether this string starts with a number that needs "an" (e.g.
+ * "an 18% increase")
+ *
+ * @param string
+ * the string
+ * @return true
if this string starts with 11, 18, or 8,
+ * excluding strings that start with 180 or 110
+ */
+
+ public static bool requiresAn(string stringa)
+ {
+ var req = false;
+
+ var lowercaseInput = stringa.toLowerCase();
+
+ if (lowercaseInput.matches(AN_AGREEMENT) && !isAnException(lowercaseInput))
+ {
+ req = true;
+
+ }
+ else
+ {
+ var numPref = getNumericPrefix(lowercaseInput);
+
+ if (numPref != null && numPref.length() > 0
+ && numPref.matches(@"^(8|11|18).*$"))
+ {
+ var num = int.Parse(numPref);
+ req = checkNum(num);
+ }
+ }
+
+ return req;
+ }
+
+ /*
+ * check whether a string beginning with a vowel is an exception and doesn't
+ * take "an" (e.g. "a one percent change")
+ *
+ * @return
+ */
+
+ private static bool isAnException(string stringa)
+ {
+ foreach (var ex in AN_EXCEPTIONS)
+ {
+ if (stringa.matches("^" + ex + ".*"))
+ {
+ // if (string.equalsIgnoreCase(ex)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /*
+ * Returns true
if the number starts with 8, 11 or 18 and is
+ * either less than 100 or greater than 1000, but excluding 180,000 etc.
+ */
+
+ private static bool checkNum(int num)
+ {
+ var needsAn = false;
+
+ // eight, eleven, eighty and eighteen
+ if (num == 11 || num == 18 || num == 8 || (num >= 80 && num < 90))
+ {
+ needsAn = true;
+
+ }
+ else if (num > 1000)
+ {
+ // num = Math.Round(num / 1000);
+ num = num/1000;
+ needsAn = checkNum(num);
+ }
+
+ return needsAn;
+ }
+
+ /*
+ * Retrieve the numeral prefix of a string.
+ */
+
+ private static string getNumericPrefix(string stringa)
+ {
+ var numeric = new StringBuilder();
+
+ if (stringa != null)
+ {
+ stringa = stringa.Trim();
+
+ if (stringa.length() > 0)
+ {
+
+ var buffer = new StringBuilder(stringa);
+ var first = buffer.charAt(0);
+
+ if (first.isDigit())
+ {
+ numeric.append(first);
+
+ for (var i = 1; i < buffer.length(); i++)
+ {
+ var next = buffer.charAt(i);
+
+ if (next.isDigit())
+ {
+ numeric.append(next);
+
+ // skip commas within numbers
+ }
+ else if (next.Equals(','))
+ {
+ continue;
+
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ return numeric.length() == 0 ? null : numeric.ToString();
+ }
+
+
+ /**
+ * Check to see if a string ends with the indefinite article "a" and it agrees with {@code np}.
+ * @param text
+ * @param np
+ * @return an altered version of {@code text} to use "an" if it agrees with {@code np}, the original string otherwise.
+ */
+
+ public static string checkEndsWithIndefiniteArticle(string text, string np)
+ {
+
+ var tokens = text.Split(' ');
+
+ var lastToken = tokens[tokens.Length - 1];
+
+ if (lastToken.equalsIgnoreCase("a") && DeterminerAgrHelper.requiresAn(np))
+ {
+
+ tokens[tokens.Length - 1] = "an";
+
+ return stringArrayToString(tokens);
+
+ }
+
+ return text;
+
+ }
+
+ // Turns ["a","b","c"] into "a b c"
+ private static string stringArrayToString(string[] sArray)
+ {
+
+ var buf = new StringBuilder();
+
+ for (var i = 0; i < sArray.Length; i++)
+ {
+
+ buf.Append(sArray[i]);
+
+ if (i != sArray.Length - 1)
+ {
+
+ buf.Append(" ");
+
+ }
+
+ }
+
+ return buf.ToString();
+
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelperTest.cs b/SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelperTest.cs
new file mode 100644
index 0000000..dbed2bc
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelperTest.cs
@@ -0,0 +1,103 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SharpNLG.Extensions;
+
+namespace SimpleNLGTests.external
+{
+
+ public class DeterminerAgrHelperTest
+ {
+
+ [Test]
+ public void testRequiresAn()
+ {
+
+ Assert.IsTrue(DeterminerAgrHelper.requiresAn("elephant"));
+
+ Assert.IsFalse(DeterminerAgrHelper.requiresAn("cow"));
+
+ // Does not hand phonetics
+ Assert.IsFalse(DeterminerAgrHelper.requiresAn("hour"));
+
+ // But does have exceptions for some numerals
+ Assert.IsFalse(DeterminerAgrHelper.requiresAn("one"));
+
+ Assert.IsFalse(DeterminerAgrHelper.requiresAn("100"));
+
+ }
+
+ [Test]
+ public void testCheckEndsWithIndefiniteArticle1()
+ {
+
+ var cannedText = "I see a";
+
+ var np = "elephant";
+
+ var expected = "I see an";
+
+ var actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np);
+
+ Assert.AreEqual(expected, actual);
+
+ }
+
+ [Test]
+ public void testCheckEndsWithIndefiniteArticle2()
+ {
+
+ var cannedText = "I see a";
+
+ var np = "cow";
+
+ var expected = "I see a";
+
+ var actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np);
+
+ Assert.AreEqual(expected, actual);
+
+ }
+
+ [Test]
+ public void testCheckEndsWithIndefiniteArticle3()
+ {
+
+ var cannedText = "I see an";
+
+ var np = "cow";
+
+ // Does not handle "an" -> "a"
+ var expected = "I see an";
+
+ var actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np);
+
+ Assert.AreEqual(expected, actual);
+
+ }
+ }
+}
diff --git a/SharpSimpleNLGUnitTests/morphology/MorphologyProcessor.cs b/SharpSimpleNLGUnitTests/morphology/MorphologyProcessor.cs
new file mode 100644
index 0000000..2ccfeda
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/morphology/MorphologyProcessor.cs
@@ -0,0 +1,302 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using System.Collections.Generic;
+using SharpNLG.Extensions;
+using SimpleNLG.Extensions;
+
+namespace SimpleNLG
+{
+ /**
+ *
+ * This is the processor for handling morphology within the SimpleNLG. The
+ * processor inflects words form the base form depending on the features applied
+ * to the word. For example, kiss is inflected to kissed for
+ * past tense, dog is inflected to dogs for pluralisation.
+ *
+ *
+ *
+ * As a matter of course, the processor will first use any user-defined
+ * inflection for the world. If no inflection is provided then the lexicon, if
+ * it exists, will be examined for the correct inflection. Failing this a set of
+ * very basic rules will be examined to inflect the word.
+ *
+ *
+ *
+ * All processing modules perform realisation on a tree of
+ * NLGElement
s. The modules can alter the tree in whichever way
+ * they wish. For example, the syntax processor replaces phrase elements with
+ * list elements consisting of inflected words while the morphology processor
+ * replaces inflected words with string elements.
+ *
+ *
+ *
+ * N.B. the use of module , processing module and
+ * processor is interchangeable. They all mean an instance of this
+ * class.
+ *
+ *
+ *
+ * @author D. Westwater, University of Aberdeen.
+ * @version 4.0
+ */
+
+ public class MorphologyProcessor : NLGModule
+ {
+
+
+ public override void initialise()
+ {
+ // Do nothing
+ }
+
+
+ public override INLGElement realise(INLGElement element)
+ {
+ INLGElement realisedElement = null;
+
+ if (element is InflectedWordElement)
+ {
+ realisedElement = doMorphology((InflectedWordElement) element);
+
+ }
+ else if (element is StringElement)
+ {
+ realisedElement = element;
+
+ }
+ else if (element is WordElement)
+ {
+ // AG: now retrieves the default spelling variant, not the baseform
+ // string baseForm = ((WordElement) element).getBaseForm();
+ var defaultSpell = ((WordElement) element).getDefaultSpellingVariant();
+
+ if (defaultSpell != null)
+ {
+ realisedElement = new StringElement(defaultSpell);
+ }
+
+ }
+ else if (element is DocumentElement)
+ {
+ List children = element.getChildren();
+ ((DocumentElement) element).setComponents(realise(children));
+ realisedElement = element;
+
+ }
+ else if (element is ListElement)
+ {
+ realisedElement = new ListElement();
+ ((ListElement) realisedElement).addComponents(realise(element.getChildren()));
+
+ }
+ else if (element is CoordinatedPhraseElement)
+ {
+ List children = element.getChildren();
+ ((CoordinatedPhraseElement) element).clearCoordinates();
+
+ if (children != null && children.size() > 0)
+ {
+ ((CoordinatedPhraseElement) element).addCoordinate(realise(children.get(0)));
+
+ for (var index = 1; index < children.size(); index++)
+ {
+ ((CoordinatedPhraseElement) element).addCoordinate(realise(children.get(index)));
+ }
+
+ realisedElement = element;
+ }
+
+ }
+ else if (element != null)
+ {
+ realisedElement = element;
+ }
+
+ return realisedElement;
+ }
+
+ /**
+ * This is the main method for performing the morphology. It effectively
+ * examines the lexical category of the element and calls the relevant set
+ * of rules from MorphologyRules.
+ *
+ * @param element
+ * the InflectedWordElement
+ * @return an NLGElement
reflecting the correct inflection for
+ * the word.
+ */
+
+ private INLGElement doMorphology(InflectedWordElement element)
+ {
+ INLGElement realisedElement = null;
+ if (element.getFeatureAsBoolean(InternalFeature.NON_MORPH.ToString()))
+ {
+ realisedElement = new StringElement(element.getBaseForm());
+ realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ element.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()));
+
+ }
+ else
+ {
+ INLGElement baseWord = element.getFeatureAsElement(InternalFeature.BASE_WORD.ToString());
+
+ if (baseWord == null && this.lexicon != null)
+ {
+ baseWord = this.lexicon.lookupWord(element.getBaseForm());
+ }
+
+ var category = element.getCategory();
+
+ if (category is ILexicalCategory)
+ {
+ switch ((LexicalCategoryEnum)category.enumType)
+ {
+ case LexicalCategoryEnum.PRONOUN:
+ realisedElement = MorphologyRules.doPronounMorphology(element);
+ break;
+
+ case LexicalCategoryEnum.NOUN:
+ realisedElement = MorphologyRules.doNounMorphology(element, (WordElement) baseWord);
+ break;
+
+ case LexicalCategoryEnum.VERB:
+ realisedElement = MorphologyRules.doVerbMorphology(element, (WordElement) baseWord);
+ break;
+
+ case LexicalCategoryEnum.ADJECTIVE:
+ realisedElement = MorphologyRules.doAdjectiveMorphology(element, (WordElement) baseWord);
+ break;
+
+ case LexicalCategoryEnum.ADVERB:
+ realisedElement = MorphologyRules.doAdverbMorphology(element, (WordElement) baseWord);
+ break;
+
+ default:
+ realisedElement = new StringElement(element.getBaseForm());
+ realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ element.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()));
+ break;
+ }
+ }
+ }
+ return realisedElement;
+ }
+
+
+ public override List realise(List elements)
+ {
+ var realisedElements = new List();
+ INLGElement currentElement = null;
+ INLGElement determiner = null;
+ INLGElement prevElement = null;
+
+ if (elements != null)
+ {
+ foreach (var eachElement in elements)
+ {
+ currentElement = realise(eachElement);
+
+ if (currentElement != null)
+ {
+ //pass the discourse function and appositive features -- important for orth processor
+ currentElement.setFeature(Feature.APPOSITIVE.ToString(),
+ eachElement.getFeature(Feature.APPOSITIVE.ToString()));
+ var function = eachElement.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString());
+
+ if (function != null)
+ {
+ currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), function);
+ }
+
+ if (prevElement != null && prevElement is StringElement
+ && eachElement is InflectedWordElement
+ && (eachElement.getCategory().enumType == (int)LexicalCategoryEnum.NOUN))
+ {
+
+ var prevString = prevElement.getRealisation();
+
+ //realisedElements.get(realisedElements.size() - 1)
+
+ prevElement.setRealisation(DeterminerAgrHelper.checkEndsWithIndefiniteArticle(prevString,
+ currentElement.getRealisation()));
+
+ }
+
+ // realisedElements.add(realise(currentElement));
+ realisedElements.add(currentElement);
+
+ if (determiner == null && DiscourseFunction.SPECIFIER.Equals(currentElement.getFeature(
+ InternalFeature.DISCOURSE_FUNCTION.ToString())))
+ {
+ determiner = currentElement;
+ determiner.setFeature(Feature.NUMBER.ToString(),
+ eachElement.getFeature(Feature.NUMBER.ToString()));
+ // MorphologyRules.doDeterminerMorphology(determiner,
+ // currentElement.getRealisation());
+
+ }
+ else if (determiner != null)
+ {
+
+ if (currentElement is ListElement)
+ {
+ // list elements: ensure det matches first element
+ INLGElement firstChild = ((ListElement) currentElement).getChildren().get(0);
+
+ if (firstChild != null)
+ {
+ //AG: need to check if child is a coordinate
+ if (firstChild is CoordinatedPhraseElement)
+ {
+ MorphologyRules.doDeterminerMorphology(determiner,
+ firstChild.getChildren().get(0).getRealisation());
+ }
+ else
+ {
+ MorphologyRules.doDeterminerMorphology(determiner, firstChild.getRealisation());
+ }
+ }
+
+ }
+ else
+ {
+ // everything else: ensure det matches realisation
+ MorphologyRules.doDeterminerMorphology(determiner, currentElement.getRealisation());
+ }
+
+ determiner = null;
+ }
+ }
+ prevElement = eachElement;
+ }
+ }
+
+ return realisedElements;
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/morphology/MorphologyRules.cs b/SharpSimpleNLGUnitTests/morphology/MorphologyRules.cs
new file mode 100644
index 0000000..70f67fc
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/morphology/MorphologyRules.cs
@@ -0,0 +1,1148 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+ using System.Text;
+ using SharpNLG.Extensions;
+ using SimpleNLG.Extensions;
+
+namespace SimpleNLG
+{
+ /**
+ *
+ * This abstract class contains a number of rules for doing simple inflection.
+ *
+ *
+ *
+ * As a matter of course, the processor will first use any user-defined
+ * inflection for the world. If no inflection is provided then the lexicon, if
+ * it exists, will be examined for the correct inflection. Failing this a set of
+ * very basic rules will be examined to inflect the word.
+ *
+ *
+ *
+ * All processing modules perform realisation on a tree of
+ * NLGElement
s. The modules can alter the tree in whichever way
+ * they wish. For example, the syntax processor replaces phrase elements with
+ * list elements consisting of inflected words while the morphology processor
+ * replaces inflected words with string elements.
+ *
+ *
+ *
+ * N.B. the use of module , processing module and
+ * processor is interchangeable. They all mean an instance of this
+ * class.
+ *
+ *
+ *
+ * @author D. Westwater, University of Aberdeen.
+ * @version 4.0 16-Mar-2011 modified to use correct base form (ER)
+ */
+
+ public abstract class MorphologyRules : NLGModule
+ {
+
+ /**
+ * A triple array of Pronouns organised by singular/plural,
+ * possessive/reflexive/subjective/objective and by gender/person.
+ */
+
+ private static string[][][] PRONOUNS = new string[][][]
+ { new string[][]
+ {
+ new string[] {"I", "you", "he", "she", "it"},
+ new string[]{"me", "you", "him", "her", "it"},
+ new string[]{"myself", "yourself", "himself", "herself", "itself"},
+ new string[]{"mine", "yours", "his", "hers", "its"},
+ new string[] {"my", "your", "his", "her", "its"}
+ },
+ new string[][]{
+ new string[]{"we", "you", "they", "they", "they"},
+ new string[]{"us", "you", "them", "them", "them"},
+ new string[]{
+ "ourselves",
+ "yourselves",
+ "themselves",
+ "themselves",
+ "themselves"
+ },
+ new string[]{"ours", "yours", "theirs", "theirs", "theirs"},
+ new string[] {"our", "your", "their", "their", "their"}
+ }
+ };
+
+ private static string[] WH_PRONOUNS = {"who", "what", "which", "where", "why", "how", "how many"};
+
+ /**
+ * This method performs the morphology for nouns.
+ *
+ * @param element
+ * the InflectedWordElement
.
+ * @param baseWord
+ * the WordElement
as created from the lexicon
+ * entry.
+ * @return a StringElement
representing the word after
+ * inflection.
+ */
+
+ public static StringElement doNounMorphology(InflectedWordElement element, WordElement baseWord)
+ {
+ var realised = new StringBuilder();
+
+ // base form from baseWord if it exists, otherwise from element
+ var baseForm = getBaseForm(element, baseWord);
+
+ if (element.isPlural() && !element.getFeatureAsBoolean(LexicalFeature.PROPER))
+ {
+
+ string pluralForm = null;
+
+ // AG changed: now check if default infl is uncount
+ // if (element.getFeatureAsBoolean(LexicalFeature.NON_COUNT)
+ // ) {
+ // pluralForm = baseForm;
+ var elementDefaultInfl = element.getFeature(LexicalFeature.DEFAULT_INFL);
+
+ if (elementDefaultInfl != null && Inflection.UNCOUNT.Equals(elementDefaultInfl))
+ {
+ pluralForm = baseForm;
+
+ }
+ else
+ {
+ pluralForm = element.getFeatureAsString(LexicalFeature.PLURAL);
+ }
+
+ if (pluralForm == null && baseWord != null)
+ {
+ // AG changed: now check if default infl is uncount
+ // if (baseWord.getFeatureAsBoolean(LexicalFeature.NON_COUNT)
+ // ) {
+ // pluralForm = baseForm;
+ var baseDefaultInfl = baseWord.getFeatureAsString(LexicalFeature.DEFAULT_INFL);
+ if (baseDefaultInfl != null && baseDefaultInfl.Equals("uncount"))
+ {
+ pluralForm = baseForm;
+ }
+ else
+ {
+ pluralForm = baseWord.getFeatureAsString(LexicalFeature.PLURAL);
+ }
+ }
+
+ if (pluralForm == null)
+ {
+ var pattern = element.getFeature(LexicalFeature.DEFAULT_INFL);
+ if (Inflection.GRECO_LATIN_REGULAR.Equals(pattern))
+ {
+ pluralForm = buildGrecoLatinPluralNoun(baseForm);
+ }
+ else
+ {
+ pluralForm = buildRegularPluralNoun(baseForm);
+ }
+ }
+ realised.append(pluralForm);
+
+ }
+ else
+ {
+ realised.append(baseForm);
+ }
+
+ checkPossessive(element, realised);
+ var realisedElement = new StringElement(realised.ToString());
+ realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ element.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()));
+ return realisedElement;
+ }
+
+ /**
+ * Builds a plural for regular nouns. The rules are performed in this order:
+ *
+ * For nouns ending -Cy , where C is any consonant, the ending
+ * becomes -ies . For example, fly becomes flies .
+ * For nouns ending -ch , -s , -sh , -x
+ * or -z the ending becomes -es . For example, box
+ * becomes boxes .
+ * All other nouns have -s appended the other end. For example,
+ * dog becomes dogs .
+ *
+ *
+ * @param baseForm
+ * the base form of the word.
+ * @return the inflected word.
+ */
+
+ private static string buildRegularPluralNoun(string baseForm)
+ {
+ string plural = null;
+ if (baseForm != null)
+ {
+ // .NET doesnt support character class subtraction the same was as Java
+ // was .*[b-z-[eiou]]y\\b
+ if (baseForm.matches(@".*[b-z-[eiou]]y\b"))
+ {
+
+ plural = baseForm.replaceAll(@"y\b", @"ies");
+
+ //AG: changed regex from ".*[szx(ch)(sh)]\\b" (tip of the hat to Ian Tabolt)
+ }
+ else if (baseForm.matches(@".*([szx]|[cs]h)\b"))
+ {
+
+ plural = baseForm + "es";
+
+ }
+ else
+ {
+ plural = baseForm + "s";
+ }
+ }
+ return plural;
+ }
+
+ /**
+ * Builds a plural for Greco-Latin regular nouns. The rules are performed in
+ * this order:
+ *
+ * For nouns ending -us the ending becomes -i . For
+ * example, focus becomes foci .
+ * For nouns ending -ma the ending becomes -mata . For
+ * example, trauma becomes traumata .
+ * For nouns ending -a the ending becomes -ae . For
+ * example, larva becomes larvae .
+ * For nouns ending -um or -on the ending becomes
+ * -a . For example, taxon becomes taxa .
+ * For nouns ending -sis the ending becomes -ses . For
+ * example, analysis becomes analyses .
+ * For nouns ending -is the ending becomes -ides . For
+ * example, cystis becomes cystides .
+ * For nouns ending -men the ending becomes -mina . For
+ * example, foramen becomes foramina .
+ * For nouns ending -ex the ending becomes -ices . For
+ * example, index becomes indices .
+ * For nouns ending -x the ending becomes -ces . For
+ * example, matrix becomes matrices .
+ *
+ *
+ * @param baseForm
+ * the base form of the word.
+ * @return the inflected word.
+ */
+
+ private static string buildGrecoLatinPluralNoun(string baseForm)
+ {
+ string plural = null;
+ if (baseForm != null)
+ {
+ if (baseForm.endsWith("us"))
+ {
+
+ plural = baseForm.replaceAll(@"us\b", "i");
+ }
+ else if (baseForm.endsWith("ma"))
+ {
+
+ plural = baseForm + "ta";
+ }
+ else if (baseForm.endsWith("a"))
+ {
+
+ plural = baseForm + "e";
+ }
+ else if (baseForm.matches(@".*[(um)(on)]\\b"))
+ {
+
+ plural = baseForm.replaceAll(@"[(um)(on)]\\b", "a");
+ }
+ else if (baseForm.endsWith("sis"))
+ {
+
+ plural = baseForm.replaceAll(@"sis\b", "ses");
+ }
+ else if (baseForm.endsWith("is"))
+ {
+
+ plural = baseForm.replaceAll(@"is\b", "ides");
+ }
+ else if (baseForm.endsWith("men"))
+ {
+
+ plural = baseForm.replaceAll(@"men\b", "mina");
+ }
+ else if (baseForm.endsWith("ex"))
+ {
+
+ plural = baseForm.replaceAll(@"ex\b", "ices");
+ }
+ else if (baseForm.endsWith("x"))
+ {
+
+ plural = baseForm.replaceAll(@"x\b", "ces");
+ }
+ else
+ {
+ plural = baseForm;
+ }
+ }
+ return plural;
+ }
+
+ /**
+ * This method performs the morphology for verbs.
+ *
+ * @param element
+ * the InflectedWordElement
.
+ * @param baseWord
+ * the WordElement
as created from the lexicon
+ * entry.
+ * @return a StringElement
representing the word after
+ * inflection.
+ */
+
+ public static INLGElement doVerbMorphology(InflectedWordElement element, WordElement baseWord)
+ {
+
+ string realised = null;
+ var numberValue = element.getFeature(Feature.NUMBER.ToString());
+ var personValue = element.getFeature(Feature.PERSON.ToString());
+ var tenseValue = element.getFeatureTense(Feature.TENSE.ToString());
+
+
+ var formValue = element.getFeature(Feature.FORM.ToString());
+ var patternValue = element.getFeature(LexicalFeature.DEFAULT_INFL);
+
+ // base form from baseWord if it exists, otherwise from element
+ var baseForm = getBaseForm(element, baseWord);
+
+ if (element.getFeatureAsBoolean(Feature.NEGATED.ToString()) || Form.BARE_INFINITIVE.Equals(formValue))
+ {
+ realised = baseForm;
+
+ }
+ else if (Form.PRESENT_PARTICIPLE.Equals(formValue))
+ {
+ realised = element.getFeatureAsString(LexicalFeature.PRESENT_PARTICIPLE);
+
+ if (realised == null && baseWord != null)
+ {
+ realised = baseWord.getFeatureAsString(LexicalFeature.PRESENT_PARTICIPLE);
+ }
+
+ if (realised == null)
+ {
+ if (Inflection.REGULAR_DOUBLE.Equals(patternValue))
+ {
+ realised = buildDoublePresPartVerb(baseForm);
+ }
+ else
+ {
+ realised = buildRegularPresPartVerb(baseForm);
+ }
+ }
+
+ }
+ else if (Tense.PAST.Equals(tenseValue) || Form.PAST_PARTICIPLE.Equals(formValue))
+ {
+
+ if (Form.PAST_PARTICIPLE.Equals(formValue))
+ {
+ realised = element.getFeatureAsString(LexicalFeature.PAST_PARTICIPLE);
+
+ if (realised == null && baseWord != null)
+ {
+ realised = baseWord.getFeatureAsString(LexicalFeature.PAST_PARTICIPLE);
+ }
+
+ if (realised == null)
+ {
+ if ("be".equalsIgnoreCase(baseForm))
+ {
+
+ realised = "been";
+ }
+ else if (Inflection.REGULAR_DOUBLE.Equals(patternValue))
+ {
+ realised = buildDoublePastVerb(baseForm);
+ }
+ else
+ {
+ realised = buildRegularPastVerb(baseForm, numberValue, personValue);
+ }
+ }
+
+ }
+ else
+ {
+ realised = element.getFeatureAsString(LexicalFeature.PAST);
+
+ if (realised == null && baseWord != null)
+ {
+ realised = baseWord.getFeatureAsString(LexicalFeature.PAST);
+ }
+
+ if (realised == null)
+ {
+ if (Inflection.REGULAR_DOUBLE.Equals(patternValue))
+ {
+ realised = buildDoublePastVerb(baseForm);
+ }
+ else
+ {
+ realised = buildRegularPastVerb(baseForm, numberValue, personValue);
+ }
+ }
+ }
+
+ }
+ else if ((numberValue == null || NumberAgreement.SINGULAR.Equals(numberValue)) && (personValue == null
+ || Person.THIRD.Equals(
+ personValue)) &&
+ (Tense.PRESENT.Equals(tenseValue)))
+ {
+
+ realised = element.getFeatureAsString(LexicalFeature.PRESENT3S);
+
+ if (realised == null && baseWord != null && !"be".equalsIgnoreCase(baseForm))
+ {
+
+ realised = baseWord.getFeatureAsString(LexicalFeature.PRESENT3S);
+ }
+ if (realised == null)
+ {
+ realised = buildPresent3SVerb(baseForm);
+ }
+
+ }
+ else
+ {
+ if ("be".equalsIgnoreCase(baseForm))
+ {
+
+ if (Person.FIRST.Equals(personValue) && (NumberAgreement.SINGULAR.Equals(numberValue)
+ || numberValue == null))
+ {
+ realised = "am";
+ }
+ else
+ {
+ realised = "are";
+ }
+ }
+ else
+ {
+ realised = baseForm;
+ }
+ }
+ var realisedElement = new StringElement(realised);
+ realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ element.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()));
+ return realisedElement;
+ }
+
+ /**
+ * return the base form of a word
+ *
+ * @param element
+ * @param baseWord
+ * @return
+ */
+
+ private static string getBaseForm(InflectedWordElement element, WordElement baseWord)
+ {
+ // unclear what the right behaviour should be
+ // for now, prefer baseWord.getBaseForm() to element.getBaseForm() for
+ // verbs (ie, "is" mapped to "be")
+ // but prefer element.getBaseForm() to baseWord.getBaseForm() for other
+ // words (ie, "children" not mapped to "child")
+
+ // AG: changed this to get the default spelling variant
+ // needed to preserve spelling changes in the VP
+
+ if ((int)LexicalCategoryEnum.VERB == element.getCategory().enumType)
+ {
+ if (baseWord != null && baseWord.getDefaultSpellingVariant() != null)
+ return baseWord.getDefaultSpellingVariant();
+ else
+ return element.getBaseForm();
+ }
+ else
+ {
+ if (element.getBaseForm() != null)
+ return element.getBaseForm();
+ else if (baseWord == null)
+ return null;
+ else
+ return baseWord.getDefaultSpellingVariant();
+ }
+
+ // if (LexicalCategory.VERB == element.getCategory()) {
+ // if (baseWord != null && baseWord.getBaseForm() != null)
+ // return baseWord.getBaseForm();
+ // else
+ // return element.getBaseForm();
+ // } else {
+ // if (element.getBaseForm() != null)
+ // return element.getBaseForm();
+ // else if (baseWord == null)
+ // return null;
+ // else
+ // return baseWord.getBaseForm();
+ // }
+ }
+
+ /**
+ * Checks to see if the noun is possessive. If it is then nouns in ending in
+ * -s become -s' while every other noun has -'s appended to
+ * the end.
+ *
+ * @param element
+ * the InflectedWordElement
+ * @param realised
+ * the realisation of the word.
+ */
+
+ private static void checkPossessive(InflectedWordElement element, StringBuilder realised)
+ {
+
+ if (element.getFeatureAsBoolean(Feature.POSSESSIVE.ToString()))
+ {
+ if (realised.charAt(realised.length() - 1) == 's')
+ {
+ realised.append("\'");
+
+ }
+ else
+ {
+ realised.append("'s");
+ }
+ }
+ }
+
+ /**
+ * Builds the third-person singular form for regular verbs. The rules are
+ * performed in this order:
+ *
+ * If the verb is be the realised form is is .
+ * For verbs ending -ch , -s , -sh , -x
+ * or -z the ending becomes -es . For example,
+ * preach becomes preaches .
+ * For verbs ending -y the ending becomes -ies . For
+ * example, fly becomes flies .
+ * For every other verb, -s is added to the end of the word.
+ *
+ *
+ * @param baseForm
+ * the base form of the word.
+ * @return the inflected word.
+ */
+
+ private static string buildPresent3SVerb(string baseForm)
+ {
+ string morphology = null;
+ if (baseForm != null)
+ {
+ if (baseForm.equalsIgnoreCase("be"))
+ {
+
+ morphology = "is";
+ }
+ else if (baseForm.matches(@".*[szx(ch)(sh)]\\b"))
+ {
+
+ morphology = baseForm + "es";
+ }
+ else if (baseForm.matches(@".*[b-z-[eiou]]y\\b"))
+ {
+
+ morphology = baseForm.replaceAll(@"y\b", "ies");
+ }
+ else
+ {
+ morphology = baseForm + "s";
+ }
+ }
+ return morphology;
+ }
+
+ /**
+ * Builds the past-tense form for regular verbs. The rules are performed in
+ * this order:
+ *
+ * If the verb is be and the number agreement is plural then
+ * the realised form is were .
+ * If the verb is be and the number agreement is singular then
+ * the realised form is was , unless the person is second, in which
+ * case it's were .
+ * For verbs ending -e the ending becomes -ed . For
+ * example, chased becomes chased .
+ * For verbs ending -Cy , where C is any consonant, the ending
+ * becomes -ied . For example, dry becomes dried .
+ * For every other verb, -ed is added to the end of the word.
+ *
+ *
+ * @param baseForm
+ * the base form of the word.
+ * @param number
+ * the number agreement for the word.
+ * @param person
+ * the person
+ * @return the inflected word.
+ */
+
+ private static string buildRegularPastVerb(string baseForm, object number, object person)
+ {
+ string morphology = null;
+ if (baseForm != null)
+ {
+ if (baseForm.equalsIgnoreCase("be"))
+ {
+
+ if (NumberAgreement.PLURAL.Equals(number))
+ {
+ morphology = "were";
+
+ // AG - bug fix to handle second person past (courtesy of
+ // Minh Le)
+ }
+ else if (Person.SECOND.Equals(person))
+ {
+ morphology = "were";
+ }
+ else
+ {
+ morphology = "was";
+ }
+ }
+ else if (baseForm.endsWith("e"))
+ {
+
+ morphology = baseForm + "d";
+ }
+ // NOTE .NET does not support character class subtraction
+ // ref: http://www.rexegg.com/regex-class-operations.html#intersection_workaround
+ // Java previous was: .*[b-z&&[^eiou]]y\\b
+ else if (baseForm.matches(".*[b-z-[eiou]]y\\b"))
+ {
+
+ morphology = baseForm.replaceAll(@"y\b", "ied");
+ }
+ else
+ {
+ morphology = baseForm + "ed";
+ }
+ }
+ return morphology;
+ }
+
+ /**
+ * Builds the past-tense form for verbs that follow the doubling form of the
+ * last consonant. -ed is added to the end after the last consonant
+ * is doubled. For example, tug becomes tugged .
+ *
+ * @param baseForm
+ * the base form of the word.
+ * @return the inflected word.
+ */
+
+ private static string buildDoublePastVerb(string baseForm)
+ {
+ string morphology = null;
+ if (baseForm != null)
+ {
+ morphology = baseForm + baseForm.charAt(baseForm.length() - 1) + "ed";
+ }
+ return morphology;
+ }
+
+ /**
+ * Builds the present participle form for regular verbs. The rules are
+ * performed in this order:
+ *
+ * If the verb is be then the realised form is being .
+ * For verbs ending -ie the ending becomes -ying . For
+ * example, tie becomes tying .
+ * For verbs ending -ee , -oe or -ye then
+ * -ing is added to the end. For example, canoe becomes
+ * canoeing .
+ * For other verbs ending in -e the ending becomes
+ * -ing . For example, chase becomes chasing .
+ * For all other verbs, -ing is added to the end. For example,
+ * dry becomes drying .
+ *
+ *
+ * @param baseForm
+ * the base form of the word.
+ * @return the inflected word.
+ */
+
+ private static string buildRegularPresPartVerb(string baseForm)
+ {
+ string morphology = null;
+ if (baseForm != null)
+ {
+ if (baseForm.equalsIgnoreCase("be"))
+ {
+
+ morphology = "being";
+ }
+ else if (baseForm.endsWith("ie"))
+ {
+
+ morphology = baseForm.replaceAll(@"ie\b", "ying");
+ }
+ else if (baseForm.matches(".*[^iyeo]e\\b"))
+ {
+
+ morphology = baseForm.replaceAll(@"e\b", "ing");
+ }
+ else
+ {
+ morphology = baseForm + "ing";
+ }
+ }
+ return morphology;
+ }
+
+ /**
+ * Builds the present participle form for verbs that follow the doubling
+ * form of the last consonant. -ing is added to the end after the
+ * last consonant is doubled. For example, tug becomes
+ * tugging .
+ *
+ * @param baseForm
+ * the base form of the word.
+ * @return the inflected word.
+ */
+
+ private static string buildDoublePresPartVerb(string baseForm)
+ {
+ string morphology = null;
+ if (baseForm != null)
+ {
+ morphology = baseForm + baseForm.charAt(baseForm.length() - 1) + "ing";
+ }
+ return morphology;
+ }
+
+ /**
+ * This method performs the morphology for adjectives.
+ *
+ * @param element
+ * the InflectedWordElement
.
+ * @param baseWord
+ * the WordElement
as created from the lexicon
+ * entry.
+ * @return a StringElement
representing the word after
+ * inflection.
+ */
+
+ public static INLGElement doAdjectiveMorphology(InflectedWordElement element, WordElement baseWord)
+ {
+
+ string realised = null;
+ var patternValue = element.getFeature(LexicalFeature.DEFAULT_INFL);
+
+ // base form from baseWord if it exists, otherwise from element
+ var baseForm = getBaseForm(element, baseWord);
+
+ if (element.getFeatureAsBoolean(Feature.IS_COMPARATIVE.ToString()))
+ {
+ realised = element.getFeatureAsString(LexicalFeature.COMPARATIVE);
+
+ if (realised == null && baseWord != null)
+ {
+ realised = baseWord.getFeatureAsString(LexicalFeature.COMPARATIVE);
+ }
+ if (realised == null)
+ {
+ if (Inflection.REGULAR_DOUBLE.Equals(patternValue))
+ {
+ realised = buildDoubleCompAdjective(baseForm);
+ }
+ else
+ {
+ realised = buildRegularComparative(baseForm);
+ }
+ }
+ }
+ else if (element.getFeatureAsBoolean(Feature.IS_SUPERLATIVE.ToString()))
+ {
+
+ realised = element.getFeatureAsString(LexicalFeature.SUPERLATIVE);
+
+ if (realised == null && baseWord != null)
+ {
+ realised = baseWord.getFeatureAsString(LexicalFeature.SUPERLATIVE);
+ }
+ if (realised == null)
+ {
+ if (Inflection.REGULAR_DOUBLE.Equals(patternValue))
+ {
+ realised = buildDoubleSuperAdjective(baseForm);
+ }
+ else
+ {
+ realised = buildRegularSuperlative(baseForm);
+ }
+ }
+ }
+ else
+ {
+ realised = baseForm;
+ }
+ var realisedElement = new StringElement(realised);
+ realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ element.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()));
+ return realisedElement;
+ }
+
+ /**
+ * Builds the comparative form for adjectives that follow the doubling form
+ * of the last consonant. -er is added to the end after the last
+ * consonant is doubled. For example, fat becomes fatter .
+ *
+ * @param baseForm
+ * the base form of the word.
+ * @return the inflected word.
+ */
+
+ private static string buildDoubleCompAdjective(string baseForm)
+ {
+ string morphology = null;
+ if (baseForm != null)
+ {
+ morphology = baseForm + baseForm.charAt(baseForm.length() - 1) + "er";
+ }
+ return morphology;
+ }
+
+ /**
+ * Builds the comparative form for regular adjectives. The rules are
+ * performed in this order:
+ *
+ * For adjectives ending -Cy , where C is any consonant, the
+ * ending becomes -ier . For example, brainy becomes
+ * brainier .
+ * For adjectives ending -e the ending becomes -er .
+ * For example, fine becomes finer .
+ * For all other adjectives, -er is added to the end. For
+ * example, clear becomes clearer .
+ *
+ *
+ * @param baseForm
+ * the base form of the word.
+ * @return the inflected word.
+ */
+
+ private static string buildRegularComparative(string baseForm)
+ {
+ string morphology = null;
+ if (baseForm != null)
+ {
+ if (baseForm.matches(@".*[b-z-[eiou]]y\\b"))
+ {
+
+ morphology = baseForm.replaceAll(@"y\b", "ier");
+ }
+ else if (baseForm.endsWith("e"))
+ {
+
+ morphology = baseForm + "r";
+ }
+ else
+ {
+ morphology = baseForm + "er";
+ }
+ }
+ return morphology;
+ }
+
+ /**
+ * Builds the superlative form for adjectives that follow the doubling form
+ * of the last consonant. -est is added to the end after the last
+ * consonant is doubled. For example, fat becomes fattest .
+ *
+ * @param baseForm
+ * the base form of the word.
+ * @return the inflected word.
+ */
+
+ private static string buildDoubleSuperAdjective(string baseForm)
+ {
+ string morphology = null;
+ if (baseForm != null)
+ {
+ morphology = baseForm + baseForm.charAt(baseForm.length() - 1) + "est";
+ }
+ return morphology;
+ }
+
+ /**
+ * Builds the superlative form for regular adjectives. The rules are
+ * performed in this order:
+ *
+ * For verbs ending -Cy , where C is any consonant, the ending
+ * becomes -iest . For example, brainy becomes
+ * brainiest .
+ * For verbs ending -e the ending becomes -est . For
+ * example, fine becomes finest .
+ * For all other verbs, -est is added to the end. For example,
+ * clear becomes clearest .
+ *
+ *
+ * @param baseForm
+ * the base form of the word.
+ * @return the inflected word.
+ */
+
+ private static string buildRegularSuperlative(string baseForm)
+ {
+ string morphology = null;
+ if (baseForm != null)
+ {
+ if (baseForm.matches(@".*[b-z-[eiou]]y\\b"))
+ {
+
+ morphology = baseForm.replaceAll(@"y\b", "iest");
+ }
+ else if (baseForm.endsWith("e"))
+ {
+
+ morphology = baseForm + "st";
+ }
+ else
+ {
+ morphology = baseForm + "est";
+ }
+ }
+ return morphology;
+ }
+
+ /**
+ * This method performs the morphology for adverbs.
+ *
+ * @param element
+ * the InflectedWordElement
.
+ * @param baseWord
+ * the WordElement
as created from the lexicon
+ * entry.
+ * @return a StringElement
representing the word after
+ * inflection.
+ */
+
+ public static INLGElement doAdverbMorphology(InflectedWordElement element, WordElement baseWord)
+ {
+
+ string realised = null;
+
+ // base form from baseWord if it exists, otherwise from element
+ var baseForm = getBaseForm(element, baseWord);
+
+ if (element.getFeatureAsBoolean(Feature.IS_COMPARATIVE.ToString()))
+ {
+ realised = element.getFeatureAsString(LexicalFeature.COMPARATIVE);
+
+ if (realised == null && baseWord != null)
+ {
+ realised = baseWord.getFeatureAsString(LexicalFeature.COMPARATIVE);
+ }
+ if (realised == null)
+ {
+ realised = buildRegularComparative(baseForm);
+ }
+ }
+ else if (element.getFeatureAsBoolean(Feature.IS_SUPERLATIVE.ToString()))
+ {
+
+ realised = element.getFeatureAsString(LexicalFeature.SUPERLATIVE);
+
+ if (realised == null && baseWord != null)
+ {
+ realised = baseWord.getFeatureAsString(LexicalFeature.SUPERLATIVE);
+ }
+ if (realised == null)
+ {
+ realised = buildRegularSuperlative(baseForm);
+ }
+ }
+ else
+ {
+ realised = baseForm;
+ }
+ var realisedElement = new StringElement(realised);
+ realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ element.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()));
+ return realisedElement;
+ }
+
+ /**
+ * This method performs the morphology for pronouns.
+ *
+ * @param element
+ * the InflectedWordElement
.
+ * @return a StringElement
representing the word after
+ * inflection.
+ */
+
+ public static INLGElement doPronounMorphology(InflectedWordElement element)
+ {
+ string realised = null;
+
+ if (!element.getFeatureAsBoolean(InternalFeature.NON_MORPH.ToString()) && !isWHPronoun(element))
+ {
+ var genderValue = element.getFeature(LexicalFeature.GENDER);
+ var personValue = element.getFeature(Feature.PERSON.ToString());
+ var discourseValue = element.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString());
+
+ var numberIndex = element.isPlural() ? 1 : 0;
+ var genderIndex = (genderValue is Gender) ? ((Gender) genderValue).ordinal() : 2;
+
+ var personIndex = (personValue is Person) ? ((Person) personValue).ordinal() : 2;
+
+ if (personIndex == 2)
+ {
+ personIndex += genderIndex;
+ }
+
+ var positionIndex = 0;
+
+ if (element.getFeatureAsBoolean(LexicalFeature.REFLEXIVE))
+ {
+ positionIndex = 2;
+ }
+ else if (element.getFeatureAsBoolean(Feature.POSSESSIVE.ToString()))
+ {
+ positionIndex = 3;
+ if (DiscourseFunction.SPECIFIER.Equals(discourseValue))
+ {
+ positionIndex++;
+ }
+ }
+ else
+ {
+ positionIndex = (DiscourseFunction.SUBJECT.Equals(discourseValue) && !element.getFeatureAsBoolean(
+ Feature.PASSIVE.ToString())) ||
+ (DiscourseFunction.OBJECT.Equals(discourseValue) &&
+ element.getFeatureAsBoolean(Feature.PASSIVE.ToString()))
+ || DiscourseFunction.SPECIFIER.Equals(discourseValue) || (
+ DiscourseFunction.COMPLEMENT.Equals(discourseValue)
+ && element.getFeatureAsBoolean(Feature.PASSIVE.ToString()))
+ ? 0
+ : 1;
+ }
+ realised = PRONOUNS[numberIndex][positionIndex][personIndex];
+ }
+ else
+ {
+ realised = element.getBaseForm();
+ }
+ var realisedElement = new StringElement(realised);
+ realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ element.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()));
+
+ return realisedElement;
+ }
+
+ private static bool isWHPronoun(InflectedWordElement word)
+ {
+ var bases = word.getBaseForm();
+ var wh = false;
+
+ if (bases != null)
+ {
+ for (var i = 0; i < WH_PRONOUNS.Length && !wh; i++)
+ {
+ wh = WH_PRONOUNS[i].Equals(bases);
+ }
+ }
+
+ return wh;
+
+ }
+
+ /**
+ * This method performs the morphology for determiners.
+ *
+ * @param determiner
+ * the InflectedWordElement
.
+ * @param realisation
+ * the current realisation of the determiner.
+ */
+
+ public static void doDeterminerMorphology(INLGElement determiner, string realisation)
+ {
+
+ if (realisation != null)
+ {
+
+ if (!(determiner.getRealisation().Equals("a")))
+ {
+ if (determiner.isPlural())
+ {
+ // Use default inflection rules:
+ if ("that".Equals(determiner.getRealisation()))
+ {
+ determiner.setRealisation("those");
+ }
+ else if ("this".Equals(determiner.getRealisation()))
+ {
+ determiner.setRealisation("these");
+ }
+ }
+ else if (!determiner.isPlural())
+ {
+ // Use default push back to base form rules:
+ if ("those".Equals(determiner.getRealisation()))
+ {
+ determiner.setRealisation("that");
+ }
+ else if ("these".Equals(determiner.getRealisation()))
+ {
+ determiner.setRealisation("this");
+ }
+
+ }
+ }
+
+ // Special "a" determiner and perform a/an agreement:
+ if (determiner.getRealisation().Equals("a"))
+ {
+
+ if (determiner.isPlural())
+ {
+ determiner.setRealisation("some");
+ }
+ else if (DeterminerAgrHelper.requiresAn(realisation))
+ {
+ determiner.setRealisation("an");
+ }
+ }
+
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/morphology/english/DeterminerAgrHelperTest.java b/SharpSimpleNLGUnitTests/morphology/english/DeterminerAgrHelperTest.java
new file mode 100644
index 0000000..42b4160
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/morphology/english/DeterminerAgrHelperTest.java
@@ -0,0 +1,75 @@
+package simplenlg.morphology.english;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class DeterminerAgrHelperTest {
+
+ @Test
+ public void testRequiresAn() {
+
+ assertTrue(DeterminerAgrHelper.requiresAn("elephant"));
+
+ assertFalse(DeterminerAgrHelper.requiresAn("cow"));
+
+ // Does not hand phonetics
+ assertFalse(DeterminerAgrHelper.requiresAn("hour"));
+
+ // But does have exceptions for some numerals
+ assertFalse(DeterminerAgrHelper.requiresAn("one"));
+
+ assertFalse(DeterminerAgrHelper.requiresAn("100"));
+
+ }
+
+ @Test
+ public void testCheckEndsWithIndefiniteArticle1() {
+
+ String cannedText = "I see a";
+
+ String np = "elephant";
+
+ String expected = "I see an";
+
+ String actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np);
+
+ assertEquals(expected, actual);
+
+ }
+
+ @Test
+ public void testCheckEndsWithIndefiniteArticle2() {
+
+ String cannedText = "I see a";
+
+ String np = "cow";
+
+ String expected = "I see a";
+
+ String actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np);
+
+ assertEquals(expected, actual);
+
+ }
+
+ @Test
+ public void testCheckEndsWithIndefiniteArticle3() {
+
+ String cannedText = "I see an";
+
+ String np = "cow";
+
+ // Does not handle "an" -> "a"
+ String expected = "I see an";
+
+ String actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np);
+
+ assertEquals(expected, actual);
+
+ }
+
+
+
+
+}
diff --git a/SharpSimpleNLGUnitTests/realiser/RealiserTest.cs b/SharpSimpleNLGUnitTests/realiser/RealiserTest.cs
new file mode 100644
index 0000000..2e22846
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/realiser/RealiserTest.cs
@@ -0,0 +1,173 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using System.Collections.Generic;
+using NUnit.Framework;
+using SimpleNLG;
+using SimpleNLG.Extensions;
+
+namespace SimpleNLGTests.realiser
+{
+ /**
+ * JUnit test class for the {@link Realiser} class.
+ *
+ * @author Saad Mahamood
+ */
+
+ public class RealiserTest
+ {
+
+ [SetUpFixture]
+ public class SetupForRealiserTest
+ {
+ public static Lexicon lexicon = Lexicon.getDefaultLexicon();
+ public static NLGFactory phraseFactory = new NLGFactory(lexicon);
+ public static Realiser realiser = new Realiser(lexicon);
+ }
+
+
+
+ /**
+ * Test the realization of List of NLGElements that is null
+ */
+ [Test]
+ public void emptyNLGElementRealiserTest()
+ {
+ List elements = new List();
+ List realisedElements = SetupForRealiserTest.realiser.realise(elements);
+ // Expect emtpy listed returned:
+ Assert.IsNotNull(realisedElements);
+ Assert.AreEqual(0, realisedElements.size());
+ }
+
+
+ /**
+ * Test the realization of List of NLGElements that is null
+ */
+ [Test]
+ public void nullNLGElementRealiserTest()
+ {
+ List elements = null;
+ List realisedElements = SetupForRealiserTest.realiser.realise(elements);
+ // Expect emtpy listed returned:
+ Assert.IsNotNull(realisedElements);
+ Assert.AreEqual(0, realisedElements.size());
+
+ }
+
+ /**
+ * Tests the realization of multiple NLGElements in a list.
+ */
+ [Test]
+ public void multipleNLGElementListRealiserTest()
+ {
+ List elements = new List();
+ // Create test NLGElements to realize:
+
+ // "The cat jumping on the counter."
+ DocumentElement sentence1 = SetupForRealiserTest.phraseFactory.createSentence();
+ NPPhraseSpec subject_1 = SetupForRealiserTest.phraseFactory.createNounPhrase("the", "cat");
+ VPPhraseSpec verb_1 = SetupForRealiserTest.phraseFactory.createVerbPhrase("jump");
+ verb_1.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE);
+ PPPhraseSpec prep_1 = SetupForRealiserTest.phraseFactory.createPrepositionPhrase();
+ NPPhraseSpec object_1 = SetupForRealiserTest.phraseFactory.createNounPhrase();
+ object_1.setDeterminer("the");
+ object_1.setNoun("counter");
+ prep_1.addComplement(object_1);
+ prep_1.setPreposition("on");
+ SPhraseSpec clause_1 = SetupForRealiserTest.phraseFactory.createClause();
+ clause_1.setSubject(subject_1);
+ clause_1.setVerbPhrase(verb_1);
+ clause_1.setObject(prep_1);
+ sentence1.addComponent(clause_1);
+
+ // "The dog running on the counter."
+ DocumentElement sentence2 = SetupForRealiserTest.phraseFactory.createSentence();
+ NPPhraseSpec subject_2 = SetupForRealiserTest.phraseFactory.createNounPhrase("the", "dog");
+ VPPhraseSpec verb_2 = SetupForRealiserTest.phraseFactory.createVerbPhrase("run");
+ verb_2.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE);
+ PPPhraseSpec prep_2 = SetupForRealiserTest.phraseFactory.createPrepositionPhrase();
+ NPPhraseSpec object_2 = SetupForRealiserTest.phraseFactory.createNounPhrase();
+ object_2.setDeterminer("the");
+ object_2.setNoun("counter");
+ prep_2.addComplement(object_2);
+ prep_2.setPreposition("on");
+ SPhraseSpec clause_2 = SetupForRealiserTest.phraseFactory.createClause();
+ clause_2.setSubject(subject_2);
+ clause_2.setVerbPhrase(verb_2);
+ clause_2.setObject(prep_2);
+ sentence2.addComponent(clause_2);
+
+
+ elements.add(sentence1);
+ elements.add(sentence2);
+
+ List realisedElements = SetupForRealiserTest.realiser.realise(elements);
+
+ Assert.IsNotNull(realisedElements);
+ Assert.AreEqual(2, realisedElements.size());
+ Assert.AreEqual("The cat jumping on the counter.", realisedElements.get(0).getRealisation());
+ Assert.AreEqual("The dog running on the counter.", realisedElements.get(1).getRealisation());
+
+ }
+
+ /**
+ * Tests the correct pluralization with possessives (GitHub issue #9)
+ */
+ [Test]
+ public void correctPluralizationWithPossessives()
+ {
+ NPPhraseSpec sisterNP = SetupForRealiserTest.phraseFactory.createNounPhrase("sister");
+ INLGElement word = SetupForRealiserTest.phraseFactory.createInflectedWord("Albert Einstein",
+ new LexicalCategory_NOUN());
+ word.setFeature(LexicalFeature.PROPER, true);
+ NPPhraseSpec possNP = SetupForRealiserTest.phraseFactory.createNounPhrase(word);
+ possNP.setFeature(Feature.POSSESSIVE.ToString(), true);
+ sisterNP.setSpecifier(possNP);
+
+
+ Assert.AreEqual("Albert Einstein's sister",
+ SetupForRealiserTest.realiser.realise(sisterNP).getRealisation());
+
+ sisterNP.setPlural(true);
+
+ SetupForRealiserTest.realiser.setDebugMode(true);
+ Assert.AreEqual("Albert Einstein's sisters",
+ SetupForRealiserTest.realiser.realise(sisterNP).getRealisation());
+
+ sisterNP.setPlural(false);
+
+ possNP.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
+ possNP.setFeature(Feature.PRONOMINAL.ToString(), true);
+ Assert.AreEqual("his sister",
+ SetupForRealiserTest.realiser.realise(sisterNP).getRealisation());
+ sisterNP.setPlural(true);
+ Assert.AreEqual("his sisters",
+ SetupForRealiserTest.realiser.realise(sisterNP).getRealisation());
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/realiser/english/RealiserTest.java b/SharpSimpleNLGUnitTests/realiser/english/RealiserTest.java
new file mode 100644
index 0000000..7dd58c1
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/realiser/english/RealiserTest.java
@@ -0,0 +1,173 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.realiser.english;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+
+
+import simplenlg.features.Feature;
+import simplenlg.features.Form;
+import simplenlg.features.LexicalFeature;
+import simplenlg.features.Gender;
+import simplenlg.framework.DocumentElement;
+import simplenlg.framework.NLGElement;
+import simplenlg.framework.NLGFactory;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.lexicon.Lexicon;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.PPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.phrasespec.VPPhraseSpec;
+
+/**
+ * JUnit test class for the {@link Realiser} class.
+ *
+ * @author Saad Mahamood
+ */
+public class RealiserTest {
+
+ private Lexicon lexicon;
+ private NLGFactory nlgFactory;
+ private Realiser realiser = null;
+
+
+ @Before
+ public void setup() {
+ lexicon = Lexicon.getDefaultLexicon();
+ nlgFactory = new NLGFactory(lexicon);
+ realiser = new Realiser(lexicon);
+ }
+
+
+ /**
+ * Test the realization of List of NLGElements that is null
+ */
+ @Test
+ public void emptyNLGElementRealiserTest() {
+ ArrayList elements = new ArrayList();
+ List realisedElements = realiser.realise(elements);
+ // Expect emtpy listed returned:
+ Assert.assertNotNull(realisedElements);
+ Assert.assertEquals(0, realisedElements.size());
+
+ }
+
+
+ /**
+ * Test the realization of List of NLGElements that is null
+ */
+ @Test
+ public void nullNLGElementRealiserTest() {
+ ArrayList elements = null;
+ List realisedElements = realiser.realise(elements);
+ // Expect emtpy listed returned:
+ Assert.assertNotNull(realisedElements);
+ Assert.assertEquals(0, realisedElements.size());
+
+ }
+
+ /**
+ * Tests the realization of multiple NLGElements in a list.
+ */
+ @Test
+ public void multipleNLGElementListRealiserTest() {
+ ArrayList elements = new ArrayList();
+ // Create test NLGElements to realize:
+
+ // "The cat jumping on the counter."
+ DocumentElement sentence1 = nlgFactory.createSentence();
+ NPPhraseSpec subject_1 = nlgFactory.createNounPhrase("the", "cat");
+ VPPhraseSpec verb_1 = nlgFactory.createVerbPhrase("jump");
+ verb_1.setFeature(Feature.FORM, Form.PRESENT_PARTICIPLE);
+ PPPhraseSpec prep_1 = nlgFactory.createPrepositionPhrase();
+ NPPhraseSpec object_1 = nlgFactory.createNounPhrase();
+ object_1.setDeterminer("the");
+ object_1.setNoun("counter");
+ prep_1.addComplement(object_1);
+ prep_1.setPreposition("on");
+ SPhraseSpec clause_1 = nlgFactory.createClause();
+ clause_1.setSubject(subject_1);
+ clause_1.setVerbPhrase(verb_1);
+ clause_1.setObject(prep_1);
+ sentence1.addComponent(clause_1);
+
+ // "The dog running on the counter."
+ DocumentElement sentence2 = nlgFactory.createSentence();
+ NPPhraseSpec subject_2 = nlgFactory.createNounPhrase("the", "dog");
+ VPPhraseSpec verb_2 = nlgFactory.createVerbPhrase("run");
+ verb_2.setFeature(Feature.FORM, Form.PRESENT_PARTICIPLE);
+ PPPhraseSpec prep_2 = nlgFactory.createPrepositionPhrase();
+ NPPhraseSpec object_2 = nlgFactory.createNounPhrase();
+ object_2.setDeterminer("the");
+ object_2.setNoun("counter");
+ prep_2.addComplement(object_2);
+ prep_2.setPreposition("on");
+ SPhraseSpec clause_2 = nlgFactory.createClause();
+ clause_2.setSubject(subject_2);
+ clause_2.setVerbPhrase(verb_2);
+ clause_2.setObject(prep_2);
+ sentence2.addComponent(clause_2);
+
+
+ elements.add(sentence1);
+ elements.add(sentence2);
+
+ List realisedElements = realiser.realise(elements);
+
+ Assert.assertNotNull(realisedElements);
+ Assert.assertEquals(2, realisedElements.size());
+ Assert.assertEquals("The cat jumping on the counter.", realisedElements.get(0).getRealisation());
+ Assert.assertEquals("The dog running on the counter.", realisedElements.get(1).getRealisation());
+
+ }
+
+ /**
+ * Tests the correct pluralization with possessives (GitHub issue #9)
+ */
+ @Test
+ public void correctPluralizationWithPossessives() {
+ NPPhraseSpec sisterNP = nlgFactory.createNounPhrase("sister");
+ NLGElement word = nlgFactory.createInflectedWord("Albert Einstein",
+ LexicalCategory.NOUN);
+ word.setFeature(LexicalFeature.PROPER, true);
+ NPPhraseSpec possNP = nlgFactory.createNounPhrase(word);
+ possNP.setFeature(Feature.POSSESSIVE, true);
+ sisterNP.setSpecifier(possNP);
+ Assert.assertEquals("Albert Einstein's sister",
+ realiser.realise(sisterNP).getRealisation());
+ sisterNP.setPlural(true);
+ Assert.assertEquals("Albert Einstein's sisters",
+ realiser.realise(sisterNP).getRealisation());
+ sisterNP.setPlural(false);
+ possNP.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
+ possNP.setFeature(Feature.PRONOMINAL, true);
+ Assert.assertEquals("his sister",
+ realiser.realise(sisterNP).getRealisation());
+ sisterNP.setPlural(true);
+ Assert.assertEquals("his sisters",
+ realiser.realise(sisterNP).getRealisation());
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/AdjectivePhraseTest.cs b/SharpSimpleNLGUnitTests/syntax/AdjectivePhraseTest.cs
new file mode 100644
index 0000000..3c9c705
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/AdjectivePhraseTest.cs
@@ -0,0 +1,160 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+ /**
+ * JUnit test class for the {@link Realiser} class.
+ *
+ * @author Saad Mahamood
+ */
+
+ public class AdjectivePhraseTest : SimpleNLG4TestBase
+ {
+
+
+ /**
+ * Test premodification & coordination of Adjective Phrases (Not much else
+ * to simplenlg.test)
+ */
+ [Test]
+ public void testAdj()
+ {
+
+ // form the adjphrase "incredibly salacious"
+ this.salacious.addPreModifier(this.phraseFactory
+ .createAdverbPhrase("incredibly"));
+ Assert.AreEqual("incredibly salacious", this.realiser
+ .realise(this.salacious).getRealisation());
+
+ // form the adjphrase "incredibly beautiful"
+ this.beautiful.addPreModifier("amazingly");
+ Assert.AreEqual("amazingly beautiful", this.realiser
+ .realise(this.beautiful).getRealisation());
+
+ // coordinate the two aps
+ var coordap = new CoordinatedPhraseElement(
+ this.salacious, this.beautiful);
+ Assert.AreEqual("incredibly salacious and amazingly beautiful",
+ this.realiser.realise(coordap).getRealisation());
+
+ // changing the inner conjunction
+ coordap.setFeature(Feature.CONJUNCTION.ToString(), "or");
+ Assert.AreEqual("incredibly salacious or amazingly beautiful",
+ this.realiser.realise(coordap).getRealisation());
+
+ // coordinate this with a new AdjPhraseSpec
+ var coord2 = new CoordinatedPhraseElement(coordap,
+ this.stunning);
+ //this.realiser.setDebugMode(true);
+ Assert.AreEqual(
+ "incredibly salacious or amazingly beautiful and stunning",
+ this.realiser.realise(coord2).getRealisation());
+
+ // add a premodifier the coordinate phrase, yielding
+ // "seriously and undeniably incredibly salacious or amazingly beautiful
+ // and stunning"
+ var preMod = new CoordinatedPhraseElement(
+ new StringElement("seriously"), new StringElement("undeniably"));
+
+ coord2.addPreModifier(preMod);
+ Assert.AreEqual(
+ "seriously and undeniably incredibly salacious or amazingly beautiful and stunning",
+ this.realiser.realise(coord2).getRealisation());
+
+ // adding a coordinate rather than coordinating should give a different
+ // result
+ coordap.addCoordinate(this.stunning);
+ Assert.AreEqual(
+ "incredibly salacious, amazingly beautiful or stunning",
+ this.realiser.realise(coordap).getRealisation());
+
+ }
+
+ /**
+ * Simple test of adverbials
+ */
+ [Test]
+
+ public void testAdv()
+ {
+
+ var sent = this.phraseFactory.createClause("John", "eat");
+
+ var adv = this.phraseFactory.createAdverbPhrase("quickly");
+
+ sent.addPreModifier(adv);
+
+ Assert.AreEqual("John quickly eats", this.realiser.realise(sent)
+ .getRealisation());
+
+ adv.addPreModifier("very");
+
+ Assert.AreEqual("John very quickly eats", this.realiser.realise(
+ sent).getRealisation());
+
+ }
+
+ /**
+ * Test participles as adjectives
+ */
+ [Test]
+
+ public void testParticipleAdj()
+ {
+ var ap = this.phraseFactory
+ .createAdjectivePhrase(this.lexicon.getWord("associated",
+ new LexicalCategory_ADJECTIVE()));
+ Assert.AreEqual("associated", this.realiser.realise(ap)
+ .getRealisation());
+ }
+
+ /**
+ * Test for multiple adjective modifiers with comma-separation. Example courtesy of William Bradshaw (Data2Text Ltd).
+ */
+ [Test]
+ public void testMultipleModifiers()
+ {
+ var np = this.phraseFactory
+ .createNounPhrase(this.lexicon.getWord("message",
+ new LexicalCategory_NOUN()));
+ np.addPreModifier(this.lexicon.getWord("active",
+ new LexicalCategory_ADJECTIVE()));
+ np.addPreModifier(this.lexicon.getWord("temperature",
+ new LexicalCategory_ADJECTIVE()));
+ Assert.AreEqual("active, temperature message", this.realiser.realise(np).getRealisation());
+
+ //now we set the realiser not to separate using commas
+ this.realiser.setCommaSepPremodifiers(false);
+ Assert.AreEqual("active temperature message", this.realiser.realise(np).getRealisation());
+
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/ClauseAggregationTest.cs b/SharpSimpleNLGUnitTests/syntax/ClauseAggregationTest.cs
new file mode 100644
index 0000000..98e8388
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/ClauseAggregationTest.cs
@@ -0,0 +1,259 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using System.Collections.Generic;
+using NUnit.Framework;
+using SimpleNLG;
+using SimpleNLG.Extensions;
+
+namespace SimpleNLGTests.syntax
+{
+/**
+ * Some tests for aggregation.
+ *
+ * @author Albert Gatt, University of Malta & University of Aberdeen
+ *
+ */
+
+ public class ClauseAggregationTest : SimpleNLG4TestBase
+ {
+ // set up a few more fixtures
+ /** The s4. */
+ public SPhraseSpec s5, s6;
+ public Aggregator aggregator = new Aggregator();
+ public ClauseCoordinationRule coord = new ClauseCoordinationRule();
+ public ForwardConjunctionReductionRule fcr = new ForwardConjunctionReductionRule();
+ public BackwardConjunctionReductionRule bcr = new BackwardConjunctionReductionRule();
+
+ /**
+ * Instantiates a new clause aggregation test.
+ *
+ * @param name
+ * the name
+ */
+
+ [SetUp]
+ protected override void setUp()
+ {
+ aggregator.initialise();
+
+ // the woman kissed the man behind the curtain
+ s1 = this.phraseFactory.createClause();
+ s1.setSubject(this.woman);
+ s1.setVerbPhrase(this.phraseFactory.createVerbPhrase("kiss"));
+ s1.setObject(this.man);
+ s1.addPostModifier(this.phraseFactory
+ .createPrepositionPhrase("behind", this.phraseFactory
+ .createNounPhrase("the", "curtain")));
+
+ // the woman kicked the dog on the rock
+ s2 = this.phraseFactory.createClause();
+ s2.setSubject(this.phraseFactory.createNounPhrase("the", "woman"));
+ s2.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick"));
+ s2.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
+ s2.addPostModifier(this.onTheRock);
+
+ // the woman kicked the dog behind the curtain
+ s3 = this.phraseFactory.createClause();
+ s3.setSubject(this.phraseFactory.createNounPhrase("the", "woman"));
+ s3.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick"));
+ s3.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
+ s3.addPostModifier(this.phraseFactory
+ .createPrepositionPhrase("behind", this.phraseFactory
+ .createNounPhrase("the", "curtain")));
+
+ // the man kicked the dog behind the curtain
+ s4 = this.phraseFactory.createClause();
+ s4.setSubject(this.man);
+ s4.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick"));
+ s4.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
+ s4.addPostModifier(this.behindTheCurtain);
+
+ // the girl kicked the dog behind the curtain
+ s5 = this.phraseFactory.createClause();
+ s5.setSubject(this.phraseFactory.createNounPhrase("the", "girl"));
+ s5.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick"));
+ s5.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
+ s5.addPostModifier(this.behindTheCurtain);
+
+ // the woman kissed the dog behind the curtain
+ s6 = this.phraseFactory.createClause();
+ s6.setSubject(this.phraseFactory.createNounPhrase("the", "woman"));
+ s6.setVerbPhrase(this.phraseFactory.createVerbPhrase("kiss"));
+ s6.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
+ s6.addPostModifier(this.phraseFactory
+ .createPrepositionPhrase("behind", this.phraseFactory
+ .createNounPhrase("the", "curtain")));
+ }
+
+
+ [TearDown]
+ public void tearDown()
+ {
+ s1 = null;
+ s2 = null;
+ s3 = null;
+ s4 = null;
+ s5 = null;
+ s6 = null;
+
+ }
+ /**
+ * Test clause coordination with two sentences with same subject but
+ * different postmodifiers: fails
+ */
+ [Test]
+ public void testCoordinationSameSubjectFail()
+ {
+ var elements = new List { this.s1, this.s2};
+ var result = this.coord.apply(elements);
+ Assert.AreEqual(1, result.size());
+ }
+
+ /**
+ * Test clause coordination with two sentences one of which is passive:
+ * fails
+ */
+ [Test]
+ public void testCoordinationPassiveFail()
+ {
+ s1.setFeature(Feature.PASSIVE.ToString(), true);
+ var elements = new List {s1, s2};
+ var result = coord.apply(elements);
+ Assert.AreEqual(2, result.size());
+ }
+
+ // /**
+ // * Test clause coordination with 2 sentences with same subject: succeeds
+ // */
+ // [Test]
+ // public void testCoordinationSameSubjectSuccess() {
+ // List elements = Arrays.asList((NLGElement) this.s1,
+ // (NLGElement) this.s3);
+ // List result = this.coord.apply(elements);
+ // Assert.assertTrue(result.size() == 1); // should only be one sentence
+ // NLGElement aggregated = result.get(0);
+ // Assert
+ // .AreEqual(
+ // "the woman kisses the man and kicks the dog behind the curtain",
+ // this.realiser.realise(aggregated).getRealisation());
+ // }
+
+ /**
+ * Test clause coordination with 2 sentences with same VP: succeeds
+ */
+ [Test]
+ public void testCoordinationSameVP()
+ {
+ var elements = new List { s3, s4 };
+ var result = coord.apply(elements);
+ Assert.IsTrue(result.size() == 1); // should only be one sentence
+ var aggregated = result.get(0);
+ Assert.AreEqual(
+ "the woman kicks the dog behind the curtain",
+ this.realiser.realise(aggregated).getRealisation());
+ }
+
+ [Test]
+ public void testCoordinationWithModifiers()
+ {
+ // now add a couple of front modifiers
+ s3.addFrontModifier(this.phraseFactory
+ .createAdverbPhrase("however"));
+ s4.addFrontModifier(this.phraseFactory
+ .createAdverbPhrase("however"));
+ var elements = new List { s3, s4 };
+ var result = coord.apply(elements);
+ Assert.IsTrue(result.size() == 1); // should only be one sentence
+ var aggregated = result.get(0);
+ Assert
+ .AreEqual(
+ "however the woman kicks the dog behind the curtain",
+ this.realiser.realise(aggregated).getRealisation());
+ }
+
+ /**
+ * Test coordination of 3 sentences with the same VP
+ */
+ // [Test]
+ public void testCoordinationSameVP2()
+ {
+ var elements = new List { s3, s4, s5 };
+ var result = coord.apply(elements);
+ Assert.IsTrue(result.size() == 1); // should only be one sentence
+ var aggregated = result.get(0);
+ Assert
+ .AreEqual(
+ "the woman and the man and the girl kick the dog behind the curtain",
+ this.realiser.realise(aggregated).getRealisation());
+ }
+
+ /**
+ * Forward conjunction reduction test
+ */
+ [Test]
+ public void testForwardConjReduction()
+ {
+ var aggregated = fcr.apply(s2, s3);
+ Assert
+ .AreEqual(
+ "the woman kicks the dog on the rock and kicks the dog behind the curtain",
+ this.realiser.realise(aggregated).getRealisation());
+ }
+
+ /**
+ * Backward conjunction reduction test
+ */
+ [Test]
+ public void testBackwardConjunctionReduction()
+ {
+ var aggregated = bcr.apply(s3, s6);
+ Assert
+ .AreEqual(
+ "the woman kicks and the woman kisses the dog behind the curtain",
+ this.realiser.realise(aggregated).getRealisation());
+ }
+
+ /**
+ * Test multiple aggregation procedures in a single aggregator.
+ */
+// [Test]
+// public void testForwardBackwardConjunctionReduction() {
+// this.aggregator.addRule(this.fcr);
+// this.aggregator.addRule(this.bcr);
+// realiser.setDebugMode(true);
+// List result = this.aggregator.realise(Arrays.asList((NLGElement) this.s2, (NLGElement) this.s3));
+// Assert.assertTrue(result.size() == 1); // should only be one sentence
+// NLGElement aggregated = result.get(0);
+// NLGElement aggregated = this.phraseFactory.createdCoordinatedPhrase(this.s2, this.s3);
+// Assert
+// .AreEqual(
+// "the woman kicks the dog on the rock and behind the curtain",
+// this.realiser.realise(aggregated).getRealisation());
+// }
+
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/ClauseTest.cs b/SharpSimpleNLGUnitTests/syntax/ClauseTest.cs
new file mode 100644
index 0000000..159292e
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/ClauseTest.cs
@@ -0,0 +1,886 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+using SimpleNLG.Extensions;
+
+namespace SimpleNLGTests.syntax
+{
+ // TODO: Auto-generated Javadoc
+ /**
+ * The Class STest.
+ */
+
+ public class ClauseTest : SimpleNLG4TestBase
+ {
+ /** The realiser. */
+
+ /**
+ * Initial test for basic sentences.
+ */
+
+ [Test]
+ public void testBasic()
+ {
+ Assert.AreEqual("the woman kisses the man", this.realiser
+ .realise(s1).getRealisation());
+ Assert.AreEqual("there is the dog on the rock", this.realiser
+ .realise(s2).getRealisation());
+
+ setUp();
+ Assert.AreEqual("the man gives the woman John's flower",
+ this.realiser.realise(s3).getRealisation());
+ this.realiser.setDebugMode(true);
+ Assert
+ .AreEqual(
+ "however tomorrow Jane and Andrew will pick up the balls in the shop",
+ this.realiser.realise(s4).getRealisation());
+ }
+
+ /**
+ * Test did not
+ */
+
+ [Test]
+ public void testDidNot()
+ {
+ SPhraseSpec o = this.phraseFactory.createClause("John", "eat");
+ o.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ o.setFeature(Feature.NEGATED.ToString(), true);
+ this.realiser.setLexicon(this.lexicon);
+ Assert.AreEqual("John did not eat", this.realiser.realise(o).getRealisation());
+ }
+
+ /**
+ * Test did not
+ */
+
+ [Test]
+ public void testVPNegation()
+ {
+ // negate the VP
+ var vp = this.phraseFactory.createVerbPhrase("lie");
+ vp.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ vp.setFeature(Feature.NEGATED.ToString(), true);
+ var compl = this.phraseFactory.createVerbPhrase("etherize");
+ compl.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ vp.setComplement(compl);
+
+ var s = this.phraseFactory.createClause(this.phraseFactory
+ .createNounPhrase("the", "patient"), vp);
+
+ Assert.AreEqual("the patient did not lie etherized",
+ this.realiser.realise(s).getRealisation());
+
+ }
+
+ /**
+ * Test that pronominal args are being correctly cast as NPs.
+ */
+
+ [Test]
+ public void testPronounArguments()
+ {
+ // the subject of s2 should have been cast into a pronominal NP
+ var subj = s2.getFeatureAsElementList(
+ InternalFeature.SUBJECTS.ToString()).get(0);
+ Assert.IsTrue(subj.isA(PhraseCategoryEnum.NOUN_PHRASE));
+ // Assert.assertTrue(LexicalCategory.PRONOUN.AreEqual(((PhraseElement)
+ // subj)
+ // .getCategory()));
+ }
+
+ /**
+ * Tests for setting tense, aspect and passive from the sentence interface.
+ */
+
+ [Test]
+ public void testTenses()
+ {
+ // simple past
+ s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ Assert.AreEqual("the man gave the woman John's flower",
+ this.realiser.realise(s3).getRealisation());
+
+ // perfect
+ s3.setFeature(Feature.PERFECT.ToString(), true);
+ Assert.AreEqual("the man had given the woman John's flower",
+ this.realiser.realise(s3).getRealisation());
+
+ // negation
+ s3.setFeature(Feature.NEGATED.ToString(), true);
+ Assert.AreEqual("the man had not given the woman John's flower",
+ this.realiser.realise(s3).getRealisation());
+
+ s3.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ Assert.AreEqual(
+ "the man had not been giving the woman John's flower",
+ this.realiser.realise(s3).getRealisation());
+
+ // passivisation with direct and indirect object
+ // s3.setFeature(Feature.PASSIVE.ToString(), true);
+ // Assert.AreEqual(
+ // "John's flower had not been being given the woman by the man",
+ // realiser.realise(s3).getRealisation());
+ }
+
+ /**
+ * Test what happens when a sentence is subordinated as complement of a
+ * verb.
+ */
+
+ [Test]
+ public void testSubordination()
+ {
+
+ // subordinate sentence by setting it as complement of a verb
+ this.say.addComplement(s3);
+
+ // check the getter
+ Assert.AreEqual(ClauseStatus.SUBORDINATE, s3
+ .getFeature(InternalFeature.CLAUSE_STATUS.ToString()));
+
+ // check realisation
+ Assert.AreEqual("says that the man gives the woman John's flower",
+ this.realiser.realise(this.say).getRealisation());
+ }
+
+ /**
+ * Test the various forms of a sentence, including subordinates.
+ */
+ /**
+ *
+ */
+
+ [Test]
+ public void testForm()
+ {
+
+ // check the getter method
+ Assert.AreEqual(Form.NORMAL, s1.getFeatureAsElement(
+ InternalFeature.VERB_PHRASE.ToString()).getFeature(Feature.FORM.ToString()));
+
+ // infinitive
+ s1.setFeature(Feature.FORM.ToString(), Form.INFINITIVE);
+ Assert
+ .AreEqual(
+ "to kiss the man", this.realiser.realise(s1).getRealisation());
+
+ // gerund with "there"
+ s2.setFeature(Feature.FORM.ToString(), Form.GERUND);
+ Assert.AreEqual("there being the dog on the rock", this.realiser
+ .realise(s2).getRealisation());
+
+ // gerund with possessive
+ s3.setFeature(Feature.FORM.ToString(), Form.GERUND);
+ Assert.AreEqual("the man's giving the woman John's flower",
+ this.realiser.realise(s3).getRealisation());
+
+ // imperative
+ // the man gives the woman John's flower
+ s3 = this.phraseFactory.createClause();
+
+ s3.setVerbPhrase(this.give);
+ s3.setFeature(Feature.FORM.ToString(), Form.IMPERATIVE);
+
+ Assert.AreEqual("give the woman John's flower", this.realiser
+ .realise(s3).getRealisation());
+
+
+
+ this.say = this.phraseFactory.createVerbPhrase("say");
+ this.say.addComplement(s3);
+ this.realiser.setDebugMode(true);
+ Assert.AreEqual("says to give the woman John's flower",
+ this.realiser.realise(this.say).getRealisation());
+
+ // imperative -- case II
+ s4.setFeature(Feature.FORM.ToString(), Form.IMPERATIVE);
+ Assert.AreEqual("however tomorrow pick up the balls in the shop",
+ this.realiser.realise(s4).getRealisation());
+
+ // infinitive -- case II
+ s4 = this.phraseFactory.createClause();
+ s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
+ s4.addFrontModifier("tomorrow");
+
+ var subject = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"), this.phraseFactory
+ .createNounPhrase("Andrew"));
+
+ s4.setFeature(InternalFeature.SUBJECTS.ToString(), subject);
+
+ var pick = this.phraseFactory.createVerbPhrase("pick up");
+ s4.setFeature(InternalFeature.VERB_PHRASE.ToString(), pick);
+ s4.setObject("the balls");
+ s4.addPostModifier("in the shop");
+ s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ s4.setFeature(Feature.FORM.ToString(), Form.INFINITIVE);
+ Assert.AreEqual(
+ "however to pick up the balls in the shop tomorrow",
+ this.realiser.realise(s4).getRealisation());
+ }
+
+ /**
+ * Slightly more complex tests for forms.
+ */
+
+ [Test]
+ public void testForm2()
+ {
+ // set s4 as subject of a new sentence
+ var temp = this.phraseFactory.createClause(s4, "be",
+ "recommended");
+
+ Assert.AreEqual(
+ "however tomorrow Jane and Andrew's picking up the " +
+ "balls in the shop is recommended",
+ this.realiser.realise(temp).getRealisation());
+
+ // compose this with a new sentence
+ // ER - switched direct and indirect object in sentence
+ var temp2 = this.phraseFactory.createClause("I", "tell", temp);
+ temp2.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+
+ var indirectObject = this.phraseFactory
+ .createNounPhrase("John");
+
+ temp2.setIndirectObject(indirectObject);
+
+ Assert.AreEqual("I will tell John that however tomorrow Jane and " +
+ "Andrew's picking up the balls in the shop is " +
+ "recommended",
+ this.realiser.realise(temp2).getRealisation());
+
+ // turn s4 to imperative and put it in indirect object position
+
+ s4 = this.phraseFactory.createClause();
+ s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
+ s4.addFrontModifier("tomorrow");
+
+ var subject = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"), this.phraseFactory
+ .createNounPhrase("Andrew"));
+
+ s4.setSubject(subject);
+
+ var pick = this.phraseFactory.createVerbPhrase("pick up");
+ s4.setVerbPhrase(pick);
+ s4.setObject("the balls");
+ s4.addPostModifier("in the shop");
+ s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ s4.setFeature(Feature.FORM.ToString(), Form.IMPERATIVE);
+
+ temp2 = this.phraseFactory.createClause("I", "tell", s4);
+ indirectObject = this.phraseFactory.createNounPhrase("John");
+ temp2.setIndirectObject(indirectObject);
+ temp2.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+
+ Assert.AreEqual("I will tell John however to pick up the balls "
+ + "in the shop tomorrow", this.realiser.realise(temp2)
+ .getRealisation());
+ }
+
+ /**
+ * Tests for gerund forms and genitive subjects.
+ */
+
+ [Test]
+ public void testGerundsubject()
+ {
+
+ // the man's giving the woman John's flower upset Peter
+ var _s4 = this.phraseFactory.createClause();
+ _s4.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset"));
+ _s4.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ _s4.setObject(this.phraseFactory.createNounPhrase("Peter"));
+ s3.setFeature(Feature.PERFECT.ToString(), true);
+
+ // set the sentence as subject of another: makes it a gerund
+ _s4.setSubject(s3);
+
+ // suppress the genitive realisation of the NP subject in gerund
+ // sentences
+ s3.setFeature(Feature.SUPPRESS_GENITIVE_IN_GERUND.ToString(), true);
+
+ // check the realisation: subject should not be genitive
+ Assert.AreEqual(
+ "the man having given the woman John's flower upset Peter",
+ this.realiser.realise(_s4).getRealisation());
+
+ }
+
+ /**
+ * Some tests for multiple embedded sentences.
+ */
+
+ [Test]
+ public void testComplexSentence1()
+ {
+ setUp();
+ // the man's giving the woman John's flower upset Peter
+ var complexS = this.phraseFactory.createClause();
+ complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset"));
+ complexS.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ complexS.setObject(this.phraseFactory.createNounPhrase("Peter"));
+ s3.setFeature(Feature.PERFECT.ToString(), true);
+ complexS.setSubject(s3);
+
+ // check the realisation: subject should be genitive
+ Assert.AreEqual(
+ "the man's having given the woman John's flower upset Peter",
+ this.realiser.realise(complexS).getRealisation());
+
+ setUp();
+ // coordinate sentences in subject position
+ var s5 = this.phraseFactory.createClause();
+ s5.setSubject(this.phraseFactory.createNounPhrase("some", "person"));
+ s5.setVerbPhrase(this.phraseFactory.createVerbPhrase("stroke"));
+ s5.setObject(this.phraseFactory.createNounPhrase("the", "cat"));
+
+ var coord = new CoordinatedPhraseElement(s3,
+ s5);
+ complexS = this.phraseFactory.createClause();
+ complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset"));
+ complexS.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ complexS.setObject(this.phraseFactory.createNounPhrase("Peter"));
+ complexS.setSubject(coord);
+ s3.setFeature(Feature.PERFECT.ToString(), true);
+
+ Assert.AreEqual("the man's having given the woman John's flower "
+ + "and some person's stroking the cat upset Peter",
+ this.realiser.realise(complexS).getRealisation());
+
+ setUp();
+ // now subordinate the complex sentence
+ // coord.setClauseStatus(SPhraseSpec.ClauseType.MAIN);
+ var s6 = this.phraseFactory.createClause();
+ s6.setVerbPhrase(this.phraseFactory.createVerbPhrase("tell"));
+ s6.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ s6.setSubject(this.phraseFactory.createNounPhrase("the", "boy"));
+ // ER - switched indirect and direct object
+ var indirect = this.phraseFactory.createNounPhrase("every",
+ "girl");
+ s6.setIndirectObject(indirect);
+ complexS = this.phraseFactory.createClause();
+ complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset"));
+ complexS.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ complexS.setObject(this.phraseFactory.createNounPhrase("Peter"));
+ s6.setObject(complexS);
+ coord = new CoordinatedPhraseElement(s3, s5);
+ complexS.setSubject(coord);
+ s3.setFeature(Feature.PERFECT.ToString(), true);
+ Assert.AreEqual(
+ "the boy told every girl that the man's having given the woman "
+ + "John's flower and some person's stroking the cat "
+ + "upset Peter",
+ this.realiser.realise(s6).getRealisation());
+
+ }
+
+ /**
+ * More coordination tests.
+ */
+
+ [Test]
+ public void testComplexSentence3()
+ {
+ setUp();
+
+ s1 = this.phraseFactory.createClause();
+ s1.setSubject(this.woman);
+ s1.setVerb("kiss");
+ s1.setObject(this.man);
+
+ var _man = this.phraseFactory.createNounPhrase("the", "man");
+ s3 = this.phraseFactory.createClause();
+ s3.setSubject(_man);
+ s3.setVerb("give");
+
+ var flower = this.phraseFactory.createNounPhrase("flower");
+ var john = this.phraseFactory.createNounPhrase("John");
+ john.setFeature(Feature.POSSESSIVE.ToString(), true);
+ flower.setSpecifier(john);
+ s3.setObject(flower);
+
+ var _woman = this.phraseFactory.createNounPhrase(
+ "the", "woman");
+ s3.setIndirectObject(_woman);
+
+ // the coordinate sentence allows us to raise and lower complementiser
+ var coord2 = new CoordinatedPhraseElement(s1,
+ s3);
+ coord2.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+
+ this.realiser.setDebugMode(true);
+ Assert
+ .AreEqual(
+ "the woman kissed the man and the man gave the woman John's flower",
+ this.realiser.realise(coord2).getRealisation());
+ }
+
+ // /**
+ // * Sentence with clausal subject with verb "be" and a progressive feature
+ // */
+ // public void testComplexSentence2() {
+ // SPhraseSpec subject = phraseFactory.createClause(
+ // phraseFactory.createNounPhrase("the", "child"),
+ // phraseFactory.createVerbPhrase("be"), phraseFactory
+ // .createWord("difficult", LexicalCategory.ADJECTIVE));
+ // subject.setFeature(Feature.PROGRESSIVE, true);
+ // }
+
+ /**
+ * Tests recogition of strings in API.
+ */
+
+ [Test]
+ public void testStringRecognition()
+ {
+
+ // test recognition of forms of "be"
+ var _s1 = this.phraseFactory.createClause(
+ "my cat", "be", "sad");
+ Assert.AreEqual(
+ "my cat is sad", this.realiser.realise(_s1).getRealisation());
+
+ // test recognition of pronoun for afreement
+ var _s2 = this.phraseFactory
+ .createClause("I", "want", "Mary");
+
+ Assert.AreEqual(
+ "I want Mary", this.realiser.realise(_s2).getRealisation());
+
+ // test recognition of pronoun for correct form
+ var subject = this.phraseFactory.createNounPhrase("dog");
+ subject.setFeature(InternalFeature.SPECIFIER.ToString(), "a");
+ subject.addPostModifier("from next door");
+ var obj = this.phraseFactory.createNounPhrase("I");
+ var s = this.phraseFactory.createClause(subject,
+ "chase", obj);
+ s.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ Assert.AreEqual("a dog from next door is chasing me",
+ this.realiser.realise(s).getRealisation());
+ }
+
+ /**
+ * Tests complex agreement.
+ */
+
+ [Test]
+ public void testAgreement()
+ {
+
+ // basic agreement
+ var np = this.phraseFactory.createNounPhrase("dog");
+ np.setSpecifier("the");
+ np.addPreModifier("angry");
+ var _s1 = this.phraseFactory
+ .createClause(np, "chase", "John");
+ Assert.AreEqual("the angry dog chases John", this.realiser
+ .realise(_s1).getRealisation());
+
+ // plural
+ np = this.phraseFactory.createNounPhrase("dog");
+ np.setSpecifier("the");
+ np.addPreModifier("angry");
+ np.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+ _s1 = this.phraseFactory.createClause(np, "chase", "John");
+ Assert.AreEqual("the angry dogs chase John", this.realiser
+ .realise(_s1).getRealisation());
+
+ // test agreement with "there is"
+ np = this.phraseFactory.createNounPhrase("dog");
+ np.addPreModifier("angry");
+ np.setFeature(Feature.NUMBER.ToString(), NumberAgreement.SINGULAR);
+ np.setSpecifier("a");
+ var _s2 = this.phraseFactory.createClause("there", "be", np);
+ Assert.AreEqual("there is an angry dog", this.realiser
+ .realise(_s2).getRealisation());
+
+ // plural with "there"
+ np = this.phraseFactory.createNounPhrase("dog");
+ np.addPreModifier("angry");
+ np.setSpecifier("a");
+ np.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+ _s2 = this.phraseFactory.createClause("there", "be", np);
+ Assert.AreEqual("there are some angry dogs", this.realiser
+ .realise(_s2).getRealisation());
+ }
+
+ /**
+ * Tests passive.
+ */
+
+ [Test]
+ public void testPassive()
+ {
+ // passive with just complement
+ var _s1 = this.phraseFactory.createClause(null,
+ "intubate", this.phraseFactory.createNounPhrase("the", "baby"));
+
+ _s1.setFeature(Feature.PASSIVE.ToString(), true);
+
+ Assert.AreEqual("the baby is intubated", this.realiser
+ .realise(_s1).getRealisation());
+
+ // passive with subject and complement
+ _s1 = this.phraseFactory.createClause(null,
+ "intubate", this.phraseFactory.createNounPhrase("the", "baby"));
+
+ _s1.setSubject(this.phraseFactory.createNounPhrase("the nurse"));
+ _s1.setFeature(Feature.PASSIVE.ToString(), true);
+ Assert.AreEqual("the baby is intubated by the nurse",
+ this.realiser.realise(_s1).getRealisation());
+
+ // passive with subject and indirect object
+ var _s2 = this.phraseFactory.createClause(null, "give",
+ this.phraseFactory.createNounPhrase("the", "baby"));
+
+ var morphine = this.phraseFactory
+ .createNounPhrase("50ug of morphine");
+ _s2.setIndirectObject(morphine);
+ _s2.setFeature(Feature.PASSIVE.ToString(), true);
+ Assert.AreEqual("the baby is given 50ug of morphine",
+ this.realiser.realise(_s2).getRealisation());
+
+ // passive with subject, complement and indirect object
+ _s2 = this.phraseFactory.createClause(this.phraseFactory
+ .createNounPhrase("the", "nurse"), "give",
+ this.phraseFactory.createNounPhrase("the", "baby"));
+
+ morphine = this.phraseFactory.createNounPhrase("50ug of morphine");
+ _s2.setIndirectObject(morphine);
+ _s2.setFeature(Feature.PASSIVE.ToString(), true);
+ Assert.AreEqual("the baby is given 50ug of morphine by the nurse",
+ this.realiser.realise(_s2).getRealisation());
+
+ // test agreement in passive
+ var _s3 = this.phraseFactory.createClause(
+ new CoordinatedPhraseElement("my dog", "your cat"), "chase",
+ "George");
+ _s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ _s3.addFrontModifier("yesterday");
+ Assert.AreEqual("yesterday my dog and your cat chased George",
+ this.realiser.realise(_s3).getRealisation());
+
+ _s3 = this.phraseFactory.createClause(new CoordinatedPhraseElement(
+ "my dog", "your cat"), "chase",
+ this.phraseFactory.createNounPhrase("George"));
+ _s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ _s3.addFrontModifier("yesterday");
+ _s3.setFeature(Feature.PASSIVE.ToString(), true);
+ Assert.AreEqual(
+ "yesterday George was chased by my dog and your cat",
+ this.realiser.realise(_s3).getRealisation());
+
+ // test correct pronoun forms
+ var _s4 = this.phraseFactory.createClause(this.phraseFactory
+ .createNounPhrase("he"), "chase",
+ this.phraseFactory.createNounPhrase("I"));
+ Assert.AreEqual("he chases me", this.realiser.realise(_s4)
+ .getRealisation());
+ _s4 = this.phraseFactory
+ .createClause(
+ this.phraseFactory.createNounPhrase("he"), "chase", this.phraseFactory.createNounPhrase("me"));
+
+ _s4.setFeature(Feature.PASSIVE.ToString(), true);
+ Assert
+ .AreEqual(
+ "I am chased by him", this.realiser.realise(_s4).getRealisation());
+
+ // same thing, but giving the S constructor "me". Should recognise
+ // correct pro
+ // anyway
+ var _s5 = this.phraseFactory
+ .createClause("him", "chase", "I");
+ Assert.AreEqual(
+ "he chases me", this.realiser.realise(_s5).getRealisation());
+
+ _s5 = this.phraseFactory.createClause("him", "chase", "I");
+ _s5.setFeature(Feature.PASSIVE.ToString(), true);
+ Assert
+ .AreEqual(
+ "I am chased by him", this.realiser.realise(_s5).getRealisation());
+ }
+
+ /**
+ * Test that complements set within the VP are raised when sentence is
+ * passivised.
+ */
+
+ [Test]
+ public void testPassiveWithInternalVPComplement()
+ {
+ var vp = this.phraseFactory.createVerbPhrase(this.phraseFactory
+ .createWord("upset", new LexicalCategory_VERB()));
+ vp.addComplement(this.phraseFactory.createNounPhrase("the", "man"));
+ var _s6 = this.phraseFactory.createClause(this.phraseFactory
+ .createNounPhrase("the", "child"), vp);
+ _s6.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ Assert.AreEqual("the child upset the man", this.realiser.realise(
+ _s6).getRealisation());
+
+ _s6.setFeature(Feature.PASSIVE.ToString(), true);
+ Assert.AreEqual("the man was upset by the child", this.realiser
+ .realise(_s6).getRealisation());
+ }
+
+ /**
+ * Tests tenses with modals.
+ */
+
+ [Test]
+ public void testModal()
+ {
+
+ setUp();
+ // simple modal in present tense
+ s3.setFeature(Feature.MODAL.ToString(), "should");
+ Assert.AreEqual("the man should give the woman John's flower",
+ this.realiser.realise(s3).getRealisation());
+
+ // modal + future -- uses present
+ setUp();
+ s3.setFeature(Feature.MODAL.ToString(), "should");
+ s3.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ Assert.AreEqual("the man should give the woman John's flower",
+ this.realiser.realise(s3).getRealisation());
+
+ // modal + present progressive
+ setUp();
+ s3.setFeature(Feature.MODAL.ToString(), "should");
+ s3.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ s3.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ Assert.AreEqual("the man should be giving the woman John's flower",
+ this.realiser.realise(s3).getRealisation());
+
+ // modal + past tense
+ setUp();
+ s3.setFeature(Feature.MODAL.ToString(), "should");
+ s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ Assert.AreEqual(
+ "the man should have given the woman John's flower",
+ this.realiser.realise(s3).getRealisation());
+
+ // modal + past progressive
+ setUp();
+ s3.setFeature(Feature.MODAL.ToString(), "should");
+ s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ s3.setFeature(Feature.PROGRESSIVE.ToString(), true);
+
+ Assert.AreEqual(
+ "the man should have been giving the woman John's flower",
+ this.realiser.realise(s3).getRealisation());
+
+ }
+
+ /**
+ * Test for passivisation with mdoals
+ */
+
+ [Test]
+ public void testModalWithPassive()
+ {
+ var obj = this.phraseFactory.createNounPhrase("the",
+ "pizza");
+ var post = this.phraseFactory.createAdjectivePhrase("good");
+ var aso = this.phraseFactory.createAdverbPhrase("as");
+ aso.addComplement(post);
+ var verb = this.phraseFactory.createVerbPhrase("classify");
+ verb.addPostModifier( aso );
+ verb.addComplement(obj);
+ var s = this.phraseFactory.createClause();
+ s.setVerbPhrase(verb);
+ s.setFeature(Feature.MODAL.ToString(), "can");
+ // s.setFeature(Feature.FORM, Form.INFINITIVE);
+ s.setFeature(Feature.PASSIVE.ToString(), true);
+ Assert.AreEqual("the pizza can be classified as good",
+ this.realiser.realise(s).getRealisation());
+ }
+
+ [Test]
+ public void testPassiveWithPPCompl()
+ {
+ // passive with just complement
+ var subject = this.phraseFactory.createNounPhrase("wave");
+ subject.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+ var obj = this.phraseFactory.createNounPhrase("surfer");
+ obj.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+
+ var _s1 = this.phraseFactory.createClause(subject,
+ "carry", obj);
+
+ // add a PP complement
+ var pp = this.phraseFactory.createPrepositionPhrase("to",
+ this.phraseFactory.createNounPhrase("the", "shore"));
+ pp.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ DiscourseFunction.INDIRECT_OBJECT);
+ _s1.addComplement(pp);
+
+ _s1.setFeature(Feature.PASSIVE.ToString(), true);
+ this.realiser.setDebugMode(true);
+ Assert.AreEqual(
+ "surfers are carried to the shore by waves", this.realiser
+ .realise(_s1).getRealisation());
+ }
+
+ [Test]
+ public void testPassiveWithPPMod()
+ {
+ // passive with just complement
+ var subject = this.phraseFactory.createNounPhrase("wave");
+ subject.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+ var obj = this.phraseFactory.createNounPhrase("surfer");
+ obj.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+
+ var _s1 = this.phraseFactory.createClause(subject,
+ "carry", obj);
+
+ // add a PP complement
+ var pp = this.phraseFactory.createPrepositionPhrase("to",
+ this.phraseFactory.createNounPhrase("the", "shore"));
+ _s1.addPostModifier(pp);
+
+ _s1.setFeature(Feature.PASSIVE.ToString(), true);
+
+ Assert.AreEqual(
+ "surfers are carried to the shore by waves", this.realiser
+ .realise(_s1).getRealisation());
+ }
+
+ [Test]
+ public void testCuePhrase()
+ {
+ var subject = this.phraseFactory.createNounPhrase("wave");
+ subject.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+ var obj = this.phraseFactory.createNounPhrase("surfer");
+ obj.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+
+ var _s1 = this.phraseFactory.createClause(subject,
+ "carry", obj);
+
+ // add a PP complement
+ var pp = this.phraseFactory.createPrepositionPhrase("to",
+ this.phraseFactory.createNounPhrase("the", "shore"));
+ _s1.addPostModifier(pp);
+
+ _s1.setFeature(Feature.PASSIVE.ToString(), true);
+
+ _s1.addFrontModifier("however");
+
+
+ //without comma separation of cue phrase
+ Assert.AreEqual(
+ "however surfers are carried to the shore by waves", this.realiser
+ .realise(_s1).getRealisation());
+
+ //with comma separation
+ this.realiser.setCommaSepCuephrase(true);
+ Assert.AreEqual(
+ "however, surfers are carried to the shore by waves", this.realiser
+ .realise(_s1).getRealisation());
+ }
+
+
+ /**
+ * Check that setComplement replaces earlier complements
+ */
+
+ [Test]
+ public void setComplementTest()
+ {
+ var s = this.phraseFactory.createClause();
+ s.setSubject("I");
+ s.setVerb("see");
+ s.setObject("a dog");
+
+ Assert.AreEqual("I see a dog", this.realiser.realise(s)
+ .getRealisation());
+
+ s.setObject("a cat");
+ Assert.AreEqual("I see a cat", this.realiser.realise(s)
+ .getRealisation());
+
+ s.setObject("a wolf");
+ Assert.AreEqual("I see a wolf", this.realiser.realise(s)
+ .getRealisation());
+
+ }
+
+
+ /**
+ * Test for subclauses involving WH-complements Based on a query by Owen
+ * Bennett
+ */
+
+ [Test]
+ public void subclausesTest()
+ {
+ // Once upon a time, there was an Accountant, called Jeff, who lived in
+ // a forest.
+
+ // main sentence
+ var acct = this.phraseFactory.createNounPhrase("a",
+ "accountant");
+
+ // first postmodifier of "an accountant"
+ var sub1 = this.phraseFactory.createVerbPhrase("call");
+ sub1.addComplement("Jeff");
+ sub1.setFeature(Feature.FORM.ToString(), Form.PAST_PARTICIPLE);
+ // this is an appositive modifier, which makes simplenlg put it between
+ // commas
+ sub1.setFeature(Feature.APPOSITIVE.ToString(), true);
+ acct.addPostModifier(sub1);
+
+ // second postmodifier of "an accountant" is "who lived in a forest"
+ var sub2 = this.phraseFactory.createClause();
+ var subvp = this.phraseFactory.createVerbPhrase("live");
+ subvp.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ subvp.setComplement(this.phraseFactory.createPrepositionPhrase("in",
+ this.phraseFactory.createNounPhrase("a", "forest")));
+ sub2.setVerbPhrase(subvp);
+ // simplenlg can't yet handle wh-clauses in NPs, so we need to hack it
+ // by setting the subject to "who"
+ sub2.setSubject("who");
+ acct.addPostModifier(sub2);
+
+ // main sentence
+ var s = this.phraseFactory.createClause("there", "be", acct);
+ s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+
+ // add front modifier "once upon a time"
+ s.addFrontModifier("once upon a time");
+
+ Assert.AreEqual(
+ "once upon a time there was an accountant, called Jeff, who lived in a forest",
+ this.realiser.realise(s).getRealisation());
+
+ }
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/CoordinationTest.cs b/SharpSimpleNLGUnitTests/syntax/CoordinationTest.cs
new file mode 100644
index 0000000..ad1a7f9
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/CoordinationTest.cs
@@ -0,0 +1,200 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+ /**
+ * Some tests for coordination, especially of coordinated VPs with modifiers.
+ *
+ * @author Albert Gatt
+ *
+ */
+
+ public class CoordinationTest : SimpleNLG4TestBase
+ {
+
+
+
+ /**
+ * Check that empty coordinate phrases are not realised as "null"
+ */
+ [Test]
+
+ public void emptyCoordinationTest()
+ {
+ //this.realiser.setDebugMode(true);
+ // first a simple phrase with no coordinates
+ var coord = this.phraseFactory.createCoordinatedPhrase();
+ //Assert.AreEqual("", this.realiser.realise(coord).getRealisation());
+
+ // now one with a premodifier and nothing else
+ coord.addPreModifier(this.phraseFactory.createAdjectivePhrase("nice"));
+ Assert.AreEqual("nice", this.realiser.realise(coord)
+ .getRealisation());
+ }
+
+ /**
+ * Test pre and post-modification of coordinate VPs inside a sentence.
+ */
+ [Test]
+
+ public void testModifiedCoordVP()
+ {
+ var coord = this.phraseFactory
+ .createCoordinatedPhrase(this.getUp, this.fallDown);
+ coord.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ Assert.AreEqual("got up and fell down", this.realiser
+ .realise(coord).getRealisation());
+
+ // add a premodifier
+ coord.addPreModifier("slowly");
+ Assert.AreEqual("slowly got up and fell down", this.realiser
+ .realise(coord).getRealisation());
+
+ // adda postmodifier
+ coord.addPostModifier(this.behindTheCurtain);
+ Assert.AreEqual("slowly got up and fell down behind the curtain",
+ this.realiser.realise(coord).getRealisation());
+
+ // put within the context of a sentence
+ var s = this.phraseFactory.createClause("Jake", coord);
+ s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ Assert.AreEqual(
+ "Jake slowly got up and fell down behind the curtain",
+ this.realiser.realise(s).getRealisation());
+
+ // add premod to the sentence
+ s.addPreModifier(this.lexicon
+ .getWord("however", new LexicalCategory_ADVERB()));
+ Assert.AreEqual(
+ "Jake however slowly got up and fell down behind the curtain",
+ this.realiser.realise(s).getRealisation());
+
+ // add postmod to the sentence
+ s.addPostModifier(this.inTheRoom);
+ Assert.AreEqual(
+ "Jake however slowly got up and fell down behind the curtain in the room",
+ this.realiser.realise(s).getRealisation());
+ }
+
+ /**
+ * Test due to Chris Howell -- create a complex sentence with front modifier
+ * and coordinateVP. this is a version in which we create the coordinate
+ * phrase directly.
+ */
+ [Test]
+
+ public void testCoordinateVPComplexSubject()
+ {
+ // "As a result of the procedure the patient had an adverse contrast media reaction and went into cardiogenic shock."
+ var s = this.phraseFactory.createClause();
+
+ s.setSubject(this.phraseFactory.createNounPhrase("the", "patient"));
+
+ // first VP
+ var vp1 = this.phraseFactory.createVerbPhrase(this.lexicon
+ .getWord("have", new LexicalCategory_VERB()));
+ var np1 = this.phraseFactory.createNounPhrase("a",
+ this.lexicon.getWord("contrast media reaction",
+ new LexicalCategory_NOUN()));
+ np1.addPreModifier(this.lexicon.getWord("adverse",
+ new LexicalCategory_ADJECTIVE()));
+ vp1.addComplement(np1);
+
+ // second VP
+ var vp2 = this.phraseFactory.createVerbPhrase(this.lexicon
+ .getWord("go", new LexicalCategory_VERB()));
+ var pp = this.phraseFactory
+ .createPrepositionPhrase("into", this.lexicon.getWord(
+ "cardiogenic shock", new LexicalCategory_NOUN()));
+ vp2.addComplement(pp);
+
+ // coordinate
+ var coord = this.phraseFactory
+ .createCoordinatedPhrase(vp1, vp2);
+ coord.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ Assert.AreEqual(
+ "had an adverse contrast media reaction and went into cardiogenic shock",
+ this.realiser.realise(coord).getRealisation());
+
+ // now put this in the sentence
+ s.setVerbPhrase(coord);
+ s.addFrontModifier("As a result of the procedure");
+ Assert.AreEqual(
+ "As a result of the procedure the patient had an adverse contrast media reaction and went into cardiogenic shock",
+ this.realiser.realise(s).getRealisation());
+
+ }
+
+ /**
+ * Test setting a conjunction to null
+ */
+
+ public void testNullConjunction()
+ {
+ var p = this.phraseFactory.createClause("I", "be", "happy");
+ var q = this.phraseFactory.createClause("I", "eat", "fish");
+ var pq = this.phraseFactory
+ .createCoordinatedPhrase();
+ pq.addCoordinate(p);
+ pq.addCoordinate(q);
+ pq.setFeature(Feature.CONJUNCTION.ToString(), "");
+
+ // should come out without conjunction
+ Assert.AreEqual("I am happy I eat fish", this.realiser.realise(pq)
+ .getRealisation());
+
+ // should come out without conjunction
+ pq.setFeature(Feature.CONJUNCTION.ToString(), null);
+ Assert.AreEqual("I am happy I eat fish", this.realiser.realise(pq)
+ .getRealisation());
+
+ }
+
+ /**
+ * Check that the negation feature on a child of a coordinate phrase remains
+ * as set, unless explicitly set otherwise at the parent level.
+ */
+ [Test]
+
+ public void testNegationFeature()
+ {
+ var s1 = this.phraseFactory
+ .createClause("he", "have", "asthma");
+ var s2 = this.phraseFactory.createClause("he", "have",
+ "diabetes");
+ s1.setFeature(Feature.NEGATED.ToString(), true);
+ var coord = this.phraseFactory
+ .createCoordinatedPhrase(s1, s2);
+ var realisation = this.realiser.realise(coord).getRealisation();
+ Assert.AreEqual("he does not have asthma and he has diabetes",
+ realisation);
+ }
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/DeterminerTest.cs b/SharpSimpleNLGUnitTests/syntax/DeterminerTest.cs
new file mode 100644
index 0000000..61d20b4
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/DeterminerTest.cs
@@ -0,0 +1,400 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+
+namespace SimpleNLGTests.syntax
+{
+
+ /**
+ * Some determiner tests -- in particular for indefinite articles like "a" or "an".
+ *
+ * @author Saad Mahamood, Data2Text Limited.
+ *
+ */
+
+ public class DeterminerTest : SimpleNLG4TestBase
+ {
+
+ /**
+ * testLowercaseConstant - Test for when there is a lower case constant
+ */
+
+ [Test]
+ public void testLowercaseConstant()
+ {
+
+ var sentence = this.phraseFactory.createClause();
+
+ var subject = this.phraseFactory.createNounPhrase("a", "dog");
+ sentence.setSubject(subject);
+
+ var output = this.realiser.realiseSentence(sentence);
+
+ Assert.AreEqual("A dog.", output);
+ }
+
+ /**
+ * testLowercaseVowel - Test for "an" as a specifier.
+ */
+
+ [Test]
+ public void testLowercaseVowel()
+ {
+ var sentence = this.phraseFactory.createClause();
+
+ var subject = this.phraseFactory.createNounPhrase("a", "owl");
+ sentence.setSubject(subject);
+
+ var output = this.realiser.realiseSentence(sentence);
+
+ Assert.AreEqual("An owl.", output);
+ }
+
+ /**
+ * testUppercaseConstant - Test for when there is a upper case constant
+ */
+
+ [Test]
+ public void testUppercaseConstant()
+ {
+
+ var sentence = this.phraseFactory.createClause();
+
+ var subject = this.phraseFactory.createNounPhrase("a", "Cat");
+ sentence.setSubject(subject);
+
+ var output = this.realiser.realiseSentence(sentence);
+
+ Assert.AreEqual("A Cat.", output);
+ }
+
+ /**
+ * testUppercaseVowel - Test for "an" as a specifier for upper subjects.
+ */
+
+ [Test]
+ public void testUppercaseVowel()
+ {
+ var sentence = this.phraseFactory.createClause();
+
+ var subject = this.phraseFactory.createNounPhrase("a", "Emu");
+ sentence.setSubject(subject);
+
+ var output = this.realiser.realiseSentence(sentence);
+
+ Assert.AreEqual("An Emu.", output);
+ }
+
+ /**
+ * testNumericA - Test for "a" specifier with a numeric subject
+ */
+
+ [Test]
+ public void testNumericA()
+ {
+ var sentence = this.phraseFactory.createClause();
+
+ var subject = this.phraseFactory.createNounPhrase("a", "7");
+ sentence.setSubject(subject);
+
+ var output = this.realiser.realiseSentence(sentence);
+
+ Assert.AreEqual("A 7.", output);
+ }
+
+ /**
+ * testNumericAn - Test for "an" specifier with a numeric subject
+ */
+
+ [Test]
+ public void testNumericAn()
+ {
+ var sentence = this.phraseFactory.createClause();
+
+ var subject = this.phraseFactory.createNounPhrase("a", "11");
+ sentence.setSubject(subject);
+
+ var output = this.realiser.realiseSentence(sentence);
+
+ Assert.AreEqual("An 11.", output);
+ }
+
+ /**
+ * testIrregularSubjects - Test irregular subjects that don't conform to the
+ * vowel vs. constant divide.
+ */
+
+ [Test]
+ public void testIrregularSubjects()
+ {
+ var sentence = this.phraseFactory.createClause();
+
+ var subject = this.phraseFactory.createNounPhrase("a", "one");
+ sentence.setSubject(subject);
+
+ var output = this.realiser.realiseSentence(sentence);
+
+ Assert.AreEqual("A one.", output);
+ }
+
+ /**
+ * testSingluarThisDeterminerNPObject - Test for "this" when used in the singular form as a determiner in a NP Object
+ */
+
+ [Test]
+ public void testSingluarThisDeterminerNPObject()
+ {
+ var sentence_1 = this.phraseFactory.createClause();
+
+ var nounPhrase_1 = this.phraseFactory.createNounPhrase("this", "monkey");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.AreEqual("This monkey.", this.realiser.realiseSentence(sentence_1));
+ }
+
+ /**
+ * testPluralThisDeterminerNPObject - Test for "this" when used in the plural form as a determiner in a NP Object
+ */
+
+ [Test]
+ public void testPluralThisDeterminerNPObject()
+ {
+ var sentence_1 = this.phraseFactory.createClause();
+
+ var nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(true);
+ nounPhrase_1.setDeterminer("this");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.AreEqual("These monkeys.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testSingluarThatDeterminerNPObject - Test for "that" when used in the singular form as a determiner in a NP Object
+ */
+
+ [Test]
+ public void testSingluarThatDeterminerNPObject()
+ {
+ var sentence_1 = this.phraseFactory.createClause();
+
+ var nounPhrase_1 = this.phraseFactory.createNounPhrase("that", "monkey");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.AreEqual("That monkey.", this.realiser.realiseSentence(sentence_1));
+ }
+
+ /**
+ * testPluralThatDeterminerNPObject - Test for "that" when used in the plural form as a determiner in a NP Object
+ */
+
+ [Test]
+ public void testPluralThatDeterminerNPObject()
+ {
+ var sentence_1 = this.phraseFactory.createClause();
+
+ var nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(true);
+ nounPhrase_1.setDeterminer("that");
+ sentence_1.setObject(nounPhrase_1);
+
+ this.realiser.setDebugMode(true);
+ Assert.AreEqual("Those monkeys.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testSingularThoseDeterminerNPObject - Test for "those" when used in the singular form as a determiner in a NP Object
+ */
+
+ [Test]
+ public void testSingularThoseDeterminerNPObject()
+ {
+ var sentence_1 = this.phraseFactory.createClause();
+
+ var nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(false);
+ nounPhrase_1.setDeterminer("those");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.AreEqual("That monkey.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testSingularTheseDeterminerNPObject - Test for "these" when used in the singular form as a determiner in a NP Object
+ */
+
+ [Test]
+ public void testSingularTheseDeterminerNPObject()
+ {
+ var sentence_1 = this.phraseFactory.createClause();
+
+ var nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(false);
+ nounPhrase_1.setDeterminer("these");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.AreEqual("This monkey.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testPluralThoseDeterminerNPObject - Test for "those" when used in the plural form as a determiner in a NP Object
+ */
+
+ [Test]
+ public void testPluralThoseDeterminerNPObject()
+ {
+ var sentence_1 = this.phraseFactory.createClause();
+
+ var nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(true);
+ nounPhrase_1.setDeterminer("those");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.AreEqual("Those monkeys.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testPluralTheseDeterminerNPObject - Test for "these" when used in the plural form as a determiner in a NP Object
+ */
+
+ [Test]
+ public void testPluralTheseDeterminerNPObject()
+ {
+ var sentence_1 = this.phraseFactory.createClause();
+
+ var nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(true);
+ nounPhrase_1.setDeterminer("these");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.AreEqual("These monkeys.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testSingularTheseDeterminerNPObject - Test for "these" when used in the singular form as a determiner in a NP Object
+ * using the NIHDB Lexicon.
+ */
+
+/*
+ public void testSingularTheseDeterminerNPObject_NIHDBLexicon()
+ {
+ this.lexicon = new NIHDBLexicon(DB_FILENAME);
+ this.phraseFactory = new NLGFactory(this.lexicon);
+ this.realiser = new Realiser(this.lexicon);
+
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(false);
+ nounPhrase_1.setDeterminer("these");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.AreEqual("This monkey.", this.realiser.realiseSentence(sentence_1));
+
+ }
+ */
+
+ /**
+ * testSingularThoseDeterminerNPObject - Test for "those" when used in the singular form as a determiner in a NP Object
+ * using the NIHDB Lexicon
+ */
+
+/*
+ public void testSingularThoseDeterminerNPObject_NIHDBLexicon()
+ {
+ this.lexicon = new NIHDBLexicon(DB_FILENAME);
+ this.phraseFactory = new NLGFactory(this.lexicon);
+ this.realiser = new Realiser(this.lexicon);
+
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(false);
+ nounPhrase_1.setDeterminer("those");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.AreEqual("That monkey.", this.realiser.realiseSentence(sentence_1));
+
+ }
+ */
+
+
+ /**
+ * testPluralThatDeterminerNPObject - Test for "that" when used in the plural form as a determiner in a NP Object
+ * using the NIHDB Lexicon.
+ */
+
+ /*
+ public void testPluralThatDeterminerNPObject_NIHDBLexicon()
+ {
+ this.lexicon = new NIHDBLexicon(DB_FILENAME);
+ this.phraseFactory = new NLGFactory(this.lexicon);
+ this.realiser = new Realiser(this.lexicon);
+
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(true);
+ nounPhrase_1.setDeterminer("that");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.AreEqual("Those monkeys.", this.realiser.realiseSentence(sentence_1));
+
+ }
+ */
+
+ /**
+ * testPluralThisDeterminerNPObject - Test for "this" when used in the plural form as a determiner in a NP Object
+ * using the NIHDBLexicon.
+ */
+
+ /*
+ public void testPluralThisDeterminerNPObject_NIHDBLexicon()
+ {
+ this.lexicon = new NIHDBLexicon(DB_FILENAME);
+ this.phraseFactory = new NLGFactory(this.lexicon);
+ this.realiser = new Realiser(this.lexicon);
+
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(true);
+ nounPhrase_1.setDeterminer("this");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.AreEqual("These monkeys.", this.realiser.realiseSentence(sentence_1));
+
+ }
+ */
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/DocumentElementTest.cs b/SharpSimpleNLGUnitTests/syntax/DocumentElementTest.cs
new file mode 100644
index 0000000..6d526f5
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/DocumentElementTest.cs
@@ -0,0 +1,209 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using System.Collections.Generic;
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+
+ /**
+ * Tests for the DocumentElement class.
+ *
+ * @author ereiter
+ */
+
+ public class DocumentElementTest : SimpleNLG4TestBase
+ {
+
+ private SPhraseSpec p1, p2, p3;
+
+ /**
+ * Instantiates a new document element test.
+ *
+ * @param name
+ * the name
+ */
+
+ [SetUp]
+ protected override void setUp()
+ {
+ p1 = this.phraseFactory.createClause("you", "be", "happy");
+ p2 = this.phraseFactory.createClause("I", "be", "sad");
+ p3 = this.phraseFactory.createClause("they", "be", "nervous");
+ }
+
+
+ /**
+ * Basic tests.
+ */
+
+ [Test]
+ public void testBasics()
+ {
+ var s1 = this.phraseFactory.createSentence(p1);
+ var s2 = this.phraseFactory.createSentence(p2);
+ var s3 = this.phraseFactory.createSentence(p3);
+
+ var par1 = this.phraseFactory.createParagraph(new List { s1, s2, s3});
+
+ Assert.AreEqual("You are happy. I am sad. They are nervous.\n\n",
+ this.realiser.realise(par1).getRealisation());
+
+ }
+
+ /**
+ * Ensure that no extra whitespace is inserted into a realisation if a
+ * constituent is empty. (This is to check for a bug fix for addition of
+ * spurious whitespace).
+ */
+
+ public void testExtraWhitespace()
+ {
+ var np1 = this.phraseFactory.createNounPhrase("a", "vessel");
+
+ // empty coordinate as premod
+ np1.setPreModifier(this.phraseFactory.createCoordinatedPhrase());
+ Assert.AreEqual("a vessel", this.realiser.realise(np1)
+ .getRealisation());
+
+ // empty adjP as premod
+ np1.setPreModifier(this.phraseFactory.createAdjectivePhrase());
+ Assert.AreEqual("a vessel", this.realiser.realise(np1)
+ .getRealisation());
+
+ // empty string
+ np1.setPreModifier("");
+ Assert.AreEqual("a vessel", this.realiser.realise(np1)
+ .getRealisation());
+
+ }
+
+ /**
+ * test whether sents can be embedded in a section without intervening paras
+ */
+
+ [Test]
+ public void testEmbedding()
+ {
+ var sent = this.phraseFactory.createSentence("This is a test");
+ var sent2 = this.phraseFactory.createSentence(this.phraseFactory
+ .createClause("John", "be", "missing"));
+ var section = this.phraseFactory.createSection("SECTION TITLE");
+ section.addComponent(sent);
+ section.addComponent(sent2);
+
+ Assert.AreEqual(
+ "SECTION TITLE\nThis is a test.\n\nJohn is missing.\n\n",
+ this.realiser.realise(section).getRealisation());
+ }
+
+ [Test]
+ public void testSections()
+ {
+ // doc which contains a section, and two paras
+ var doc = this.phraseFactory
+ .createDocument("Test Document");
+
+ var section = this.phraseFactory
+ .createSection("Test Section");
+ doc.addComponent(section);
+
+ var para1 = this.phraseFactory.createParagraph();
+ var sent1 = this.phraseFactory
+ .createSentence("This is the first test paragraph");
+ para1.addComponent(sent1);
+ section.addComponent(para1);
+
+ var para2 = this.phraseFactory.createParagraph();
+ var sent2 = this.phraseFactory
+ .createSentence("This is the second test paragraph");
+ para2.addComponent(sent2);
+ section.addComponent(para2);
+
+ Assert
+ .AreEqual(
+ "Test Document\n\nTest Section\nThis is the first test paragraph.\n\nThis is the second test paragraph.\n\n",
+ this.realiser.realise(doc).getRealisation());
+ //
+ // Realiser htmlRealiser = new Realiser();
+ // htmlRealiser.setHTML(true);
+ // Assert
+ // .AreEqual(
+ // "Test Document \r\nTest Section \r\nTest Subsection \r\nThis is the first test paragraph. \r\nThis is the second test paragraph. \r\n \r\n\r\n",
+ // htmlRealiser.realise(doc));
+ //
+ // // now lets try a doc with a header, header-less section and
+ // subsection,
+ // // and 2 paras (no list)
+ // doc = new TextSpec();
+ // doc.setDocument();
+ // doc.setHeading("Test Document2");
+ //
+ // section = new TextSpec();
+ // section.setDocStructure(DocStructure.SECTION);
+ // ;
+ // doc.addSpec(section);
+ //
+ // subsection = new TextSpec();
+ // subsection.setDocStructure(DocStructure.SUBSECTION);
+ // section.addSpec(subsection);
+ //
+ // // use list from above, with indent
+ // subsection.addChild(list);
+ // list.setIndentedList(false);
+ //
+ // Assert
+ // .AreEqual(
+ // "Test Document2\r\n\r\nThis is the first test paragraph.\r\n\r\nThis is the second test paragraph.\r\n",
+ // this.realiser.realise(doc));
+ //
+ // Assert
+ // .AreEqual(
+ // "Test Document2 \r\nThis is the first test paragraph.
\r\nThis is the second test paragraph.
\r\n\r\n",
+ // htmlRealiser.realise(doc));
+
+ }
+
+ /**
+ * Tests for lists and embedded lists
+ */
+
+ public void testListItems()
+ {
+ var list = this.phraseFactory.createList();
+ list.addComponent(this.phraseFactory.createListItem(p1));
+ list.addComponent(this.phraseFactory.createListItem(p2));
+ list.addComponent(this.phraseFactory.createListItem(this.phraseFactory
+ .createCoordinatedPhrase(p1, p2)));
+ var realisation = this.realiser.realise(list).getRealisation();
+ Assert.AreEqual(
+ "* you are happy\n* I am sad\n* you are happy and I am sad\n",
+ realisation);
+ }
+ }
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/ElisionTest.cs b/SharpSimpleNLGUnitTests/syntax/ElisionTest.cs
new file mode 100644
index 0000000..59a64f5
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/ElisionTest.cs
@@ -0,0 +1,97 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+ public class ElisionTest : SimpleNLG4TestBase
+ {
+
+
+ /**
+ * Test elision of phrases in various places in the sentence
+ */
+// public void testPhraseElision() {
+// SPhraseSpec s1 = this.phraseFactory.createClause();
+// s1.setSubject(this.np4); //the rock
+// this.kiss.setComplement(this.np5);//kiss the curtain
+// s1.setVerbPhrase(this.kiss);
+//
+// Assert.AreEqual("the rock kisses the curtain", this.realiser.realise(s1).getRealisation());
+//
+// //elide subject np
+// this.np4.setFeature(Feature.ELIDED, true);
+// Assert.AreEqual("kisses the curtain", this.realiser.realise(s1).getRealisation());
+//
+// //elide vp
+// this.np4.setFeature(Feature.ELIDED, false);
+// this.kiss.setFeature(Feature.ELIDED, true);
+// Assert.AreEqual("the rock", this.realiser.realise(s1).getRealisation());
+//
+// //elide complement only
+// this.kiss.setFeature(Feature.ELIDED, false);
+// this.np5.setFeature(Feature.ELIDED, true);
+// Assert.AreEqual("the rock kisses", this.realiser.realise(s1).getRealisation());
+// }
+
+/* DISABLED here as this test doesnt pass in current build of Java SimpleNLG */
+ /**
+ * Test for elision of specific words rather than phrases
+ */
+
+ //[Test]
+ public void wordElisionTest()
+ {
+ this.realiser.setDebugMode(true);
+ var s1 = this.phraseFactory.createClause();
+ s1.setSubject(this.np4); //the rock
+ this.kiss.setComplement(this.np5); //kiss the curtain
+ s1.setVerbPhrase(this.kiss);
+
+ this.np5.setFeature(Feature.ELIDED.ToString(), true);
+ Assert.AreEqual("the rock kisses", this.realiser.realise(s1).getRealisation());
+ }
+
+
+
+ /**
+ * Test for elision of specific words rather than phrases
+ *
+ [Test]
+ public void testWordElision() {
+ this.realiser.setDebugMode(true);
+ SPhraseSpec s1 = this.phraseFactory.createClause();
+ s1.setSubject(this.np4); //the rock
+ this.kiss.setComplement(this.np5);//kiss the curtain
+ s1.setVerbPhrase(this.kiss);
+
+ this.kiss.getHead().setFeature(Feature.ELIDED, true);
+ Assert.AreEqual("the rock kisses the curtain", this.realiser.realise(s1).getRealisation());
+ } */
+ }
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/FeatureTest.cs b/SharpSimpleNLGUnitTests/syntax/FeatureTest.cs
new file mode 100644
index 0000000..61916ac
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/FeatureTest.cs
@@ -0,0 +1,346 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+ /**
+ * Tests that check that realization of different Features against NLGElements.
+ *
+ * @author François Portet
+ */
+
+ public class FeatureTest : SimpleNLG4TestBase
+ {
+
+ /**
+ * Tests use of the Possessive Feature.
+ */
+
+ [Test]
+ public void testPossessiveFeature_PastTense()
+ {
+ // Create the pronoun 'she'
+ var she = this.phraseFactory.createWord("she", new LexicalCategory_PRONOUN());
+
+ // Set possessive on the pronoun to make it 'her'
+ she.setFeature(Feature.POSSESSIVE.ToString(), true);
+
+ // Create a noun phrase with the subject lover and the determiner
+ // as she
+ var herLover = this.phraseFactory.createNounPhrase(she, "lover");
+
+ // Create a clause to say 'he be her lover'
+ var clause = this.phraseFactory.createClause("he", "be", herLover);
+
+ // Add the cue phrase need the comma as orthography
+ // currently doesn't handle this.
+ // This could be expanded to be a noun phrase with determiner
+ // 'two' and noun 'week', set to plural and with a premodifier of
+ // 'after'
+ clause.setFeature(Feature.CUE_PHRASE.ToString(), "after two weeks,");
+
+ // Add the 'for a fortnight' as a post modifier. Alternatively
+ // this could be added as a prepositional phrase 'for' with a
+ // complement of a noun phrase ('a' 'fortnight')
+ clause.addPostModifier("for a fortnight");
+
+ // Set 'be' to 'was' as past tense
+ clause.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+
+ // Add the clause to a sentence.
+ var sentence1 = this.phraseFactory.createSentence(clause);
+
+ // Realise the sentence
+ var realised = this.realiser.realise(sentence1);
+
+ Assert.AreEqual("After two weeks, he was her lover for a fortnight.",
+ realised.getRealisation());
+ }
+
+ /**
+ * Basic tests.
+ */
+
+ [Test]
+ public void testTwoPossessiveFeature_PastTense()
+ {
+ // Create the pronoun 'she'
+ var she = this.phraseFactory.createWord("she", new LexicalCategory_PRONOUN());
+
+ // Set possessive on the pronoun to make it 'her'
+ she.setFeature(Feature.POSSESSIVE.ToString(), true);
+
+ // Create a noun phrase with the subject lover and the determiner
+ // as she
+ var herLover = this.phraseFactory.createNounPhrase(she, "lover");
+ herLover.setPlural(true);
+
+ // Create the pronoun 'he'
+ NLGElement he = this.phraseFactory.createNounPhrase(new LexicalCategory_PRONOUN(), "he");
+ he.setPlural(true);
+
+ // Create a clause to say 'they be her lovers'
+ var clause = this.phraseFactory.createClause(he, "be", herLover);
+ clause.setFeature(Feature.POSSESSIVE.ToString(), true);
+
+ // Add the cue phrase need the comma as orthography
+ // currently doesn't handle this.
+ // This could be expanded to be a noun phrase with determiner
+ // 'two' and noun 'week', set to plural and with a premodifier of
+ // 'after'
+ clause.setFeature(Feature.CUE_PHRASE.ToString(), "after two weeks,");
+
+ // Add the 'for a fortnight' as a post modifier. Alternatively
+ // this could be added as a prepositional phrase 'for' with a
+ // complement of a noun phrase ('a' 'fortnight')
+ clause.addPostModifier("for a fortnight");
+
+ // Set 'be' to 'was' as past tense
+ clause.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+
+ // Add the clause to a sentence.
+ var sentence1 = this.phraseFactory.createSentence(clause);
+
+ // Realise the sentence
+ var realised = this.realiser.realise(sentence1);
+
+ Assert.AreEqual("After two weeks, they were her lovers for a fortnight.",
+ realised.getRealisation());
+ }
+
+ /**
+ * Test use of the Complementiser feature by combining two S's using cue phrase and gerund.
+ */
+
+ [Test]
+ public void testComplementiserFeature_PastTense()
+ {
+ var born = this.phraseFactory.createClause("Dave Bus", "be", "born");
+ born.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ born.addPostModifier("in");
+ born.setFeature(Feature.COMPLEMENTISER.ToString(), "which");
+
+ var theHouse = this.phraseFactory.createNounPhrase("the", "house");
+ theHouse.addComplement(born);
+
+ var clause = this.phraseFactory.createClause(theHouse, "be",
+ this.phraseFactory.createPrepositionPhrase("in", "Edinburgh"));
+ var sentence = this.phraseFactory.createSentence(clause);
+ var realised = this.realiser.realise(sentence);
+
+ // Retrieve the realisation and dump it to the console
+ Assert.AreEqual("The house which Dave Bus was born in is in Edinburgh.",
+ realised.getRealisation());
+ }
+
+ /**
+ * Test use of the Complementiser feature in a {@link CoordinatedPhraseElement} by combine two S's using cue phrase and gerund.
+ */
+
+ [Test]
+ public void testComplementiserFeatureInACoordinatePhrase_PastTense()
+ {
+ var dave = this.phraseFactory.createWord("Dave Bus", new LexicalCategory_NOUN());
+ var albert = this.phraseFactory.createWord("Albert", new LexicalCategory_NOUN());
+
+ var coord1 = new CoordinatedPhraseElement(
+ dave, albert);
+
+ var born = this.phraseFactory.createClause(coord1, "be", "born");
+ born.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ born.addPostModifier("in");
+ born.setFeature(Feature.COMPLEMENTISER.ToString(), "which");
+
+ var theHouse = this.phraseFactory.createNounPhrase("the", "house");
+ theHouse.addComplement(born);
+
+ var clause = this.phraseFactory.createClause(theHouse, "be",
+ this.phraseFactory.createPrepositionPhrase("in", "Edinburgh"));
+ var sentence = this.phraseFactory.createSentence(clause);
+
+ var realised = this.realiser.realise(sentence);
+
+ // Retrieve the realisation and dump it to the console
+ Assert.AreEqual("The house which Dave Bus and Albert were born in is in Edinburgh.",
+ realised.getRealisation());
+ }
+
+ /**
+ * Test the use of the Progressive and Complementiser Features in future tense.
+ */
+
+ [Test]
+ public void testProgressiveAndComplementiserFeatures_FutureTense()
+ {
+ // Inner clause is 'I' 'make' 'sentence' 'for'.
+ var inner = this.phraseFactory.createClause("I", "make", "sentence for");
+ // Inner clause set to progressive.
+ inner.setFeature(Feature.PROGRESSIVE.ToString(), true);
+
+ //Complementiser on inner clause is 'whom'
+ inner.setFeature(Feature.COMPLEMENTISER.ToString(), "whom");
+
+ // create the engineer and add the inner clause as post modifier
+ var engineer = this.phraseFactory.createNounPhrase("the engineer");
+ engineer.addComplement(inner);
+
+ // Outer clause is: 'the engineer' 'go' (preposition 'to' 'holidays')
+ var outer = this.phraseFactory.createClause(engineer, "go",
+ this.phraseFactory.createPrepositionPhrase("to", "holidays"));
+
+ // Outer clause tense is Future.
+ outer.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+
+ // Possibly progressive as well not sure.
+ outer.setFeature(Feature.PROGRESSIVE.ToString(), true);
+
+ //Outer clause postmodifier would be 'tomorrow'
+ outer.addPostModifier("tomorrow");
+ var sentence = this.phraseFactory.createSentence(outer);
+ var realised = this.realiser.realise(sentence);
+
+ // Retrieve the realisation and dump it to the console
+ Assert.AreEqual("The engineer whom I am making sentence for will be going to holidays tomorrow.",
+ realised.getRealisation());
+ }
+
+
+ /**
+ * Tests the use of the Complementiser, Passive, Perfect features in past tense.
+ */
+
+ [Test]
+ public void testComplementiserPassivePerfectFeatures_PastTense()
+ {
+ var inner = this.phraseFactory.createClause("I", "play", "poker");
+ inner.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ inner.setFeature(Feature.COMPLEMENTISER.ToString(), "where");
+
+ var house = this.phraseFactory.createNounPhrase("the", "house");
+ house.addComplement(inner);
+
+ var outer = this.phraseFactory.createClause(null, "abandon", house);
+
+ outer.addPostModifier("since 1986");
+
+ outer.setFeature(Feature.PASSIVE.ToString(), true);
+ outer.setFeature(Feature.PERFECT.ToString(), true);
+
+ var sentence = this.phraseFactory.createSentence(outer);
+ var realised = this.realiser.realise(sentence);
+
+ // Retrieve the realisation and dump it to the console
+ Assert.AreEqual("The house where I played poker has been abandoned since 1986.",
+ realised.getRealisation());
+ }
+
+ /**
+ * Tests the user of the progressive and complementiser featuers in past tense.
+ */
+
+ [Test]
+ public void testProgressiveComplementiserFeatures_PastTense()
+ {
+ var sandwich = this.phraseFactory.createNounPhrase(new LexicalCategory_NOUN(), "sandwich");
+ sandwich.setPlural(true);
+ //
+ var first = this.phraseFactory.createClause("I", "make", sandwich);
+ first.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ first.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ first.setPlural(false);
+
+ var second = this.phraseFactory.createClause("the mayonnaise", "run out");
+ second.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ //
+ second.setFeature(Feature.COMPLEMENTISER.ToString(), "when");
+
+ first.addComplement(second);
+
+ var sentence = this.phraseFactory.createSentence(first);
+ var realised = this.realiser.realise(sentence);
+
+ // Retrieve the realisation and dump it to the console
+ Assert.AreEqual("I was making sandwiches when the mayonnaise ran out.",
+ realised.getRealisation());
+ }
+
+ /**
+ * Test the use of Passive in creating a Passive sentence structure: + [be] + + [by] + [Subject].
+ */
+
+ [Test]
+ public void testPassiveFeature()
+ {
+ var phrase = this.phraseFactory.createClause("recession", "affect", "value");
+ phrase.setFeature(Feature.PASSIVE.ToString(), true);
+ var sentence = this.phraseFactory.createSentence(phrase);
+ var realised = this.realiser.realise(sentence);
+
+ Assert.AreEqual("Value is affected by recession.", realised.getRealisation());
+ }
+
+
+ /**
+ * Test for repetition of the future auxiliary "will", courtesy of Luxor
+ * Vlonjati
+ */
+
+ [Test]
+ public void testFutureTense()
+ {
+ var test = this.phraseFactory.createClause();
+
+ var subj = this.phraseFactory.createNounPhrase("I");
+
+ var verb = this.phraseFactory.createVerbPhrase("go");
+
+ var adverb = this.phraseFactory
+ .createAdverbPhrase("tomorrow");
+
+ test.setSubject(subj);
+ test.setVerbPhrase(verb);
+ test.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ test.addPostModifier(adverb);
+ var sentence = this.realiser.realiseSentence(test);
+ Assert.AreEqual("I will go tomorrow.", sentence);
+
+ var test2 = this.phraseFactory.createClause();
+ var vb = this.phraseFactory.createWord("go", new LexicalCategory_VERB());
+ test2.setSubject(subj);
+ test2.setVerb(vb);
+ test2.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ test2.addPostModifier(adverb);
+ var sentence2 = this.realiser.realiseSentence(test);
+ Assert.AreEqual("I will go tomorrow.", sentence2);
+
+ }
+
+
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/HTMLFormatterTest.cs b/SharpSimpleNLGUnitTests/syntax/HTMLFormatterTest.cs
new file mode 100644
index 0000000..6306455
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/HTMLFormatterTest.cs
@@ -0,0 +1,138 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Test;
+
+import simplenlg.format.english.HTMLFormatter;
+import simplenlg.framework.DocumentElement;
+import simplenlg.framework.NLGElement;
+import simplenlg.phrasespec.SPhraseSpec;
+
+// HTMLFormatter and HTMLFormatterTest ~ author James Christie, but taken from TextFormatter and TextFormatterTest
+
+public class HTMLFormatterTest extends SimpleNLG4Test {
+
+ /**
+ * Instantiates a new document element test.
+ *
+ * @param name
+ * the name
+ */
+ public HTMLFormatterTest(String name) {
+ super(name);
+ }
+
+ @Override
+ @After
+ public void tearDown() {
+ super.tearDown();
+ }
+
+
+ /**
+ * Check the correct [part] web page contents are being generated
+ */
+ [Test]
+ public final void testWebPageContent( ) {
+ // now build a document ...
+ DocumentElement document = phraseFactory.createDocument( "This is a title" ) ;
+
+ DocumentElement section = phraseFactory.createSection( "This is a section" ) ;
+
+ DocumentElement paragraph1 = phraseFactory.createParagraph( ) ;
+ DocumentElement sentence11 = phraseFactory.createSentence( "This is the first sentence of paragraph 1" ) ;
+ paragraph1.addComponent( sentence11 ) ;
+ DocumentElement sentence12 = phraseFactory.createSentence( "This is the second sentence of paragraph 1" ) ;
+ paragraph1.addComponent( sentence12 ) ;
+ section.addComponent( paragraph1 ) ;
+ document.addComponent( section ) ;
+
+ DocumentElement paragraph2 = phraseFactory.createParagraph( ) ;
+ DocumentElement sentence2 = phraseFactory.createSentence( "This is the first sentence of paragraph 2" ) ;
+ paragraph2.addComponent( sentence2 ) ;
+ document.addComponent( paragraph2 ) ;
+
+ DocumentElement paragraph3 = phraseFactory.createParagraph( ) ;
+ DocumentElement sentence3 = phraseFactory.createSentence( "This is the first sentence of paragraph 3" ) ;
+ paragraph3.addComponent( sentence3 ) ;
+ document.addComponent( paragraph3 ) ;
+
+ // now for a second section with three sentences in one paragraph using arrays.asList function
+ SPhraseSpec p1 = phraseFactory.createClause( "Mary", "chase", "the monkey" ) ;
+ SPhraseSpec p2 = phraseFactory.createClause( "the monkey", "fight back" ) ;
+ SPhraseSpec p3 = phraseFactory.createClause( "Mary", "be", "nervous" ) ;
+
+ DocumentElement s1 = phraseFactory.createSentence( p1 ) ;
+ DocumentElement s2 = phraseFactory.createSentence( p2 ) ;
+ DocumentElement s3 = phraseFactory.createSentence( p3 ) ;
+
+ DocumentElement para1x3 = phraseFactory.createParagraph( Arrays.asList( s1, s2, s3 ) ) ;
+
+ DocumentElement sectionList = phraseFactory.createSection( "This section contains lists" ) ;
+ sectionList.addComponent( para1x3 ) ;
+ document.addComponent( sectionList ) ;
+
+ // from David Westwater 4-10-11
+ DocumentElement element = phraseFactory.createList( ) ;
+ List < NLGElement > list = new ArrayList < NLGElement > ( ) ;
+ list.add( phraseFactory.createListItem( phraseFactory.createStringElement( "Item 1" ) ) ) ;
+ list.add( phraseFactory.createListItem( phraseFactory.createStringElement( "Item 2" ) ) ) ;
+ list.add( phraseFactory.createListItem( phraseFactory.createStringElement( "Item 3" ) ) ) ;
+
+ element.addComponents( list ) ;
+ document.addComponent( element ) ;
+
+ // ... finally produce some output with HMTL tags ...
+ System.out.println( "HTML realisation ~ \n=============================\n" ) ;
+
+ String output = "" ;
+
+ // this.realiser.setFormatter( new TextFormatter( ) ) ;
+ this.realiser.setFormatter( new HTMLFormatter( ) ) ;
+ // realiser.setDebugMode( true ) ; // hide after testing
+ output += realiser.realise( document ).getRealisation( ) ;
+
+ System.out.println( output ) ; // just to visually check what is being produced
+
+ String expectedResults =
+ "This is a title " +
+ "This is a section " +
+ "This is the first sentence of paragraph 1. This is the second sentence of paragraph 1.
" +
+ "This is the first sentence of paragraph 2.
" +
+ "This is the first sentence of paragraph 3.
" +
+ "This section contains lists " +
+ "Mary chases the monkey. The monkey fights back. Mary is nervous.
" +
+ "" +
+ "Item 1 " +
+ "Item 2 " +
+ "Item 3 " +
+ " " ;
+
+ Equals( expectedResults, output ) ; // when realisation is working then complete this test
+ } // testWebPageContents
+} // class
+
+
diff --git a/SharpSimpleNLGUnitTests/syntax/InterrogativeTest.cs b/SharpSimpleNLGUnitTests/syntax/InterrogativeTest.cs
new file mode 100644
index 0000000..38190b2
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/InterrogativeTest.cs
@@ -0,0 +1,847 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+ /**
+ * JUnit test case for interrogatives.
+ *
+ * @author agatt
+ */
+
+ public class InterrogativeTest : SimpleNLG4TestBase
+ {
+
+ // set up a few more fixtures
+ /** The s5. */
+
+
+ [SetUp]
+ protected override void setUp()
+ {
+
+ // // the man gives the woman John's flower
+ var john = this.phraseFactory.createNounPhrase("John");
+ john.setFeature(Feature.POSSESSIVE.ToString(), true);
+ var flower = this.phraseFactory.createNounPhrase(john,
+ "flower");
+ var _woman = this.phraseFactory.createNounPhrase(
+ "the", "woman");
+ s3 = this.phraseFactory.createClause(this.man, this.give, flower);
+ s3.setIndirectObject(_woman);
+
+ var subjects = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"),
+ this.phraseFactory.createNounPhrase("Andrew"));
+ s4 = this.phraseFactory.createClause(subjects, "pick up",
+ "the balls");
+ s4.addPostModifier("in the shop");
+ s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
+ s4.addFrontModifier("tomorrow");
+ s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ // s5 = new SPhraseSpec();
+ // s5.setSubject(new NPPhraseSpec("the", "dog"));
+ // s5.setHead("be");
+ // s5.setComplement(new NPPhraseSpec("the", "rock"),
+ // DiscourseFunction.OBJECT);
+
+ }
+
+ /**
+ * Tests a couple of fairly simple questions.
+ */
+
+ [Test]
+ public void testSimpleQuestions()
+ {
+ setUp();
+ this.phraseFactory.setLexicon(this.lexicon);
+ this.realiser.setLexicon(this.lexicon);
+
+ // simple present
+ s1 = this.phraseFactory.createClause(this.woman, this.kiss,
+ this.man);
+ s1.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
+ s1.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+
+ var docFactory = new NLGFactory(this.lexicon);
+ var sent = docFactory.createSentence(s1);
+ Assert.AreEqual("Does the woman kiss the man?", this.realiser
+ .realise(sent).getRealisation());
+
+ // simple past
+ // sentence: "the woman kissed the man"
+ s1 = this.phraseFactory.createClause(this.woman, this.kiss,
+ this.man);
+ s1.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ s1.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ Assert.AreEqual("did the woman kiss the man", this.realiser
+ .realise(s1).getRealisation());
+
+ // copular/existential: be-fronting
+ // sentence = "there is the dog on the rock"
+ s2 = this.phraseFactory.createClause("there", "be", this.dog);
+ s2.addPostModifier(this.onTheRock);
+ s2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ Assert.AreEqual("is there the dog on the rock", this.realiser
+ .realise(s2).getRealisation());
+
+ // perfective
+ // sentence -- "there has been the dog on the rock"
+ s2 = this.phraseFactory.createClause("there", "be", this.dog);
+ s2.addPostModifier(this.onTheRock);
+ s2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ s2.setFeature(Feature.PERFECT.ToString(), true);
+ Assert.AreEqual("has there been the dog on the rock",
+ this.realiser.realise(s2).getRealisation());
+
+ // progressive
+ // sentence: "the man was giving the woman John's flower"
+ var john = this.phraseFactory.createNounPhrase("John");
+ john.setFeature(Feature.POSSESSIVE.ToString(), true);
+ var flower = this.phraseFactory.createNounPhrase(john,
+ "flower");
+ var _woman = this.phraseFactory.createNounPhrase(
+ "the", "woman");
+ s3 = this.phraseFactory.createClause(this.man, this.give, flower);
+ s3.setIndirectObject(_woman);
+ s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ s3.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ s3.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ var realised = this.realiser.realise(s3);
+ Assert.AreEqual("was the man giving the woman John's flower",
+ realised.getRealisation());
+
+ // modal
+ // sentence: "the man should be giving the woman John's flower"
+ setUp();
+ john = this.phraseFactory.createNounPhrase("John");
+ john.setFeature(Feature.POSSESSIVE.ToString(), true);
+ flower = this.phraseFactory.createNounPhrase(john, "flower");
+ _woman = this.phraseFactory.createNounPhrase("the", "woman");
+ s3 = this.phraseFactory.createClause(this.man, this.give, flower);
+ s3.setIndirectObject(_woman);
+ s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ s3.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ s3.setFeature(Feature.MODAL.ToString(), "should");
+ Assert.AreEqual(
+ "should the man have given the woman John's flower",
+ this.realiser.realise(s3).getRealisation());
+
+ // complex case with cue phrases
+ // sentence: "however, tomorrow, Jane and Andrew will pick up the balls
+ // in the shop"
+ // this gets the front modifier "tomorrow" shifted to the end
+ setUp();
+ var subjects = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"),
+ this.phraseFactory.createNounPhrase("Andrew"));
+ s4 = this.phraseFactory.createClause(subjects, "pick up",
+ "the balls");
+ s4.addPostModifier("in the shop");
+ s4.setFeature(Feature.CUE_PHRASE.ToString(), "however,");
+ s4.addFrontModifier("tomorrow");
+ s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ Assert.AreEqual(
+ "however, will Jane and Andrew pick up the balls in the shop tomorrow",
+ this.realiser.realise(s4).getRealisation());
+ }
+
+ /**
+ * Test for sentences with negation.
+ */
+
+ [Test]
+ public void testNegatedQuestions()
+ {
+ setUp();
+ this.phraseFactory.setLexicon(this.lexicon);
+ this.realiser.setLexicon(this.lexicon);
+
+ // sentence: "the woman did not kiss the man"
+ s1 = this.phraseFactory.createClause(this.woman, "kiss", this.man);
+ s1.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ s1.setFeature(Feature.NEGATED.ToString(), true);
+ s1.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ Assert.AreEqual("did the woman not kiss the man", this.realiser
+ .realise(s1).getRealisation());
+
+ // sentence: however, tomorrow, Jane and Andrew will not pick up the
+ // balls in the shop
+ var subjects = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"),
+ this.phraseFactory.createNounPhrase("Andrew"));
+ s4 = this.phraseFactory.createClause(subjects, "pick up",
+ "the balls");
+ s4.addPostModifier("in the shop");
+ s4.setFeature(Feature.CUE_PHRASE.ToString(), "however,");
+ s4.addFrontModifier("tomorrow");
+ s4.setFeature(Feature.NEGATED.ToString(), true);
+ s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ Assert.AreEqual(
+ "however, will Jane and Andrew not pick up the balls in the shop tomorrow",
+ this.realiser.realise(s4).getRealisation());
+ }
+
+ /**
+ * Tests for coordinate VPs in question form.
+ */
+
+ // Disabled due to test setup issues [Test]
+ public void testCoordinateVPQuestions()
+ {
+
+ // create a complex vp: "kiss the dog and walk in the room"
+ reset();
+ var complex = new CoordinatedPhraseElement(this.kiss, this.walk);
+ this.kiss.addComplement(this.dog);
+ this.walk.addComplement(this.inTheRoom);
+
+ // sentence: "However, tomorrow, Jane and Andrew will kiss the dog and
+ // will walk in the room"
+ var subjects = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"),
+ this.phraseFactory.createNounPhrase("Andrew"));
+ s4 = this.phraseFactory.createClause(subjects, complex);
+ s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
+ s4.addFrontModifier("tomorrow");
+ s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+
+ Assert.AreEqual(
+ "however tomorrow Jane and Andrew will kiss the dog and will walk in the room",
+ this.realiser.realise(s4).getRealisation());
+
+ // setting to interrogative should automatically give us a single,
+ // wide-scope aux
+ reset();
+ subjects = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"),
+ this.phraseFactory.createNounPhrase("Andrew"));
+ complex = new CoordinatedPhraseElement(this.kiss, this.walk);
+ s4 = this.phraseFactory.createClause(subjects, complex);
+ s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
+ s4.addFrontModifier("tomorrow");
+ s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+
+ Assert.AreEqual(
+ "however will Jane and Andrew kiss the dog and walk in the room tomorrow",
+ this.realiser.realise(s4).getRealisation());
+
+ // slightly more complex -- perfective
+ reset();
+ this.realiser.setLexicon(this.lexicon);
+ subjects = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"),
+ this.phraseFactory.createNounPhrase("Andrew"));
+ complex = new CoordinatedPhraseElement(this.kiss, this.walk);
+ this.kiss.addComplement(this.dog);
+ this.walk.addComplement(this.inTheRoom);
+ s4 = this.phraseFactory.createClause(subjects, complex);
+ s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
+ s4.addFrontModifier("tomorrow");
+ s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ s4.setFeature(Feature.PERFECT.ToString(), true);
+
+ Assert.AreEqual(
+ "however will Jane and Andrew have kissed the dog and walked in the room tomorrow",
+ this.realiser.realise(s4).getRealisation());
+ }
+
+ /**
+ * Test for simple WH questions in present tense.
+ */
+
+ [Test]
+ public void testSimpleQuestions2()
+ {
+ setUp();
+ this.realiser.setLexicon(this.lexicon);
+ var s = this.phraseFactory.createClause("the woman", "kiss",
+ "the man");
+
+ // try with the simple yes/no type first
+ s.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ Assert.AreEqual("does the woman kiss the man", this.realiser
+ .realise(s).getRealisation());
+
+ // now in the passive
+ s = this.phraseFactory.createClause("the woman", "kiss",
+ "the man");
+ s.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ s.setFeature(Feature.PASSIVE.ToString(), true);
+ Assert.AreEqual("is the man kissed by the woman", this.realiser
+ .realise(s).getRealisation());
+
+ // // subject interrogative with simple present
+ // // sentence: "the woman kisses the man"
+ s = this.phraseFactory.createClause("the woman", "kiss",
+ "the man");
+ s.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
+
+ Assert.AreEqual("who kisses the man", this.realiser.realise(s)
+ .getRealisation());
+
+ // object interrogative with simple present
+ s = this.phraseFactory.createClause("the woman", "kiss",
+ "the man");
+ s.setFeature(Feature.INTERROGATIVE_TYPE.ToString().ToString(), InterrogativeType.WHO_OBJECT);
+ Assert.AreEqual("who does the woman kiss", this.realiser
+ .realise(s).getRealisation());
+
+ // subject interrogative with passive
+ s = this.phraseFactory.createClause("the woman", "kiss",
+ "the man");
+ s.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
+ s.setFeature(Feature.PASSIVE.ToString(), true);
+ Assert.AreEqual("who is the man kissed by", this.realiser
+ .realise(s).getRealisation());
+ }
+
+ /**
+ * Test for wh questions.
+ */
+
+ [Test]
+ public void testWHQuestions()
+ {
+
+ // subject interrogative
+ setUp();
+ this.realiser.setLexicon(this.lexicon);
+ s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
+ InterrogativeType.WHO_SUBJECT);
+ Assert.AreEqual(
+ "however who will pick up the balls in the shop tomorrow",
+ this.realiser.realise(s4).getRealisation());
+
+ // subject interrogative in passive
+ setUp();
+ s4.setFeature(Feature.PASSIVE.ToString(), true);
+ s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
+ InterrogativeType.WHO_SUBJECT);
+
+ Assert.AreEqual(
+ "however who will the balls be picked up in the shop by tomorrow",
+ this.realiser.realise(s4).getRealisation());
+
+ // object interrogative
+ setUp();
+ s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
+ InterrogativeType.WHAT_OBJECT);
+ Assert.AreEqual(
+ "however what will Jane and Andrew pick up in the shop tomorrow",
+ this.realiser.realise(s4).getRealisation());
+
+ // object interrogative with passive
+ setUp();
+ s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
+ InterrogativeType.WHAT_OBJECT);
+ s4.setFeature(Feature.PASSIVE.ToString(), true);
+
+ Assert.AreEqual(
+ "however what will be picked up in the shop by Jane and Andrew tomorrow",
+ this.realiser.realise(s4).getRealisation());
+
+ // how-question + passive
+ setUp();
+ s4.setFeature(Feature.PASSIVE.ToString(), true);
+ s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.HOW);
+ Assert.AreEqual(
+ "however how will the balls be picked up in the shop by Jane and Andrew tomorrow",
+ this.realiser.realise(s4).getRealisation());
+
+ // // why-question + passive
+ setUp();
+ s4.setFeature(Feature.PASSIVE.ToString(), true);
+ s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
+ Assert.AreEqual(
+ "however why will the balls be picked up in the shop by Jane and Andrew tomorrow",
+ this.realiser.realise(s4).getRealisation());
+
+ // how question with modal
+ setUp();
+ s4.setFeature(Feature.PASSIVE.ToString(), true);
+ s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.HOW);
+ s4.setFeature(Feature.MODAL.ToString(), "should");
+ Assert.AreEqual(
+ "however how should the balls be picked up in the shop by Jane and Andrew tomorrow",
+ this.realiser.realise(s4).getRealisation());
+
+ // indirect object
+ setUp();
+ this.realiser.setLexicon(this.lexicon);
+ s3.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
+ InterrogativeType.WHO_INDIRECT_OBJECT);
+ Assert.AreEqual("who does the man give John's flower to",
+ this.realiser.realise(s3).getRealisation());
+ }
+
+ /**
+ * WH movement in the progressive
+ */
+
+ [Test]
+ public void testProgrssiveWHSubjectQuestions()
+ {
+ var p = this.phraseFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("eat");
+ p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
+ p.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
+ Assert.AreEqual("who is eating the pie",
+ this.realiser.realise(p).getRealisation());
+ }
+
+ /**
+ * WH movement in the progressive
+ */
+
+ [Test]
+ public void testProgrssiveWHObjectQuestions()
+ {
+ var p = this.phraseFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("eat");
+ p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
+ p.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
+ Assert.AreEqual("what is Mary eating",
+ this.realiser.realise(p).getRealisation());
+
+ // AG -- need to check this; it doesn't work
+ // p.setFeature(Feature.NEGATED, true);
+ // Assert.AreEqual("what is Mary not eating",
+ // this.realiser.realise(p).getRealisation());
+
+ }
+
+ /**
+ * Negation with WH movement for subject
+ */
+
+ [Test]
+ public void testNegatedWHSubjQuestions()
+ {
+ var p = this.phraseFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("eat");
+ p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
+ p.setFeature(Feature.NEGATED.ToString(), true);
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
+ Assert.AreEqual("who does not eat the pie",
+ this.realiser.realise(p).getRealisation());
+ }
+
+ /**
+ * Negation with WH movement for object
+ */
+
+ [Test]
+ public void testNegatedWHObjQuestions()
+ {
+ var p = this.phraseFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("eat");
+ p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
+ p.setFeature(Feature.NEGATED.ToString(), true);
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
+ var realisation = this.realiser.realise(p);
+ Assert.AreEqual("what does Mary not eat",
+ realisation.getRealisation());
+ }
+
+ /**
+ * Test questyions in the tutorial.
+ */
+
+ [Test]
+ public void testTutorialQuestions()
+ {
+ setUp();
+ this.realiser.setLexicon(this.lexicon);
+
+ var p = this.phraseFactory.createClause("Mary", "chase",
+ "George");
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ Assert.AreEqual("does Mary chase George", this.realiser.realise(p)
+ .getRealisation());
+
+ p = this.phraseFactory.createClause("Mary", "chase",
+ "George");
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
+ Assert.AreEqual("who does Mary chase", this.realiser.realise(p)
+ .getRealisation());
+
+ }
+
+ /**
+ * Subject WH Questions with modals
+ */
+
+ [Test]
+ public void testModalWHSubjectQuestion()
+ {
+ var p = this.phraseFactory.createClause(this.dog, "upset",
+ this.man);
+ p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ Assert.AreEqual("the dog upset the man", this.realiser.realise(p)
+ .getRealisation());
+
+ // first without modal
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
+ Assert.AreEqual("who upset the man", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
+ Assert.AreEqual("what upset the man", this.realiser.realise(p)
+ .getRealisation());
+
+ // now with modal auxiliary
+ p.setFeature(Feature.MODAL.ToString(), "may");
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
+ Assert.AreEqual("who may have upset the man", this.realiser
+ .realise(p).getRealisation());
+
+ p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ Assert.AreEqual("who may upset the man", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
+ Assert.AreEqual("what may have upset the man", this.realiser
+ .realise(p).getRealisation());
+
+ p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ Assert.AreEqual("what may upset the man", this.realiser.realise(p)
+ .getRealisation());
+ }
+
+ /**
+ * Subject WH Questions with modals
+ */
+
+ [Test]
+ public void testModalWHObjectQuestion()
+ {
+ var p = this.phraseFactory.createClause(this.dog, "upset",
+ this.man);
+ p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
+
+ Assert.AreEqual("who did the dog upset", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.MODAL.ToString(), "may");
+ Assert.AreEqual("who may the dog have upset", this.realiser
+ .realise(p).getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
+ Assert.AreEqual("what may the dog have upset", this.realiser
+ .realise(p).getRealisation());
+
+ p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
+ Assert.AreEqual("who may the dog upset", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
+ Assert.AreEqual("what may the dog upset", this.realiser.realise(p)
+ .getRealisation());
+ }
+
+ /**
+ * Questions with tenses requiring auxiliaries + subject WH
+ */
+
+ [Test]
+ public void testAuxWHSubjectQuestion()
+ {
+ var p = this.phraseFactory.createClause(this.dog, "upset",
+ this.man);
+ p.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
+ p.setFeature(Feature.PERFECT.ToString(), true);
+ Assert.AreEqual("the dog has upset the man",
+ this.realiser.realise(p).getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
+ Assert.AreEqual("who has upset the man", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
+ Assert.AreEqual("what has upset the man", this.realiser.realise(p)
+ .getRealisation());
+ }
+
+ /**
+ * Questions with tenses requiring auxiliaries + subject WH
+ */
+
+ [Test]
+ public void testAuxWHObjectQuestion()
+ {
+ var p = this.phraseFactory.createClause(this.dog, "upset",
+ this.man);
+
+ // first without any aux
+ p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
+ Assert.AreEqual("what did the dog upset", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
+ Assert.AreEqual("who did the dog upset", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
+ p.setFeature(Feature.PERFECT.ToString().ToString(), true);
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
+ Assert.AreEqual("who has the dog upset", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
+ Assert.AreEqual("what has the dog upset", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ p.setFeature(Feature.PERFECT.ToString(), true);
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
+ Assert.AreEqual("who will the dog have upset", this.realiser
+ .realise(p).getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
+ Assert.AreEqual("what will the dog have upset", this.realiser
+ .realise(p).getRealisation());
+
+ }
+
+ /**
+ * Test for questions with "be"
+ */
+
+ [Test]
+ public void testBeQuestions()
+ {
+ var p = this.phraseFactory.createClause(
+ this.phraseFactory.createNounPhrase("a", "ball"),
+ this.phraseFactory.createWord("be", new LexicalCategory_VERB()),
+ this.phraseFactory.createNounPhrase("a", "toy"));
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
+ Assert.AreEqual("what is a ball", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ Assert.AreEqual("is a ball a toy", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
+ Assert.AreEqual("what is a toy", this.realiser.realise(p)
+ .getRealisation());
+
+ var p2 = this.phraseFactory.createClause("Mary", "be",
+ "beautiful");
+ p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
+ Assert.AreEqual("why is Mary beautiful", this.realiser.realise(p2)
+ .getRealisation());
+
+ p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHERE);
+ Assert.AreEqual("where is Mary beautiful", this.realiser.realise(p2)
+ .getRealisation());
+
+ p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
+ Assert.AreEqual("who is beautiful", this.realiser.realise(p2)
+ .getRealisation());
+ }
+
+ /**
+ * Test for questions with "be" in future tense
+ */
+
+ [Test]
+ public void testBeQuestionsFuture()
+ {
+ var p = this.phraseFactory.createClause(
+ this.phraseFactory.createNounPhrase("a", "ball"),
+ this.phraseFactory.createWord("be", new LexicalCategory_VERB()),
+ this.phraseFactory.createNounPhrase("a", "toy"));
+ p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
+ Assert.AreEqual("what will a ball be", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ Assert.AreEqual("will a ball be a toy", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
+ Assert.AreEqual("what will be a toy", this.realiser.realise(p)
+ .getRealisation());
+
+ var p2 = this.phraseFactory.createClause("Mary", "be",
+ "beautiful");
+ p2.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
+ Assert.AreEqual("why will Mary be beautiful", this.realiser
+ .realise(p2).getRealisation());
+
+ p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHERE);
+ Assert.AreEqual("where will Mary be beautiful", this.realiser
+ .realise(p2).getRealisation());
+
+ p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
+ Assert.AreEqual("who will be beautiful", this.realiser.realise(p2)
+ .getRealisation());
+ }
+
+ /**
+ * Tests for WH questions with be in past tense
+ */
+
+ [Test]
+ public void testBeQuestionsPast()
+ {
+ var p = this.phraseFactory.createClause(
+ this.phraseFactory.createNounPhrase("a", "ball"),
+ this.phraseFactory.createWord("be", new LexicalCategory_VERB()),
+ this.phraseFactory.createNounPhrase("a", "toy"));
+ p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
+ Assert.AreEqual("what was a ball", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ Assert.AreEqual("was a ball a toy", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
+ Assert.AreEqual("what was a toy", this.realiser.realise(p)
+ .getRealisation());
+
+ var p2 = this.phraseFactory.createClause("Mary", "be",
+ "beautiful");
+ p2.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
+ Assert.AreEqual("why was Mary beautiful", this.realiser.realise(p2)
+ .getRealisation());
+
+ p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHERE);
+ Assert.AreEqual("where was Mary beautiful", this.realiser.realise(p2)
+ .getRealisation());
+
+ p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
+ Assert.AreEqual("who was beautiful", this.realiser.realise(p2)
+ .getRealisation());
+ }
+
+
+ /**
+ * Test WHERE, HOW and WHY questions, with copular predicate "be"
+ */
+
+ public void testSimpleBeWHQuestions()
+ {
+ var p = this.phraseFactory.createClause("I", "be");
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHERE);
+ Assert.AreEqual("Where am I?", this.realiser.realiseSentence(p));
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
+ Assert.AreEqual("Why am I?", this.realiser.realiseSentence(p));
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.HOW);
+ Assert.AreEqual("How am I?", this.realiser.realiseSentence(p));
+
+ }
+
+ /**
+ * Test a simple "how" question, based on query from Albi Oxa
+ */
+
+ [Test]
+ public void testHowPredicateQuestion()
+ {
+ var test = this.phraseFactory.createClause();
+ var subject = this.phraseFactory.createNounPhrase("You");
+
+ subject.setFeature(Feature.PRONOMINAL.ToString(), true);
+ subject.setFeature(Feature.PERSON.ToString(), Person.SECOND);
+ test.setSubject(subject);
+ test.setVerb("be");
+
+ test.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
+ InterrogativeType.HOW_PREDICATE);
+ test.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
+
+ var result = this.realiser.realiseSentence(test);
+ Assert.AreEqual("How are you?", result);
+
+ }
+
+ /**
+ * Case 1 checks that "What do you think about John?" can be generated.
+ *
+ * Case 2 checks that the same clause is generated, even when an object is
+ * declared.
+ */
+
+ [Test]
+ public void testWhatObjectInterrogative()
+ {
+ var lexicon = Lexicon.getDefaultLexicon();
+ var nlg = new NLGFactory(lexicon);
+ var realiser = new Realiser(lexicon);
+
+ // Case 1, no object is explicitly given:
+ var clause = nlg.createClause("you", "think");
+ var aboutJohn = nlg.createPrepositionPhrase("about", "John");
+ clause.addPostModifier(aboutJohn);
+ clause.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
+ InterrogativeType.WHAT_OBJECT);
+ var realisation = realiser.realiseSentence(clause);
+ Assert.AreEqual("What do you think about John?", realisation);
+
+ // Case 2:
+ // Add "bad things" as the object so the object doesn't remain null:
+ clause.setObject("bad things");
+ realisation = realiser.realiseSentence(clause);
+ Assert.AreEqual("What do you think about John?", realisation);
+ }
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/NounPhraseTest.cs b/SharpSimpleNLGUnitTests/syntax/NounPhraseTest.cs
new file mode 100644
index 0000000..48f52b3
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/NounPhraseTest.cs
@@ -0,0 +1,643 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using System;
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+ /**
+ * Tests for the NPPhraseSpec and CoordinateNPPhraseSpec classes.
+ *
+ * @author agatt
+ */
+
+ public class NounPhraseTest : SimpleNLG4TestBase
+ {
+
+
+ /**
+ * Test the setPlural() method in noun phrases.
+ */
+
+ [Test]
+ public void testPlural()
+ {
+ this.np4.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+ Assert.AreEqual(
+ "the rocks", this.realiser.realise(this.np4).getRealisation());
+
+
+ this.np5.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+ Assert
+ .AreEqual(
+ "the curtains", this.realiser.realise(this.np5).getRealisation());
+
+
+ this.np5.setFeature(Feature.NUMBER.ToString(), NumberAgreement.SINGULAR);
+ Assert.AreEqual(NumberAgreement.SINGULAR, this.np5
+ .getFeature(Feature.NUMBER.ToString()));
+ Assert
+ .AreEqual(
+ "the curtain", this.realiser.realise(this.np5).getRealisation());
+
+
+ this.np5.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+ Assert
+ .AreEqual(
+ "the curtains", this.realiser.realise(this.np5).getRealisation());
+
+ }
+
+ /**
+ * Test the pronominalisation method for full NPs.
+ */
+
+ [Test]
+ public void testPronominalisation()
+ {
+ // sing
+ this.proTest1.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
+ this.proTest1.setFeature(Feature.PRONOMINAL.ToString(), true);
+ Assert.AreEqual(
+ "she", this.realiser.realise(this.proTest1).getRealisation());
+
+
+ // sing, possessive
+ this.proTest1.setFeature(Feature.POSSESSIVE.ToString(), true);
+ Assert.AreEqual(
+ "her", this.realiser.realise(this.proTest1).getRealisation());
+
+
+ // plural pronoun
+ this.proTest2.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+ this.proTest2.setFeature(Feature.PRONOMINAL.ToString(), true);
+ Assert.AreEqual(
+ "they", this.realiser.realise(this.proTest2).getRealisation());
+
+
+ // accusative: "them"
+ this.proTest2.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ DiscourseFunction.OBJECT);
+ Assert.AreEqual(
+ "them", this.realiser.realise(this.proTest2).getRealisation());
+
+ }
+
+ /**
+ * Test the pronominalisation method for full NPs (more thorough than above)
+ */
+
+ [Test]
+ public void testPronominalisation2()
+ {
+ // Ehud - added extra pronominalisation tests
+ var pro = this.phraseFactory.createNounPhrase("Mary");
+ pro.setFeature(Feature.PRONOMINAL.ToString(), true);
+ pro.setFeature(Feature.PERSON.ToString(), Person.FIRST);
+ var sent = this.phraseFactory.createClause(pro, "like", "John");
+ Assert
+ .AreEqual("I like John.", this.realiser
+ .realiseSentence(sent));
+
+ pro = this.phraseFactory.createNounPhrase("Mary");
+ pro.setFeature(Feature.PRONOMINAL.ToString(), true);
+ pro.setFeature(Feature.PERSON.ToString(), Person.SECOND);
+ sent = this.phraseFactory.createClause(pro, "like", "John");
+ Assert.AreEqual("You like John.", this.realiser
+ .realiseSentence(sent));
+
+ pro = this.phraseFactory.createNounPhrase("Mary");
+ pro.setFeature(Feature.PRONOMINAL.ToString(), true);
+ pro.setFeature(Feature.PERSON.ToString(), Person.THIRD);
+ pro.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
+ sent = this.phraseFactory.createClause(pro, "like", "John");
+ Assert.AreEqual("She likes John.", this.realiser
+ .realiseSentence(sent));
+
+ pro = this.phraseFactory.createNounPhrase("Mary");
+ pro.setFeature(Feature.PRONOMINAL.ToString(), true);
+ pro.setFeature(Feature.PERSON.ToString(), Person.FIRST);
+ pro.setPlural(true);
+ sent = this.phraseFactory.createClause(pro, "like", "John");
+ Assert.AreEqual("We like John.", this.realiser
+ .realiseSentence(sent));
+
+ pro = this.phraseFactory.createNounPhrase("Mary");
+ pro.setFeature(Feature.PRONOMINAL.ToString(), true);
+ pro.setFeature(Feature.PERSON.ToString(), Person.SECOND);
+ pro.setPlural(true);
+ sent = this.phraseFactory.createClause(pro, "like", "John");
+ Assert.AreEqual("You like John.", this.realiser
+ .realiseSentence(sent));
+
+ pro = this.phraseFactory.createNounPhrase("Mary");
+ pro.setFeature(Feature.PRONOMINAL.ToString(), true);
+ pro.setFeature(Feature.PERSON.ToString(), Person.THIRD);
+ pro.setPlural(true);
+ pro.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
+ sent = this.phraseFactory.createClause(pro, "like", "John");
+ Assert.AreEqual("They like John.", this.realiser
+ .realiseSentence(sent));
+
+ pro = this.phraseFactory.createNounPhrase("John");
+ pro.setFeature(Feature.PRONOMINAL.ToString(), true);
+ pro.setFeature(Feature.PERSON.ToString(), Person.FIRST);
+ sent = this.phraseFactory.createClause("Mary", "like", pro);
+ Assert.AreEqual("Mary likes me.", this.realiser
+ .realiseSentence(sent));
+
+ pro = this.phraseFactory.createNounPhrase("John");
+ pro.setFeature(Feature.PRONOMINAL.ToString(), true);
+ pro.setFeature(Feature.PERSON.ToString(), Person.SECOND);
+ sent = this.phraseFactory.createClause("Mary", "like", pro);
+ Assert.AreEqual("Mary likes you.", this.realiser
+ .realiseSentence(sent));
+
+ pro = this.phraseFactory.createNounPhrase("John");
+ pro.setFeature(Feature.PRONOMINAL.ToString(), true);
+ pro.setFeature(Feature.PERSON.ToString(), Person.THIRD);
+ pro.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
+ sent = this.phraseFactory.createClause("Mary", "like", pro);
+ Assert.AreEqual("Mary likes him.", this.realiser
+ .realiseSentence(sent));
+
+ pro = this.phraseFactory.createNounPhrase("John");
+ pro.setFeature(Feature.PRONOMINAL.ToString(), true);
+ pro.setFeature(Feature.PERSON.ToString(), Person.FIRST);
+ pro.setPlural(true);
+ sent = this.phraseFactory.createClause("Mary", "like", pro);
+ Assert.AreEqual("Mary likes us.", this.realiser
+ .realiseSentence(sent));
+
+ pro = this.phraseFactory.createNounPhrase("John");
+ pro.setFeature(Feature.PRONOMINAL.ToString(), true);
+ pro.setFeature(Feature.PERSON.ToString(), Person.SECOND);
+ pro.setPlural(true);
+ sent = this.phraseFactory.createClause("Mary", "like", pro);
+ Assert.AreEqual("Mary likes you.", this.realiser
+ .realiseSentence(sent));
+
+ pro = this.phraseFactory.createNounPhrase("John");
+ pro.setFeature(Feature.PRONOMINAL.ToString(), true);
+ pro.setFeature(Feature.PERSON.ToString(), Person.THIRD);
+ pro.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
+ pro.setPlural(true);
+ sent = this.phraseFactory.createClause("Mary", "like", pro);
+ Assert.AreEqual("Mary likes them.", this.realiser
+ .realiseSentence(sent));
+ }
+
+ /**
+ * Test premodification in NPS.
+ */
+
+ [Test]
+ public void testPremodification()
+ {
+ this.man.addPreModifier(this.salacious);
+ Assert.AreEqual("the salacious man", this.realiser
+ .realise(this.man).getRealisation());
+
+ this.woman.addPreModifier(this.beautiful);
+ Assert.AreEqual("the beautiful woman", this.realiser.realise(
+ this.woman).getRealisation());
+
+ this.dog.addPreModifier(this.stunning);
+ Assert.AreEqual("the stunning dog",
+ this.realiser.realise(this.dog)
+ .getRealisation());
+
+ // premodification with a WordElement
+ this.man.setPreModifier(this.phraseFactory.createWord("idiotic",
+ new LexicalCategory_ADJECTIVE()));
+ Assert.AreEqual("the idiotic man", this.realiser
+ .realise(this.man).getRealisation());
+
+ }
+
+ /**
+ * Test prepositional postmodification.
+ */
+
+ [Test]
+ public void testPostmodification()
+ {
+ this.man.addPostModifier(this.onTheRock);
+ Assert.AreEqual("the man on the rock", this.realiser.realise(
+ this.man).getRealisation());
+
+ this.woman.addPostModifier(this.behindTheCurtain);
+ Assert.AreEqual("the woman behind the curtain", this.realiser
+ .realise(this.woman).getRealisation());
+
+ // postmodification with a WordElement
+ this.man.setPostModifier(this.phraseFactory.createWord("jack",
+ new LexicalCategory_NOUN()));
+ Assert.AreEqual("the man jack", this.realiser.realise(
+ this.man).getRealisation());
+ }
+
+ /**
+ * Test nominal complementation
+ */
+
+ [Test]
+ public void testComplementation()
+ {
+ // complementation with a WordElement
+ this.man.setComplement(this.phraseFactory.createWord("jack",
+ new LexicalCategory_NOUN()));
+ Assert.AreEqual("the man jack", this.realiser.realise(
+ this.man).getRealisation());
+
+ this.woman.addComplement(this.behindTheCurtain);
+ Assert.AreEqual("the woman behind the curtain", this.realiser
+ .realise(this.woman).getRealisation());
+ }
+
+ /**
+ * Test possessive constructions.
+ */
+
+ [Test]
+ public void testPossessive()
+ {
+
+ // simple possessive 's: 'a man's'
+ var possNP = this.phraseFactory.createNounPhrase("a", "man");
+
+ possNP.setFeature(Feature.POSSESSIVE.ToString(), true);
+ Assert.AreEqual("a man's", this.realiser.realise(possNP)
+ .getRealisation());
+
+ // now set this possessive as specifier of the NP 'the dog'
+ this.dog.setFeature(InternalFeature.SPECIFIER.ToString(), possNP);
+ Assert.AreEqual("a man's dog",
+ this.realiser.realise(this.dog)
+ .getRealisation());
+
+ // convert possNP to pronoun and turn "a dog" into "his dog"
+ // need to specify gender, as default is NEUTER
+ possNP.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
+ possNP.setFeature(Feature.PRONOMINAL.ToString(), true);
+ Assert.AreEqual("his dog", this.realiser.realise(this.dog)
+ .getRealisation());
+
+ // make it slightly more complicated: "his dog's rock"
+ this.dog.setFeature(Feature.POSSESSIVE.ToString(), true); // his dog's
+
+ // his dog's rock (substituting "the"
+ // for the
+ // entire phrase)
+ this.np4.setFeature(InternalFeature.SPECIFIER.ToString(), this.dog);
+ Assert.AreEqual("his dog's rock",
+ this.realiser.realise(this.np4)
+ .getRealisation());
+ }
+
+ /**
+ * Test NP coordination.
+ */
+
+ [Test]
+ public void testCoordination()
+ {
+
+ var cnp1 = new CoordinatedPhraseElement(this.dog,
+ this.woman);
+ // simple coordination
+ Assert.AreEqual("the dog and the woman", this.realiser
+ .realise(cnp1).getRealisation());
+
+ // simple coordination with complementation of entire coordinate NP
+ cnp1.addComplement(this.behindTheCurtain);
+ Assert.AreEqual("the dog and the woman behind the curtain",
+ this.realiser.realise(cnp1).getRealisation());
+
+ // raise the specifier in this cnp
+ // Assert.AreEqual(true, cnp1.raiseSpecifier()); // should return
+ // true as all
+ // sub-nps have same spec
+ // Equals("the dog and woman behind the curtain",
+ // realiser.realise(cnp1));
+ }
+
+ /**
+ * Another battery of tests for NP coordination.
+ */
+
+ [Test]
+ public void testCoordination2()
+ {
+
+ // simple coordination of complementised nps
+ this.dog.clearComplements();
+ this.woman.clearComplements();
+
+ var cnp1 = new CoordinatedPhraseElement(this.dog,
+ this.woman);
+ cnp1.setFeature(Feature.RAISE_SPECIFIER.ToString(), true);
+ var realised = this.realiser.realise(cnp1);
+ Assert.AreEqual("the dog and woman", realised.getRealisation());
+
+ this.dog.addComplement(this.onTheRock);
+ this.woman.addComplement(this.behindTheCurtain);
+
+ var cnp2 = new CoordinatedPhraseElement(this.dog,
+ this.woman);
+
+ this.woman.setFeature(InternalFeature.RAISED.ToString(), false);
+ Assert.AreEqual(
+ "the dog on the rock and the woman behind the curtain",
+ this.realiser.realise(cnp2).getRealisation());
+
+ // complementised coordinates + outer pp modifier
+ cnp2.addPostModifier(this.inTheRoom);
+ Assert
+ .AreEqual(
+ "the dog on the rock and the woman behind the curtain in the room",
+ this.realiser.realise(cnp2).getRealisation());
+
+ // set the specifier for this cnp; should unset specifiers for all inner
+ // coordinates
+ var every = this.phraseFactory.createWord(
+ "every", new LexicalCategory_DETERMINER());
+
+ cnp2.setFeature(InternalFeature.SPECIFIER.ToString(), every);
+
+ Assert
+ .AreEqual(
+ "every dog on the rock and every woman behind the curtain in the room",
+ this.realiser.realise(cnp2).getRealisation());
+
+ // pronominalise one of the constituents
+ this.dog.setFeature(Feature.PRONOMINAL.ToString(), true); // ="it"
+ this.dog.setFeature(InternalFeature.SPECIFIER.ToString(), this.phraseFactory
+ .createWord("the", new LexicalCategory_DETERMINER()));
+ // raising spec still returns true as spec has been set
+ cnp2.setFeature(Feature.RAISE_SPECIFIER.ToString(), true);
+
+ // CNP should be realised with pronominal internal const
+ Assert.AreEqual(
+ "it and every woman behind the curtain in the room",
+ this.realiser.realise(cnp2).getRealisation());
+ }
+
+ /**
+ * Test possessives in coordinate NPs.
+ */
+
+ [Test]
+ public void testPossessiveCoordinate()
+ {
+ // simple coordination
+ var cnp2 = new CoordinatedPhraseElement(this.dog,
+ this.woman);
+ Assert.AreEqual("the dog and the woman", this.realiser
+ .realise(cnp2).getRealisation());
+
+ // set possessive -- wide-scope by default
+ cnp2.setFeature(Feature.POSSESSIVE.ToString(), true);
+ Assert.AreEqual("the dog and the woman's", this.realiser.realise(
+ cnp2).getRealisation());
+
+ // set possessive with pronoun
+ this.dog.setFeature(Feature.PRONOMINAL.ToString(), true);
+ this.dog.setFeature(Feature.POSSESSIVE.ToString(), true);
+ cnp2.setFeature(Feature.POSSESSIVE.ToString(), true);
+ Assert.AreEqual("its and the woman's", this.realiser.realise(cnp2)
+ .getRealisation());
+
+ }
+
+ /**
+ * Test A vs An.
+ */
+
+ [Test]
+ public void testAAn()
+ {
+ var _dog = this.phraseFactory.createNounPhrase("a", "dog");
+
+ Assert.AreEqual("a dog", this.realiser.realise(_dog)
+ .getRealisation());
+
+ _dog.addPreModifier("enormous");
+
+ Assert.AreEqual("an enormous dog", this.realiser.realise(_dog)
+ .getRealisation());
+
+ var elephant = this.phraseFactory.createNounPhrase(
+ "a", "elephant");
+ Assert.AreEqual("an elephant", this.realiser.realise(elephant)
+ .getRealisation());
+
+ elephant.addPreModifier("big");
+ Assert.AreEqual("a big elephant", this.realiser.realise(elephant)
+ .getRealisation());
+
+ // test treating of plural specifiers
+ _dog.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+
+ Assert.AreEqual("some enormous dogs", this.realiser.realise(_dog)
+ .getRealisation());
+ }
+
+ /**
+ * Further tests for a/an agreement with coordinated premodifiers
+ */
+
+ public void testAAnCoord()
+ {
+ var _dog = this.phraseFactory.createNounPhrase("a", "dog");
+ _dog.addPreModifier(this.phraseFactory.createCoordinatedPhrase(
+ "enormous", "black"));
+ var realisation = this.realiser.realise(_dog).getRealisation();
+ Assert.AreEqual("an enormous and black dog", realisation);
+ }
+
+ /**
+ * Test for a/an agreement with numbers
+ */
+
+ public void testAAnWithNumbers()
+ {
+ var num = this.phraseFactory.createNounPhrase("a", "change");
+ String realisation;
+
+ // no an with "one"
+ num.setPreModifier("one percent");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("a one percent change", realisation);
+
+ // an with "eighty"
+ num.setPreModifier("eighty percent");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("an eighty percent change", realisation);
+
+ // an with 80
+ num.setPreModifier("80%");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("an 80% change", realisation);
+
+ // an with 80000
+ num.setPreModifier("80000");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("an 80000 change", realisation);
+
+ // an with 11,000
+ num.setPreModifier("11,000");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("an 11,000 change", realisation);
+
+ // an with 18
+ num.setPreModifier("18%");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("an 18% change", realisation);
+
+ // a with 180
+ num.setPreModifier("180");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("a 180 change", realisation);
+
+ // a with 1100
+ num.setPreModifier("1100");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("a 1100 change", realisation);
+
+ // a with 180,000
+ num.setPreModifier("180,000");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("a 180,000 change", realisation);
+
+ // an with 11000
+ num.setPreModifier("11000");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("an 11000 change", realisation);
+
+ // an with 18000
+ num.setPreModifier("18000");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("an 18000 change", realisation);
+
+ // an with 18.1
+ num.setPreModifier("18.1%");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("an 18.1% change", realisation);
+
+ // an with 11.1
+ num.setPreModifier("11.1%");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.AreEqual("an 11.1% change", realisation);
+
+ }
+
+ /**
+ * Test Modifier "guess" placement.
+ */
+
+ [Test]
+ public void testModifier()
+ {
+ var _dog = this.phraseFactory.createNounPhrase("a", "dog");
+
+ _dog.addPreModifier("angry");
+
+ Assert.AreEqual("an angry dog", this.realiser.realise(_dog)
+ .getRealisation());
+
+ _dog.addPostModifier("in the park");
+ Assert.AreEqual("an angry dog in the park", this.realiser.realise(
+ _dog).getRealisation());
+
+ var cat = this.phraseFactory.createNounPhrase("a", "cat");
+
+ cat.addPreModifier(this.phraseFactory.createAdjectivePhrase("angry"));
+ Assert.AreEqual("an angry cat", this.realiser.realise(cat)
+ .getRealisation());
+
+ cat.addPostModifier(this.phraseFactory.createPrepositionPhrase(
+ "in", "the park"));
+ Assert.AreEqual("an angry cat in the park", this.realiser.realise(
+ cat).getRealisation());
+
+ }
+
+ [Test]
+ public void testPluralNounsBelongingToASingular()
+ {
+
+ var sent = this.phraseFactory.createClause("I", "count up");
+ sent.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ var obj = this.phraseFactory.createNounPhrase("digit");
+ obj.setPlural(true);
+ var possessor = this.phraseFactory.createNounPhrase("the", "box");
+ possessor.setPlural(false);
+ possessor.setFeature(Feature.POSSESSIVE.ToString(), true);
+ obj.setSpecifier(possessor);
+ sent.setObject(obj);
+
+ Assert.AreEqual("I counted up the box's digits", this.realiser.realise(sent)
+ .getRealisation());
+ }
+
+
+ [Test]
+ public void testSingularNounsBelongingToAPlural()
+ {
+
+ var sent = this.phraseFactory.createClause("I", "clean");
+ sent.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ var obj = this.phraseFactory.createNounPhrase("car");
+ obj.setPlural(false);
+ var possessor = this.phraseFactory.createNounPhrase("the", "parent");
+ possessor.setPlural(true);
+ possessor.setFeature(Feature.POSSESSIVE.ToString(), true);
+ obj.setSpecifier(possessor);
+ sent.setObject(obj);
+
+ Assert.AreEqual("I cleaned the parents' car", this.realiser.realise(sent)
+ .getRealisation());
+ }
+
+ /**
+ * Test for appositive postmodifiers
+ */
+
+ [Test]
+ public void testAppositivePostmodifier()
+ {
+ var _dog = this.phraseFactory.createNounPhrase("the", "dog");
+ var _rott = this.phraseFactory.createNounPhrase("a", "rottweiler");
+ _rott.setFeature(Feature.APPOSITIVE.ToString(), true);
+ _dog.addPostModifier(_rott);
+ var _sent = this.phraseFactory.createClause(_dog, "ran");
+ Assert.AreEqual("The dog, a rottweiler runs.", this.realiser.realiseSentence(_sent));
+ }
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/OrthographyFormatTest.cs b/SharpSimpleNLGUnitTests/syntax/OrthographyFormatTest.cs
new file mode 100644
index 0000000..29df4c5
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/OrthographyFormatTest.cs
@@ -0,0 +1,195 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using System.Collections.Generic;
+using System.Text;
+using NUnit.Framework;
+using SimpleNLG;
+using SimpleNLG.Extensions;
+
+namespace SimpleNLGTests.syntax
+{
+ public class OrthographyFormatTest : SimpleNLG4TestBase
+ {
+
+ public DocumentElement list1, list2;
+ public DocumentElement listItem1, listItem2, listItem3;
+ public string list1Realisation = new StringBuilder().Append("\n* behind the curtain").Append("\n").ToString();
+
+ public string list2Realisation;
+
+ [SetUp]
+ public new void setUp()
+ {
+ list2Realisation = new StringBuilder("* in the room").append("\n* ").append(list1Realisation).append("\n").ToString();
+
+ // need to set formatter for realiser (set to null in the test
+ // superclass)
+ this.realiser.setFormatter(new TextFormatter());
+
+ // a couple phrases as list items
+ listItem1 = this.phraseFactory.createListItem(this.inTheRoom);
+ listItem2 = this.phraseFactory
+ .createListItem(this.behindTheCurtain);
+ listItem3 = this.phraseFactory.createListItem(this.onTheRock);
+
+ // a simple depth-1 list of phrases
+ list1 = this.phraseFactory
+ .createList( new List
+ {
+ listItem1, listItem2
+ });
+
+ /* a list consisting of one phrase (depth-1) + a list )(depth-2)
+ list2 = this.phraseFactory.createList(
+ new List { new List
+ {
+ listItem3,
+ this.phraseFactory.createListItem(list1)
+ }}); */
+ }
+
+
+ /**
+ * Test the realisation of a list with an embedded list
+ */
+
+ //[Test]
+ public void testEmbeddedListOrthography()
+ {
+ var realised = this.realiser.realise(list2);
+ Assert.AreEqual(list2Realisation, realised.getRealisation());
+ }
+
+ /**
+ * Test the realisation of appositive pre-modifiers with commas around them.
+ */
+
+ [Test]
+ public void testAppositivePreModifiers()
+ {
+ var subject = this.phraseFactory.createNounPhrase("I");
+ var obj = this.phraseFactory.createNounPhrase("a bag");
+
+ var _s1 = this.phraseFactory.createClause(subject,
+ "carry", obj);
+
+ // add a PP complement
+ var pp = this.phraseFactory.createPrepositionPhrase("on",
+ this.phraseFactory.createNounPhrase("most", "Tuesdays"));
+ _s1.addPreModifier(pp);
+
+ //without appositive feature on pp
+ Assert.AreEqual(
+ "I on most Tuesdays carry a bag", this.realiser
+ .realise(_s1).getRealisation());
+
+ //with appositive feature
+ pp.setFeature(Feature.APPOSITIVE.ToString(), true);
+ Assert.AreEqual(
+ "I, on most Tuesdays, carry a bag", this.realiser
+ .realise(_s1).getRealisation());
+ }
+
+
+ /**
+ * Test the realisation of appositive pre-modifiers with commas around them.
+ */
+
+ [Test]
+ public void testCommaSeparatedFrontModifiers()
+ {
+ var subject = this.phraseFactory.createNounPhrase("I");
+ var obj = this.phraseFactory.createNounPhrase("a bag");
+
+ var _s1 = this.phraseFactory.createClause(subject,
+ "carry", obj);
+
+ // add a PP complement
+ var pp1 = this.phraseFactory.createPrepositionPhrase("on",
+ this.phraseFactory.createNounPhrase("most", "Tuesdays"));
+ _s1.addFrontModifier(pp1);
+
+ var pp2 = this.phraseFactory.createPrepositionPhrase("since",
+ this.phraseFactory.createNounPhrase("1991"));
+ _s1.addFrontModifier(pp2);
+ pp1.setFeature(Feature.APPOSITIVE.ToString(), true);
+ pp2.setFeature(Feature.APPOSITIVE.ToString(), true);
+
+ //without setCommaSepCuephrase
+ Assert.AreEqual(
+ "on most Tuesdays since 1991 I carry a bag", this.realiser
+ .realise(_s1).getRealisation());
+
+ //with setCommaSepCuephrase
+ this.realiser.setCommaSepCuephrase(true);
+ Assert.AreEqual(
+ "on most Tuesdays, since 1991, I carry a bag", this.realiser
+ .realise(_s1).getRealisation());
+ }
+
+ /**
+ * Ensure we don't end up with doubled commas.
+ */
+
+ [Test]
+ public void testNoDoubledCommas()
+ {
+ var subject = this.phraseFactory.createNounPhrase("I");
+ var obj = this.phraseFactory.createNounPhrase("a bag");
+
+ var _s1 = this.phraseFactory.createClause(subject,
+ "carry", obj);
+
+ var pp1 = this.phraseFactory.createPrepositionPhrase("on",
+ this.phraseFactory.createNounPhrase("most", "Tuesdays"));
+ _s1.addFrontModifier(pp1);
+
+ var pp2 = this.phraseFactory.createPrepositionPhrase("since",
+ this.phraseFactory.createNounPhrase("1991"));
+ var pp3 = this.phraseFactory.createPrepositionPhrase("except",
+ this.phraseFactory.createNounPhrase("yesterday"));
+
+ pp2.setFeature(Feature.APPOSITIVE.ToString(), true);
+ pp3.setFeature(Feature.APPOSITIVE.ToString(), true);
+
+ pp1.addPostModifier(pp2);
+ pp1.addPostModifier(pp3);
+
+ this.realiser.setCommaSepCuephrase(true);
+
+ Assert.AreEqual(
+ "on most Tuesdays, since 1991, except yesterday, I carry a bag", this.realiser
+ .realise(_s1).getRealisation());
+ // without my fix (that we're testing here), you'd end up with
+ // "on most Tuesdays, since 1991,, except yesterday, I carry a bag"
+ }
+
+// <[on most Tuesdays, since 1991, except yesterday, ]I carry a bag> but was:<[]I carry a bag>
+
+
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/PhraseSpecTest.cs b/SharpSimpleNLGUnitTests/syntax/PhraseSpecTest.cs
new file mode 100644
index 0000000..9a26a77
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/PhraseSpecTest.cs
@@ -0,0 +1,92 @@
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+
+ /**
+ * test suite for simple XXXPhraseSpec classes
+ * @author ereiter
+ *
+ */
+
+ public class PhraseSpecTest : SimpleNLG4TestBase
+ {
+
+
+
+ /**
+ * Check that empty phrases are not realised as "null"
+ */
+
+ [Test]
+ public void emptyPhraseRealisationTest()
+ {
+ var emptyClause = this.phraseFactory.createClause();
+ Assert.AreEqual("", this.realiser.realise(emptyClause)
+ .getRealisation());
+ }
+
+
+ /**
+ * Test SPhraseSpec
+ */
+
+ [Test]
+ public void testSPhraseSpec()
+ {
+
+ // simple test of methods
+ var c1 = (SPhraseSpec) this.phraseFactory.createClause();
+ c1.setVerb("give");
+ c1.setSubject("John");
+ c1.setObject("an apple");
+ c1.setIndirectObject("Mary");
+ c1.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ c1.setFeature(Feature.NEGATED.ToString(), true);
+
+ // check getXXX methods
+ Assert.AreEqual("give", getBaseForm(c1.getVerb()));
+ Assert.AreEqual("John", getBaseForm(c1.getSubject()));
+ Assert.AreEqual("an apple", getBaseForm(c1.getObject()));
+ Assert.AreEqual("Mary", getBaseForm(c1.getIndirectObject()));
+
+ Assert.AreEqual("John did not give Mary an apple", this.realiser
+ .realise(c1).getRealisation());
+
+
+
+ // test modifier placement
+ var c2 = this.phraseFactory.createClause();
+ c2.setVerb("see");
+ c2.setSubject("the man");
+ c2.setObject("me");
+ c2.addModifier("fortunately");
+ c2.addModifier("quickly");
+ c2.addModifier("in the park");
+ // try setting tense directly as a feature
+ c2.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ this.realiser.setDebugMode(true);
+ Assert.AreEqual("fortunately the man quickly saw me in the park",
+ this.realiser
+ .realise(c2).getRealisation());
+ }
+
+ // get string for head of constituent
+ private string getBaseForm(INLGElement constituent)
+ {
+ if (constituent == null)
+ return null;
+ else if (constituent is StringElement)
+ return constituent.getRealisation();
+ else if (constituent is WordElement)
+ return ((WordElement) constituent).getBaseForm();
+ else if (constituent is InflectedWordElement)
+ return getBaseForm(((InflectedWordElement) constituent).getBaseWord());
+ else if (constituent is PhraseElement)
+ return getBaseForm(((PhraseElement) constituent).getHead());
+ else
+ return null;
+ }
+ }
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/PremodifierTest.cs b/SharpSimpleNLGUnitTests/syntax/PremodifierTest.cs
new file mode 100644
index 0000000..00213c8
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/PremodifierTest.cs
@@ -0,0 +1,101 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+ public class PremodifierTest : SimpleNLG4TestBase
+ {
+
+
+
+ /**
+ * Test change from "a" to "an" in the presence of a premodifier with a
+ * vowel
+ */
+
+ [Test]
+ public void indefiniteWithPremodifierTest()
+ {
+ var s = this.phraseFactory.createClause("there", "be");
+ s.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
+ var np = this.phraseFactory.createNounPhrase("a", "stenosis");
+ s.setObject(np);
+
+ // check without modifiers -- article should be "a"
+ Assert.AreEqual("there is a stenosis", this.realiser.realise(s)
+ .getRealisation());
+
+ // add a single modifier -- should turn article to "an"
+ np.addPreModifier(this.phraseFactory.createAdjectivePhrase("eccentric"));
+ Assert.AreEqual("there is an eccentric stenosis", this.realiser
+ .realise(s).getRealisation());
+ }
+
+ /**
+ * Test for comma separation between premodifers
+ */
+
+ [Test]
+ public void multipleAdjPremodifiersTest()
+ {
+ var np = this.phraseFactory.createNounPhrase("a", "stenosis");
+ np.addPreModifier(this.phraseFactory.createAdjectivePhrase("eccentric"));
+ np.addPreModifier(this.phraseFactory.createAdjectivePhrase("discrete"));
+ Assert.AreEqual("an eccentric, discrete stenosis", this.realiser
+ .realise(np).getRealisation());
+ }
+
+ /**
+ * Test for comma separation between verb premodifiers
+ */
+
+ [Test]
+ public void multipleAdvPremodifiersTest()
+ {
+ var adv1 = this.phraseFactory.createAdverbPhrase("slowly");
+ var adv2 = this.phraseFactory
+ .createAdverbPhrase("discretely");
+
+ // case 1: concatenated premods: should have comma
+ var vp = this.phraseFactory.createVerbPhrase("run");
+ vp.addPreModifier(adv1);
+ vp.addPreModifier(adv2);
+ Assert.AreEqual("slowly, discretely runs", this.realiser
+ .realise(vp).getRealisation());
+
+ // case 2: coordinated premods: no comma
+ var vp2 = this.phraseFactory.createVerbPhrase("eat");
+ vp2.addPreModifier(this.phraseFactory.createCoordinatedPhrase(adv1,
+ adv2));
+ Assert.AreEqual("slowly and discretely eats", this.realiser
+ .realise(vp2).getRealisation());
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/PrepositionalPhraseTest.cs b/SharpSimpleNLGUnitTests/syntax/PrepositionalPhraseTest.cs
new file mode 100644
index 0000000..9d19180
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/PrepositionalPhraseTest.cs
@@ -0,0 +1,105 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+ // TODO: Auto-generated Javadoc
+ /**
+ * This class groups together some tests for prepositional phrases and
+ * coordinate prepositional phrases.
+ * @author agatt
+ */
+
+ public class PrepositionalPhraseTest : SimpleNLG4TestBase
+ {
+
+
+ [Test]
+ public void testBasic()
+ {
+ Assert.AreEqual("in the room", this.realiser
+ .realise(this.inTheRoom).getRealisation());
+ Assert.AreEqual("behind the curtain", this.realiser
+ .realise(this.behindTheCurtain).getRealisation());
+ Assert.AreEqual("on the rock", this.realiser
+ .realise(this.onTheRock).getRealisation());
+ }
+
+ /**
+ * Test for coordinate NP complements of PPs.
+ */
+
+ [Test]
+ public void testComplementation()
+ {
+ this.inTheRoom.clearComplements();
+ this.inTheRoom.addComplement(new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("the", "room"),
+ this.phraseFactory.createNounPhrase("a", "car")));
+ Assert.AreEqual("in the room and a car", this.realiser
+ .realise(this.inTheRoom).getRealisation());
+ }
+
+ /**
+ * Test for PP coordination.
+ */
+
+ public void testCoordination()
+ {
+ // simple coordination
+
+ var coord1 = new CoordinatedPhraseElement(
+ this.inTheRoom, this.behindTheCurtain);
+ Assert.AreEqual("in the room and behind the curtain", this.realiser
+ .realise(coord1).getRealisation());
+
+ // change the conjunction
+ coord1.setFeature(Feature.CONJUNCTION.ToString(), "or");
+ Assert.AreEqual("in the room or behind the curtain", this.realiser
+ .realise(coord1).getRealisation());
+
+ // new coordinate
+ var coord2 = new CoordinatedPhraseElement(
+ this.onTheRock, this.underTheTable);
+ coord2.setFeature(Feature.CONJUNCTION.ToString(), "or");
+ Assert.AreEqual("on the rock or under the table", this.realiser
+ .realise(coord2).getRealisation());
+
+ // coordinate two coordinates
+ var coord3 = new CoordinatedPhraseElement(coord1,
+ coord2);
+
+ var text = this.realiser.realise(coord3).getRealisation();
+ Assert
+ .AreEqual(
+ "in the room or behind the curtain and on the rock or under the table",
+ text);
+ }
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/SimpleNLG4Test.cs b/SharpSimpleNLGUnitTests/syntax/SimpleNLG4Test.cs
new file mode 100644
index 0000000..99f8453
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/SimpleNLG4Test.cs
@@ -0,0 +1,245 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+ /**
+ * This class is the base class for all JUnit simplenlg.test cases for
+ * simplenlg. It sets up a a JUnit fixture, i.e. the basic objects (basic
+ * constituents) that all other tests can use.
+ * @author agatt
+ */
+
+ public class SimpleNLG4TestBase
+ {
+
+ public Realiser realiser { get; set; }
+
+ public NLGFactory phraseFactory { get; set; }
+
+ public Lexicon lexicon { get; set; }
+
+ /** The pro test2. */
+ public NPPhraseSpec man, woman, dog, boy, np4, np5, np6, proTest1, proTest2;
+
+ /** The salacious. */
+ public AdjPhraseSpec beautiful, stunning, salacious;
+
+ /** The under the table. */
+ public PPPhraseSpec onTheRock, behindTheCurtain, inTheRoom, underTheTable;
+
+ /** The say. */
+ public VPPhraseSpec kick, kiss, walk, talk, getUp, fallDown, give, say;
+ // set up a few more fixtures
+ /** The s4. */
+ public SPhraseSpec s1, s2, s3, s4;
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see simplenlg.test.SimplenlgTest#setUp()
+ */
+
+ [SetUp]
+ protected virtual void setUp()
+ {
+ this.lexicon = Lexicon.getDefaultLexicon();
+
+ this.phraseFactory = new NLGFactory(this.lexicon);
+ this.realiser = new Realiser(this.lexicon);
+
+ this.man = this.phraseFactory.createNounPhrase("the", "man");
+ this.woman = this.phraseFactory.createNounPhrase("the", "woman");
+ this.dog = this.phraseFactory.createNounPhrase("the", "dog");
+ this.boy = this.phraseFactory.createNounPhrase("the", "boy");
+
+ this.beautiful = this.phraseFactory.createAdjectivePhrase("beautiful");
+ this.stunning = this.phraseFactory.createAdjectivePhrase("stunning");
+ this.salacious = this.phraseFactory.createAdjectivePhrase("salacious");
+
+ this.onTheRock = this.phraseFactory.createPrepositionPhrase("on");
+ this.np4 = this.phraseFactory.createNounPhrase("the", "rock");
+ this.onTheRock.addComplement(this.np4);
+
+ this.behindTheCurtain = this.phraseFactory.createPrepositionPhrase("behind");
+ this.np5 = this.phraseFactory.createNounPhrase("the", "curtain");
+ this.behindTheCurtain.addComplement(this.np5);
+
+ this.inTheRoom = this.phraseFactory.createPrepositionPhrase("in");
+ this.np6 = this.phraseFactory.createNounPhrase("the", "room");
+ this.inTheRoom.addComplement(this.np6);
+
+ this.underTheTable = this.phraseFactory.createPrepositionPhrase("under");
+ this.underTheTable.addComplement(this.phraseFactory.createNounPhrase("the", "table"));
+
+
+ this.proTest1 = this.phraseFactory.createNounPhrase("the", "singer");
+ this.proTest2 = this.phraseFactory.createNounPhrase("some", "person");
+
+ this.kick = this.phraseFactory.createVerbPhrase("kick");
+ this.kiss = this.phraseFactory.createVerbPhrase("kiss");
+ this.walk = this.phraseFactory.createVerbPhrase("walk");
+ this.talk = this.phraseFactory.createVerbPhrase("talk");
+ this.getUp = this.phraseFactory.createVerbPhrase("get up");
+ this.fallDown = this.phraseFactory.createVerbPhrase("fall down");
+ this.give = this.phraseFactory.createVerbPhrase("give");
+ this.say = this.phraseFactory.createVerbPhrase("say");
+
+ // the woman kisses the man
+ s1 = this.phraseFactory.createClause();
+ s1.setSubject(this.woman);
+ s1.setVerbPhrase(this.kiss);
+ s1.setObject(this.man);
+
+ // there is the dog on the rock
+ s2 = this.phraseFactory.createClause();
+ s2.setSubject("there");
+ s2.setVerb("be");
+ s2.setObject(this.dog);
+ s2.addPostModifier(this.onTheRock);
+
+ // the man gives the woman John's flower
+ s3 = this.phraseFactory.createClause();
+ s3.setSubject(this.man);
+ s3.setVerbPhrase(this.give);
+
+ var flower = this.phraseFactory.createNounPhrase("flower");
+ var john = this.phraseFactory.createNounPhrase("John");
+ john.setFeature(Feature.POSSESSIVE.ToString(), true);
+ flower.setFeature(InternalFeature.SPECIFIER.ToString(), john);
+ s3.setObject(flower);
+ s3.setIndirectObject(this.woman);
+
+ s4 = this.phraseFactory.createClause();
+ s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
+ s4.addFrontModifier("tomorrow");
+
+ var subject = this.phraseFactory
+ .createCoordinatedPhrase(this.phraseFactory
+ .createNounPhrase("Jane"), this.phraseFactory
+ .createNounPhrase("Andrew"));
+
+ s4.setSubject(subject);
+
+ var pick = this.phraseFactory.createVerbPhrase("pick up");
+ s4.setVerbPhrase(pick);
+ s4.setObject("the balls");
+ s4.addPostModifier("in the shop");
+ s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ }
+
+ protected void reset()
+ {
+ this.phraseFactory = new NLGFactory(this.lexicon);
+ this.realiser = new Realiser(this.lexicon);
+
+ this.man = this.phraseFactory.createNounPhrase("the", "man");
+ this.woman = this.phraseFactory.createNounPhrase("the", "woman");
+ this.dog = this.phraseFactory.createNounPhrase("the", "dog");
+ this.boy = this.phraseFactory.createNounPhrase("the", "boy");
+
+ this.beautiful = this.phraseFactory.createAdjectivePhrase("beautiful");
+ this.stunning = this.phraseFactory.createAdjectivePhrase("stunning");
+ this.salacious = this.phraseFactory.createAdjectivePhrase("salacious");
+
+ this.onTheRock = this.phraseFactory.createPrepositionPhrase("on");
+ this.np4 = this.phraseFactory.createNounPhrase("the", "rock");
+ this.onTheRock.addComplement(this.np4);
+
+ this.behindTheCurtain = this.phraseFactory.createPrepositionPhrase("behind");
+ this.np5 = this.phraseFactory.createNounPhrase("the", "curtain");
+ this.behindTheCurtain.addComplement(this.np5);
+
+ this.inTheRoom = this.phraseFactory.createPrepositionPhrase("in");
+ this.np6 = this.phraseFactory.createNounPhrase("the", "room");
+ this.inTheRoom.addComplement(this.np6);
+
+ this.underTheTable = this.phraseFactory.createPrepositionPhrase("under");
+ this.underTheTable.addComplement(this.phraseFactory.createNounPhrase("the", "table"));
+
+
+ this.proTest1 = this.phraseFactory.createNounPhrase("the", "singer");
+ this.proTest2 = this.phraseFactory.createNounPhrase("some", "person");
+
+ this.kick = this.phraseFactory.createVerbPhrase("kick");
+ this.kiss = this.phraseFactory.createVerbPhrase("kiss");
+ this.walk = this.phraseFactory.createVerbPhrase("walk");
+ this.talk = this.phraseFactory.createVerbPhrase("talk");
+ this.getUp = this.phraseFactory.createVerbPhrase("get up");
+ this.fallDown = this.phraseFactory.createVerbPhrase("fall down");
+ this.give = this.phraseFactory.createVerbPhrase("give");
+ this.say = this.phraseFactory.createVerbPhrase("say");
+
+ // the woman kisses the man
+ s1 = this.phraseFactory.createClause();
+ s1.setSubject(this.woman);
+ s1.setVerbPhrase(this.kiss);
+ s1.setObject(this.man);
+
+ // there is the dog on the rock
+ s2 = this.phraseFactory.createClause();
+ s2.setSubject("there");
+ s2.setVerb("be");
+ s2.setObject(this.dog);
+ s2.addPostModifier(this.onTheRock);
+
+ // the man gives the woman John's flower
+ s3 = this.phraseFactory.createClause();
+ s3.setSubject(this.man);
+ s3.setVerbPhrase(this.give);
+
+ var flower = this.phraseFactory.createNounPhrase("flower");
+ var john = this.phraseFactory.createNounPhrase("John");
+ john.setFeature(Feature.POSSESSIVE.ToString(), true);
+ flower.setFeature(InternalFeature.SPECIFIER.ToString(), john);
+ s3.setObject(flower);
+ s3.setIndirectObject(this.woman);
+
+ s4 = this.phraseFactory.createClause();
+ s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
+ s4.addFrontModifier("tomorrow");
+
+ var subject = this.phraseFactory
+ .createCoordinatedPhrase(this.phraseFactory
+ .createNounPhrase("Jane"), this.phraseFactory
+ .createNounPhrase("Andrew"));
+
+ s4.setSubject(subject);
+
+ var pick = this.phraseFactory.createVerbPhrase("pick up");
+ s4.setVerbPhrase(pick);
+ s4.setObject("the balls");
+ s4.addPostModifier("in the shop");
+ s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/StandAloneExample.cs b/SharpSimpleNLGUnitTests/syntax/StandAloneExample.cs
new file mode 100644
index 0000000..6967f6c
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/StandAloneExample.cs
@@ -0,0 +1,117 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests
+{
+ /**
+ * @author Dave Westwater, Data2Text Ltd
+ *
+ */
+
+public class StandAloneExample {
+
+ /**
+ * @param args
+ */
+ public static void (string[] args) {
+
+ // below is a simple complete example of using simplenlg V4
+ // afterwards is an example of using simplenlg just for morphology
+
+ // set up
+ Lexicon lexicon = new XMLLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+
+ // create sentences
+ // "John did not go to the bigger park. He played football there."
+ var thePark = nlgFactory.createNounPhrase("the", "park"); // create an NP
+ var bigp = nlgFactory.createAdjectivePhrase("big"); // create AdjP
+ bigp.setFeature(Feature.IS_COMPARATIVE, true); // use comparative form ("bigger")
+ thePark.addModifier(bigp); // add adj as modifier in NP
+ // above relies on default placement rules. You can force placement as a premodifier
+ // (before head) by using addPreModifier
+ var toThePark = nlgFactory.createPrepositionPhrase("to"); // create a PP
+ toThePark.setObject(thePark); // set PP object
+ // could also just say nlgFactory.createPrepositionPhrase("to", the Park);
+
+ var johnGoToThePark = nlgFactory.createClause("John", // create sentence
+ "go", toThePark);
+
+ johnGoToThePark.setFeature(Feature.TENSE,Tense.PAST); // set tense
+ johnGoToThePark.setFeature(Feature.NEGATED, true); // set negated
+
+ // note that constituents (such as subject and object) are set with setXXX methods
+ // while features are set with setFeature
+
+ var sentence = nlgFactory // create a sentence DocumentElement from SPhraseSpec
+ .createSentence(johnGoToThePark);
+
+ // below creates a sentence DocumentElement by concatenating strings
+ var hePlayed = new StringElement("he played");
+ var there = new StringElement("there");
+ var football = new WordElement("football");
+
+ var sentence2 = nlgFactory.createSentence();
+ sentence2.addComponent(hePlayed);
+ sentence2.addComponent(football);
+ sentence2.addComponent(there);
+
+ // now create a paragraph which contains these sentences
+ var paragraph = nlgFactory.createParagraph();
+ paragraph.addComponent(sentence);
+ paragraph.addComponent(sentence2);
+
+ // create a realiser. Note that a lexicon is specified, this should be
+ // the same one used by the NLGFactory
+ var realiser = new Realiser(lexicon);
+ //realiser.setDebugMode(true); // uncomment this to print out debug info during realisation
+ var realised = realiser.realise(paragraph);
+
+ System.out.println(realised.getRealisation());
+
+ // end of main example
+
+ // second example - using simplenlg just for morphology
+ // below is clumsy as direct access to morphology isn't properly supported in V4.2
+ // hopefully will be better supported in later versions
+
+ // get word element for "child"
+ var word = (WordElement) nlgFactory.createWord("child", LexicalCategory.NOUN);
+ // create InflectedWordElement from word element
+ var inflectedWord = new InflectedWordElement(word);
+ // set the inflected word to plural
+ inflectedWord.setPlural(true);
+ // realise the inflected word
+ var result = realiser.realise(inflectedWord).getRealisation();
+
+ System.out.println(result);
+ }
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/StringElementTest.cs b/SharpSimpleNLGUnitTests/syntax/StringElementTest.cs
new file mode 100644
index 0000000..9b69084
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/StringElementTest.cs
@@ -0,0 +1,413 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+ /**
+ * Tests for string elements as parts of larger phrases
+ *
+ * @author bertugatt
+ *
+ */
+
+ public class StringElementTest : SimpleNLG4TestBase
+ {
+
+ /**
+ * Test that string elements can be used as heads of NP
+ */
+
+ [Test]
+ public void stringElementAsHeadTest()
+ {
+ var np = this.phraseFactory.createNounPhrase();
+ np.setHead(this.phraseFactory.createStringElement("dogs and cats"));
+ np.setSpecifier(this.phraseFactory.createWord("the",
+ new LexicalCategory_DETERMINER()));
+ Assert.AreEqual("the dogs and cats", this.realiser.realise(np)
+ .getRealisation());
+ }
+
+ /**
+ * Sentences whose VP is a canned string
+ */
+
+ [Test]
+ public void stringElementAsVPTest()
+ {
+ var s = this.phraseFactory.createClause();
+ s.setVerbPhrase(this.phraseFactory.createStringElement("eats and drinks"));
+ s.setSubject(this.phraseFactory.createStringElement("the big fat man"));
+ Assert.AreEqual("the big fat man eats and drinks", this.realiser
+ .realise(s).getRealisation());
+ }
+
+ /**
+ * Test for when the SPhraseSpec has a NPSpec added directly after it:
+ * "Mary loves NP[the cow]."
+ */
+
+ [Test]
+ public void tailNPStringElementTest()
+ {
+ var senSpec = this.phraseFactory.createClause();
+ senSpec.addComplement((this.phraseFactory.createStringElement("mary loves")));
+ var np = this.phraseFactory.createNounPhrase();
+ np.setHead("cow");
+ np.setDeterminer("the");
+ senSpec.addComplement(np);
+ var completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ Assert.AreEqual("Mary loves the cow.", this.realiser.realise(completeSen).getRealisation());
+ }
+
+ /**
+ * Test for a NP followed by a canned text: "NP[A cat] loves a dog".
+ */
+
+ [Test]
+ public void frontNPStringElementTest()
+ {
+ var senSpec = this.phraseFactory.createClause();
+ var np = this.phraseFactory.createNounPhrase();
+ np.setHead("cat");
+ np.setDeterminer("the");
+ senSpec.addComplement(np);
+ senSpec.addComplement(this.phraseFactory.createStringElement("loves a dog"));
+ var completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ Assert.AreEqual("The cat loves a dog.", this.realiser.realise(completeSen).getRealisation());
+ }
+
+
+ /**
+ * Test for a StringElement followed by a NP followed by a StringElement
+ * "The world loves NP[ABBA] but not a sore loser."
+ */
+
+ [Test]
+ public void mulitpleStringElementsTest()
+ {
+ var senSpec = this.phraseFactory.createClause();
+ senSpec.addComplement(this.phraseFactory.createStringElement("the world loves"));
+ var np = this.phraseFactory.createNounPhrase();
+ np.setHead("ABBA");
+ senSpec.addComplement(np);
+ senSpec.addComplement(this.phraseFactory.createStringElement("but not a sore loser"));
+ var completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ Assert.AreEqual("The world loves ABBA but not a sore loser.", this.realiser.realise(completeSen).getRealisation());
+ }
+
+ /**
+ * Test for multiple NP phrases with a single StringElement phrase:
+ * "NP[John is] a trier NP[for cheese]."
+ */
+
+ [Test]
+ public void mulitpleNPElementsTest()
+ {
+ var senSpec = this.phraseFactory.createClause();
+ var frontNoun = this.phraseFactory.createNounPhrase();
+ frontNoun.setHead("john");
+ senSpec.addComplement(frontNoun);
+ senSpec.addComplement(this.phraseFactory.createStringElement("is a trier"));
+ var backNoun = this.phraseFactory.createNounPhrase();
+ backNoun.setDeterminer("for");
+ backNoun.setNoun("cheese");
+ senSpec.addComplement(backNoun);
+ var completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ Assert.AreEqual("John is a trier for cheese.", this.realiser.realise(completeSen).getRealisation());
+
+ }
+
+
+ /**
+ * White space check: Test to see how SNLG deals with additional whitespaces:
+ *
+ * NP[The Nasdaq] rose steadily during NP[early trading], however it plummeted due to NP[a shock] after NP[IBM] announced poor
+ * NP[first quarter results].
+ */
+
+ [Test]
+ public void whiteSpaceNPTest()
+ {
+ var senSpec = this.phraseFactory.createClause();
+ var firstNoun = this.phraseFactory.createNounPhrase();
+ firstNoun.setDeterminer("the");
+ firstNoun.setNoun("Nasdaq");
+ senSpec.addComplement(firstNoun);
+ senSpec.addComplement(this.phraseFactory.createStringElement(" rose steadily during "));
+ var secondNoun = this.phraseFactory.createNounPhrase();
+ secondNoun.setSpecifier("early");
+ secondNoun.setNoun("trading");
+ senSpec.addComplement(secondNoun);
+ senSpec.addComplement(this.phraseFactory.createStringElement(" , however it plummeted due to"));
+ var thirdNoun = this.phraseFactory.createNounPhrase();
+ thirdNoun.setSpecifier("a");
+ thirdNoun.setNoun("shock");
+ senSpec.addComplement(thirdNoun);
+ senSpec.addComplement(this.phraseFactory.createStringElement(" after "));
+ var fourthNoun = this.phraseFactory.createNounPhrase();
+ fourthNoun.setNoun("IBM");
+ senSpec.addComplement(fourthNoun);
+ senSpec.addComplement(this.phraseFactory.createStringElement("announced poor "));
+ var fifthNoun = this.phraseFactory.createNounPhrase();
+ fifthNoun.setSpecifier("first quarter");
+ fifthNoun.setNoun("results");
+ fifthNoun.setPlural(true);
+ senSpec.addComplement(fifthNoun);
+ var completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ Assert.AreEqual(
+ "The Nasdaq rose steadily during early trading, however it plummeted due to a shock after IBM announced poor first quarter results.",
+ this.realiser.realise(completeSen).getRealisation());
+ }
+
+ /**
+ * Point absorption test: Check to see if SNLG respects abbreviations at the end of a sentence.
+ * "NP[Yahya] was sleeping his own and dreaming etc."
+ */
+
+ public void pointAbsorptionTest()
+ {
+ var senSpec = this.phraseFactory.createClause();
+ var firstNoun = this.phraseFactory.createNounPhrase();
+ firstNoun.setNoun("yaha");
+ senSpec.addComplement(firstNoun);
+ senSpec.addComplement("was sleeping on his own and dreaming etc.");
+ var completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ Assert.AreEqual("Yaha was sleeping on his own and dreaming etc.",
+ this.realiser.realise(completeSen).getRealisation());
+
+
+ }
+
+ /**
+ * Point absorption test: As above, but with trailing white space.
+ * "NP[Yaha] was sleeping his own and dreaming etc. "
+ */
+
+ public void pointAbsorptionTrailingWhiteSpaceTest()
+ {
+ var senSpec = this.phraseFactory.createClause();
+ var firstNoun = this.phraseFactory.createNounPhrase();
+ firstNoun.setNoun("yaha");
+ senSpec.addComplement(firstNoun);
+ senSpec.addComplement("was sleeping on his own and dreaming etc. ");
+ var completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ Assert.AreEqual("Yaha was sleeping on his own and dreaming etc.",
+ this.realiser.realise(completeSen).getRealisation());
+ }
+
+ /**
+ * Abbreviation test: Check to see how SNLG deals with abbreviations in the middle of a sentence.
+ *
+ * "NP[Yahya] and friends etc. went to NP[the park] to play."
+ */
+
+ [Test]
+ public void middleAbbreviationTest()
+ {
+ var senSpec = this.phraseFactory.createClause();
+ var firstNoun = this.phraseFactory.createNounPhrase();
+ firstNoun.setNoun("yahya");
+ senSpec.addComplement(firstNoun);
+ senSpec.addComplement(this.phraseFactory.createStringElement("and friends etc. went to"));
+ var secondNoun = this.phraseFactory.createNounPhrase();
+ secondNoun.setDeterminer("the");
+ secondNoun.setNoun("park");
+ senSpec.addComplement(secondNoun);
+ senSpec.addComplement("to play");
+ var completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ Assert.AreEqual("Yahya and friends etc. went to the park to play.",
+ this.realiser.realise(completeSen).getRealisation());
+ }
+
+
+ /**
+ * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
+ * "I see an NP[elephant]"
+ */
+
+ [Test]
+ public void stringIndefiniteArticleInflectionVowelTest()
+ {
+ var senSpec = this.phraseFactory.createClause();
+ senSpec.addComplement(this.phraseFactory.createStringElement("I see a"));
+ var firstNoun = this.phraseFactory.createNounPhrase("elephant");
+ senSpec.addComplement(firstNoun);
+ var completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ Assert.AreEqual("I see an elephant.",
+ this.realiser.realise(completeSen).getRealisation());
+
+ }
+
+ /**
+ * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
+ * "I see NP[a elephant]" -->
+ */
+
+ [Test]
+ public void NPIndefiniteArticleInflectionVowelTest()
+ {
+ var senSpec = this.phraseFactory.createClause();
+ senSpec.addComplement(this.phraseFactory.createStringElement("I see"));
+ var firstNoun = this.phraseFactory.createNounPhrase("elephant");
+ firstNoun.setDeterminer("a");
+ senSpec.addComplement(firstNoun);
+ var completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ Assert.AreEqual("I see an elephant.",
+ this.realiser.realise(completeSen).getRealisation());
+
+ }
+
+
+ /**
+ * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
+ * "I see an NP[cow]"
+ */
+
+ // Unknown status in Java Library [Test]
+ public void stringIndefiniteArticleInflectionConsonantTest()
+ {
+ var senSpec = this.phraseFactory.createClause();
+ senSpec.addComplement(this.phraseFactory.createStringElement("I see an"));
+ var firstNoun = this.phraseFactory.createNounPhrase("cow");
+ senSpec.addComplement(firstNoun);
+ var completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ this.realiser.setDebugMode(true);
+ // Do not attempt "an" -> "a"
+ Assert.AreNotEqual("I see an cow.",
+ this.realiser.realise(completeSen).getRealisation());
+ }
+
+ /**
+ * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
+ * "I see NP[an cow]" -->
+ */
+
+ [Test]
+ public void NPIndefiniteArticleInflectionConsonantTest()
+ {
+ var senSpec = this.phraseFactory.createClause();
+ senSpec.addComplement(this.phraseFactory.createStringElement("I see"));
+ var firstNoun = this.phraseFactory.createNounPhrase("cow");
+ firstNoun.setDeterminer("an");
+ senSpec.addComplement(firstNoun);
+ var completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ // Do not attempt "an" -> "a"
+ Assert.AreEqual("I see an cow.",
+ this.realiser.realise(completeSen).getRealisation());
+ }
+
+
+ /**
+ * aggregationStringElementTest: Test to see if we can aggregate two StringElements in a CoordinatedPhraseElement.
+ */
+
+ [Test]
+ public void aggregationStringElementTest()
+ {
+
+ var coordinate =
+ this.phraseFactory.createCoordinatedPhrase(new StringElement("John is going to Tesco"),
+ new StringElement("Mary is going to Sainsburys"));
+ var sentence = this.phraseFactory.createClause();
+ sentence.addComplement(coordinate);
+
+ Assert.AreEqual("John is going to Tesco and Mary is going to Sainsburys.",
+ this.realiser.realiseSentence(sentence));
+ }
+
+
+ /**
+ * Tests that no empty space is added when a StringElement is instantiated with an empty string
+ * or null object.
+ */
+
+ [Test]
+ public void nullAndEmptyStringElementTest()
+ {
+
+ var nullStringElement = this.phraseFactory.createStringElement(null);
+ var emptyStringElement = this.phraseFactory.createStringElement("");
+ var beautiful = this.phraseFactory.createStringElement("beautiful");
+ var horseLike = this.phraseFactory.createStringElement("horse-like");
+ var creature = this.phraseFactory.createStringElement("creature");
+
+ // Test1: null or empty at beginning
+ var test1 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
+ test1.addPostModifier(emptyStringElement);
+ test1.addPostModifier(beautiful);
+ test1.addPostModifier(horseLike);
+ test1.addPostModifier(creature);
+ Assert.AreEqual("A unicorn is regarded as a beautiful horse-like creature.",
+ this.realiser.realiseSentence(test1));
+
+ // Test2: empty or null at end
+ var test2 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
+ test2.addPostModifier(beautiful);
+ test2.addPostModifier(horseLike);
+ test2.addPostModifier(creature);
+ test2.addPostModifier(nullStringElement);
+ Assert.AreEqual("A unicorn is regarded as a beautiful horse-like creature.",
+ this.realiser.realiseSentence(test2));
+
+ // Test3: empty or null in the middle
+ var test3 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
+ test3.addPostModifier("beautiful");
+ test3.addPostModifier("horse-like");
+ test3.addPostModifier("");
+ test3.addPostModifier("creature");
+ Assert.AreEqual("A unicorn is regarded as a beautiful horse-like creature.",
+ this.realiser.realiseSentence(test3));
+
+ // Test4: empty or null in the middle with empty or null at beginning
+ var test4 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
+ test4.addPostModifier("");
+ test4.addPostModifier("beautiful");
+ test4.addPostModifier("horse-like");
+ test4.addPostModifier(nullStringElement);
+ test4.addPostModifier("creature");
+ Assert.AreEqual("A unicorn is regarded as a beautiful horse-like creature.",
+ this.realiser.realiseSentence(test4));
+
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/TutorialTest.cs b/SharpSimpleNLGUnitTests/syntax/TutorialTest.cs
new file mode 100644
index 0000000..4fda0f9
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/TutorialTest.cs
@@ -0,0 +1,465 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using System.Collections.Generic;
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+ /**
+ * Tests from SimpleNLG tutorial
+ *
+ *
+ *
+ * Copyright (C) 2011, University of Aberdeen
+ *
+ *
+ * @author Ehud Reiter
+ *
+ */
+
+ public class TutorialTest
+ {
+
+
+
+ [Test]
+ public void section3_Test()
+ {
+ var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+
+ NLGElement s1 = nlgFactory.createSentence("my dog is happy");
+
+ var r = new Realiser(lexicon);
+
+ var output = r.realiseSentence(s1);
+
+ Assert.AreEqual("My dog is happy.", output);
+ }
+
+ /**
+ * test section 5 code
+ */
+
+ [Test]
+ public void section5_Test()
+ {
+ var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+ var realiser = new Realiser(lexicon);
+
+ var p = nlgFactory.createClause();
+ p.setSubject("my dog");
+ p.setVerb("chase");
+ p.setObject("George");
+
+ var output = realiser.realiseSentence(p);
+ Assert.AreEqual("My dog chases George.", output);
+ }
+
+ /**
+ * test section 6 code
+ */
+
+ [Test]
+ public void section6_Test()
+ {
+ var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+ var realiser = new Realiser(lexicon);
+
+ var p = nlgFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("chase");
+ p.setObject("George");
+
+ p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ var output = realiser.realiseSentence(p);
+ Assert.AreEqual("Mary chased George.", output);
+
+ p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("Mary will chase George.", output);
+
+ p.setFeature(Feature.NEGATED.ToString(), true);
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("Mary will not chase George.", output);
+
+ p = nlgFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("chase");
+ p.setObject("George");
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
+ InterrogativeType.YES_NO);
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("Does Mary chase George?", output);
+
+ p.setSubject("Mary");
+ p.setVerb("chase");
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("Who does Mary chase?", output);
+
+ p = nlgFactory.createClause();
+ p.setSubject("the dog");
+ p.setVerb("wake up");
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("The dog wakes up.", output);
+
+ }
+
+ /**
+ * test ability to use variant words
+ */
+
+ [Test]
+ public void variantsTest()
+ {
+ var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+ var realiser = new Realiser(lexicon);
+
+ var p = nlgFactory.createClause();
+ p.setSubject("my dog");
+ p.setVerb("is"); // variant of be
+ p.setObject("George");
+
+ var output = realiser.realiseSentence(p);
+ Assert.AreEqual("My dog is George.", output);
+
+ p = nlgFactory.createClause();
+ p.setSubject("my dog");
+ p.setVerb("chases"); // variant of chase
+ p.setObject("George");
+
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("My dog chases George.", output);
+
+
+ p = nlgFactory.createClause();
+ p.setSubject(nlgFactory.createNounPhrase("the", "dogs")); // variant of "dog"
+ p.setVerb("is"); // variant of be
+ p.setObject("happy"); // variant of happy
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("The dog is happy.", output);
+
+ p = nlgFactory.createClause();
+ p.setSubject(nlgFactory.createNounPhrase("the", "children")); // variant of "child"
+ p.setVerb("is"); // variant of be
+ p.setObject("happy"); // variant of happy
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("The child is happy.", output);
+
+ // following functionality is enabled
+ p = nlgFactory.createClause();
+ p.setSubject(nlgFactory.createNounPhrase("the", "dogs")); // variant of "dog"
+ p.setVerb("is"); // variant of be
+ p.setObject("happy"); // variant of happy
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("The dog is happy.", output); //corrected automatically
+ }
+
+ /* Following code tests the section 5 to 15
+ * sections 5 & 6 are repeated here in order to match the simplenlg tutorial version 4
+ * James Christie
+ * June 2011
+ */
+
+ /**
+ * test section 5 to match simplenlg tutorial version 4's code
+ */
+
+ [Test]
+ public void section5A_Test()
+ {
+ var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+ var realiser = new Realiser(lexicon);
+
+ var p = nlgFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("chase");
+ p.setObject("the monkey");
+
+ var output = realiser.realiseSentence(p);
+ Assert.AreEqual("Mary chases the monkey.", output);
+ } // testSection5A
+
+ /**
+ * test section 6 to match simplenlg tutorial version 4' code
+ */
+
+ [Test]
+ public void section6A_Test()
+ {
+ var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+ var realiser = new Realiser(lexicon);
+
+ var p = nlgFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("chase");
+ p.setObject("the monkey");
+
+ p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ var output = realiser.realiseSentence(p);
+ Assert.AreEqual("Mary chased the monkey.", output);
+
+ p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("Mary will chase the monkey.", output);
+
+ p.setFeature(Feature.NEGATED.ToString(), true);
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("Mary will not chase the monkey.", output);
+
+ p = nlgFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("chase");
+ p.setObject("the monkey");
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("Does Mary chase the monkey?", output);
+
+ p.setSubject("Mary");
+ p.setVerb("chase");
+ p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
+ output = realiser.realiseSentence(p);
+ Assert.AreEqual("Who does Mary chase?", output);
+ }
+
+ /**
+ * test section 7 code
+ */
+
+ [Test]
+ public void section7_Test()
+ {
+ var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+ var realiser = new Realiser(lexicon);
+
+ var p = nlgFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("chase");
+ p.setObject("the monkey");
+ p.addComplement("very quickly");
+ p.addComplement("despite her exhaustion");
+
+ var output = realiser.realiseSentence(p);
+ Assert.AreEqual("Mary chases the monkey very quickly despite her exhaustion.", output);
+ }
+
+ /**
+ * test section 8 code
+ */
+
+ [Test]
+ public void section8_Test()
+ {
+ var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+ var realiser = new Realiser(lexicon);
+ //realiser.setDebugMode(true);
+ var subject = nlgFactory.createNounPhrase("Mary");
+ var obj = nlgFactory.createNounPhrase("the monkey");
+ var verb = nlgFactory.createVerbPhrase("chase");
+ subject.addModifier("fast");
+
+ var p = nlgFactory.createClause();
+ p.setSubject(subject);
+ p.setVerb(verb);
+ p.setObject(obj);
+
+ var outputA = realiser.realiseSentence(p);
+ Assert.AreEqual("Fast Mary chases the monkey.", outputA);
+
+ verb.addModifier("quickly");
+
+ var outputB = realiser.realiseSentence(p);
+ Assert.AreEqual("Fast Mary quickly chases the monkey.", outputB);
+ }
+
+ // there is no code specified in section 9
+
+ /**
+ * test section 10 code
+ */
+
+ [Test]
+ public void section10_Test()
+ {
+ var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+ var realiser = new Realiser(lexicon);
+
+ var subject1 = nlgFactory.createNounPhrase("Mary");
+ var subject2 = nlgFactory.createNounPhrase("your", "giraffe");
+
+ // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API
+ var subj = nlgFactory.createCoordinatedPhrase(subject1, subject2);
+
+ var verb = nlgFactory.createVerbPhrase("chase");
+
+ var p = nlgFactory.createClause();
+ p.setSubject(subj);
+ p.setVerb(verb);
+ p.setObject("the monkey");
+
+ var outputA = realiser.realiseSentence(p);
+ Assert.AreEqual("Mary and your giraffe chase the monkey.", outputA);
+
+ var object1 = nlgFactory.createNounPhrase("the monkey");
+ var object2 = nlgFactory.createNounPhrase("George");
+
+ // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API
+ var obj = nlgFactory.createCoordinatedPhrase(object1, object2);
+ obj.addCoordinate("Martha");
+ p.setObject(obj);
+
+ var outputB = realiser.realiseSentence(p);
+ Assert.AreEqual("Mary and your giraffe chase the monkey, George and Martha.", outputB);
+
+ obj.setFeature(Feature.CONJUNCTION.ToString(), "or");
+
+ var outputC = realiser.realiseSentence(p);
+ Assert.AreEqual("Mary and your giraffe chase the monkey, George or Martha.", outputC);
+ }
+
+ /**
+ * test section 11 code
+ */
+
+ [Test]
+ public void section11_Test()
+ {
+ var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+
+ var realiser = new Realiser(lexicon);
+
+ var pA = nlgFactory.createClause("Mary", "chase", "the monkey");
+ pA.addComplement("in the park");
+
+ var outputA = realiser.realiseSentence(pA);
+ Assert.AreEqual("Mary chases the monkey in the park.", outputA);
+
+ // alternative build paradigm
+ var place = nlgFactory.createNounPhrase("park");
+ var pB = nlgFactory.createClause("Mary", "chase", "the monkey");
+
+ // next line is depreciated ~ may be corrected in the API
+ place.setDeterminer("the");
+ var pp = nlgFactory.createPrepositionPhrase();
+ pp.addComplement(place);
+ pp.setPreposition("in");
+
+ pB.addComplement(pp);
+
+ var outputB = realiser.realiseSentence(pB);
+ Assert.AreEqual("Mary chases the monkey in the park.", outputB);
+
+ place.addPreModifier("leafy");
+
+ var outputC = realiser.realiseSentence(pB);
+ Assert.AreEqual("Mary chases the monkey in the leafy park.", outputC);
+ } // testSection11
+
+ // section12 only has a code table as illustration
+
+ /**
+ * test section 13 code
+ */
+
+ [Test]
+ public void section13_Test()
+ {
+ var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+
+ var realiser = new Realiser(lexicon);
+
+ var s1 = nlgFactory.createClause("my cat", "like", "fish");
+ var s2 = nlgFactory.createClause("my dog", "like", "big bones");
+ var s3 = nlgFactory.createClause("my horse", "like", "grass");
+
+ var c = nlgFactory.createCoordinatedPhrase();
+ c.addCoordinate(s1);
+ c.addCoordinate(s2);
+ c.addCoordinate(s3);
+
+ var outputA = realiser.realiseSentence(c);
+ Assert.AreEqual("My cat likes fish, my dog likes big bones and my horse likes grass.", outputA);
+
+ var p = nlgFactory.createClause("I", "be", "happy");
+ var q = nlgFactory.createClause("I", "eat", "fish");
+ q.setFeature(Feature.COMPLEMENTISER.ToString(), "because");
+ q.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ p.addComplement(q);
+
+ var outputB = realiser.realiseSentence(p);
+ Assert.AreEqual("I am happy because I ate fish.", outputB);
+ }
+
+ /**
+ * test section 14 code
+ */
+
+ [Test]
+ public void section14_Test()
+ {
+ var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+
+ var realiser = new Realiser(lexicon);
+
+ var p1 = nlgFactory.createClause("Mary", "chase", "the monkey");
+ var p2 = nlgFactory.createClause("The monkey", "fight back");
+ var p3 = nlgFactory.createClause("Mary", "be", "nervous");
+
+ var s1 = nlgFactory.createSentence(p1);
+ var s2 = nlgFactory.createSentence(p2);
+ var s3 = nlgFactory.createSentence(p3);
+
+ var par1 = nlgFactory.createParagraph(new List { s1, s2, s3});
+
+ var output14a = realiser.realise(par1).getRealisation();
+ Assert.AreEqual("Mary chases the monkey. The monkey fights back. Mary is nervous.\n\n", output14a);
+
+ var section = nlgFactory.createSection("The Trials and Tribulation of Mary and the Monkey");
+ section.addComponent(par1);
+ var output14b = realiser.realise(section).getRealisation();
+ Assert.AreEqual(
+ "The Trials and Tribulation of Mary and the Monkey\nMary chases the monkey. The monkey fights back. Mary is nervous.\n\n",
+ output14b);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/VerbPhraseTest.cs b/SharpSimpleNLGUnitTests/syntax/VerbPhraseTest.cs
new file mode 100644
index 0000000..c6f5931
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/VerbPhraseTest.cs
@@ -0,0 +1,472 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "SharpSimpleNLG".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
+ */
+
+/* Additional Notes:
+ * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
+ * - This is a port of the Java version to C# with no additional features
+ * - I have left the "Initial Developer" section to reflect this fact
+ * - Any questions, comments, feedback on this port can be sent to Nick Hodge
+ */
+
+using NUnit.Framework;
+using SimpleNLG;
+
+namespace SimpleNLGTests.syntax
+{
+ /**
+ * These are tests for the verb phrase and coordinate VP classes.
+ * @author agatt
+ */
+
+ public class VerbPhraseTest : SimpleNLG4TestBase
+ {
+
+
+ /**
+ * Some tests to check for an early bug which resulted in reduplication of
+ * verb particles in the past tense e.g. "fall down down" or "creep up up"
+ */
+
+ [Test]
+ public void testVerbParticle()
+ {
+ var v = this.phraseFactory.createVerbPhrase("fall down");
+
+ Assert.AreEqual(
+ "down", v.getFeatureAsString(Feature.PARTICLE.ToString()));
+
+ Assert.AreEqual(
+ "fall", ((WordElement) v.getVerb()).getBaseForm());
+
+ v.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ v.setFeature(Feature.PERSON.ToString(), Person.THIRD);
+ v.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+
+ Assert.AreEqual(
+ "fell down", this.realiser.realise(v).getRealisation());
+
+ v.setFeature(Feature.FORM.ToString(), Form.PAST_PARTICIPLE);
+ Assert.AreEqual(
+ "fallen down", this.realiser.realise(v).getRealisation());
+ }
+
+ /**
+ * Tests for the tense and aspect.
+ */
+
+ [Test]
+ public void simplePastTest()
+ {
+ // "fell down"
+ this.fallDown.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ Assert.AreEqual(
+ "fell down", this.realiser.realise(this.fallDown).getRealisation());
+
+ }
+
+ /**
+ * Test tense aspect.
+ */
+
+ [Test]
+ public void tenseAspectTest()
+ {
+ // had fallen down
+ this.realiser.setLexicon(this.lexicon);
+ this.fallDown.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ this.fallDown.setFeature(Feature.PERFECT.ToString(), true);
+
+ Assert.AreEqual("had fallen down", this.realiser.realise(
+ this.fallDown).getRealisation());
+
+ // had been falling down
+ this.fallDown.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ Assert.AreEqual("had been falling down", this.realiser.realise(
+ this.fallDown).getRealisation());
+
+ // will have been kicked
+ this.kick.setFeature(Feature.PASSIVE.ToString(), true);
+ this.kick.setFeature(Feature.PERFECT.ToString(), true);
+ this.kick.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ Assert.AreEqual("will have been kicked", this.realiser.realise(
+ this.kick).getRealisation());
+
+ // will have been being kicked
+ this.kick.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ Assert.AreEqual("will have been being kicked", this.realiser
+ .realise(this.kick).getRealisation());
+
+ // will not have been being kicked
+ this.kick.setFeature(Feature.NEGATED.ToString(), true);
+ Assert.AreEqual("will not have been being kicked", this.realiser
+ .realise(this.kick).getRealisation());
+
+ // passivisation should suppress the complement
+ this.kick.clearComplements();
+ this.kick.addComplement(this.man);
+ Assert.AreEqual("will not have been being kicked", this.realiser
+ .realise(this.kick).getRealisation());
+
+ // de-passivisation should now give us "will have been kicking the man"
+ this.kick.setFeature(Feature.PASSIVE.ToString(), false);
+ Assert.AreEqual("will not have been kicking the man", this.realiser
+ .realise(this.kick).getRealisation());
+
+ // remove the future tense --
+ // this is a test of an earlier bug that would still realise "will"
+ this.kick.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
+ Assert.AreEqual("has not been kicking the man", this.realiser
+ .realise(this.kick).getRealisation());
+ }
+
+ /**
+ * Test for realisation of VP complements.
+ */
+
+ [Test]
+ public void complementationTest()
+ {
+
+ // was kissing Mary
+ var mary = this.phraseFactory.createNounPhrase("Mary");
+ mary.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.OBJECT);
+ this.kiss.clearComplements();
+ this.kiss.addComplement(mary);
+ this.kiss.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ this.kiss.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+
+ Assert.AreEqual("was kissing Mary", this.realiser
+ .realise(this.kiss).getRealisation());
+
+ var mary2 = new CoordinatedPhraseElement(mary,
+ this.phraseFactory.createNounPhrase("Susan"));
+ // add another complement -- should come out as "Mary and Susan"
+ this.kiss.clearComplements();
+ this.kiss.addComplement(mary2);
+ Assert.AreEqual("was kissing Mary and Susan", this.realiser
+ .realise(this.kiss).getRealisation());
+
+ // passivise -- should make the direct object complement disappear
+ // Note: The verb doesn't come out as plural because agreement
+ // is determined by the sentential subjects and this VP isn't inside a
+ // sentence
+ this.kiss.setFeature(Feature.PASSIVE.ToString(), true);
+ Assert.AreEqual("was being kissed", this.realiser
+ .realise(this.kiss).getRealisation());
+
+ // make it plural (this is usually taken care of in SPhraseSpec)
+ this.kiss.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+ Assert.AreEqual("were being kissed", this.realiser.realise(
+ this.kiss).getRealisation());
+
+ // depassivise and add post-mod: yields "was kissing Mary in the room"
+ this.kiss.addPostModifier(this.inTheRoom);
+ this.kiss.setFeature(Feature.PASSIVE.ToString(), false);
+ this.kiss.setFeature(Feature.NUMBER.ToString(), NumberAgreement.SINGULAR);
+ Assert.AreEqual("was kissing Mary and Susan in the room",
+ this.realiser.realise(this.kiss).getRealisation());
+
+ // passivise again: should make direct object disappear, but not postMod
+ // ="was being kissed in the room"
+ this.kiss.setFeature(Feature.PASSIVE.ToString(), true);
+ this.kiss.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
+ Assert.AreEqual("were being kissed in the room", this.realiser
+ .realise(this.kiss).getRealisation());
+ }
+
+ /**
+ * This tests for the default complement ordering, relative to pre and
+ * postmodifiers.
+ */
+
+ [Test]
+ public void complementationTest_2()
+ {
+ // give the woman the dog
+ this.woman.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ DiscourseFunction.INDIRECT_OBJECT);
+ this.dog.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ DiscourseFunction.OBJECT);
+ this.give.clearComplements();
+ this.give.addComplement(this.dog);
+ this.give.addComplement(this.woman);
+ Assert.AreEqual("gives the woman the dog", this.realiser.realise(
+ this.give).getRealisation());
+
+ // add a few premodifiers and postmodifiers
+ this.give.addPreModifier("slowly");
+ this.give.addPostModifier(this.behindTheCurtain);
+ this.give.addPostModifier(this.inTheRoom);
+ Assert.AreEqual(
+ "slowly gives the woman the dog behind the curtain in the room",
+ this.realiser.realise(this.give).getRealisation());
+
+ // reset the arguments
+ this.give.clearComplements();
+ this.give.addComplement(this.dog);
+ var womanBoy = new CoordinatedPhraseElement(
+ this.woman, this.boy);
+ womanBoy.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ DiscourseFunction.INDIRECT_OBJECT);
+ this.give.addComplement(womanBoy);
+
+ // if we unset the passive, we should get the indirect objects
+ // they won't be coordinated
+ this.give.setFeature(Feature.PASSIVE.ToString(), false);
+ Assert.AreEqual(
+ "slowly gives the woman and the boy the dog behind the curtain in the room",
+ this.realiser.realise(this.give).getRealisation());
+
+ // set them to a coordinate instead
+ // set ONLY the complement INDIRECT_OBJECT, leaves OBJECT intact
+ this.give.clearComplements();
+ this.give.addComplement(womanBoy);
+ this.give.addComplement(this.dog);
+ var complements = this.give
+ .getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString());
+
+ var indirectCount = 0;
+ foreach (var eachElement in complements)
+ {
+ if (DiscourseFunction.INDIRECT_OBJECT.Equals(eachElement
+ .getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString())))
+ {
+ indirectCount++;
+ }
+ }
+ Assert.AreEqual(1, indirectCount); // only one indirect object
+ // where
+ // there were two before
+
+ Assert.AreEqual(
+ "slowly gives the woman and the boy the dog behind the curtain in the room",
+ this.realiser.realise(this.give).getRealisation());
+ }
+
+ /**
+ * Test for complements raised in the passive case.
+ */
+
+ [Test]
+ public void passiveComplementTest()
+ {
+ NPPhraseSpec woman2 = this.phraseFactory.createNounPhrase("the", "woman");
+ NPPhraseSpec dog2 = this.phraseFactory.createNounPhrase("the", "dog");
+ VPPhraseSpec give2 = this.phraseFactory.createVerbPhrase("give");
+ PPPhraseSpec behindTheCurtain2 = this.phraseFactory.createPrepositionPhrase("behind");
+ NPPhraseSpec np52 = this.phraseFactory.createNounPhrase("the", "curtain");
+ behindTheCurtain2.addComplement(np52);
+
+ PPPhraseSpec inTheRoom2 = this.phraseFactory.createPrepositionPhrase("in");
+ NPPhraseSpec np62 = this.phraseFactory.createNounPhrase("the", "room");
+ inTheRoom2.addComplement(np62);
+
+
+ // add some arguments
+ dog2.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ DiscourseFunction.OBJECT);
+ woman2.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
+ DiscourseFunction.INDIRECT_OBJECT);
+ give2.addComplement(dog2);
+ give2.addComplement(woman2);
+ Assert.AreEqual("gives the woman the dog", this.realiser.realise(
+ give2).getRealisation());
+
+ // add a few premodifiers and postmodifiers
+ give2.addPreModifier("slowly");
+ give2.addPostModifier(behindTheCurtain2);
+ give2.addPostModifier(inTheRoom2);
+ Assert.AreEqual(
+ "slowly gives the woman the dog behind the curtain in the room",
+ this.realiser.realise(give2).getRealisation());
+
+ // passivise: This should suppress "the dog"
+ give2.clearComplements();
+ give2.addComplement(dog2);
+ give2.addComplement(woman2);
+ give2.setFeature(Feature.PASSIVE.ToString(), true);
+
+ Assert.AreEqual(
+ "is slowly given the woman behind the curtain in the room",
+ this.realiser.realise(give2).getRealisation());
+ }
+
+ /**
+ * Test VP with sentential complements. This tests for structures like "said
+ * that John was walking"
+ */
+
+ [Test]
+ public void clausalComplementTest()
+ {
+ this.phraseFactory.setLexicon(this.lexicon);
+ var s = this.phraseFactory.createClause();
+
+ s.setSubject(this.phraseFactory
+ .createNounPhrase("John"));
+
+ // Create a sentence first
+ var maryAndSusan = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Mary"),
+ this.phraseFactory.createNounPhrase("Susan"));
+
+ this.kiss.clearComplements();
+ s.setVerbPhrase(this.kiss);
+ s.setObject(maryAndSusan);
+ s.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ s.addPostModifier(this.inTheRoom);
+ Assert.AreEqual("John was kissing Mary and Susan in the room",
+ this.realiser.realise(s).getRealisation());
+
+ // make the main VP past
+ this.say.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ Assert.AreEqual("said", this.realiser.realise(this.say)
+ .getRealisation());
+
+ // now add the sentence as complement of "say". Should make the sentence
+ // subordinate
+ // note that sentential punctuation is suppressed
+ this.say.addComplement(s);
+ Assert.AreEqual(
+ "said that John was kissing Mary and Susan in the room",
+ this.realiser.realise(this.say).getRealisation());
+
+ // add a postModifier to the main VP
+ // yields [says [that John was kissing Mary and Susan in the room]
+ // [behind the curtain]]
+ this.say.addPostModifier(this.behindTheCurtain);
+ Assert.AreEqual(
+ "said that John was kissing Mary and Susan in the room behind the curtain",
+ this.realiser.realise(this.say).getRealisation());
+
+ // create a new sentential complement
+ var s2 = this.phraseFactory.createClause(this.phraseFactory
+ .createNounPhrase("all"),
+ "be",
+ this.phraseFactory.createAdjectivePhrase("fine"));
+
+ s2.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ Assert.AreEqual("all will be fine", this.realiser.realise(s2)
+ .getRealisation());
+
+ // add the new complement to the VP
+ // yields [said [that John was kissing Mary and Susan in the room and
+ // all will be fine] [behind the curtain]]
+ var s3 = new CoordinatedPhraseElement(s, s2);
+ this.say.clearComplements();
+ this.say.addComplement(s3);
+
+ // first with outer complementiser suppressed
+ s3.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true);
+ Assert.AreEqual(
+ "said that John was kissing Mary and Susan in the room "
+ + "and all will be fine behind the curtain",
+ this.realiser.realise(this.say).getRealisation());
+
+ setUp();
+
+ s = this.phraseFactory.createClause();
+
+ s.setSubject(this.phraseFactory
+ .createNounPhrase("John"));
+
+ // Create a sentence first
+ maryAndSusan = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Mary"),
+ this.phraseFactory.createNounPhrase("Susan"));
+
+ s.setVerbPhrase(this.kiss);
+ s.setObject(maryAndSusan);
+ s.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ s.addPostModifier(this.inTheRoom);
+ s2 = this.phraseFactory.createClause(this.phraseFactory
+ .createNounPhrase("all"),
+ "be",
+ this.phraseFactory.createAdjectivePhrase("fine"));
+
+ s2.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
+ // then with complementiser not suppressed and not aggregated
+ s3 = new CoordinatedPhraseElement(s, s2);
+ this.say.addComplement(s3);
+ this.say.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ this.say.addPostModifier(this.behindTheCurtain);
+
+ this.realiser.setDebugMode(true);
+ Assert.AreEqual(
+ "said that John was kissing Mary and Susan in the room and "
+ + "that all will be fine behind the curtain",
+ this.realiser.realise(this.say).getRealisation());
+
+ }
+
+ /**
+ * Test VP coordination and aggregation:
+ *
+ * If the simplenlg.features of a coordinate VP are set, they should be
+ * inherited by its daughter VP;
+ * 2. We can aggregate the coordinate VP so it's realised with one
+ * wide-scope auxiliary
+ */
+
+ [Test]
+ public void coordinationTest()
+ {
+ // simple case
+ VPPhraseSpec kiss2 = this.phraseFactory.createVerbPhrase("kiss");
+ kiss2.addComplement(this.dog);
+ VPPhraseSpec kick2 = this.phraseFactory.createVerbPhrase("kick");
+ kick2.addComplement(this.boy);
+
+ var coord1 = new CoordinatedPhraseElement(
+ kiss2, kick2);
+
+ coord1.setFeature(Feature.PERSON.ToString(), Person.THIRD);
+ coord1.setFeature(Feature.TENSE.ToString(), Tense.PAST);
+ Assert.AreEqual("kissed the dog and kicked the boy", this.realiser
+ .realise(coord1).getRealisation());
+
+ // with negation: should be inherited by all components
+ coord1.setFeature(Feature.NEGATED.ToString(), true);
+ this.realiser.setLexicon(this.lexicon);
+ Assert.AreEqual("did not kiss the dog and did not kick the boy",
+ this.realiser.realise(coord1).getRealisation());
+
+ // set a modal
+ coord1.setFeature(Feature.MODAL.ToString(), "could");
+ Assert.AreEqual(
+ "could not have kissed the dog and could not have kicked the boy",
+ this.realiser.realise(coord1).getRealisation());
+
+ // set perfect and progressive
+ coord1.setFeature(Feature.PERFECT.ToString(), true);
+ coord1.setFeature(Feature.PROGRESSIVE.ToString(), true);
+ Assert.AreEqual("could not have been kissing the dog and "
+ + "could not have been kicking the boy", this.realiser.realise(
+ coord1).getRealisation());
+
+ // now aggregate
+ coord1.setFeature(Feature.AGGREGATE_AUXILIARY.ToString(), true);
+ Assert.AreEqual(
+ "could not have been kissing the dog and kicking the boy",
+ this.realiser.realise(coord1).getRealisation());
+ }
+ }
+}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/english/AdjectivePhraseTest.java b/SharpSimpleNLGUnitTests/syntax/english/AdjectivePhraseTest.java
new file mode 100644
index 0000000..e08e03a
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/AdjectivePhraseTest.java
@@ -0,0 +1,168 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.syntax.english;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.framework.CoordinatedPhraseElement;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.PhraseElement;
+import simplenlg.framework.StringElement;
+
+/**
+ * This class incorporates a few tests for adjectival phrases. Also tests for
+ * adverbial phrase specs, which are very similar
+ *
+ * @author agatt
+ */
+public class AdjectivePhraseTest extends SimpleNLG4Test {
+
+ /**
+ * Instantiates a new adj p test.
+ *
+ * @param name
+ * the name
+ */
+ public AdjectivePhraseTest(String name) {
+ super(name);
+ }
+
+
+ @Override
+ @After
+ public void tearDown() {
+ super.tearDown();
+ }
+
+
+ /**
+ * Test premodification & coordination of Adjective Phrases (Not much else
+ * to simplenlg.test)
+ */
+ @Test
+ public void testAdj() {
+
+ // form the adjphrase "incredibly salacious"
+ this.salacious.addPreModifier(this.phraseFactory
+ .createAdverbPhrase("incredibly")); //$NON-NLS-1$
+ Assert.assertEquals("incredibly salacious", this.realiser //$NON-NLS-1$
+ .realise(this.salacious).getRealisation());
+
+ // form the adjphrase "incredibly beautiful"
+ this.beautiful.addPreModifier("amazingly"); //$NON-NLS-1$
+ Assert.assertEquals("amazingly beautiful", this.realiser //$NON-NLS-1$
+ .realise(this.beautiful).getRealisation());
+
+ // coordinate the two aps
+ CoordinatedPhraseElement coordap = new CoordinatedPhraseElement(
+ this.salacious, this.beautiful);
+ Assert.assertEquals("incredibly salacious and amazingly beautiful", //$NON-NLS-1$
+ this.realiser.realise(coordap).getRealisation());
+
+ // changing the inner conjunction
+ coordap.setFeature(Feature.CONJUNCTION, "or"); //$NON-NLS-1$
+ Assert.assertEquals("incredibly salacious or amazingly beautiful", //$NON-NLS-1$
+ this.realiser.realise(coordap).getRealisation());
+
+ // coordinate this with a new AdjPhraseSpec
+ CoordinatedPhraseElement coord2 = new CoordinatedPhraseElement(coordap,
+ this.stunning);
+ Assert.assertEquals(
+ "incredibly salacious or amazingly beautiful and stunning", //$NON-NLS-1$
+ this.realiser.realise(coord2).getRealisation());
+
+ // add a premodifier the coordinate phrase, yielding
+ // "seriously and undeniably incredibly salacious or amazingly beautiful
+ // and stunning"
+ CoordinatedPhraseElement preMod = new CoordinatedPhraseElement(
+ new StringElement("seriously"), new StringElement("undeniably")); //$NON-NLS-1$//$NON-NLS-2$
+
+ coord2.addPreModifier(preMod);
+ Assert.assertEquals(
+ "seriously and undeniably incredibly salacious or amazingly beautiful and stunning", //$NON-NLS-1$
+ this.realiser.realise(coord2).getRealisation());
+
+ // adding a coordinate rather than coordinating should give a different
+ // result
+ coordap.addCoordinate(this.stunning);
+ Assert.assertEquals(
+ "incredibly salacious, amazingly beautiful or stunning", //$NON-NLS-1$
+ this.realiser.realise(coordap).getRealisation());
+
+ }
+
+ /**
+ * Simple test of adverbials
+ */
+ @Test
+ public void testAdv() {
+
+ PhraseElement sent = this.phraseFactory.createClause("John", "eat"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ PhraseElement adv = this.phraseFactory.createAdverbPhrase("quickly"); //$NON-NLS-1$
+
+ sent.addPreModifier(adv);
+
+ Assert.assertEquals("John quickly eats", this.realiser.realise(sent) //$NON-NLS-1$
+ .getRealisation());
+
+ adv.addPreModifier("very"); //$NON-NLS-1$
+
+ Assert.assertEquals("John very quickly eats", this.realiser.realise( //$NON-NLS-1$
+ sent).getRealisation());
+
+ }
+
+ /**
+ * Test participles as adjectives
+ */
+ @Test
+ public void testParticipleAdj() {
+ PhraseElement ap = this.phraseFactory
+ .createAdjectivePhrase(this.lexicon.getWord("associated",
+ LexicalCategory.ADJECTIVE));
+ Assert.assertEquals("associated", this.realiser.realise(ap)
+ .getRealisation());
+ }
+
+ /**
+ * Test for multiple adjective modifiers with comma-separation. Example courtesy of William Bradshaw (Data2Text Ltd).
+ */
+ @Test
+ public void testMultipleModifiers() {
+ PhraseElement np = this.phraseFactory
+ .createNounPhrase(this.lexicon.getWord("message",
+ LexicalCategory.NOUN));
+ np.addPreModifier(this.lexicon.getWord("active",
+ LexicalCategory.ADJECTIVE));
+ np.addPreModifier(this.lexicon.getWord("temperature",
+ LexicalCategory.ADJECTIVE));
+ Assert.assertEquals("active, temperature message", this.realiser.realise(np).getRealisation());
+
+ //now we set the realiser not to separate using commas
+ this.realiser.setCommaSepPremodifiers(false);
+ Assert.assertEquals("active temperature message", this.realiser.realise(np).getRealisation());
+
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/ClauseAggregationTest.java b/SharpSimpleNLGUnitTests/syntax/english/ClauseAggregationTest.java
new file mode 100644
index 0000000..73d90c9
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/ClauseAggregationTest.java
@@ -0,0 +1,273 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.syntax.english;
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.aggregation.BackwardConjunctionReductionRule;
+import simplenlg.aggregation.Aggregator;
+import simplenlg.aggregation.ClauseCoordinationRule;
+import simplenlg.aggregation.ForwardConjunctionReductionRule;
+import simplenlg.features.Feature;
+import simplenlg.framework.NLGElement;
+import simplenlg.phrasespec.SPhraseSpec;
+
+/**
+ * Some tests for aggregation.
+ *
+ * @author Albert Gatt, University of Malta & University of Aberdeen
+ *
+ */
+public class ClauseAggregationTest extends SimpleNLG4Test {
+ // set up a few more fixtures
+ /** The s4. */
+ SPhraseSpec s1, s2, s3, s4, s5, s6;
+ Aggregator aggregator;
+ ClauseCoordinationRule coord;
+ ForwardConjunctionReductionRule fcr;
+ BackwardConjunctionReductionRule bcr;
+
+ /**
+ * Instantiates a new clause aggregation test.
+ *
+ * @param name
+ * the name
+ */
+ public ClauseAggregationTest(String name) {
+ super(name);
+ aggregator = new Aggregator();
+ aggregator.initialise();
+ coord = new ClauseCoordinationRule();
+ fcr = new ForwardConjunctionReductionRule();
+ bcr = new BackwardConjunctionReductionRule();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see simplenlg.test.SimplenlgTest#setUp()
+ */
+ @Override
+ @Before
+ protected void setUp() {
+ super.setUp();
+
+ // the woman kissed the man behind the curtain
+ this.s1 = this.phraseFactory.createClause();
+ this.s1.setSubject(this.woman);
+ this.s1.setVerbPhrase(this.phraseFactory.createVerbPhrase("kiss"));
+ this.s1.setObject(this.man);
+ this.s1.addPostModifier(this.phraseFactory
+ .createPrepositionPhrase("behind", this.phraseFactory
+ .createNounPhrase("the", "curtain")));
+
+ // the woman kicked the dog on the rock
+ this.s2 = this.phraseFactory.createClause();
+ this.s2.setSubject(this.phraseFactory.createNounPhrase("the", "woman")); //$NON-NLS-1$
+ this.s2.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick")); //$NON-NLS-1$
+ this.s2.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
+ this.s2.addPostModifier(this.onTheRock);
+
+ // the woman kicked the dog behind the curtain
+ this.s3 = this.phraseFactory.createClause();
+ this.s3.setSubject(this.phraseFactory.createNounPhrase("the", "woman")); //$NON-NLS-1$
+ this.s3.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick")); //$NON-NLS-1$
+ this.s3.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
+ this.s3.addPostModifier(this.phraseFactory
+ .createPrepositionPhrase("behind", this.phraseFactory
+ .createNounPhrase("the", "curtain")));
+
+ // the man kicked the dog behind the curtain
+ this.s4 = this.phraseFactory.createClause();
+ this.s4.setSubject(this.man); //$NON-NLS-1$
+ this.s4.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick")); //$NON-NLS-1$
+ this.s4.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
+ this.s4.addPostModifier(this.behindTheCurtain);
+
+ // the girl kicked the dog behind the curtain
+ this.s5 = this.phraseFactory.createClause();
+ this.s5.setSubject(this.phraseFactory.createNounPhrase("the", "girl")); //$NON-NLS-1$
+ this.s5.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick")); //$NON-NLS-1$
+ this.s5.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
+ this.s5.addPostModifier(this.behindTheCurtain);
+
+ // the woman kissed the dog behind the curtain
+ this.s6 = this.phraseFactory.createClause();
+ this.s6.setSubject(this.phraseFactory.createNounPhrase("the", "woman")); //$NON-NLS-1$
+ this.s6.setVerbPhrase(this.phraseFactory.createVerbPhrase("kiss")); //$NON-NLS-1$
+ this.s6.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
+ this.s6.addPostModifier(this.phraseFactory
+ .createPrepositionPhrase("behind", this.phraseFactory
+ .createNounPhrase("the", "curtain")));
+ }
+
+ @After
+ public void tearDown() {
+ super.tearDown();
+
+ this.s1 = null; this.s2 = null; this.s3 = null;
+ this.s4 = null; this.s5 = null; this.s6 = null;
+ this.aggregator = null;
+ this.coord = null;
+ this.fcr = null;
+ this.bcr = null;
+ }
+
+ /**
+ * Test clause coordination with two sentences with same subject but
+ * different postmodifiers: fails
+ */
+ @Test
+ public void testCoordinationSameSubjectFail() {
+ List elements = Arrays.asList((NLGElement) this.s1,
+ (NLGElement) this.s2);
+ List result = this.coord.apply(elements);
+ Assert.assertEquals(2, result.size());
+ }
+
+ /**
+ * Test clause coordination with two sentences one of which is passive:
+ * fails
+ */
+ @Test
+ public void testCoordinationPassiveFail() {
+ this.s1.setFeature(Feature.PASSIVE, true);
+ List elements = Arrays.asList((NLGElement) this.s1,
+ (NLGElement) this.s2);
+ List result = this.coord.apply(elements);
+ Assert.assertEquals(2, result.size());
+ }
+
+// /**
+// * Test clause coordination with 2 sentences with same subject: succeeds
+// */
+// @Test
+// public void testCoordinationSameSubjectSuccess() {
+// List elements = Arrays.asList((NLGElement) this.s1,
+// (NLGElement) this.s3);
+// List result = this.coord.apply(elements);
+// Assert.assertTrue(result.size() == 1); // should only be one sentence
+// NLGElement aggregated = result.get(0);
+// Assert
+// .assertEquals(
+// "the woman kisses the man and kicks the dog behind the curtain", //$NON-NLS-1$
+// this.realiser.realise(aggregated).getRealisation());
+// }
+
+ /**
+ * Test clause coordination with 2 sentences with same VP: succeeds
+ */
+ @Test
+ public void testCoordinationSameVP() {
+ List elements = Arrays.asList((NLGElement) this.s3,
+ (NLGElement) this.s4);
+ List result = this.coord.apply(elements);
+ Assert.assertTrue(result.size() == 1); // should only be one sentence
+ NLGElement aggregated = result.get(0);
+ Assert.assertEquals(
+ "the woman and the man kick the dog behind the curtain", //$NON-NLS-1$
+ this.realiser.realise(aggregated).getRealisation());
+ }
+
+ /**
+ * Coordination of sentences with front modifiers: should preserve the mods
+ */
+ @Test
+ public void testCoordinationWithModifiers() {
+ // now add a couple of front modifiers
+ this.s3.addFrontModifier(this.phraseFactory
+ .createAdverbPhrase("however"));
+ this.s4.addFrontModifier(this.phraseFactory
+ .createAdverbPhrase("however"));
+ List elements = Arrays.asList((NLGElement) this.s3,
+ (NLGElement) this.s4);
+ List result = this.coord.apply(elements);
+ Assert.assertTrue(result.size() == 1); // should only be one sentence
+ NLGElement aggregated = result.get(0);
+ Assert
+ .assertEquals(
+ "however the woman and the man kick the dog behind the curtain", //$NON-NLS-1$
+ this.realiser.realise(aggregated).getRealisation());
+ }
+
+ /**
+ * Test coordination of 3 sentences with the same VP
+ */
+ public void testCoordinationSameVP2() {
+ List elements = Arrays.asList((NLGElement) this.s3,
+ (NLGElement) this.s4, (NLGElement) this.s5);
+ List result = this.coord.apply(elements);
+ Assert.assertTrue(result.size() == 1); // should only be one sentence
+ NLGElement aggregated = result.get(0);
+ Assert
+ .assertEquals(
+ "the woman and the man and the girl kick the dog behind the curtain", //$NON-NLS-1$
+ this.realiser.realise(aggregated).getRealisation());
+ }
+
+ /**
+ * Forward conjunction reduction test
+ */
+ @Test
+ public void testForwardConjReduction() {
+ NLGElement aggregated = this.fcr.apply(this.s2, this.s3);
+ Assert
+ .assertEquals(
+ "the woman kicks the dog on the rock and kicks the dog behind the curtain", //$NON-NLS-1$
+ this.realiser.realise(aggregated).getRealisation());
+ }
+
+ /**
+ * Backward conjunction reduction test
+ */
+ @Test
+ public void testBackwardConjunctionReduction() {
+ NLGElement aggregated = this.bcr.apply(this.s3, this.s6);
+ Assert
+ .assertEquals(
+ "the woman kicks and the woman kisses the dog behind the curtain",
+ this.realiser.realise(aggregated).getRealisation());
+ }
+
+ /**
+ * Test multiple aggregation procedures in a single aggregator.
+ */
+// @Test
+// public void testForwardBackwardConjunctionReduction() {
+// this.aggregator.addRule(this.fcr);
+// this.aggregator.addRule(this.bcr);
+// realiser.setDebugMode(true);
+// List result = this.aggregator.realise(Arrays.asList((NLGElement) this.s2, (NLGElement) this.s3));
+// Assert.assertTrue(result.size() == 1); // should only be one sentence
+// NLGElement aggregated = result.get(0);
+// NLGElement aggregated = this.phraseFactory.createdCoordinatedPhrase(this.s2, this.s3);
+// Assert
+// .assertEquals(
+// "the woman kicks the dog on the rock and behind the curtain", //$NON-NLS-1$
+// this.realiser.realise(aggregated).getRealisation());
+// }
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/ClauseTest.java b/SharpSimpleNLGUnitTests/syntax/english/ClauseTest.java
new file mode 100644
index 0000000..397c8df
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/ClauseTest.java
@@ -0,0 +1,926 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.features.ClauseStatus;
+import simplenlg.features.DiscourseFunction;
+import simplenlg.features.Feature;
+import simplenlg.features.Form;
+import simplenlg.features.InternalFeature;
+import simplenlg.features.NumberAgreement;
+import simplenlg.features.Tense;
+import simplenlg.framework.CoordinatedPhraseElement;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.NLGElement;
+import simplenlg.framework.PhraseCategory;
+import simplenlg.framework.PhraseElement;
+import simplenlg.phrasespec.AdjPhraseSpec;
+import simplenlg.phrasespec.AdvPhraseSpec;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.PPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.phrasespec.VPPhraseSpec;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class STest.
+ */
+public class ClauseTest extends SimpleNLG4Test {
+
+ // set up a few more fixtures
+ /** The s4. */
+ SPhraseSpec s1, s2, s3, s4;
+
+ /**
+ * Instantiates a new s test.
+ *
+ * @param name
+ * the name
+ */
+ public ClauseTest(String name) {
+ super(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see simplenlg.test.SimplenlgTest#setUp()
+ */
+ @Override
+ @Before
+ protected void setUp() {
+ super.setUp();
+
+ // the woman kisses the man
+ this.s1 = this.phraseFactory.createClause();
+ this.s1.setSubject(this.woman);
+ this.s1.setVerbPhrase(this.kiss);
+ this.s1.setObject(this.man);
+
+ // there is the dog on the rock
+ this.s2 = this.phraseFactory.createClause();
+ this.s2.setSubject("there"); //$NON-NLS-1$
+ this.s2.setVerb("be"); //$NON-NLS-1$
+ this.s2.setObject(this.dog);
+ this.s2.addPostModifier(this.onTheRock);
+
+ // the man gives the woman John's flower
+ this.s3 = this.phraseFactory.createClause();
+ this.s3.setSubject(this.man);
+ this.s3.setVerbPhrase(this.give);
+
+ NPPhraseSpec flower = this.phraseFactory.createNounPhrase("flower"); //$NON-NLS-1$
+ NPPhraseSpec john = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
+ john.setFeature(Feature.POSSESSIVE, true);
+ flower.setFeature(InternalFeature.SPECIFIER, john);
+ this.s3.setObject(flower);
+ this.s3.setIndirectObject(this.woman);
+
+ this.s4 = this.phraseFactory.createClause();
+ this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
+ this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
+
+ CoordinatedPhraseElement subject = this.phraseFactory
+ .createCoordinatedPhrase(this.phraseFactory
+ .createNounPhrase("Jane"), this.phraseFactory //$NON-NLS-1$
+ .createNounPhrase("Andrew")); //$NON-NLS-1$
+
+ this.s4.setSubject(subject);
+
+ PhraseElement pick = this.phraseFactory.createVerbPhrase("pick up"); //$NON-NLS-1$
+ this.s4.setVerbPhrase(pick);
+ this.s4.setObject("the balls"); //$NON-NLS-1$
+ this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
+ this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
+ }
+
+ @After
+ public void tearDown() {
+ super.tearDown();
+
+ this.s1 = null;
+ this.s2 = null;
+ this.s3 = null;
+ this.s4 = null;
+ }
+
+
+ /**
+ * Initial test for basic sentences.
+ */
+ @Test
+ public void testBasic() {
+ Assert.assertEquals("the woman kisses the man", this.realiser //$NON-NLS-1$
+ .realise(this.s1).getRealisation());
+ Assert.assertEquals("there is the dog on the rock", this.realiser //$NON-NLS-1$
+ .realise(this.s2).getRealisation());
+
+ setUp();
+ Assert.assertEquals("the man gives the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+ Assert
+ .assertEquals(
+ "however tomorrow Jane and Andrew will pick up the balls in the shop", //$NON-NLS-1$
+ this.realiser.realise(this.s4).getRealisation());
+ }
+
+ /**
+ * Test did not
+ */
+ @Test
+ public void testDidNot() {
+ PhraseElement s = phraseFactory.createClause("John", "eat");
+ s.setFeature(Feature.TENSE, Tense.PAST);
+ s.setFeature(Feature.NEGATED, true);
+
+ Assert.assertEquals("John did not eat", //$NON-NLS-1$
+ this.realiser.realise(s).getRealisation());
+
+ }
+
+ /**
+ * Test did not
+ */
+ @Test
+ public void testVPNegation() {
+ // negate the VP
+ PhraseElement vp = phraseFactory.createVerbPhrase("lie");
+ vp.setFeature(Feature.TENSE, Tense.PAST);
+ vp.setFeature(Feature.NEGATED, true);
+ PhraseElement compl = phraseFactory.createVerbPhrase("etherize");
+ compl.setFeature(Feature.TENSE, Tense.PAST);
+ vp.setComplement(compl);
+
+ SPhraseSpec s = phraseFactory.createClause(phraseFactory
+ .createNounPhrase("the", "patient"), vp);
+
+ Assert.assertEquals("the patient did not lie etherized", //$NON-NLS-1$
+ this.realiser.realise(s).getRealisation());
+
+ }
+
+ /**
+ * Test that pronominal args are being correctly cast as NPs.
+ */
+ @Test
+ public void testPronounArguments() {
+ // the subject of s2 should have been cast into a pronominal NP
+ NLGElement subj = this.s2.getFeatureAsElementList(
+ InternalFeature.SUBJECTS).get(0);
+ Assert.assertTrue(subj.isA(PhraseCategory.NOUN_PHRASE));
+ // Assert.assertTrue(LexicalCategory.PRONOUN.equals(((PhraseElement)
+ // subj)
+ // .getCategory()));
+ }
+
+ /**
+ * Tests for setting tense, aspect and passive from the sentence interface.
+ */
+ @Test
+ public void testTenses() {
+ // simple past
+ this.s3.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals("the man gave the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+
+ // perfect
+ this.s3.setFeature(Feature.PERFECT, true);
+ Assert.assertEquals("the man had given the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+
+ // negation
+ this.s3.setFeature(Feature.NEGATED, true);
+ Assert.assertEquals("the man had not given the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+
+ this.s3.setFeature(Feature.PROGRESSIVE, true);
+ Assert.assertEquals(
+ "the man had not been giving the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+
+ // passivisation with direct and indirect object
+ this.s3.setFeature(Feature.PASSIVE, true);
+ // Assert.assertEquals(
+ // "John's flower had not been being given the woman by the man", //$NON-NLS-1$
+ // this.realiser.realise(this.s3).getRealisation());
+ }
+
+ /**
+ * Test what happens when a sentence is subordinated as complement of a
+ * verb.
+ */
+ @Test
+ public void testSubordination() {
+
+ // subordinate sentence by setting it as complement of a verb
+ this.say.addComplement(this.s3);
+
+ // check the getter
+ Assert.assertEquals(ClauseStatus.SUBORDINATE, this.s3
+ .getFeature(InternalFeature.CLAUSE_STATUS));
+
+ // check realisation
+ Assert.assertEquals("says that the man gives the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.say).getRealisation());
+ }
+
+ /**
+ * Test the various forms of a sentence, including subordinates.
+ */
+ /**
+ *
+ */
+ @Test
+ public void testForm() {
+
+ // check the getter method
+ Assert.assertEquals(Form.NORMAL, this.s1.getFeatureAsElement(
+ InternalFeature.VERB_PHRASE).getFeature(Feature.FORM));
+
+ // infinitive
+ this.s1.setFeature(Feature.FORM, Form.INFINITIVE);
+ Assert
+ .assertEquals(
+ "to kiss the man", this.realiser.realise(this.s1).getRealisation()); //$NON-NLS-1$
+
+ // gerund with "there"
+ this.s2.setFeature(Feature.FORM, Form.GERUND);
+ Assert.assertEquals("there being the dog on the rock", this.realiser //$NON-NLS-1$
+ .realise(this.s2).getRealisation());
+
+ // gerund with possessive
+ this.s3.setFeature(Feature.FORM, Form.GERUND);
+ Assert.assertEquals("the man's giving the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+
+ // imperative
+ this.s3.setFeature(Feature.FORM, Form.IMPERATIVE);
+
+ Assert.assertEquals("give the woman John's flower", this.realiser //$NON-NLS-1$
+ .realise(this.s3).getRealisation());
+
+ // subordinating the imperative to a verb should turn it to infinitive
+ this.say.addComplement(this.s3);
+
+ Assert.assertEquals("says to give the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.say).getRealisation());
+
+ // imperative -- case II
+ this.s4.setFeature(Feature.FORM, Form.IMPERATIVE);
+ Assert.assertEquals("however tomorrow pick up the balls in the shop", //$NON-NLS-1$
+ this.realiser.realise(this.s4).getRealisation());
+
+ // infinitive -- case II
+ this.s4 = this.phraseFactory.createClause();
+ this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
+ this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
+
+ CoordinatedPhraseElement subject = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"), this.phraseFactory //$NON-NLS-1$
+ .createNounPhrase("Andrew")); //$NON-NLS-1$
+
+ this.s4.setFeature(InternalFeature.SUBJECTS, subject);
+
+ PhraseElement pick = this.phraseFactory.createVerbPhrase("pick up"); //$NON-NLS-1$
+ this.s4.setFeature(InternalFeature.VERB_PHRASE, pick);
+ this.s4.setObject("the balls"); //$NON-NLS-1$
+ this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
+ this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
+ this.s4.setFeature(Feature.FORM, Form.INFINITIVE);
+ Assert.assertEquals(
+ "however to pick up the balls in the shop tomorrow", //$NON-NLS-1$
+ this.realiser.realise(this.s4).getRealisation());
+ }
+
+ /**
+ * Slightly more complex tests for forms.
+ */
+ @Test
+ public void testForm2() {
+ // set s4 as subject of a new sentence
+ SPhraseSpec temp = this.phraseFactory.createClause(this.s4, "be", //$NON-NLS-1$
+ "recommended"); //$NON-NLS-1$
+
+ Assert.assertEquals(
+ "however tomorrow Jane and Andrew's picking up the " + //$NON-NLS-1$
+ "balls in the shop is recommended", //$NON-NLS-1$
+ this.realiser.realise(temp).getRealisation());
+
+ // compose this with a new sentence
+ // ER - switched direct and indirect object in sentence
+ SPhraseSpec temp2 = this.phraseFactory.createClause("I", "tell", temp); //$NON-NLS-1$ //$NON-NLS-2$
+ temp2.setFeature(Feature.TENSE, Tense.FUTURE);
+
+ PhraseElement indirectObject = this.phraseFactory
+ .createNounPhrase("John"); //$NON-NLS-1$
+
+ temp2.setIndirectObject(indirectObject);
+
+ Assert.assertEquals("I will tell John that however tomorrow Jane and " + //$NON-NLS-1$
+ "Andrew's picking up the balls in the shop is " + //$NON-NLS-1$
+ "recommended", //$NON-NLS-1$
+ this.realiser.realise(temp2).getRealisation());
+
+ // turn s4 to imperative and put it in indirect object position
+
+ this.s4 = this.phraseFactory.createClause();
+ this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
+ this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
+
+ CoordinatedPhraseElement subject = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"), this.phraseFactory //$NON-NLS-1$
+ .createNounPhrase("Andrew")); //$NON-NLS-1$
+
+ this.s4.setSubject(subject);
+
+ PhraseElement pick = this.phraseFactory.createVerbPhrase("pick up"); //$NON-NLS-1$
+ this.s4.setVerbPhrase(pick);
+ this.s4.setObject("the balls"); //$NON-NLS-1$
+ this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
+ this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
+ this.s4.setFeature(Feature.FORM, Form.IMPERATIVE);
+
+ temp2 = this.phraseFactory.createClause("I", "tell", this.s4); //$NON-NLS-1$ //$NON-NLS-2$
+ indirectObject = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
+ temp2.setIndirectObject(indirectObject);
+ temp2.setFeature(Feature.TENSE, Tense.FUTURE);
+
+ Assert.assertEquals("I will tell John however to pick up the balls " //$NON-NLS-1$
+ + "in the shop tomorrow", this.realiser.realise(temp2) //$NON-NLS-1$
+ .getRealisation());
+ }
+
+ /**
+ * Tests for gerund forms and genitive subjects.
+ */
+ @Test
+ public void testGerundsubject() {
+
+ // the man's giving the woman John's flower upset Peter
+ SPhraseSpec _s4 = this.phraseFactory.createClause();
+ _s4.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset")); //$NON-NLS-1$
+ _s4.setFeature(Feature.TENSE, Tense.PAST);
+ _s4.setObject(this.phraseFactory.createNounPhrase("Peter")); //$NON-NLS-1$
+ this.s3.setFeature(Feature.PERFECT, true);
+
+ // set the sentence as subject of another: makes it a gerund
+ _s4.setSubject(this.s3);
+
+ // suppress the genitive realisation of the NP subject in gerund
+ // sentences
+ this.s3.setFeature(Feature.SUPPRESS_GENITIVE_IN_GERUND, true);
+
+ // check the realisation: subject should not be genitive
+ Assert.assertEquals(
+ "the man having given the woman John's flower upset Peter", //$NON-NLS-1$
+ this.realiser.realise(_s4).getRealisation());
+
+ }
+
+ /**
+ * Some tests for multiple embedded sentences.
+ */
+ @Test
+ public void testComplexSentence1() {
+ setUp();
+ // the man's giving the woman John's flower upset Peter
+ SPhraseSpec complexS = this.phraseFactory.createClause();
+ complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset")); //$NON-NLS-1$
+ complexS.setFeature(Feature.TENSE, Tense.PAST);
+ complexS.setObject(this.phraseFactory.createNounPhrase("Peter")); //$NON-NLS-1$
+ this.s3.setFeature(Feature.PERFECT, true);
+ complexS.setSubject(this.s3);
+
+ // check the realisation: subject should be genitive
+ Assert.assertEquals(
+ "the man's having given the woman John's flower upset Peter", //$NON-NLS-1$
+ this.realiser.realise(complexS).getRealisation());
+
+ setUp();
+ // coordinate sentences in subject position
+ SPhraseSpec s5 = this.phraseFactory.createClause();
+ s5.setSubject(this.phraseFactory.createNounPhrase("some", "person")); //$NON-NLS-1$ //$NON-NLS-2$
+ s5.setVerbPhrase(this.phraseFactory.createVerbPhrase("stroke")); //$NON-NLS-1$
+ s5.setObject(this.phraseFactory.createNounPhrase("the", "cat")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ CoordinatedPhraseElement coord = new CoordinatedPhraseElement(this.s3,
+ s5);
+ complexS = this.phraseFactory.createClause();
+ complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset")); //$NON-NLS-1$
+ complexS.setFeature(Feature.TENSE, Tense.PAST);
+ complexS.setObject(this.phraseFactory.createNounPhrase("Peter")); //$NON-NLS-1$
+ complexS.setSubject(coord);
+ this.s3.setFeature(Feature.PERFECT, true);
+
+ Assert.assertEquals("the man's having given the woman John's flower " //$NON-NLS-1$
+ + "and some person's stroking the cat upset Peter", //$NON-NLS-1$
+ this.realiser.realise(complexS).getRealisation());
+
+ setUp();
+ // now subordinate the complex sentence
+ // coord.setClauseStatus(SPhraseSpec.ClauseType.MAIN);
+ SPhraseSpec s6 = this.phraseFactory.createClause();
+ s6.setVerbPhrase(this.phraseFactory.createVerbPhrase("tell")); //$NON-NLS-1$
+ s6.setFeature(Feature.TENSE, Tense.PAST);
+ s6.setSubject(this.phraseFactory.createNounPhrase("the", "boy")); //$NON-NLS-1$ //$NON-NLS-2$
+ // ER - switched indirect and direct object
+ PhraseElement indirect = this.phraseFactory.createNounPhrase("every", //$NON-NLS-1$
+ "girl"); //$NON-NLS-1$
+ s6.setIndirectObject(indirect);
+ complexS = this.phraseFactory.createClause();
+ complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset")); //$NON-NLS-1$
+ complexS.setFeature(Feature.TENSE, Tense.PAST);
+ complexS.setObject(this.phraseFactory.createNounPhrase("Peter")); //$NON-NLS-1$
+ s6.setObject(complexS);
+ coord = new CoordinatedPhraseElement(this.s3, s5);
+ complexS.setSubject(coord);
+ this.s3.setFeature(Feature.PERFECT, true);
+ Assert.assertEquals(
+ "the boy told every girl that the man's having given the woman " //$NON-NLS-1$
+ + "John's flower and some person's stroking the cat " //$NON-NLS-1$
+ + "upset Peter", //$NON-NLS-1$
+ this.realiser.realise(s6).getRealisation());
+
+ }
+
+ /**
+ * More coordination tests.
+ */
+ @Test
+ public void testComplexSentence3() {
+ setUp();
+
+ this.s1 = this.phraseFactory.createClause();
+ this.s1.setSubject(this.woman);
+ this.s1.setVerb("kiss");
+ this.s1.setObject(this.man);
+
+ PhraseElement _man = this.phraseFactory.createNounPhrase("the", "man"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.s3 = this.phraseFactory.createClause();
+ this.s3.setSubject(_man);
+ this.s3.setVerb("give");
+
+ NPPhraseSpec flower = this.phraseFactory.createNounPhrase("flower"); //$NON-NLS-1$
+ NPPhraseSpec john = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
+ john.setFeature(Feature.POSSESSIVE, true);
+ flower.setSpecifier(john);
+ this.s3.setObject(flower);
+
+ PhraseElement _woman = this.phraseFactory.createNounPhrase(
+ "the", "woman"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.s3.setIndirectObject(_woman);
+
+ // the coordinate sentence allows us to raise and lower complementiser
+ CoordinatedPhraseElement coord2 = new CoordinatedPhraseElement(this.s1,
+ this.s3);
+ coord2.setFeature(Feature.TENSE, Tense.PAST);
+
+ this.realiser.setDebugMode(true);
+ Assert
+ .assertEquals(
+ "the woman kissed the man and the man gave the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(coord2).getRealisation());
+ }
+
+ // /**
+ // * Sentence with clausal subject with verb "be" and a progressive feature
+ // */
+ // public void testComplexSentence2() {
+ // SPhraseSpec subject = this.phraseFactory.createClause(
+ // this.phraseFactory.createNounPhrase("the", "child"),
+ // this.phraseFactory.createVerbPhrase("be"), this.phraseFactory
+ // .createWord("difficult", LexicalCategory.ADJECTIVE));
+ // subject.setFeature(Feature.PROGRESSIVE, true);
+ // }
+
+ /**
+ * Tests recogition of strings in API.
+ */
+ @Test
+ public void testStringRecognition() {
+
+ // test recognition of forms of "be"
+ PhraseElement _s1 = this.phraseFactory.createClause(
+ "my cat", "be", "sad"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Assert.assertEquals(
+ "my cat is sad", this.realiser.realise(_s1).getRealisation()); //$NON-NLS-1$
+
+ // test recognition of pronoun for afreement
+ PhraseElement _s2 = this.phraseFactory
+ .createClause("I", "want", "Mary"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ Assert.assertEquals(
+ "I want Mary", this.realiser.realise(_s2).getRealisation()); //$NON-NLS-1$
+
+ // test recognition of pronoun for correct form
+ PhraseElement subject = this.phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$
+ subject.setFeature(InternalFeature.SPECIFIER, "a"); //$NON-NLS-1$
+ subject.addPostModifier("from next door"); //$NON-NLS-1$
+ PhraseElement object = this.phraseFactory.createNounPhrase("I"); //$NON-NLS-1$
+ PhraseElement s = this.phraseFactory.createClause(subject,
+ "chase", object); //$NON-NLS-1$
+ s.setFeature(Feature.PROGRESSIVE, true);
+ Assert.assertEquals("a dog from next door is chasing me", //$NON-NLS-1$
+ this.realiser.realise(s).getRealisation());
+ }
+
+ /**
+ * Tests complex agreement.
+ */
+ @Test
+ public void testAgreement() {
+
+ // basic agreement
+ NPPhraseSpec np = this.phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$
+ np.setSpecifier("the"); //$NON-NLS-1$
+ np.addPreModifier("angry"); //$NON-NLS-1$
+ PhraseElement _s1 = this.phraseFactory
+ .createClause(np, "chase", "John"); //$NON-NLS-1$ //$NON-NLS-2$
+ Assert.assertEquals("the angry dog chases John", this.realiser //$NON-NLS-1$
+ .realise(_s1).getRealisation());
+
+ // plural
+ np = this.phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$
+ np.setSpecifier("the"); //$NON-NLS-1$
+ np.addPreModifier("angry"); //$NON-NLS-1$
+ np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ _s1 = this.phraseFactory.createClause(np, "chase", "John"); //$NON-NLS-1$ //$NON-NLS-2$
+ Assert.assertEquals("the angry dogs chase John", this.realiser //$NON-NLS-1$
+ .realise(_s1).getRealisation());
+
+ // test agreement with "there is"
+ np = this.phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$
+ np.addPreModifier("angry"); //$NON-NLS-1$
+ np.setFeature(Feature.NUMBER, NumberAgreement.SINGULAR);
+ np.setSpecifier("a"); //$NON-NLS-1$
+ PhraseElement _s2 = this.phraseFactory.createClause("there", "be", np); //$NON-NLS-1$ //$NON-NLS-2$
+ Assert.assertEquals("there is an angry dog", this.realiser //$NON-NLS-1$
+ .realise(_s2).getRealisation());
+
+ // plural with "there"
+ np = this.phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$
+ np.addPreModifier("angry"); //$NON-NLS-1$
+ np.setSpecifier("a"); //$NON-NLS-1$
+ np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ _s2 = this.phraseFactory.createClause("there", "be", np); //$NON-NLS-1$ //$NON-NLS-2$
+ Assert.assertEquals("there are some angry dogs", this.realiser //$NON-NLS-1$
+ .realise(_s2).getRealisation());
+ }
+
+ /**
+ * Tests passive.
+ */
+ @Test
+ public void testPassive() {
+ // passive with just complement
+ SPhraseSpec _s1 = this.phraseFactory.createClause(null,
+ "intubate", this.phraseFactory.createNounPhrase("the", "baby")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ _s1.setFeature(Feature.PASSIVE, true);
+
+ Assert.assertEquals("the baby is intubated", this.realiser //$NON-NLS-1$
+ .realise(_s1).getRealisation());
+
+ // passive with subject and complement
+ _s1 = this.phraseFactory.createClause(null,
+ "intubate", this.phraseFactory.createNounPhrase("the", "baby")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ _s1.setSubject(this.phraseFactory.createNounPhrase("the nurse")); //$NON-NLS-1$
+ _s1.setFeature(Feature.PASSIVE, true);
+ Assert.assertEquals("the baby is intubated by the nurse", //$NON-NLS-1$
+ this.realiser.realise(_s1).getRealisation());
+
+ // passive with subject and indirect object
+ SPhraseSpec _s2 = this.phraseFactory.createClause(null, "give", //$NON-NLS-1$
+ this.phraseFactory.createNounPhrase("the", "baby")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ PhraseElement morphine = this.phraseFactory
+ .createNounPhrase("50ug of morphine"); //$NON-NLS-1$
+ _s2.setIndirectObject(morphine);
+ _s2.setFeature(Feature.PASSIVE, true);
+ Assert.assertEquals("the baby is given 50ug of morphine", //$NON-NLS-1$
+ this.realiser.realise(_s2).getRealisation());
+
+ // passive with subject, complement and indirect object
+ _s2 = this.phraseFactory.createClause(this.phraseFactory
+ .createNounPhrase("the", "nurse"), "give", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ this.phraseFactory.createNounPhrase("the", "baby")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ morphine = this.phraseFactory.createNounPhrase("50ug of morphine"); //$NON-NLS-1$
+ _s2.setIndirectObject(morphine);
+ _s2.setFeature(Feature.PASSIVE, true);
+ Assert.assertEquals("the baby is given 50ug of morphine by the nurse", //$NON-NLS-1$
+ this.realiser.realise(_s2).getRealisation());
+
+ // test agreement in passive
+ PhraseElement _s3 = this.phraseFactory.createClause(
+ new CoordinatedPhraseElement("my dog", "your cat"), "chase", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "George"); //$NON-NLS-1$
+ _s3.setFeature(Feature.TENSE, Tense.PAST);
+ _s3.addFrontModifier("yesterday"); //$NON-NLS-1$
+ Assert.assertEquals("yesterday my dog and your cat chased George", //$NON-NLS-1$
+ this.realiser.realise(_s3).getRealisation());
+
+ _s3 = this.phraseFactory.createClause(new CoordinatedPhraseElement(
+ "my dog", "your cat"), "chase", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ this.phraseFactory.createNounPhrase("George")); //$NON-NLS-1$
+ _s3.setFeature(Feature.TENSE, Tense.PAST);
+ _s3.addFrontModifier("yesterday"); //$NON-NLS-1$
+ _s3.setFeature(Feature.PASSIVE, true);
+ Assert.assertEquals(
+ "yesterday George was chased by my dog and your cat", //$NON-NLS-1$
+ this.realiser.realise(_s3).getRealisation());
+
+ // test correct pronoun forms
+ PhraseElement _s4 = this.phraseFactory.createClause(this.phraseFactory
+ .createNounPhrase("he"), "chase", //$NON-NLS-1$ //$NON-NLS-2$
+ this.phraseFactory.createNounPhrase("I")); //$NON-NLS-1$
+ Assert.assertEquals("he chases me", this.realiser.realise(_s4) //$NON-NLS-1$
+ .getRealisation());
+ _s4 = this.phraseFactory
+ .createClause(
+ this.phraseFactory.createNounPhrase("he"), "chase", this.phraseFactory.createNounPhrase("me")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ _s4.setFeature(Feature.PASSIVE, true);
+ Assert
+ .assertEquals(
+ "I am chased by him", this.realiser.realise(_s4).getRealisation()); //$NON-NLS-1$
+
+ // same thing, but giving the S constructor "me". Should recognise
+ // correct pro
+ // anyway
+ PhraseElement _s5 = this.phraseFactory
+ .createClause("him", "chase", "I"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Assert.assertEquals(
+ "he chases me", this.realiser.realise(_s5).getRealisation()); //$NON-NLS-1$
+
+ _s5 = this.phraseFactory.createClause("him", "chase", "I"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ _s5.setFeature(Feature.PASSIVE, true);
+ Assert
+ .assertEquals(
+ "I am chased by him", this.realiser.realise(_s5).getRealisation()); //$NON-NLS-1$
+ }
+
+ /**
+ * Test that complements set within the VP are raised when sentence is
+ * passivised.
+ */
+ @Test
+ public void testPassiveWithInternalVPComplement() {
+ PhraseElement vp = this.phraseFactory.createVerbPhrase(phraseFactory
+ .createWord("upset", LexicalCategory.VERB));
+ vp.addComplement(phraseFactory.createNounPhrase("the", "man"));
+ PhraseElement _s6 = this.phraseFactory.createClause(phraseFactory
+ .createNounPhrase("the", "child"), vp);
+ _s6.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals("the child upset the man", this.realiser.realise(
+ _s6).getRealisation());
+
+ _s6.setFeature(Feature.PASSIVE, true);
+ Assert.assertEquals("the man was upset by the child", this.realiser
+ .realise(_s6).getRealisation());
+ }
+
+ /**
+ * Tests tenses with modals.
+ */
+ @Test
+ public void testModal() {
+
+ setUp();
+ // simple modal in present tense
+ this.s3.setFeature(Feature.MODAL, "should"); //$NON-NLS-1$
+ Assert.assertEquals("the man should give the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+
+ // modal + future -- uses present
+ setUp();
+ this.s3.setFeature(Feature.MODAL, "should"); //$NON-NLS-1$
+ this.s3.setFeature(Feature.TENSE, Tense.FUTURE);
+ Assert.assertEquals("the man should give the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+
+ // modal + present progressive
+ setUp();
+ this.s3.setFeature(Feature.MODAL, "should"); //$NON-NLS-1$
+ this.s3.setFeature(Feature.TENSE, Tense.FUTURE);
+ this.s3.setFeature(Feature.PROGRESSIVE, true);
+ Assert.assertEquals("the man should be giving the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+
+ // modal + past tense
+ setUp();
+ this.s3.setFeature(Feature.MODAL, "should"); //$NON-NLS-1$
+ this.s3.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals(
+ "the man should have given the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+
+ // modal + past progressive
+ setUp();
+ this.s3.setFeature(Feature.MODAL, "should"); //$NON-NLS-1$
+ this.s3.setFeature(Feature.TENSE, Tense.PAST);
+ this.s3.setFeature(Feature.PROGRESSIVE, true);
+
+ Assert.assertEquals(
+ "the man should have been giving the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+
+ }
+
+ /**
+ * Test for passivisation with mdoals
+ */
+ @Test
+ public void testModalWithPassive() {
+ NPPhraseSpec object = this.phraseFactory.createNounPhrase("the",
+ "pizza");
+ AdjPhraseSpec post = this.phraseFactory.createAdjectivePhrase("good");
+ AdvPhraseSpec as = this.phraseFactory.createAdverbPhrase("as");
+ as.addComplement(post);
+ VPPhraseSpec verb = this.phraseFactory.createVerbPhrase("classify");
+ verb.addPostModifier(as);
+ verb.addComplement(object);
+ SPhraseSpec s = this.phraseFactory.createClause();
+ s.setVerbPhrase(verb);
+ s.setFeature(Feature.MODAL, "can");
+ // s.setFeature(Feature.FORM, Form.INFINITIVE);
+ s.setFeature(Feature.PASSIVE, true);
+ Assert.assertEquals("the pizza can be classified as good",
+ this.realiser.realise(s).getRealisation());
+ }
+
+ @Test
+ public void testPassiveWithPPCompl() {
+ // passive with just complement
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("wave");
+ subject.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ NPPhraseSpec object = this.phraseFactory.createNounPhrase("surfer");
+ object.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+
+ SPhraseSpec _s1 = this.phraseFactory.createClause(subject,
+ "carry", object); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ // add a PP complement
+ PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("to",
+ this.phraseFactory.createNounPhrase("the", "shore"));
+ pp.setFeature(InternalFeature.DISCOURSE_FUNCTION,
+ DiscourseFunction.INDIRECT_OBJECT);
+ _s1.addComplement(pp);
+
+ _s1.setFeature(Feature.PASSIVE, true);
+
+ Assert.assertEquals(
+ "surfers are carried to the shore by waves", this.realiser //$NON-NLS-1$
+ .realise(_s1).getRealisation());
+ }
+
+ @Test
+ public void testPassiveWithPPMod() {
+ // passive with just complement
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("wave");
+ subject.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ NPPhraseSpec object = this.phraseFactory.createNounPhrase("surfer");
+ object.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+
+ SPhraseSpec _s1 = this.phraseFactory.createClause(subject,
+ "carry", object); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ // add a PP complement
+ PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("to",
+ this.phraseFactory.createNounPhrase("the", "shore"));
+ _s1.addPostModifier(pp);
+
+ _s1.setFeature(Feature.PASSIVE, true);
+
+ Assert.assertEquals(
+ "surfers are carried to the shore by waves", this.realiser //$NON-NLS-1$
+ .realise(_s1).getRealisation());
+ }
+
+ @Test
+ public void testCuePhrase() {
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("wave");
+ subject.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ NPPhraseSpec object = this.phraseFactory.createNounPhrase("surfer");
+ object.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+
+ SPhraseSpec _s1 = this.phraseFactory.createClause(subject,
+ "carry", object); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ // add a PP complement
+ PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("to",
+ this.phraseFactory.createNounPhrase("the", "shore"));
+ _s1.addPostModifier(pp);
+
+ _s1.setFeature(Feature.PASSIVE, true);
+
+ _s1.addFrontModifier("however");
+
+
+ //without comma separation of cue phrase
+ Assert.assertEquals(
+ "however surfers are carried to the shore by waves", this.realiser //$NON-NLS-1$
+ .realise(_s1).getRealisation());
+
+ //with comma separation
+ this.realiser.setCommaSepCuephrase(true);
+ Assert.assertEquals(
+ "however, surfers are carried to the shore by waves", this.realiser //$NON-NLS-1$
+ .realise(_s1).getRealisation());
+ }
+
+
+ /**
+ * Check that setComplement replaces earlier complements
+ */
+ @Test
+ public void setComplementTest() {
+ SPhraseSpec s = this.phraseFactory.createClause();
+ s.setSubject("I");
+ s.setVerb("see");
+ s.setObject("a dog");
+
+ Assert.assertEquals("I see a dog", this.realiser.realise(s)
+ .getRealisation());
+
+ s.setObject("a cat");
+ Assert.assertEquals("I see a cat", this.realiser.realise(s)
+ .getRealisation());
+
+ s.setObject("a wolf");
+ Assert.assertEquals("I see a wolf", this.realiser.realise(s)
+ .getRealisation());
+
+ }
+
+
+ /**
+ * Test for subclauses involving WH-complements Based on a query by Owen
+ * Bennett
+ */
+ @Test
+ public void subclausesTest() {
+ // Once upon a time, there was an Accountant, called Jeff, who lived in
+ // a forest.
+
+ // main sentence
+ NPPhraseSpec acct = this.phraseFactory.createNounPhrase("a",
+ "accountant");
+
+ // first postmodifier of "an accountant"
+ VPPhraseSpec sub1 = this.phraseFactory.createVerbPhrase("call");
+ sub1.addComplement("Jeff");
+ sub1.setFeature(Feature.FORM, Form.PAST_PARTICIPLE);
+ // this is an appositive modifier, which makes simplenlg put it between
+ // commas
+ sub1.setFeature(Feature.APPOSITIVE, true);
+ acct.addPostModifier(sub1);
+
+ // second postmodifier of "an accountant" is "who lived in a forest"
+ SPhraseSpec sub2 = this.phraseFactory.createClause();
+ VPPhraseSpec subvp = this.phraseFactory.createVerbPhrase("live");
+ subvp.setFeature(Feature.TENSE, Tense.PAST);
+ subvp.setComplement(this.phraseFactory.createPrepositionPhrase("in",
+ this.phraseFactory.createNounPhrase("a", "forest")));
+ sub2.setVerbPhrase(subvp);
+ // simplenlg can't yet handle wh-clauses in NPs, so we need to hack it
+ // by setting the subject to "who"
+ sub2.setSubject("who");
+ acct.addPostModifier(sub2);
+
+ // main sentence
+ SPhraseSpec s = this.phraseFactory.createClause("there", "be", acct);
+ s.setFeature(Feature.TENSE, Tense.PAST);
+
+ // add front modifier "once upon a time"
+ s.addFrontModifier("once upon a time");
+
+ Assert.assertEquals(
+ "once upon a time there was an accountant, called Jeff, who lived in a forest",
+ this.realiser.realise(s).getRealisation());
+
+ }
+
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/CoordinationTest.java b/SharpSimpleNLGUnitTests/syntax/english/CoordinationTest.java
new file mode 100644
index 0000000..adc3db2
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/CoordinationTest.java
@@ -0,0 +1,201 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.features.Tense;
+import simplenlg.framework.CoordinatedPhraseElement;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.PPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.phrasespec.VPPhraseSpec;
+
+/**
+ * Some tests for coordination, especially of coordinated VPs with modifiers.
+ *
+ * @author Albert Gatt
+ *
+ */
+public class CoordinationTest extends SimpleNLG4Test {
+
+ public CoordinationTest(String name) {
+ super(name);
+ }
+
+ @Override
+ @After
+ public void tearDown() {
+ super.tearDown();
+ }
+
+
+ /**
+ * Check that empty coordinate phrases are not realised as "null"
+ */
+ @Test
+ public void emptyCoordinationTest() {
+ // first a simple phrase with no coordinates
+ CoordinatedPhraseElement coord = this.phraseFactory
+ .createCoordinatedPhrase();
+ Assert.assertEquals("", this.realiser.realise(coord).getRealisation());
+
+ // now one with a premodifier and nothing else
+ coord.addPreModifier(this.phraseFactory.createAdjectivePhrase("nice"));
+ Assert.assertEquals("nice", this.realiser.realise(coord)
+ .getRealisation());
+ }
+
+ /**
+ * Test pre and post-modification of coordinate VPs inside a sentence.
+ */
+ @Test
+ public void testModifiedCoordVP() {
+ CoordinatedPhraseElement coord = this.phraseFactory
+ .createCoordinatedPhrase(this.getUp, this.fallDown);
+ coord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals("got up and fell down", this.realiser
+ .realise(coord).getRealisation());
+
+ // add a premodifier
+ coord.addPreModifier("slowly");
+ Assert.assertEquals("slowly got up and fell down", this.realiser
+ .realise(coord).getRealisation());
+
+ // adda postmodifier
+ coord.addPostModifier(this.behindTheCurtain);
+ Assert.assertEquals("slowly got up and fell down behind the curtain",
+ this.realiser.realise(coord).getRealisation());
+
+ // put within the context of a sentence
+ SPhraseSpec s = this.phraseFactory.createClause("Jake", coord);
+ s.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals(
+ "Jake slowly got up and fell down behind the curtain",
+ this.realiser.realise(s).getRealisation());
+
+ // add premod to the sentence
+ s.addPreModifier(this.lexicon
+ .getWord("however", LexicalCategory.ADVERB));
+ Assert.assertEquals(
+ "Jake however slowly got up and fell down behind the curtain",
+ this.realiser.realise(s).getRealisation());
+
+ // add postmod to the sentence
+ s.addPostModifier(this.inTheRoom);
+ Assert.assertEquals(
+ "Jake however slowly got up and fell down behind the curtain in the room",
+ this.realiser.realise(s).getRealisation());
+ }
+
+ /**
+ * Test due to Chris Howell -- create a complex sentence with front modifier
+ * and coordinateVP. This is a version in which we create the coordinate
+ * phrase directly.
+ */
+ @Test
+ public void testCoordinateVPComplexSubject() {
+ // "As a result of the procedure the patient had an adverse contrast media reaction and went into cardiogenic shock."
+ SPhraseSpec s = this.phraseFactory.createClause();
+
+ s.setSubject(this.phraseFactory.createNounPhrase("the", "patient"));
+
+ // first VP
+ VPPhraseSpec vp1 = this.phraseFactory.createVerbPhrase(this.lexicon
+ .getWord("have", LexicalCategory.VERB));
+ NPPhraseSpec np1 = this.phraseFactory.createNounPhrase("a",
+ this.lexicon.getWord("contrast media reaction",
+ LexicalCategory.NOUN));
+ np1.addPreModifier(this.lexicon.getWord("adverse",
+ LexicalCategory.ADJECTIVE));
+ vp1.addComplement(np1);
+
+ // second VP
+ VPPhraseSpec vp2 = this.phraseFactory.createVerbPhrase(this.lexicon
+ .getWord("go", LexicalCategory.VERB));
+ PPPhraseSpec pp = this.phraseFactory
+ .createPrepositionPhrase("into", this.lexicon.getWord(
+ "cardiogenic shock", LexicalCategory.NOUN));
+ vp2.addComplement(pp);
+
+ // coordinate
+ CoordinatedPhraseElement coord = this.phraseFactory
+ .createCoordinatedPhrase(vp1, vp2);
+ coord.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals(
+ "had an adverse contrast media reaction and went into cardiogenic shock",
+ this.realiser.realise(coord).getRealisation());
+
+ // now put this in the sentence
+ s.setVerbPhrase(coord);
+ s.addFrontModifier("As a result of the procedure");
+ Assert.assertEquals(
+ "As a result of the procedure the patient had an adverse contrast media reaction and went into cardiogenic shock",
+ this.realiser.realise(s).getRealisation());
+
+ }
+
+ /**
+ * Test setting a conjunction to null
+ */
+ public void testNullConjunction() {
+ SPhraseSpec p = this.phraseFactory.createClause("I", "be", "happy");
+ SPhraseSpec q = this.phraseFactory.createClause("I", "eat", "fish");
+ CoordinatedPhraseElement pq = this.phraseFactory
+ .createCoordinatedPhrase();
+ pq.addCoordinate(p);
+ pq.addCoordinate(q);
+ pq.setFeature(Feature.CONJUNCTION, "");
+
+ // should come out without conjunction
+ Assert.assertEquals("I am happy I eat fish", this.realiser.realise(pq)
+ .getRealisation());
+
+ // should come out without conjunction
+ pq.setFeature(Feature.CONJUNCTION, null);
+ Assert.assertEquals("I am happy I eat fish", this.realiser.realise(pq)
+ .getRealisation());
+
+ }
+
+ /**
+ * Check that the negation feature on a child of a coordinate phrase remains
+ * as set, unless explicitly set otherwise at the parent level.
+ */
+ @Test
+ public void testNegationFeature() {
+ SPhraseSpec s1 = this.phraseFactory
+ .createClause("he", "have", "asthma");
+ SPhraseSpec s2 = this.phraseFactory.createClause("he", "have",
+ "diabetes");
+ s1.setFeature(Feature.NEGATED, true);
+ CoordinatedPhraseElement coord = this.phraseFactory
+ .createCoordinatedPhrase(s1, s2);
+ String realisation = this.realiser.realise(coord).getRealisation();
+ System.out.println(realisation);
+ Assert.assertEquals("he does not have asthma and he has diabetes",
+ realisation);
+ }
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/DeterminerTest.java b/SharpSimpleNLGUnitTests/syntax/english/DeterminerTest.java
new file mode 100644
index 0000000..670154b
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/DeterminerTest.java
@@ -0,0 +1,388 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import junit.framework.Assert;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import simplenlg.framework.NLGFactory;
+import simplenlg.lexicon.Lexicon;
+import simplenlg.lexicon.NIHDBLexicon;
+import simplenlg.lexicon.XMLLexicon;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * Some determiner tests -- in particular for indefinite articles like "a" or "an".
+ *
+ * @author Saad Mahamood, Data2Text Limited.
+ *
+ */
+public class DeterminerTest {
+
+ /** The realiser. */
+ private Realiser realiser;
+
+ private NLGFactory phraseFactory;
+
+ private Lexicon lexicon;
+
+ private final String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
+
+ /**
+ * Set up the variables we'll need for this simplenlg.test to run (Called
+ * automatically by JUnit)
+ */
+ @Before
+ public void setUp() {
+ this.lexicon = new XMLLexicon(); // built in lexicon
+
+ this.phraseFactory = new NLGFactory(this.lexicon);
+ this.realiser = new Realiser(this.lexicon);
+ }
+
+ @After
+ public void tearDown() {
+ this.realiser = null;
+
+ this.phraseFactory = null;
+
+ if(null != lexicon) {
+ lexicon = null;
+ }
+ }
+
+ /**
+ * testLowercaseConstant - Test for when there is a lower case constant
+ */
+ @Test
+ public void testLowercaseConstant() {
+
+ SPhraseSpec sentence = this.phraseFactory.createClause();
+
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "dog");
+ sentence.setSubject(subject);
+
+ String output = this.realiser.realiseSentence(sentence);
+
+ Assert.assertEquals("A dog.", output);
+ }
+
+ /**
+ * testLowercaseVowel - Test for "an" as a specifier.
+ */
+ @Test
+ public void testLowercaseVowel() {
+ SPhraseSpec sentence = this.phraseFactory.createClause();
+
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "owl");
+ sentence.setSubject(subject);
+
+ String output = this.realiser.realiseSentence(sentence);
+
+ Assert.assertEquals("An owl.", output);
+ }
+
+ /**
+ * testUppercaseConstant - Test for when there is a upper case constant
+ */
+ @Test
+ public void testUppercaseConstant() {
+
+ SPhraseSpec sentence = this.phraseFactory.createClause();
+
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "Cat");
+ sentence.setSubject(subject);
+
+ String output = this.realiser.realiseSentence(sentence);
+
+ Assert.assertEquals("A Cat.", output);
+ }
+
+ /**
+ * testUppercaseVowel - Test for "an" as a specifier for upper subjects.
+ */
+ @Test
+ public void testUppercaseVowel() {
+ SPhraseSpec sentence = this.phraseFactory.createClause();
+
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "Emu");
+ sentence.setSubject(subject);
+
+ String output = this.realiser.realiseSentence(sentence);
+
+ Assert.assertEquals("An Emu.", output);
+ }
+
+ /**
+ * testNumericA - Test for "a" specifier with a numeric subject
+ */
+ @Test
+ public void testNumericA() {
+ SPhraseSpec sentence = this.phraseFactory.createClause();
+
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "7");
+ sentence.setSubject(subject);
+
+ String output = this.realiser.realiseSentence(sentence);
+
+ Assert.assertEquals("A 7.", output);
+ }
+
+ /**
+ * testNumericAn - Test for "an" specifier with a numeric subject
+ */
+ @Test
+ public void testNumericAn() {
+ SPhraseSpec sentence = this.phraseFactory.createClause();
+
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "11");
+ sentence.setSubject(subject);
+
+ String output = this.realiser.realiseSentence(sentence);
+
+ Assert.assertEquals("An 11.", output);
+ }
+
+ /**
+ * testIrregularSubjects - Test irregular subjects that don't conform to the
+ * vowel vs. constant divide.
+ */
+ @Test
+ public void testIrregularSubjects() {
+ SPhraseSpec sentence = this.phraseFactory.createClause();
+
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "one");
+ sentence.setSubject(subject);
+
+ String output = this.realiser.realiseSentence(sentence);
+
+ Assert.assertEquals("A one.", output);
+ }
+
+ /**
+ * testSingluarThisDeterminerNPObject - Test for "this" when used in the singular form as a determiner in a NP Object
+ */
+ @Test
+ public void testSingluarThisDeterminerNPObject() {
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("this", "monkey");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.assertEquals("This monkey.", this.realiser.realiseSentence(sentence_1));
+ }
+
+ /**
+ * testPluralThisDeterminerNPObject - Test for "this" when used in the plural form as a determiner in a NP Object
+ */
+ @Test
+ public void testPluralThisDeterminerNPObject() {
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(true);
+ nounPhrase_1.setDeterminer("this");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.assertEquals("These monkeys.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testSingluarThatDeterminerNPObject - Test for "that" when used in the singular form as a determiner in a NP Object
+ */
+ @Test
+ public void testSingluarThatDeterminerNPObject() {
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("that", "monkey");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.assertEquals("That monkey.", this.realiser.realiseSentence(sentence_1));
+ }
+
+ /**
+ * testPluralThatDeterminerNPObject - Test for "that" when used in the plural form as a determiner in a NP Object
+ */
+ @Test
+ public void testPluralThatDeterminerNPObject() {
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(true);
+ nounPhrase_1.setDeterminer("that");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.assertEquals("Those monkeys.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testSingularThoseDeterminerNPObject - Test for "those" when used in the singular form as a determiner in a NP Object
+ */
+ @Test
+ public void testSingularThoseDeterminerNPObject() {
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(false);
+ nounPhrase_1.setDeterminer("those");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.assertEquals("That monkey.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testSingularTheseDeterminerNPObject - Test for "these" when used in the singular form as a determiner in a NP Object
+ */
+ @Test
+ public void testSingularTheseDeterminerNPObject() {
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(false);
+ nounPhrase_1.setDeterminer("these");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.assertEquals("This monkey.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testPluralThoseDeterminerNPObject - Test for "those" when used in the plural form as a determiner in a NP Object
+ */
+ @Test
+ public void testPluralThoseDeterminerNPObject() {
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(true);
+ nounPhrase_1.setDeterminer("those");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.assertEquals("Those monkeys.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testPluralTheseDeterminerNPObject - Test for "these" when used in the plural form as a determiner in a NP Object
+ */
+ @Test
+ public void testPluralTheseDeterminerNPObject() {
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(true);
+ nounPhrase_1.setDeterminer("these");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.assertEquals("These monkeys.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testSingularTheseDeterminerNPObject - Test for "these" when used in the singular form as a determiner in a NP Object
+ * using the NIHDB Lexicon.
+ */
+ @Test
+ public void testSingularTheseDeterminerNPObject_NIHDBLexicon() {
+ this.lexicon = new NIHDBLexicon(DB_FILENAME);
+ this.phraseFactory = new NLGFactory(this.lexicon);
+ this.realiser = new Realiser(this.lexicon);
+
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(false);
+ nounPhrase_1.setDeterminer("these");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.assertEquals("This monkey.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testSingularThoseDeterminerNPObject - Test for "those" when used in the singular form as a determiner in a NP Object
+ * using the NIHDB Lexicon
+ */
+ @Test
+ public void testSingularThoseDeterminerNPObject_NIHDBLexicon() {
+ this.lexicon = new NIHDBLexicon(DB_FILENAME);
+ this.phraseFactory = new NLGFactory(this.lexicon);
+ this.realiser = new Realiser(this.lexicon);
+
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(false);
+ nounPhrase_1.setDeterminer("those");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.assertEquals("That monkey.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testPluralThatDeterminerNPObject - Test for "that" when used in the plural form as a determiner in a NP Object
+ * using the NIHDB Lexicon.
+ */
+ @Test
+ public void testPluralThatDeterminerNPObject_NIHDBLexicon() {
+ this.lexicon = new NIHDBLexicon(DB_FILENAME);
+ this.phraseFactory = new NLGFactory(this.lexicon);
+ this.realiser = new Realiser(this.lexicon);
+
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(true);
+ nounPhrase_1.setDeterminer("that");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.assertEquals("Those monkeys.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+ /**
+ * testPluralThisDeterminerNPObject - Test for "this" when used in the plural form as a determiner in a NP Object
+ * using the NIHDBLexicon.
+ */
+ @Test
+ public void testPluralThisDeterminerNPObject_NIHDBLexicon() {
+ this.lexicon = new NIHDBLexicon(DB_FILENAME);
+ this.phraseFactory = new NLGFactory(this.lexicon);
+ this.realiser = new Realiser(this.lexicon);
+
+ SPhraseSpec sentence_1 = this.phraseFactory.createClause();
+
+ NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
+ nounPhrase_1.setPlural(true);
+ nounPhrase_1.setDeterminer("this");
+ sentence_1.setObject(nounPhrase_1);
+
+ Assert.assertEquals("These monkeys.", this.realiser.realiseSentence(sentence_1));
+
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/DocumentElementTest.java b/SharpSimpleNLGUnitTests/syntax/english/DocumentElementTest.java
new file mode 100644
index 0000000..9416f4a
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/DocumentElementTest.java
@@ -0,0 +1,209 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import java.util.Arrays;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.framework.DocumentElement;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+
+/**
+ * Tests for the DocumentElement class.
+ *
+ * @author ereiter
+ */
+public class DocumentElementTest extends SimpleNLG4Test {
+
+ private SPhraseSpec p1, p2, p3;
+
+ /**
+ * Instantiates a new document element test.
+ *
+ * @param name
+ * the name
+ */
+ public DocumentElementTest(String name) {
+ super(name);
+ }
+
+ @Before
+ public void setUp() {
+ super.setUp();
+ p1 = this.phraseFactory.createClause("you", "be", "happy");
+ p2 = this.phraseFactory.createClause("I", "be", "sad");
+ p3 = this.phraseFactory.createClause("they", "be", "nervous");
+ }
+
+ @Override
+ @After
+ public void tearDown() {
+ super.tearDown();
+ this.p1 = null;
+ this.p2 = null;
+ this.p3 = null;
+ }
+
+ /**
+ * Basic tests.
+ */
+ @Test
+ public void testBasics() {
+ DocumentElement s1 = this.phraseFactory.createSentence(p1);
+ DocumentElement s2 = this.phraseFactory.createSentence(p2);
+ DocumentElement s3 = this.phraseFactory.createSentence(p3);
+
+ DocumentElement par1 = this.phraseFactory.createParagraph(Arrays
+ .asList(s1, s2, s3));
+
+ Assert.assertEquals("You are happy. I am sad. They are nervous.\n\n",
+ this.realiser.realise(par1).getRealisation());
+
+ }
+
+ /**
+ * Ensure that no extra whitespace is inserted into a realisation if a
+ * constituent is empty. (This is to check for a bug fix for addition of
+ * spurious whitespace).
+ */
+ public void testExtraWhitespace() {
+ NPPhraseSpec np1 = this.phraseFactory.createNounPhrase("a", "vessel");
+
+ // empty coordinate as premod
+ np1.setPreModifier(this.phraseFactory.createCoordinatedPhrase());
+ Assert.assertEquals("a vessel", this.realiser.realise(np1)
+ .getRealisation());
+
+ // empty adjP as premod
+ np1.setPreModifier(this.phraseFactory.createAdjectivePhrase());
+ Assert.assertEquals("a vessel", this.realiser.realise(np1)
+ .getRealisation());
+
+ // empty string
+ np1.setPreModifier("");
+ Assert.assertEquals("a vessel", this.realiser.realise(np1)
+ .getRealisation());
+
+ }
+
+ /**
+ * test whether sents can be embedded in a section without intervening paras
+ */
+ @Test
+ public void testEmbedding() {
+ DocumentElement sent = phraseFactory.createSentence("This is a test");
+ DocumentElement sent2 = phraseFactory.createSentence(phraseFactory
+ .createClause("John", "be", "missing"));
+ DocumentElement section = phraseFactory.createSection("SECTION TITLE");
+ section.addComponent(sent);
+ section.addComponent(sent2);
+
+ Assert.assertEquals(
+ "SECTION TITLE\nThis is a test.\n\nJohn is missing.\n\n",
+ this.realiser.realise(section).getRealisation());
+ }
+
+ @Test
+ public void testSections() {
+ // doc which contains a section, and two paras
+ DocumentElement doc = this.phraseFactory
+ .createDocument("Test Document");
+
+ DocumentElement section = this.phraseFactory
+ .createSection("Test Section");
+ doc.addComponent(section);
+
+ DocumentElement para1 = this.phraseFactory.createParagraph();
+ DocumentElement sent1 = this.phraseFactory
+ .createSentence("This is the first test paragraph");
+ para1.addComponent(sent1);
+ section.addComponent(para1);
+
+ DocumentElement para2 = this.phraseFactory.createParagraph();
+ DocumentElement sent2 = this.phraseFactory
+ .createSentence("This is the second test paragraph");
+ para2.addComponent(sent2);
+ section.addComponent(para2);
+
+ Assert
+ .assertEquals(
+ "Test Document\n\nTest Section\nThis is the first test paragraph.\n\nThis is the second test paragraph.\n\n",
+ this.realiser.realise(doc).getRealisation());
+ //
+ // Realiser htmlRealiser = new Realiser();
+ // htmlRealiser.setHTML(true);
+ // Assert
+ // .assertEquals(
+ // "Test Document \r\nTest Section \r\nTest Subsection \r\nThis is the first test paragraph. \r\nThis is the second test paragraph. \r\n \r\n\r\n",
+ // htmlRealiser.realise(doc));
+ //
+ // // now lets try a doc with a header, header-less section and
+ // subsection,
+ // // and 2 paras (no list)
+ // doc = new TextSpec();
+ // doc.setDocument();
+ // doc.setHeading("Test Document2");
+ //
+ // section = new TextSpec();
+ // section.setDocStructure(DocStructure.SECTION);
+ // ;
+ // doc.addSpec(section);
+ //
+ // subsection = new TextSpec();
+ // subsection.setDocStructure(DocStructure.SUBSECTION);
+ // section.addSpec(subsection);
+ //
+ // // use list from above, with indent
+ // subsection.addChild(list);
+ // list.setIndentedList(false);
+ //
+ // Assert
+ // .assertEquals(
+ // "Test Document2\r\n\r\nThis is the first test paragraph.\r\n\r\nThis is the second test paragraph.\r\n",
+ // this.realiser.realise(doc));
+ //
+ // Assert
+ // .assertEquals(
+ // "Test Document2 \r\nThis is the first test paragraph.
\r\nThis is the second test paragraph.
\r\n\r\n",
+ // htmlRealiser.realise(doc));
+
+ }
+
+ /**
+ * Tests for lists and embedded lists
+ */
+ public void testListItems() {
+ DocumentElement list = this.phraseFactory.createList();
+ list.addComponent(this.phraseFactory.createListItem(p1));
+ list.addComponent(this.phraseFactory.createListItem(p2));
+ list.addComponent(this.phraseFactory.createListItem(this.phraseFactory
+ .createCoordinatedPhrase(p1, p2)));
+ String realisation = this.realiser.realise(list).getRealisation();
+ Assert.assertEquals(
+ "* you are happy\n* I am sad\n* you are happy and I am sad\n",
+ realisation);
+ }
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/ElisionTest.java b/SharpSimpleNLGUnitTests/syntax/english/ElisionTest.java
new file mode 100644
index 0000000..f3e761c
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/ElisionTest.java
@@ -0,0 +1,105 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import org.junit.After;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import junit.framework.Assert;
+import simplenlg.features.Feature;
+import simplenlg.phrasespec.SPhraseSpec;
+
+/**
+ * Tests for elision of phrases and words
+ */
+@Ignore
+public class ElisionTest extends SimpleNLG4Test {
+
+ public ElisionTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Test elision of phrases in various places in the sentence
+ */
+// public void testPhraseElision() {
+// SPhraseSpec s1 = this.phraseFactory.createClause();
+// s1.setSubject(this.np4); //the rock
+// this.kiss.setComplement(this.np5);//kiss the curtain
+// s1.setVerbPhrase(this.kiss);
+//
+// Assert.assertEquals("the rock kisses the curtain", this.realiser.realise(s1).getRealisation());
+//
+// //elide subject np
+// this.np4.setFeature(Feature.ELIDED, true);
+// Assert.assertEquals("kisses the curtain", this.realiser.realise(s1).getRealisation());
+//
+// //elide vp
+// this.np4.setFeature(Feature.ELIDED, false);
+// this.kiss.setFeature(Feature.ELIDED, true);
+// Assert.assertEquals("the rock", this.realiser.realise(s1).getRealisation());
+//
+// //elide complement only
+// this.kiss.setFeature(Feature.ELIDED, false);
+// this.np5.setFeature(Feature.ELIDED, true);
+// Assert.assertEquals("the rock kisses", this.realiser.realise(s1).getRealisation());
+// }
+
+ @Override
+ @After
+ public void tearDown() {
+ super.tearDown();
+ }
+
+
+ /**
+ * Test for elision of specific words rather than phrases
+ */
+ @Test
+ public void wordElisionTest() {
+ this.realiser.setDebugMode(true);
+ SPhraseSpec s1 = this.phraseFactory.createClause();
+ s1.setSubject(this.np4); //the rock
+ this.kiss.setComplement(this.np5);//kiss the curtain
+ s1.setVerbPhrase(this.kiss);
+
+ this.np5.setFeature(Feature.ELIDED, true);
+ Assert.assertEquals("the rock kisses", this.realiser.realise(s1).getRealisation());
+ }
+
+
+
+ /**
+ * Test for elision of specific words rather than phrases
+ *
+ @Test
+ public void testWordElision() {
+ this.realiser.setDebugMode(true);
+ SPhraseSpec s1 = this.phraseFactory.createClause();
+ s1.setSubject(this.np4); //the rock
+ this.kiss.setComplement(this.np5);//kiss the curtain
+ s1.setVerbPhrase(this.kiss);
+
+ this.kiss.getHead().setFeature(Feature.ELIDED, true);
+ Assert.assertEquals("the rock kisses the curtain", this.realiser.realise(s1).getRealisation());
+ } */
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/FeatureTest.java b/SharpSimpleNLGUnitTests/syntax/english/FeatureTest.java
new file mode 100644
index 0000000..7e10938
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/FeatureTest.java
@@ -0,0 +1,368 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.syntax.english;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.features.Tense;
+import simplenlg.framework.CoordinatedPhraseElement;
+import simplenlg.framework.DocumentElement;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.NLGElement;
+import simplenlg.framework.NLGFactory;
+import simplenlg.framework.PhraseElement;
+import simplenlg.phrasespec.AdvPhraseSpec;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.phrasespec.VPPhraseSpec;
+
+/**
+ * Tests that check that realization of different Features against NLGElements.
+ *
+ * @author François Portet
+ */
+
+public class FeatureTest extends SimpleNLG4Test {
+
+
+ NLGFactory docFactory = new NLGFactory(this.lexicon);
+
+ /**
+ * Instantiates a new text spec test.
+ *
+ * @param name
+ * the name
+ */
+ public FeatureTest(String name) {
+ super(name);
+ }
+
+ @Override
+ @After
+ public void tearDown() {
+ super.tearDown();
+ this.docFactory = null;
+ }
+
+ /**
+ * Tests use of the Possessive Feature.
+ */
+ @Test
+ public void testPossessiveFeature_PastTense() {
+ this.phraseFactory.setLexicon(this.lexicon);
+ this.realiser.setLexicon(this.lexicon);
+
+ // Create the pronoun 'she'
+ NLGElement she = phraseFactory.createWord("she",LexicalCategory.PRONOUN);
+
+ // Set possessive on the pronoun to make it 'her'
+ she.setFeature(Feature.POSSESSIVE, true);
+
+ // Create a noun phrase with the subject lover and the determiner
+ // as she
+ PhraseElement herLover = phraseFactory.createNounPhrase(she,"lover");
+
+ // Create a clause to say 'he be her lover'
+ PhraseElement clause = phraseFactory.createClause("he", "be", herLover);
+
+ // Add the cue phrase need the comma as orthography
+ // currently doesn't handle this.
+ // This could be expanded to be a noun phrase with determiner
+ // 'two' and noun 'week', set to plural and with a premodifier of
+ // 'after'
+ clause.setFeature(Feature.CUE_PHRASE, "after two weeks,");
+
+ // Add the 'for a fortnight' as a post modifier. Alternatively
+ // this could be added as a prepositional phrase 'for' with a
+ // complement of a noun phrase ('a' 'fortnight')
+ clause.addPostModifier("for a fortnight");
+
+ // Set 'be' to 'was' as past tense
+ clause.setFeature(Feature.TENSE,Tense.PAST);
+
+ // Add the clause to a sentence.
+ DocumentElement sentence1 = docFactory.createSentence(clause);
+
+ // Realise the sentence
+ NLGElement realised = this.realiser.realise(sentence1);
+
+ Assert.assertEquals("After two weeks, he was her lover for a fortnight.",
+ realised.getRealisation());
+ }
+
+ /**
+ * Basic tests.
+ */
+ @Test
+ public void testTwoPossessiveFeature_PastTense() {
+ this.phraseFactory.setLexicon(this.lexicon);
+
+ // Create the pronoun 'she'
+ NLGElement she = phraseFactory.createWord("she",LexicalCategory.PRONOUN);
+
+ // Set possessive on the pronoun to make it 'her'
+ she.setFeature(Feature.POSSESSIVE, true);
+
+ // Create a noun phrase with the subject lover and the determiner
+ // as she
+ PhraseElement herLover = phraseFactory.createNounPhrase(she,"lover");
+ herLover.setPlural(true);
+
+ // Create the pronoun 'he'
+ NLGElement he = phraseFactory.createNounPhrase(LexicalCategory.PRONOUN,"he");
+ he.setPlural(true);
+
+ // Create a clause to say 'they be her lovers'
+ PhraseElement clause = phraseFactory.createClause(he, "be", herLover);
+ clause.setFeature(Feature.POSSESSIVE, true);
+
+ // Add the cue phrase need the comma as orthography
+ // currently doesn't handle this.
+ // This could be expanded to be a noun phrase with determiner
+ // 'two' and noun 'week', set to plural and with a premodifier of
+ // 'after'
+ clause.setFeature(Feature.CUE_PHRASE, "after two weeks,");
+
+ // Add the 'for a fortnight' as a post modifier. Alternatively
+ // this could be added as a prepositional phrase 'for' with a
+ // complement of a noun phrase ('a' 'fortnight')
+ clause.addPostModifier("for a fortnight");
+
+ // Set 'be' to 'was' as past tense
+ clause.setFeature(Feature.TENSE,Tense.PAST);
+
+ // Add the clause to a sentence.
+ DocumentElement sentence1 = docFactory.createSentence(clause);
+
+ // Realise the sentence
+ NLGElement realised = this.realiser.realise(sentence1);
+
+ Assert.assertEquals("After two weeks, they were her lovers for a fortnight.", //$NON-NLS-1$
+ realised.getRealisation());
+ }
+
+ /**
+ * Test use of the Complementiser feature by combining two S's using cue phrase and gerund.
+ */
+ @Test
+ public void testComplementiserFeature_PastTense() {
+ this.phraseFactory.setLexicon(this.lexicon);
+
+ PhraseElement born = phraseFactory.createClause("Dave Bus", "be", "born");
+ born.setFeature(Feature.TENSE,Tense.PAST);
+ born.addPostModifier("in");
+ born.setFeature(Feature.COMPLEMENTISER, "which");
+
+ PhraseElement theHouse = phraseFactory.createNounPhrase("the", "house");
+ theHouse.addComplement(born);
+
+ PhraseElement clause = phraseFactory.createClause(theHouse, "be", phraseFactory.createPrepositionPhrase("in", "Edinburgh"));
+ DocumentElement sentence = docFactory.createSentence(clause);
+ NLGElement realised = realiser.realise(sentence);
+
+ // Retrieve the realisation and dump it to the console
+ Assert.assertEquals("The house which Dave Bus was born in is in Edinburgh.",
+ realised.getRealisation());
+ }
+
+ /**
+ * Test use of the Complementiser feature in a {@link CoordinatedPhraseElement} by combine two S's using cue phrase and gerund.
+ */
+ @Test
+ public void testComplementiserFeatureInACoordinatePhrase_PastTense() {
+ this.phraseFactory.setLexicon(this.lexicon);
+
+ NLGElement dave = phraseFactory.createWord("Dave Bus", LexicalCategory.NOUN);
+ NLGElement albert = phraseFactory.createWord("Albert", LexicalCategory.NOUN);
+
+ CoordinatedPhraseElement coord1 = new CoordinatedPhraseElement(
+ dave, albert);
+
+ PhraseElement born = phraseFactory.createClause(coord1, "be", "born");
+ born.setFeature(Feature.TENSE,Tense.PAST);
+ born.addPostModifier("in");
+ born.setFeature(Feature.COMPLEMENTISER, "which");
+
+ PhraseElement theHouse = phraseFactory.createNounPhrase("the", "house");
+ theHouse.addComplement(born);
+
+ PhraseElement clause = phraseFactory.createClause(theHouse, "be", phraseFactory.createPrepositionPhrase("in", "Edinburgh"));
+ DocumentElement sentence = docFactory.createSentence(clause);
+
+ NLGElement realised = realiser.realise(sentence);
+
+ // Retrieve the realisation and dump it to the console
+ Assert.assertEquals("The house which Dave Bus and Albert were born in is in Edinburgh.",
+ realised.getRealisation());
+ }
+
+ /**
+ * Test the use of the Progressive and Complementiser Features in future tense.
+ */
+ @Test
+ public void testProgressiveAndComplementiserFeatures_FutureTense() {
+ this.phraseFactory.setLexicon(this.lexicon);
+
+ // Inner clause is 'I' 'make' 'sentence' 'for'.
+ PhraseElement inner = phraseFactory.createClause("I","make", "sentence for");
+ // Inner clause set to progressive.
+ inner.setFeature(Feature.PROGRESSIVE,true);
+
+ //Complementiser on inner clause is 'whom'
+ inner.setFeature(Feature.COMPLEMENTISER, "whom");
+
+ // create the engineer and add the inner clause as post modifier
+ PhraseElement engineer = phraseFactory.createNounPhrase("the engineer");
+ engineer.addComplement(inner);
+
+ // Outer clause is: 'the engineer' 'go' (preposition 'to' 'holidays')
+ PhraseElement outer = phraseFactory.createClause(engineer,"go",phraseFactory.createPrepositionPhrase("to","holidays"));
+
+ // Outer clause tense is Future.
+ outer.setFeature(Feature.TENSE, Tense.FUTURE);
+
+ // Possibly progressive as well not sure.
+ outer.setFeature(Feature.PROGRESSIVE,true);
+
+ //Outer clause postmodifier would be 'tomorrow'
+ outer.addPostModifier("tomorrow");
+ DocumentElement sentence = docFactory.createSentence(outer);
+ NLGElement realised = realiser.realise(sentence);
+
+ // Retrieve the realisation and dump it to the console
+ Assert.assertEquals("The engineer whom I am making sentence for will be going to holidays tomorrow.",
+ realised.getRealisation());
+ }
+
+
+ /**
+ * Tests the use of the Complementiser, Passive, Perfect features in past tense.
+ */
+ @Test
+ public void testComplementiserPassivePerfectFeatures_PastTense() {
+ setUp();
+ this.realiser.setLexicon(this.lexicon);
+
+ PhraseElement inner = phraseFactory.createClause("I", "play", "poker");
+ inner.setFeature(Feature.TENSE,Tense.PAST);
+ inner.setFeature(Feature.COMPLEMENTISER, "where");
+
+ PhraseElement house = phraseFactory.createNounPhrase("the", "house");
+ house.addComplement(inner);
+
+ SPhraseSpec outer = phraseFactory.createClause(null, "abandon", house);
+
+ outer.addPostModifier("since 1986");
+
+ outer.setFeature(Feature.PASSIVE, true);
+ outer.setFeature(Feature.PERFECT, true);
+
+ DocumentElement sentence = docFactory.createSentence(outer);
+ NLGElement realised = realiser.realise(sentence);
+
+ // Retrieve the realisation and dump it to the console
+ Assert.assertEquals("The house where I played poker has been abandoned since 1986.",
+ realised.getRealisation());
+ }
+
+ /**
+ * Tests the user of the progressive and complementiser featuers in past tense.
+ */
+ @Test
+ public void testProgressiveComplementiserFeatures_PastTense() {
+ this.phraseFactory.setLexicon(this.lexicon);
+
+ NLGElement sandwich = phraseFactory.createNounPhrase(LexicalCategory.NOUN, "sandwich");
+ sandwich.setPlural(true);
+ //
+ PhraseElement first = phraseFactory.createClause("I", "make", sandwich);
+ first.setFeature(Feature.TENSE,Tense.PAST);
+ first.setFeature(Feature.PROGRESSIVE,true);
+ first.setPlural(false);
+
+ PhraseElement second = phraseFactory.createClause("the mayonnaise", "run out");
+ second.setFeature(Feature.TENSE,Tense.PAST);
+ //
+ second.setFeature(Feature.COMPLEMENTISER, "when");
+
+ first.addComplement(second);
+
+ DocumentElement sentence = docFactory.createSentence(first);
+ NLGElement realised = realiser.realise(sentence);
+
+ // Retrieve the realisation and dump it to the console
+ Assert.assertEquals("I was making sandwiches when the mayonnaise ran out.",
+ realised.getRealisation());
+ }
+
+ /**
+ * Test the use of Passive in creating a Passive sentence structure: + [be] + + [by] + [Subject].
+ */
+ @Test
+ public void testPassiveFeature() {
+ this.realiser.setLexicon(this.lexicon);
+
+ PhraseElement phrase = phraseFactory.createClause("recession", "affect", "value");
+ phrase.setFeature(Feature.PASSIVE, true);
+ DocumentElement sentence = docFactory.createSentence(phrase);
+ NLGElement realised = realiser.realise(sentence);
+
+ Assert.assertEquals("Value is affected by recession.", realised.getRealisation());
+ }
+
+
+ /**
+ * Test for repetition of the future auxiliary "will", courtesy of Luxor
+ * Vlonjati
+ */
+ @Test
+ public void testFutureTense() {
+ SPhraseSpec test = this.phraseFactory.createClause();
+
+ NPPhraseSpec subj = this.phraseFactory.createNounPhrase("I");
+
+ VPPhraseSpec verb = this.phraseFactory.createVerbPhrase("go");
+
+ AdvPhraseSpec adverb = this.phraseFactory
+ .createAdverbPhrase("tomorrow");
+
+ test.setSubject(subj);
+ test.setVerbPhrase(verb);
+ test.setFeature(Feature.TENSE, Tense.FUTURE);
+ test.addPostModifier(adverb);
+ String sentence = realiser.realiseSentence(test);
+ Assert.assertEquals("I will go tomorrow.", sentence);
+
+ SPhraseSpec test2 = this.phraseFactory.createClause();
+ NLGElement vb = this.phraseFactory.createWord("go", LexicalCategory.VERB);
+ test2.setSubject(subj);
+ test2.setVerb(vb);
+ test2.setFeature(Feature.TENSE, Tense.FUTURE);
+ test2.addPostModifier(adverb);
+ String sentence2 = realiser.realiseSentence(test);
+ Assert.assertEquals("I will go tomorrow.", sentence2);
+
+ }
+
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/HTMLFormatterTest.java b/SharpSimpleNLGUnitTests/syntax/english/HTMLFormatterTest.java
new file mode 100644
index 0000000..5f5c0aa
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/HTMLFormatterTest.java
@@ -0,0 +1,138 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Test;
+
+import simplenlg.format.english.HTMLFormatter;
+import simplenlg.framework.DocumentElement;
+import simplenlg.framework.NLGElement;
+import simplenlg.phrasespec.SPhraseSpec;
+
+// HTMLFormatter and HTMLFormatterTest ~ author James Christie, but taken from TextFormatter and TextFormatterTest
+
+public class HTMLFormatterTest extends SimpleNLG4Test {
+
+ /**
+ * Instantiates a new document element test.
+ *
+ * @param name
+ * the name
+ */
+ public HTMLFormatterTest(String name) {
+ super(name);
+ }
+
+ @Override
+ @After
+ public void tearDown() {
+ super.tearDown();
+ }
+
+
+ /**
+ * Check the correct [part] web page contents are being generated
+ */
+ @Test
+ public final void testWebPageContent( ) {
+ // now build a document ...
+ DocumentElement document = phraseFactory.createDocument( "This is a title" ) ;
+
+ DocumentElement section = phraseFactory.createSection( "This is a section" ) ;
+
+ DocumentElement paragraph1 = phraseFactory.createParagraph( ) ;
+ DocumentElement sentence11 = phraseFactory.createSentence( "This is the first sentence of paragraph 1" ) ;
+ paragraph1.addComponent( sentence11 ) ;
+ DocumentElement sentence12 = phraseFactory.createSentence( "This is the second sentence of paragraph 1" ) ;
+ paragraph1.addComponent( sentence12 ) ;
+ section.addComponent( paragraph1 ) ;
+ document.addComponent( section ) ;
+
+ DocumentElement paragraph2 = phraseFactory.createParagraph( ) ;
+ DocumentElement sentence2 = phraseFactory.createSentence( "This is the first sentence of paragraph 2" ) ;
+ paragraph2.addComponent( sentence2 ) ;
+ document.addComponent( paragraph2 ) ;
+
+ DocumentElement paragraph3 = phraseFactory.createParagraph( ) ;
+ DocumentElement sentence3 = phraseFactory.createSentence( "This is the first sentence of paragraph 3" ) ;
+ paragraph3.addComponent( sentence3 ) ;
+ document.addComponent( paragraph3 ) ;
+
+ // now for a second section with three sentences in one paragraph using arrays.asList function
+ SPhraseSpec p1 = phraseFactory.createClause( "Mary", "chase", "the monkey" ) ;
+ SPhraseSpec p2 = phraseFactory.createClause( "the monkey", "fight back" ) ;
+ SPhraseSpec p3 = phraseFactory.createClause( "Mary", "be", "nervous" ) ;
+
+ DocumentElement s1 = phraseFactory.createSentence( p1 ) ;
+ DocumentElement s2 = phraseFactory.createSentence( p2 ) ;
+ DocumentElement s3 = phraseFactory.createSentence( p3 ) ;
+
+ DocumentElement para1x3 = phraseFactory.createParagraph( Arrays.asList( s1, s2, s3 ) ) ;
+
+ DocumentElement sectionList = phraseFactory.createSection( "This section contains lists" ) ;
+ sectionList.addComponent( para1x3 ) ;
+ document.addComponent( sectionList ) ;
+
+ // from David Westwater 4-10-11
+ DocumentElement element = phraseFactory.createList( ) ;
+ List < NLGElement > list = new ArrayList < NLGElement > ( ) ;
+ list.add( phraseFactory.createListItem( phraseFactory.createStringElement( "Item 1" ) ) ) ;
+ list.add( phraseFactory.createListItem( phraseFactory.createStringElement( "Item 2" ) ) ) ;
+ list.add( phraseFactory.createListItem( phraseFactory.createStringElement( "Item 3" ) ) ) ;
+
+ element.addComponents( list ) ;
+ document.addComponent( element ) ;
+
+ // ... finally produce some output with HMTL tags ...
+ System.out.println( "HTML realisation ~ \n=============================\n" ) ;
+
+ String output = "" ;
+
+ // this.realiser.setFormatter( new TextFormatter( ) ) ;
+ this.realiser.setFormatter( new HTMLFormatter( ) ) ;
+ // realiser.setDebugMode( true ) ; // hide after testing
+ output += realiser.realise( document ).getRealisation( ) ;
+
+ System.out.println( output ) ; // just to visually check what is being produced
+
+ String expectedResults =
+ "This is a title " +
+ "This is a section " +
+ "This is the first sentence of paragraph 1. This is the second sentence of paragraph 1.
" +
+ "This is the first sentence of paragraph 2.
" +
+ "This is the first sentence of paragraph 3.
" +
+ "This section contains lists " +
+ "Mary chases the monkey. The monkey fights back. Mary is nervous.
" +
+ "" +
+ "Item 1 " +
+ "Item 2 " +
+ "Item 3 " +
+ " " ;
+
+ assertEquals( expectedResults, output ) ; // when realisation is working then complete this test
+ } // testWebPageContents
+} // class
+
+
diff --git a/SharpSimpleNLGUnitTests/syntax/english/InterrogativeTest.java b/SharpSimpleNLGUnitTests/syntax/english/InterrogativeTest.java
new file mode 100644
index 0000000..230964a
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/InterrogativeTest.java
@@ -0,0 +1,836 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.features.InterrogativeType;
+import simplenlg.features.Person;
+import simplenlg.features.Tense;
+import simplenlg.framework.CoordinatedPhraseElement;
+import simplenlg.framework.DocumentElement;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.NLGElement;
+import simplenlg.framework.NLGFactory;
+import simplenlg.framework.PhraseElement;
+import simplenlg.lexicon.Lexicon;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.PPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * JUnit test case for interrogatives.
+ *
+ * @author agatt
+ */
+public class InterrogativeTest extends SimpleNLG4Test {
+
+ // set up a few more fixtures
+ /** The s5. */
+ SPhraseSpec s1, s2, s3, s4, s5;
+
+ /**
+ * Instantiates a new interrogative test.
+ *
+ * @param name
+ * the name
+ */
+ public InterrogativeTest(String name) {
+ super(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see simplenlg.test.SimplenlgTest#setUp()
+ */
+ @Override
+ @Before
+ protected void setUp() {
+ super.setUp();
+
+ // // the man gives the woman John's flower
+ PhraseElement john = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
+ john.setFeature(Feature.POSSESSIVE, true);
+ PhraseElement flower = this.phraseFactory.createNounPhrase(john,
+ "flower"); //$NON-NLS-1$
+ PhraseElement _woman = this.phraseFactory.createNounPhrase(
+ "the", "woman"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.s3 = this.phraseFactory.createClause(this.man, this.give, flower);
+ this.s3.setIndirectObject(_woman);
+
+ CoordinatedPhraseElement subjects = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"), //$NON-NLS-1$
+ this.phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$
+ this.s4 = this.phraseFactory.createClause(subjects, "pick up", //$NON-NLS-1$
+ "the balls"); //$NON-NLS-1$
+ this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
+ this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
+ this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
+ this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
+ // this.s5 = new SPhraseSpec();
+ // this.s5.setSubject(new NPPhraseSpec("the", "dog"));
+ // this.s5.setHead("be");
+ // this.s5.setComplement(new NPPhraseSpec("the", "rock"),
+ // DiscourseFunction.OBJECT);
+
+ }
+
+ /**
+ * Tests a couple of fairly simple questions.
+ */
+ @Test
+ public void testSimpleQuestions() {
+ setUp();
+ this.phraseFactory.setLexicon(this.lexicon);
+ this.realiser.setLexicon(this.lexicon);
+
+ // simple present
+ this.s1 = this.phraseFactory.createClause(this.woman, this.kiss,
+ this.man);
+ this.s1.setFeature(Feature.TENSE, Tense.PRESENT);
+ this.s1.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+
+ NLGFactory docFactory = new NLGFactory(this.lexicon);
+ DocumentElement sent = docFactory.createSentence(this.s1);
+ Assert.assertEquals("Does the woman kiss the man?", this.realiser //$NON-NLS-1$
+ .realise(sent).getRealisation());
+
+ // simple past
+ // sentence: "the woman kissed the man"
+ this.s1 = this.phraseFactory.createClause(this.woman, this.kiss,
+ this.man);
+ this.s1.setFeature(Feature.TENSE, Tense.PAST);
+ this.s1.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ Assert.assertEquals("did the woman kiss the man", this.realiser //$NON-NLS-1$
+ .realise(this.s1).getRealisation());
+
+ // copular/existential: be-fronting
+ // sentence = "there is the dog on the rock"
+ this.s2 = this.phraseFactory.createClause("there", "be", this.dog); //$NON-NLS-1$ //$NON-NLS-2$
+ this.s2.addPostModifier(this.onTheRock);
+ this.s2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ Assert.assertEquals("is there the dog on the rock", this.realiser //$NON-NLS-1$
+ .realise(this.s2).getRealisation());
+
+ // perfective
+ // sentence -- "there has been the dog on the rock"
+ this.s2 = this.phraseFactory.createClause("there", "be", this.dog); //$NON-NLS-1$ //$NON-NLS-2$
+ this.s2.addPostModifier(this.onTheRock);
+ this.s2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ this.s2.setFeature(Feature.PERFECT, true);
+ Assert.assertEquals("has there been the dog on the rock", //$NON-NLS-1$
+ this.realiser.realise(this.s2).getRealisation());
+
+ // progressive
+ // sentence: "the man was giving the woman John's flower"
+ PhraseElement john = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
+ john.setFeature(Feature.POSSESSIVE, true);
+ PhraseElement flower = this.phraseFactory.createNounPhrase(john,
+ "flower"); //$NON-NLS-1$
+ PhraseElement _woman = this.phraseFactory.createNounPhrase(
+ "the", "woman"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.s3 = this.phraseFactory.createClause(this.man, this.give, flower);
+ this.s3.setIndirectObject(_woman);
+ this.s3.setFeature(Feature.TENSE, Tense.PAST);
+ this.s3.setFeature(Feature.PROGRESSIVE, true);
+ this.s3.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ NLGElement realised = this.realiser.realise(this.s3);
+ Assert.assertEquals("was the man giving the woman John's flower", //$NON-NLS-1$
+ realised.getRealisation());
+
+ // modal
+ // sentence: "the man should be giving the woman John's flower"
+ setUp();
+ john = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
+ john.setFeature(Feature.POSSESSIVE, true);
+ flower = this.phraseFactory.createNounPhrase(john, "flower"); //$NON-NLS-1$
+ _woman = this.phraseFactory.createNounPhrase("the", "woman"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.s3 = this.phraseFactory.createClause(this.man, this.give, flower);
+ this.s3.setIndirectObject(_woman);
+ this.s3.setFeature(Feature.TENSE, Tense.PAST);
+ this.s3.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ this.s3.setFeature(Feature.MODAL, "should"); //$NON-NLS-1$
+ Assert.assertEquals(
+ "should the man have given the woman John's flower", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+
+ // complex case with cue phrases
+ // sentence: "however, tomorrow, Jane and Andrew will pick up the balls
+ // in the shop"
+ // this gets the front modifier "tomorrow" shifted to the end
+ setUp();
+ CoordinatedPhraseElement subjects = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"), //$NON-NLS-1$
+ this.phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$
+ this.s4 = this.phraseFactory.createClause(subjects, "pick up", //$NON-NLS-1$
+ "the balls"); //$NON-NLS-1$
+ this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
+ this.s4.setFeature(Feature.CUE_PHRASE, "however,"); //$NON-NLS-1$
+ this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
+ this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
+ this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ Assert.assertEquals(
+ "however, will Jane and Andrew pick up the balls in the shop tomorrow", //$NON-NLS-1$
+ this.realiser.realise(this.s4).getRealisation());
+ }
+
+ /**
+ * Test for sentences with negation.
+ */
+ @Test
+ public void testNegatedQuestions() {
+ setUp();
+ this.phraseFactory.setLexicon(this.lexicon);
+ this.realiser.setLexicon(this.lexicon);
+
+ // sentence: "the woman did not kiss the man"
+ this.s1 = this.phraseFactory.createClause(this.woman, "kiss", this.man);
+ this.s1.setFeature(Feature.TENSE, Tense.PAST);
+ this.s1.setFeature(Feature.NEGATED, true);
+ this.s1.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ Assert.assertEquals("did the woman not kiss the man", this.realiser //$NON-NLS-1$
+ .realise(this.s1).getRealisation());
+
+ // sentence: however, tomorrow, Jane and Andrew will not pick up the
+ // balls in the shop
+ CoordinatedPhraseElement subjects = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"), //$NON-NLS-1$
+ this.phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$
+ this.s4 = this.phraseFactory.createClause(subjects, "pick up", //$NON-NLS-1$
+ "the balls"); //$NON-NLS-1$
+ this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
+ this.s4.setFeature(Feature.CUE_PHRASE, "however,"); //$NON-NLS-1$
+ this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
+ this.s4.setFeature(Feature.NEGATED, true);
+ this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
+ this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ Assert.assertEquals(
+ "however, will Jane and Andrew not pick up the balls in the shop tomorrow", //$NON-NLS-1$
+ this.realiser.realise(this.s4).getRealisation());
+ }
+
+ /**
+ * Tests for coordinate VPs in question form.
+ */
+ @Test
+ public void testCoordinateVPQuestions() {
+
+ // create a complex vp: "kiss the dog and walk in the room"
+ setUp();
+ CoordinatedPhraseElement complex = new CoordinatedPhraseElement(
+ this.kiss, this.walk);
+ this.kiss.addComplement(this.dog);
+ this.walk.addComplement(this.inTheRoom);
+
+ // sentence: "However, tomorrow, Jane and Andrew will kiss the dog and
+ // will walk in the room"
+ CoordinatedPhraseElement subjects = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"), //$NON-NLS-1$
+ this.phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$
+ this.s4 = this.phraseFactory.createClause(subjects, complex);
+ this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
+ this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
+ this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
+
+ Assert.assertEquals(
+ "however tomorrow Jane and Andrew will kiss the dog and will walk in the room", //$NON-NLS-1$
+ this.realiser.realise(this.s4).getRealisation());
+
+ // setting to interrogative should automatically give us a single,
+ // wide-scope aux
+ setUp();
+ subjects = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"), //$NON-NLS-1$
+ this.phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$
+ this.kiss.addComplement(this.dog);
+ this.walk.addComplement(this.inTheRoom);
+ complex = new CoordinatedPhraseElement(this.kiss, this.walk);
+ this.s4 = this.phraseFactory.createClause(subjects, complex);
+ this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
+ this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
+ this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
+ this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+
+ Assert.assertEquals(
+ "however will Jane and Andrew kiss the dog and walk in the room tomorrow", //$NON-NLS-1$
+ this.realiser.realise(this.s4).getRealisation());
+
+ // slightly more complex -- perfective
+ setUp();
+ this.realiser.setLexicon(this.lexicon);
+ subjects = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Jane"), //$NON-NLS-1$
+ this.phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$
+ complex = new CoordinatedPhraseElement(this.kiss, this.walk);
+ this.kiss.addComplement(this.dog);
+ this.walk.addComplement(this.inTheRoom);
+ this.s4 = this.phraseFactory.createClause(subjects, complex);
+ this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
+ this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
+ this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
+ this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ this.s4.setFeature(Feature.PERFECT, true);
+
+ Assert.assertEquals(
+ "however will Jane and Andrew have kissed the dog and walked in the room tomorrow", //$NON-NLS-1$
+ this.realiser.realise(this.s4).getRealisation());
+ }
+
+ /**
+ * Test for simple WH questions in present tense.
+ */
+ @Test
+ public void testSimpleQuestions2() {
+ setUp();
+ this.realiser.setLexicon(this.lexicon);
+ PhraseElement s = this.phraseFactory.createClause("the woman", "kiss", //$NON-NLS-1$ //$NON-NLS-2$
+ "the man"); //$NON-NLS-1$
+
+ // try with the simple yes/no type first
+ s.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ Assert.assertEquals("does the woman kiss the man", this.realiser //$NON-NLS-1$
+ .realise(s).getRealisation());
+
+ // now in the passive
+ s = this.phraseFactory.createClause("the woman", "kiss", //$NON-NLS-1$ //$NON-NLS-2$
+ "the man"); //$NON-NLS-1$
+ s.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ s.setFeature(Feature.PASSIVE, true);
+ Assert.assertEquals("is the man kissed by the woman", this.realiser //$NON-NLS-1$
+ .realise(s).getRealisation());
+
+ // // subject interrogative with simple present
+ // // sentence: "the woman kisses the man"
+ s = this.phraseFactory.createClause("the woman", "kiss", //$NON-NLS-1$ //$NON-NLS-2$
+ "the man"); //$NON-NLS-1$
+ s.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
+
+ Assert.assertEquals("who kisses the man", this.realiser.realise(s) //$NON-NLS-1$
+ .getRealisation());
+
+ // object interrogative with simple present
+ s = this.phraseFactory.createClause("the woman", "kiss", //$NON-NLS-1$ //$NON-NLS-2$
+ "the man"); //$NON-NLS-1$
+ s.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
+ Assert.assertEquals("who does the woman kiss", this.realiser //$NON-NLS-1$
+ .realise(s).getRealisation());
+
+ // subject interrogative with passive
+ s = this.phraseFactory.createClause("the woman", "kiss", //$NON-NLS-1$ //$NON-NLS-2$
+ "the man"); //$NON-NLS-1$
+ s.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
+ s.setFeature(Feature.PASSIVE, true);
+ Assert.assertEquals("who is the man kissed by", this.realiser //$NON-NLS-1$
+ .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(
+ "however who will pick up the balls in the shop tomorrow", //$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(
+ "however who will the balls be picked up in the shop by tomorrow", //$NON-NLS-1$
+ this.realiser.realise(this.s4).getRealisation());
+
+ // object interrogative
+ setUp();
+ this.s4.setFeature(Feature.INTERROGATIVE_TYPE,
+ InterrogativeType.WHAT_OBJECT);
+ Assert.assertEquals(
+ "however what will Jane and Andrew pick up in the shop tomorrow", //$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(
+ "however what will be picked up in the shop by Jane and Andrew tomorrow", //$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(
+ "however how will the balls be picked up in the shop by Jane and Andrew tomorrow", //$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(
+ "however why will the balls be picked up in the shop by Jane and Andrew tomorrow", //$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, "should"); //$NON-NLS-1$
+ Assert.assertEquals(
+ "however how should the balls be picked up in the shop by Jane and Andrew tomorrow", //$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("who does the man give John's flower to", //$NON-NLS-1$
+ this.realiser.realise(this.s3).getRealisation());
+ }
+
+ /**
+ * WH movement in the progressive
+ */
+ @Test
+ public void testProgrssiveWHSubjectQuestions() {
+ SPhraseSpec p = this.phraseFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("eat");
+ p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
+ p.setFeature(Feature.PROGRESSIVE, true);
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
+ Assert.assertEquals("who is eating the pie", //$NON-NLS-1$
+ this.realiser.realise(p).getRealisation());
+ }
+
+ /**
+ * WH movement in the progressive
+ */
+ @Test
+ public void testProgrssiveWHObjectQuestions() {
+ SPhraseSpec p = this.phraseFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("eat");
+ p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
+ p.setFeature(Feature.PROGRESSIVE, true);
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
+ Assert.assertEquals("what is Mary eating", //$NON-NLS-1$
+ this.realiser.realise(p).getRealisation());
+
+ // AG -- need to check this; it doesn't work
+ // p.setFeature(Feature.NEGATED, true);
+ // Assert.assertEquals("what is Mary not eating", //$NON-NLS-1$
+ // this.realiser.realise(p).getRealisation());
+
+ }
+
+ /**
+ * Negation with WH movement for subject
+ */
+ @Test
+ public void testNegatedWHSubjQuestions() {
+ SPhraseSpec p = this.phraseFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("eat");
+ p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
+ p.setFeature(Feature.NEGATED, true);
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
+ Assert.assertEquals("who does not eat the pie", //$NON-NLS-1$
+ this.realiser.realise(p).getRealisation());
+ }
+
+ /**
+ * Negation with WH movement for object
+ */
+ @Test
+ public void testNegatedWHObjQuestions() {
+ SPhraseSpec p = this.phraseFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("eat");
+ p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
+ p.setFeature(Feature.NEGATED, true);
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
+ NLGElement realisation = this.realiser.realise(p);
+ Assert.assertEquals("what does Mary not eat", //$NON-NLS-1$
+ realisation.getRealisation());
+ }
+
+ /**
+ * Test questyions in the tutorial.
+ */
+ @Test
+ public void testTutorialQuestions() {
+ setUp();
+ this.realiser.setLexicon(this.lexicon);
+
+ PhraseElement p = this.phraseFactory.createClause("Mary", "chase", //$NON-NLS-1$ //$NON-NLS-2$
+ "George"); //$NON-NLS-1$
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ Assert.assertEquals("does Mary chase George", this.realiser.realise(p) //$NON-NLS-1$
+ .getRealisation());
+
+ p = this.phraseFactory.createClause("Mary", "chase", //$NON-NLS-1$ //$NON-NLS-2$
+ "George"); //$NON-NLS-1$
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
+ Assert.assertEquals("who does Mary chase", this.realiser.realise(p) //$NON-NLS-1$
+ .getRealisation());
+
+ }
+
+ /**
+ * Subject WH Questions with modals
+ */
+ @Test
+ public void testModalWHSubjectQuestion() {
+ SPhraseSpec p = this.phraseFactory.createClause(this.dog, "upset",
+ this.man);
+ p.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals("the dog upset the man", this.realiser.realise(p)
+ .getRealisation());
+
+ // first without modal
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
+ Assert.assertEquals("who upset the man", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
+ Assert.assertEquals("what upset the man", this.realiser.realise(p)
+ .getRealisation());
+
+ // now with modal auxiliary
+ p.setFeature(Feature.MODAL, "may");
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
+ Assert.assertEquals("who may have upset the man", this.realiser
+ .realise(p).getRealisation());
+
+ p.setFeature(Feature.TENSE, Tense.FUTURE);
+ Assert.assertEquals("who may upset the man", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.TENSE, Tense.PAST);
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
+ Assert.assertEquals("what may have upset the man", this.realiser
+ .realise(p).getRealisation());
+
+ p.setFeature(Feature.TENSE, Tense.FUTURE);
+ Assert.assertEquals("what may upset the man", this.realiser.realise(p)
+ .getRealisation());
+ }
+
+ /**
+ * Subject WH Questions with modals
+ */
+ @Test
+ public void testModalWHObjectQuestion() {
+ SPhraseSpec p = this.phraseFactory.createClause(this.dog, "upset",
+ this.man);
+ p.setFeature(Feature.TENSE, Tense.PAST);
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
+
+ Assert.assertEquals("who did the dog upset", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.MODAL, "may");
+ Assert.assertEquals("who may the dog have upset", this.realiser
+ .realise(p).getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
+ Assert.assertEquals("what may the dog have upset", this.realiser
+ .realise(p).getRealisation());
+
+ p.setFeature(Feature.TENSE, Tense.FUTURE);
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
+ Assert.assertEquals("who may the dog upset", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
+ Assert.assertEquals("what may the dog upset", this.realiser.realise(p)
+ .getRealisation());
+ }
+
+ /**
+ * Questions with tenses requiring auxiliaries + subject WH
+ */
+ @Test
+ public void testAuxWHSubjectQuestion() {
+ SPhraseSpec p = this.phraseFactory.createClause(this.dog, "upset",
+ this.man);
+ p.setFeature(Feature.TENSE, Tense.PRESENT);
+ p.setFeature(Feature.PERFECT, true);
+ Assert.assertEquals("the dog has upset the man",
+ this.realiser.realise(p).getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
+ Assert.assertEquals("who has upset the man", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
+ Assert.assertEquals("what has upset the man", this.realiser.realise(p)
+ .getRealisation());
+ }
+
+ /**
+ * Questions with tenses requiring auxiliaries + subject WH
+ */
+ @Test
+ public void testAuxWHObjectQuestion() {
+ SPhraseSpec p = this.phraseFactory.createClause(this.dog, "upset",
+ this.man);
+
+ // first without any aux
+ p.setFeature(Feature.TENSE, Tense.PAST);
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
+ Assert.assertEquals("what did the dog upset", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
+ Assert.assertEquals("who did the dog upset", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.TENSE, Tense.PRESENT);
+ p.setFeature(Feature.PERFECT, true);
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
+ Assert.assertEquals("who has the dog upset", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
+ Assert.assertEquals("what has the dog upset", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.TENSE, Tense.FUTURE);
+ p.setFeature(Feature.PERFECT, true);
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
+ Assert.assertEquals("who will the dog have upset", this.realiser
+ .realise(p).getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
+ Assert.assertEquals("what will the dog have upset", this.realiser
+ .realise(p).getRealisation());
+
+ }
+
+ /**
+ * Test for questions with "be"
+ */
+ @Test
+ public void testBeQuestions() {
+ SPhraseSpec p = this.phraseFactory.createClause(
+ this.phraseFactory.createNounPhrase("a", "ball"),
+ this.phraseFactory.createWord("be", LexicalCategory.VERB),
+ this.phraseFactory.createNounPhrase("a", "toy"));
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
+ Assert.assertEquals("what is a ball", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ Assert.assertEquals("is a ball a toy", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
+ Assert.assertEquals("what is a toy", this.realiser.realise(p)
+ .getRealisation());
+
+ SPhraseSpec p2 = this.phraseFactory.createClause("Mary", "be",
+ "beautiful");
+ p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
+ Assert.assertEquals("why is Mary beautiful", this.realiser.realise(p2)
+ .getRealisation());
+
+ p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHERE);
+ Assert.assertEquals("where is Mary beautiful", this.realiser.realise(p2)
+ .getRealisation());
+
+ p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
+ Assert.assertEquals("who is beautiful", this.realiser.realise(p2)
+ .getRealisation());
+ }
+
+ /**
+ * Test for questions with "be" in future tense
+ */
+ @Test
+ public void testBeQuestionsFuture() {
+ SPhraseSpec p = this.phraseFactory.createClause(
+ this.phraseFactory.createNounPhrase("a", "ball"),
+ this.phraseFactory.createWord("be", LexicalCategory.VERB),
+ this.phraseFactory.createNounPhrase("a", "toy"));
+ p.setFeature(Feature.TENSE, Tense.FUTURE);
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
+ Assert.assertEquals("what will a ball be", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ Assert.assertEquals("will a ball be a toy", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
+ Assert.assertEquals("what will be a toy", this.realiser.realise(p)
+ .getRealisation());
+
+ SPhraseSpec p2 = this.phraseFactory.createClause("Mary", "be",
+ "beautiful");
+ p2.setFeature(Feature.TENSE, Tense.FUTURE);
+ p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
+ Assert.assertEquals("why will Mary be beautiful", this.realiser
+ .realise(p2).getRealisation());
+
+ p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHERE);
+ Assert.assertEquals("where will Mary be beautiful", this.realiser
+ .realise(p2).getRealisation());
+
+ p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
+ Assert.assertEquals("who will be beautiful", this.realiser.realise(p2)
+ .getRealisation());
+ }
+
+ /**
+ * Tests for WH questions with be in past tense
+ */
+ @Test
+ public void testBeQuestionsPast() {
+ SPhraseSpec p = this.phraseFactory.createClause(
+ this.phraseFactory.createNounPhrase("a", "ball"),
+ this.phraseFactory.createWord("be", LexicalCategory.VERB),
+ this.phraseFactory.createNounPhrase("a", "toy"));
+ p.setFeature(Feature.TENSE, Tense.PAST);
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
+ Assert.assertEquals("what was a ball", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
+ Assert.assertEquals("was a ball a toy", this.realiser.realise(p)
+ .getRealisation());
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
+ Assert.assertEquals("what was a toy", this.realiser.realise(p)
+ .getRealisation());
+
+ SPhraseSpec p2 = this.phraseFactory.createClause("Mary", "be",
+ "beautiful");
+ p2.setFeature(Feature.TENSE, Tense.PAST);
+ p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
+ Assert.assertEquals("why was Mary beautiful", this.realiser.realise(p2)
+ .getRealisation());
+
+ p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHERE);
+ Assert.assertEquals("where was Mary beautiful", this.realiser.realise(p2)
+ .getRealisation());
+
+ p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
+ Assert.assertEquals("who was beautiful", this.realiser.realise(p2)
+ .getRealisation());
+ }
+
+
+ /**
+ * Test WHERE, HOW and WHY questions, with copular predicate "be"
+ */
+ public void testSimpleBeWHQuestions() {
+ SPhraseSpec p = this.phraseFactory.createClause("I", "be");
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHERE);
+ Assert.assertEquals("Where am I?", realiser.realiseSentence(p));
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
+ Assert.assertEquals("Why am I?", realiser.realiseSentence(p));
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.HOW);
+ Assert.assertEquals("How am I?", realiser.realiseSentence(p));
+
+ }
+
+ /**
+ * Test a simple "how" question, based on query from Albi Oxa
+ */
+ @Test
+ public void testHowPredicateQuestion() {
+ SPhraseSpec test = this.phraseFactory.createClause();
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("You");
+
+ subject.setFeature(Feature.PRONOMINAL, true);
+ subject.setFeature(Feature.PERSON, Person.SECOND);
+ test.setSubject(subject);
+ test.setVerb("be");
+
+ test.setFeature(Feature.INTERROGATIVE_TYPE,
+ InterrogativeType.HOW_PREDICATE);
+ test.setFeature(Feature.TENSE, Tense.PRESENT);
+
+ String result = realiser.realiseSentence(test);
+ Assert.assertEquals("How are you?", result);
+
+ }
+
+ /**
+ * Case 1 checks that "What do you think about John?" can be generated.
+ *
+ * Case 2 checks that the same clause is generated, even when an object is
+ * declared.
+ */
+ @Test
+ public void testWhatObjectInterrogative() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon();
+ NLGFactory nlg = new NLGFactory(lexicon);
+ Realiser realiser = new Realiser(lexicon);
+
+ // Case 1, no object is explicitly given:
+ SPhraseSpec clause = nlg.createClause("you", "think");
+ PPPhraseSpec aboutJohn = nlg.createPrepositionPhrase("about", "John");
+ clause.addPostModifier(aboutJohn);
+ clause.setFeature(Feature.INTERROGATIVE_TYPE,
+ InterrogativeType.WHAT_OBJECT);
+ String realisation = realiser.realiseSentence(clause);
+ System.out.println(realisation);
+ Assert.assertEquals("What do you think about John?", realisation);
+
+ // Case 2:
+ // Add "bad things" as the object so the object doesn't remain null:
+ clause.setObject("bad things");
+ realisation = realiser.realiseSentence(clause);
+ System.out.println(realiser.realiseSentence(clause));
+ Assert.assertEquals("What do you think about John?", realisation);
+ }
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/NounPhraseTest.java b/SharpSimpleNLGUnitTests/syntax/english/NounPhraseTest.java
new file mode 100644
index 0000000..0b2dc2d
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/NounPhraseTest.java
@@ -0,0 +1,617 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell.
+ */
+
+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.framework.CoordinatedPhraseElement;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.NLGElement;
+import simplenlg.framework.PhraseElement;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+
+/**
+ * Tests for the NPPhraseSpec and CoordinateNPPhraseSpec classes.
+ *
+ * @author agatt
+ */
+public class NounPhraseTest extends SimpleNLG4Test {
+
+ /**
+ * Instantiates a new nP test.
+ *
+ * @param name
+ * the name
+ */
+ public NounPhraseTest(String name) {
+ super(name);
+ }
+
+ @Override
+ @After
+ public void tearDown() {
+ super.tearDown();
+ }
+
+
+ /**
+ * Test the setPlural() method in noun phrases.
+ */
+ @Test
+ public void testPlural() {
+ this.np4.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ Assert.assertEquals(
+ "the rocks", this.realiser.realise(this.np4).getRealisation()); //$NON-NLS-1$
+
+ this.np5.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ Assert
+ .assertEquals(
+ "the curtains", this.realiser.realise(this.np5).getRealisation()); //$NON-NLS-1$
+
+ this.np5.setFeature(Feature.NUMBER, NumberAgreement.SINGULAR);
+ Assert.assertEquals(NumberAgreement.SINGULAR, this.np5
+ .getFeature(Feature.NUMBER));
+ Assert
+ .assertEquals(
+ "the curtain", this.realiser.realise(this.np5).getRealisation()); //$NON-NLS-1$
+
+ this.np5.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ Assert
+ .assertEquals(
+ "the curtains", this.realiser.realise(this.np5).getRealisation()); //$NON-NLS-1$
+ }
+
+ /**
+ * Test the pronominalisation method for full NPs.
+ */
+ @Test
+ public void testPronominalisation() {
+ // sing
+ this.proTest1.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
+ this.proTest1.setFeature(Feature.PRONOMINAL, true);
+ Assert.assertEquals(
+ "she", this.realiser.realise(this.proTest1).getRealisation()); //$NON-NLS-1$
+
+ // sing, possessive
+ this.proTest1.setFeature(Feature.POSSESSIVE, true);
+ Assert.assertEquals(
+ "her", this.realiser.realise(this.proTest1).getRealisation()); //$NON-NLS-1$
+
+ // plural pronoun
+ this.proTest2.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ this.proTest2.setFeature(Feature.PRONOMINAL, true);
+ Assert.assertEquals(
+ "they", this.realiser.realise(this.proTest2).getRealisation()); //$NON-NLS-1$
+
+ // accusative: "them"
+ this.proTest2.setFeature(InternalFeature.DISCOURSE_FUNCTION,
+ DiscourseFunction.OBJECT);
+ Assert.assertEquals(
+ "them", this.realiser.realise(this.proTest2).getRealisation()); //$NON-NLS-1$
+ }
+
+ /**
+ * Test the pronominalisation method for full NPs (more thorough than above)
+ */
+ @Test
+ public void testPronominalisation2() {
+ // Ehud - added extra pronominalisation tests
+ NPPhraseSpec pro = phraseFactory.createNounPhrase("Mary");
+ pro.setFeature(Feature.PRONOMINAL, true);
+ pro.setFeature(Feature.PERSON, Person.FIRST);
+ SPhraseSpec sent = phraseFactory.createClause(pro, "like", "John");
+ Assert
+ .assertEquals("I like John.", this.realiser
+ .realiseSentence(sent));
+
+ pro = phraseFactory.createNounPhrase("Mary");
+ pro.setFeature(Feature.PRONOMINAL, true);
+ pro.setFeature(Feature.PERSON, Person.SECOND);
+ sent = phraseFactory.createClause(pro, "like", "John");
+ Assert.assertEquals("You like John.", this.realiser
+ .realiseSentence(sent));
+
+ pro = phraseFactory.createNounPhrase("Mary");
+ pro.setFeature(Feature.PRONOMINAL, true);
+ pro.setFeature(Feature.PERSON, Person.THIRD);
+ pro.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
+ sent = phraseFactory.createClause(pro, "like", "John");
+ Assert.assertEquals("She likes John.", this.realiser
+ .realiseSentence(sent));
+
+ pro = phraseFactory.createNounPhrase("Mary");
+ pro.setFeature(Feature.PRONOMINAL, true);
+ pro.setFeature(Feature.PERSON, Person.FIRST);
+ pro.setPlural(true);
+ sent = phraseFactory.createClause(pro, "like", "John");
+ Assert.assertEquals("We like John.", this.realiser
+ .realiseSentence(sent));
+
+ pro = phraseFactory.createNounPhrase("Mary");
+ pro.setFeature(Feature.PRONOMINAL, true);
+ pro.setFeature(Feature.PERSON, Person.SECOND);
+ pro.setPlural(true);
+ sent = phraseFactory.createClause(pro, "like", "John");
+ Assert.assertEquals("You like John.", this.realiser
+ .realiseSentence(sent));
+
+ pro = phraseFactory.createNounPhrase("Mary");
+ pro.setFeature(Feature.PRONOMINAL, true);
+ pro.setFeature(Feature.PERSON, Person.THIRD);
+ pro.setPlural(true);
+ pro.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
+ sent = phraseFactory.createClause(pro, "like", "John");
+ Assert.assertEquals("They like John.", this.realiser
+ .realiseSentence(sent));
+
+ pro = phraseFactory.createNounPhrase("John");
+ pro.setFeature(Feature.PRONOMINAL, true);
+ pro.setFeature(Feature.PERSON, Person.FIRST);
+ sent = phraseFactory.createClause("Mary", "like", pro);
+ Assert.assertEquals("Mary likes me.", this.realiser
+ .realiseSentence(sent));
+
+ pro = phraseFactory.createNounPhrase("John");
+ pro.setFeature(Feature.PRONOMINAL, true);
+ pro.setFeature(Feature.PERSON, Person.SECOND);
+ sent = phraseFactory.createClause("Mary", "like", pro);
+ Assert.assertEquals("Mary likes you.", this.realiser
+ .realiseSentence(sent));
+
+ pro = phraseFactory.createNounPhrase("John");
+ pro.setFeature(Feature.PRONOMINAL, true);
+ pro.setFeature(Feature.PERSON, Person.THIRD);
+ pro.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
+ sent = phraseFactory.createClause("Mary", "like", pro);
+ Assert.assertEquals("Mary likes him.", this.realiser
+ .realiseSentence(sent));
+
+ pro = phraseFactory.createNounPhrase("John");
+ pro.setFeature(Feature.PRONOMINAL, true);
+ pro.setFeature(Feature.PERSON, Person.FIRST);
+ pro.setPlural(true);
+ sent = phraseFactory.createClause("Mary", "like", pro);
+ Assert.assertEquals("Mary likes us.", this.realiser
+ .realiseSentence(sent));
+
+ pro = phraseFactory.createNounPhrase("John");
+ pro.setFeature(Feature.PRONOMINAL, true);
+ pro.setFeature(Feature.PERSON, Person.SECOND);
+ pro.setPlural(true);
+ sent = phraseFactory.createClause("Mary", "like", pro);
+ Assert.assertEquals("Mary likes you.", this.realiser
+ .realiseSentence(sent));
+
+ pro = phraseFactory.createNounPhrase("John");
+ pro.setFeature(Feature.PRONOMINAL, true);
+ pro.setFeature(Feature.PERSON, Person.THIRD);
+ pro.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
+ pro.setPlural(true);
+ sent = phraseFactory.createClause("Mary", "like", pro);
+ Assert.assertEquals("Mary likes them.", this.realiser
+ .realiseSentence(sent));
+ }
+
+ /**
+ * Test premodification in NPS.
+ */
+ @Test
+ public void testPremodification() {
+ this.man.addPreModifier(this.salacious);
+ Assert.assertEquals("the salacious man", this.realiser //$NON-NLS-1$
+ .realise(this.man).getRealisation());
+
+ this.woman.addPreModifier(this.beautiful);
+ Assert.assertEquals("the beautiful woman", this.realiser.realise( //$NON-NLS-1$
+ this.woman).getRealisation());
+
+ this.dog.addPreModifier(this.stunning);
+ Assert.assertEquals("the stunning dog", this.realiser.realise(this.dog) //$NON-NLS-1$
+ .getRealisation());
+
+ // premodification with a WordElement
+ this.man.setPreModifier(this.phraseFactory.createWord("idiotic",
+ LexicalCategory.ADJECTIVE));
+ Assert.assertEquals("the idiotic man", this.realiser //$NON-NLS-1$
+ .realise(this.man).getRealisation());
+
+ }
+
+ /**
+ * Test prepositional postmodification.
+ */
+ @Test
+ public void testPostmodification() {
+ this.man.addPostModifier(this.onTheRock);
+ Assert.assertEquals("the man on the rock", this.realiser.realise( //$NON-NLS-1$
+ this.man).getRealisation());
+
+ this.woman.addPostModifier(this.behindTheCurtain);
+ Assert.assertEquals("the woman behind the curtain", this.realiser //$NON-NLS-1$
+ .realise(this.woman).getRealisation());
+
+ // postmodification with a WordElement
+ this.man.setPostModifier(this.phraseFactory.createWord("jack",
+ LexicalCategory.NOUN));
+ Assert.assertEquals("the man jack", this.realiser.realise( //$NON-NLS-1$
+ this.man).getRealisation());
+ }
+
+ /**
+ * Test nominal complementation
+ */
+ @Test
+ public void testComplementation() {
+ // complementation with a WordElement
+ this.man.setComplement(this.phraseFactory.createWord("jack",
+ LexicalCategory.NOUN));
+ Assert.assertEquals("the man jack", this.realiser.realise( //$NON-NLS-1$
+ this.man).getRealisation());
+
+ this.woman.addComplement(this.behindTheCurtain);
+ Assert.assertEquals("the woman behind the curtain", this.realiser //$NON-NLS-1$
+ .realise(this.woman).getRealisation());
+ }
+
+ /**
+ * Test possessive constructions.
+ */
+ @Test
+ public void testPossessive() {
+
+ // simple possessive 's: 'a man's'
+ PhraseElement possNP = this.phraseFactory.createNounPhrase("a", "man"); //$NON-NLS-1$ //$NON-NLS-2$
+ possNP.setFeature(Feature.POSSESSIVE, true);
+ Assert.assertEquals("a man's", this.realiser.realise(possNP) //$NON-NLS-1$
+ .getRealisation());
+
+ // now set this possessive as specifier of the NP 'the dog'
+ this.dog.setFeature(InternalFeature.SPECIFIER, possNP);
+ Assert.assertEquals("a man's dog", this.realiser.realise(this.dog) //$NON-NLS-1$
+ .getRealisation());
+
+ // convert possNP to pronoun and turn "a dog" into "his dog"
+ // need to specify gender, as default is NEUTER
+ possNP.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
+ possNP.setFeature(Feature.PRONOMINAL, true);
+ Assert.assertEquals("his dog", this.realiser.realise(this.dog) //$NON-NLS-1$
+ .getRealisation());
+
+ // make it slightly more complicated: "his dog's rock"
+ this.dog.setFeature(Feature.POSSESSIVE, true); // his dog's
+
+ // his dog's rock (substituting "the"
+ // for the
+ // entire phrase)
+ this.np4.setFeature(InternalFeature.SPECIFIER, this.dog);
+ Assert.assertEquals("his dog's rock", this.realiser.realise(this.np4) //$NON-NLS-1$
+ .getRealisation());
+ }
+
+ /**
+ * Test NP coordination.
+ */
+ @Test
+ public void testCoordination() {
+
+ CoordinatedPhraseElement cnp1 = new CoordinatedPhraseElement(this.dog,
+ this.woman);
+ // simple coordination
+ Assert.assertEquals("the dog and the woman", this.realiser //$NON-NLS-1$
+ .realise(cnp1).getRealisation());
+
+ // simple coordination with complementation of entire coordinate NP
+ cnp1.addComplement(this.behindTheCurtain);
+ Assert.assertEquals("the dog and the woman behind the curtain", //$NON-NLS-1$
+ this.realiser.realise(cnp1).getRealisation());
+
+ // raise the specifier in this cnp
+ // Assert.assertEquals(true, cnp1.raiseSpecifier()); // should return
+ // true as all
+ // sub-nps have same spec
+ // assertEquals("the dog and woman behind the curtain",
+ // realiser.realise(cnp1));
+ }
+
+ /**
+ * Another battery of tests for NP coordination.
+ */
+ @Test
+ public void testCoordination2() {
+
+ // simple coordination of complementised nps
+ this.dog.clearComplements();
+ this.woman.clearComplements();
+
+ CoordinatedPhraseElement cnp1 = new CoordinatedPhraseElement(this.dog,
+ this.woman);
+ cnp1.setFeature(Feature.RAISE_SPECIFIER, true);
+ NLGElement realised = this.realiser.realise(cnp1);
+ Assert.assertEquals("the dog and woman", realised.getRealisation());
+
+ this.dog.addComplement(this.onTheRock);
+ this.woman.addComplement(this.behindTheCurtain);
+
+ CoordinatedPhraseElement cnp2 = new CoordinatedPhraseElement(this.dog,
+ this.woman);
+
+ this.woman.setFeature(InternalFeature.RAISED, false);
+ Assert.assertEquals(
+ "the dog on the rock and the woman behind the curtain", //$NON-NLS-1$
+ this.realiser.realise(cnp2).getRealisation());
+
+ // complementised coordinates + outer pp modifier
+ cnp2.addPostModifier(this.inTheRoom);
+ Assert
+ .assertEquals(
+ "the dog on the rock and the woman behind the curtain in the room", //$NON-NLS-1$
+ this.realiser.realise(cnp2).getRealisation());
+
+ // set the specifier for this cnp; should unset specifiers for all inner
+ // coordinates
+ NLGElement every = this.phraseFactory.createWord(
+ "every", LexicalCategory.DETERMINER); //$NON-NLS-1$
+
+ cnp2.setFeature(InternalFeature.SPECIFIER, every);
+
+ Assert
+ .assertEquals(
+ "every dog on the rock and every woman behind the curtain in the room", //$NON-NLS-1$
+ this.realiser.realise(cnp2).getRealisation());
+
+ // pronominalise one of the constituents
+ this.dog.setFeature(Feature.PRONOMINAL, true); // ="it"
+ this.dog.setFeature(InternalFeature.SPECIFIER, this.phraseFactory
+ .createWord("the", LexicalCategory.DETERMINER));
+ // raising spec still returns true as spec has been set
+ cnp2.setFeature(Feature.RAISE_SPECIFIER, true);
+
+ // CNP should be realised with pronominal internal const
+ Assert.assertEquals(
+ "it and every woman behind the curtain in the room", //$NON-NLS-1$
+ this.realiser.realise(cnp2).getRealisation());
+ }
+
+ /**
+ * Test possessives in coordinate NPs.
+ */
+ @Test
+ public void testPossessiveCoordinate() {
+ // simple coordination
+ CoordinatedPhraseElement cnp2 = new CoordinatedPhraseElement(this.dog,
+ this.woman);
+ Assert.assertEquals("the dog and the woman", this.realiser //$NON-NLS-1$
+ .realise(cnp2).getRealisation());
+
+ // set possessive -- wide-scope by default
+ cnp2.setFeature(Feature.POSSESSIVE, true);
+ Assert.assertEquals("the dog and the woman's", this.realiser.realise( //$NON-NLS-1$
+ cnp2).getRealisation());
+
+ // set possessive with pronoun
+ this.dog.setFeature(Feature.PRONOMINAL, true);
+ this.dog.setFeature(Feature.POSSESSIVE, true);
+ cnp2.setFeature(Feature.POSSESSIVE, true);
+ Assert.assertEquals("its and the woman's", this.realiser.realise(cnp2) //$NON-NLS-1$
+ .getRealisation());
+
+ }
+
+ /**
+ * Test A vs An.
+ */
+ @Test
+ public void testAAn() {
+ PhraseElement _dog = this.phraseFactory.createNounPhrase("a", "dog"); //$NON-NLS-1$ //$NON-NLS-2$
+ Assert.assertEquals("a dog", this.realiser.realise(_dog) //$NON-NLS-1$
+ .getRealisation());
+
+ _dog.addPreModifier("enormous"); //$NON-NLS-1$
+
+ Assert.assertEquals("an enormous dog", this.realiser.realise(_dog) //$NON-NLS-1$
+ .getRealisation());
+
+ PhraseElement elephant = this.phraseFactory.createNounPhrase(
+ "a", "elephant"); //$NON-NLS-1$ //$NON-NLS-2$
+ Assert.assertEquals("an elephant", this.realiser.realise(elephant) //$NON-NLS-1$
+ .getRealisation());
+
+ elephant.addPreModifier("big"); //$NON-NLS-1$
+ Assert.assertEquals("a big elephant", this.realiser.realise(elephant) //$NON-NLS-1$
+ .getRealisation());
+
+ // test treating of plural specifiers
+ _dog.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+
+ Assert.assertEquals("some enormous dogs", this.realiser.realise(_dog) //$NON-NLS-1$
+ .getRealisation());
+ }
+
+ /**
+ * Further tests for a/an agreement with coordinated premodifiers
+ */
+ public void testAAnCoord() {
+ NPPhraseSpec _dog = this.phraseFactory.createNounPhrase("a", "dog");
+ _dog.addPreModifier(this.phraseFactory.createCoordinatedPhrase(
+ "enormous", "black"));
+ String realisation = this.realiser.realise(_dog).getRealisation();
+ Assert.assertEquals("an enormous and black dog", realisation);
+ }
+
+ /**
+ * Test for a/an agreement with numbers
+ */
+ public void testAAnWithNumbers() {
+ NPPhraseSpec num = this.phraseFactory.createNounPhrase("a", "change");
+ String realisation;
+
+ // no an with "one"
+ num.setPreModifier("one percent");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("a one percent change", realisation);
+
+ // an with "eighty"
+ num.setPreModifier("eighty percent");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("an eighty percent change", realisation);
+
+ // an with 80
+ num.setPreModifier("80%");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("an 80% change", realisation);
+
+ // an with 80000
+ num.setPreModifier("80000");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("an 80000 change", realisation);
+
+ // an with 11,000
+ num.setPreModifier("11,000");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("an 11,000 change", realisation);
+
+ // an with 18
+ num.setPreModifier("18%");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("an 18% change", realisation);
+
+ // a with 180
+ num.setPreModifier("180");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("a 180 change", realisation);
+
+ // a with 1100
+ num.setPreModifier("1100");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("a 1100 change", realisation);
+
+ // a with 180,000
+ num.setPreModifier("180,000");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("a 180,000 change", realisation);
+
+ // an with 11000
+ num.setPreModifier("11000");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("an 11000 change", realisation);
+
+ // an with 18000
+ num.setPreModifier("18000");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("an 18000 change", realisation);
+
+ // an with 18.1
+ num.setPreModifier("18.1%");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("an 18.1% change", realisation);
+
+ // an with 11.1
+ num.setPreModifier("11.1%");
+ realisation = this.realiser.realise(num).getRealisation();
+ Assert.assertEquals("an 11.1% change", realisation);
+
+ }
+
+ /**
+ * Test Modifier "guess" placement.
+ */
+ @Test
+ public void testModifier() {
+ PhraseElement _dog = this.phraseFactory.createNounPhrase("a", "dog"); //$NON-NLS-1$ //$NON-NLS-2$
+ _dog.addPreModifier("angry"); //$NON-NLS-1$
+
+ Assert.assertEquals("an angry dog", this.realiser.realise(_dog) //$NON-NLS-1$
+ .getRealisation());
+
+ _dog.addPostModifier("in the park"); //$NON-NLS-1$
+ Assert.assertEquals("an angry dog in the park", this.realiser.realise( //$NON-NLS-1$
+ _dog).getRealisation());
+
+ PhraseElement cat = this.phraseFactory.createNounPhrase("a", "cat"); //$NON-NLS-1$ //$NON-NLS-2$
+ cat.addPreModifier(this.phraseFactory.createAdjectivePhrase("angry")); //$NON-NLS-1$
+ Assert.assertEquals("an angry cat", this.realiser.realise(cat) //$NON-NLS-1$
+ .getRealisation());
+
+ cat.addPostModifier(this.phraseFactory.createPrepositionPhrase(
+ "in", "the park")); //$NON-NLS-1$ //$NON-NLS-2$
+ Assert.assertEquals("an angry cat in the park", this.realiser.realise( //$NON-NLS-1$
+ cat).getRealisation());
+
+ }
+ @Test
+ public void testPluralNounsBelongingToASingular() {
+
+ SPhraseSpec sent = this.phraseFactory.createClause("I", "count up");
+ sent.setFeature(Feature.TENSE, Tense.PAST);
+ NPPhraseSpec obj = this.phraseFactory.createNounPhrase("digit");
+ obj.setPlural(true);
+ NPPhraseSpec possessor = this.phraseFactory.createNounPhrase("the", "box");
+ possessor.setPlural(false);
+ possessor.setFeature(Feature.POSSESSIVE, true);
+ obj.setSpecifier(possessor);
+ sent.setObject(obj);
+
+ Assert.assertEquals("I counted up the box's digits", this.realiser.realise(sent) //$NON-NLS-1$
+ .getRealisation());
+ }
+
+
+ @Test
+ public void testSingularNounsBelongingToAPlural() {
+
+ SPhraseSpec sent = this.phraseFactory.createClause("I", "clean");
+ sent.setFeature(Feature.TENSE, Tense.PAST);
+ NPPhraseSpec obj = this.phraseFactory.createNounPhrase("car");
+ obj.setPlural(false);
+ NPPhraseSpec possessor = this.phraseFactory.createNounPhrase("the", "parent");
+ possessor.setPlural(true);
+ possessor.setFeature(Feature.POSSESSIVE, true);
+ obj.setSpecifier(possessor);
+ sent.setObject(obj);
+
+ Assert.assertEquals("I cleaned the parents' car", this.realiser.realise(sent) //$NON-NLS-1$
+ .getRealisation());
+ }
+
+ /**
+ * Test for appositive postmodifiers
+ */
+ @Test
+ public void testAppositivePostmodifier() {
+ PhraseElement _dog = this.phraseFactory.createNounPhrase("the", "dog");
+ PhraseElement _rott = this.phraseFactory.createNounPhrase("a", "rottweiler");
+ _rott.setFeature(Feature.APPOSITIVE, true);
+ _dog.addPostModifier(_rott);
+ SPhraseSpec _sent = this.phraseFactory.createClause(_dog, "ran");
+ Assert.assertEquals("The dog, a rottweiler runs.", this.realiser.realiseSentence(_sent));
+ }
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/OrthographyFormatTest.java b/SharpSimpleNLGUnitTests/syntax/english/OrthographyFormatTest.java
new file mode 100644
index 0000000..3fcd900
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/OrthographyFormatTest.java
@@ -0,0 +1,205 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import java.util.Arrays;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.format.english.TextFormatter;
+import simplenlg.framework.DocumentElement;
+import simplenlg.framework.NLGElement;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.PPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.features.Feature;
+
+public class OrthographyFormatTest extends SimpleNLG4Test {
+
+ private DocumentElement list1, list2;
+ private DocumentElement listItem1, listItem2, listItem3;
+ private String list1Realisation = new StringBuffer("* in the room")
+ .append("\n* behind the curtain").append("\n").toString();
+ private String list2Realisation = new StringBuffer("* on the rock")
+ .append("\n* ").append(list1Realisation).append("\n").toString();
+
+ public OrthographyFormatTest(String name) {
+ super(name);
+ }
+
+ @Before
+ public void setUp() {
+ super.setUp();
+
+ // need to set formatter for realiser (set to null in the test
+ // superclass)
+ this.realiser.setFormatter(new TextFormatter());
+
+ // a couple phrases as list items
+ this.listItem1 = this.phraseFactory.createListItem(this.inTheRoom);
+ this.listItem2 = this.phraseFactory
+ .createListItem(this.behindTheCurtain);
+ this.listItem3 = this.phraseFactory.createListItem(this.onTheRock);
+
+ // a simple depth-1 list of phrases
+ this.list1 = this.phraseFactory
+ .createList(Arrays.asList(new DocumentElement[] {
+ this.listItem1, this.listItem2 }));
+
+ // a list consisting of one phrase (depth-1) + a list )(depth-2)
+ this.list2 = this.phraseFactory.createList(Arrays
+ .asList(new DocumentElement[] { this.listItem3,
+ this.phraseFactory.createListItem(this.list1) }));
+ }
+
+ @Override
+ @After
+ public void tearDown() {
+ super.tearDown();
+ this.list1 = null; this.list2 = null;
+ this.listItem1 = null; this.listItem2 = null; this.listItem3 = null;
+ this.list1Realisation = null;
+ list2Realisation = null;
+ }
+
+ /**
+ * Test the realisation of a simple list
+ */
+ @Test
+ public void testSimpleListOrthography() {
+ NLGElement realised = this.realiser.realise(this.list1);
+ Assert.assertEquals(this.list1Realisation, realised.getRealisation());
+ }
+
+ /**
+ * Test the realisation of a list with an embedded list
+ */
+ @Test
+ public void testEmbeddedListOrthography() {
+ NLGElement realised = this.realiser.realise(this.list2);
+ Assert.assertEquals(this.list2Realisation, realised.getRealisation());
+ }
+
+ /**
+ * Test the realisation of appositive pre-modifiers with commas around them.
+ */
+ @Test
+ public void testAppositivePreModifiers() {
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("I");
+ NPPhraseSpec object = this.phraseFactory.createNounPhrase("a bag");
+
+ SPhraseSpec _s1 = this.phraseFactory.createClause(subject,
+ "carry", object);
+
+ // add a PP complement
+ PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("on",
+ this.phraseFactory.createNounPhrase("most", "Tuesdays"));
+ _s1.addPreModifier(pp);
+
+ //without appositive feature on pp
+ Assert.assertEquals(
+ "I on most Tuesdays carry a bag", this.realiser
+ .realise(_s1).getRealisation());
+
+ //with appositive feature
+ pp.setFeature(Feature.APPOSITIVE, true);
+ Assert.assertEquals(
+ "I, on most Tuesdays, carry a bag", this.realiser
+ .realise(_s1).getRealisation());
+ }
+
+
+ /**
+ * Test the realisation of appositive pre-modifiers with commas around them.
+ */
+ @Test
+ public void testCommaSeparatedFrontModifiers() {
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("I");
+ NPPhraseSpec object = this.phraseFactory.createNounPhrase("a bag");
+
+ SPhraseSpec _s1 = this.phraseFactory.createClause(subject,
+ "carry", object);
+
+ // add a PP complement
+ PPPhraseSpec pp1 = this.phraseFactory.createPrepositionPhrase("on",
+ this.phraseFactory.createNounPhrase("most", "Tuesdays"));
+ _s1.addFrontModifier(pp1);
+
+ PPPhraseSpec pp2 = this.phraseFactory.createPrepositionPhrase("since",
+ this.phraseFactory.createNounPhrase("1991"));
+ _s1.addFrontModifier(pp2);
+ pp1.setFeature(Feature.APPOSITIVE, true);
+ pp2.setFeature(Feature.APPOSITIVE, true);
+
+ //without setCommaSepCuephrase
+ Assert.assertEquals(
+ "on most Tuesdays since 1991 I carry a bag", this.realiser
+ .realise(_s1).getRealisation());
+
+ //with setCommaSepCuephrase
+ this.realiser.setCommaSepCuephrase(true);
+ Assert.assertEquals(
+ "on most Tuesdays, since 1991, I carry a bag", this.realiser
+ .realise(_s1).getRealisation());
+ }
+
+ /**
+ * Ensure we don't end up with doubled commas.
+ */
+ @Test
+ public void testNoDoubledCommas() {
+ NPPhraseSpec subject = this.phraseFactory.createNounPhrase("I");
+ NPPhraseSpec object = this.phraseFactory.createNounPhrase("a bag");
+
+ SPhraseSpec _s1 = this.phraseFactory.createClause(subject,
+ "carry", object);
+
+ PPPhraseSpec pp1 = this.phraseFactory.createPrepositionPhrase("on",
+ this.phraseFactory.createNounPhrase("most", "Tuesdays"));
+ _s1.addFrontModifier(pp1);
+
+ PPPhraseSpec pp2 = this.phraseFactory.createPrepositionPhrase("since",
+ this.phraseFactory.createNounPhrase("1991"));
+ PPPhraseSpec pp3 = this.phraseFactory.createPrepositionPhrase("except",
+ this.phraseFactory.createNounPhrase("yesterday"));
+
+ pp2.setFeature(Feature.APPOSITIVE, true);
+ pp3.setFeature(Feature.APPOSITIVE, true);
+
+ pp1.addPostModifier(pp2);
+ pp1.addPostModifier(pp3);
+
+ this.realiser.setCommaSepCuephrase(true);
+
+ Assert.assertEquals(
+ "on most Tuesdays, since 1991, except yesterday, I carry a bag", this.realiser
+ .realise(_s1).getRealisation());
+ // without my fix (that we're testing here), you'd end up with
+ // "on most Tuesdays, since 1991,, except yesterday, I carry a bag"
+ }
+
+// <[on most Tuesdays, since 1991, except yesterday, ]I carry a bag> but was:<[]I carry a bag>
+
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/PhraseSpecTest.java b/SharpSimpleNLGUnitTests/syntax/english/PhraseSpecTest.java
new file mode 100644
index 0000000..1838704
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/PhraseSpecTest.java
@@ -0,0 +1,120 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.syntax.english;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.features.Tense;
+import simplenlg.framework.InflectedWordElement;
+import simplenlg.framework.NLGElement;
+import simplenlg.framework.PhraseElement;
+import simplenlg.framework.StringElement;
+import simplenlg.framework.WordElement;
+import simplenlg.phrasespec.SPhraseSpec;
+
+/**
+ * test suite for simple XXXPhraseSpec classes
+ * @author ereiter
+ *
+ */
+
+public class PhraseSpecTest extends SimpleNLG4Test {
+
+ public PhraseSpecTest(String name) {
+ super(name);
+ }
+
+
+ @Override
+ @After
+ public void tearDown() {
+ super.tearDown();
+ }
+
+ /**
+ * Check that empty phrases are not realised as "null"
+ */
+ @Test
+ public void emptyPhraseRealisationTest() {
+ SPhraseSpec emptyClause = this.phraseFactory.createClause();
+ Assert.assertEquals("", this.realiser.realise(emptyClause)
+ .getRealisation());
+ }
+
+
+ /**
+ * Test SPhraseSpec
+ */
+ @Test
+ public void testSPhraseSpec() {
+
+ // simple test of methods
+ SPhraseSpec c1 = (SPhraseSpec) phraseFactory.createClause();
+ c1.setVerb("give");
+ c1.setSubject("John");
+ c1.setObject("an apple");
+ c1.setIndirectObject("Mary");
+ c1.setFeature(Feature.TENSE, Tense.PAST);
+ c1.setFeature(Feature.NEGATED, true);
+
+ // check getXXX methods
+ Assert.assertEquals("give", getBaseForm(c1.getVerb()));
+ Assert.assertEquals("John", getBaseForm(c1.getSubject()));
+ Assert.assertEquals("an apple", getBaseForm(c1.getObject()));
+ Assert.assertEquals("Mary", getBaseForm(c1.getIndirectObject()));
+
+ Assert.assertEquals("John did not give Mary an apple", this.realiser //$NON-NLS-1$
+ .realise(c1).getRealisation());
+
+
+
+ // test modifier placement
+ SPhraseSpec c2 = (SPhraseSpec) phraseFactory.createClause();
+ c2.setVerb("see");
+ c2.setSubject("the man");
+ c2.setObject("me");
+ c2.addModifier("fortunately");
+ c2.addModifier("quickly");
+ c2.addModifier("in the park");
+ // try setting tense directly as a feature
+ c2.setFeature(Feature.TENSE, Tense.PAST);
+ Assert.assertEquals("fortunately the man quickly saw me in the park", this.realiser //$NON-NLS-1$
+ .realise(c2).getRealisation());
+ }
+
+ // get string for head of constituent
+ private String getBaseForm(NLGElement constituent) {
+ if (constituent == null)
+ return null;
+ else if (constituent instanceof StringElement)
+ return constituent.getRealisation();
+ else if (constituent instanceof WordElement)
+ return ((WordElement)constituent).getBaseForm();
+ else if (constituent instanceof InflectedWordElement)
+ return getBaseForm(((InflectedWordElement)constituent).getBaseWord());
+ else if (constituent instanceof PhraseElement)
+ return getBaseForm(((PhraseElement)constituent).getHead());
+ else
+ return null;
+ }
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/PremodifierTest.java b/SharpSimpleNLGUnitTests/syntax/english/PremodifierTest.java
new file mode 100644
index 0000000..e5feff2
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/PremodifierTest.java
@@ -0,0 +1,114 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, and Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.features.Tense;
+import simplenlg.framework.NLGFactory;
+import simplenlg.lexicon.Lexicon;
+import simplenlg.phrasespec.AdvPhraseSpec;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.phrasespec.VPPhraseSpec;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * {@link PremodifierTest} contains a series of JUnit test cases for Premodifiers.
+ *
+ * @author Saad Mahamood
+ */
+public class PremodifierTest {
+
+ private Lexicon lexicon = null;
+ private NLGFactory phraseFactory = null;
+ private Realiser realiser = null;
+
+ @Before
+ public void setup() {
+ lexicon = Lexicon.getDefaultLexicon();
+ phraseFactory = new NLGFactory(lexicon);
+ realiser = new Realiser(lexicon);
+ }
+
+
+
+ /**
+ * Test change from "a" to "an" in the presence of a premodifier with a
+ * vowel
+ */
+ @Test
+ public void indefiniteWithPremodifierTest() {
+ SPhraseSpec s = this.phraseFactory.createClause("there", "be");
+ s.setFeature(Feature.TENSE, Tense.PRESENT);
+ NPPhraseSpec np = this.phraseFactory.createNounPhrase("a", "stenosis");
+ s.setObject(np);
+
+ // check without modifiers -- article should be "a"
+ Assert.assertEquals("there is a stenosis", this.realiser.realise(s)
+ .getRealisation());
+
+ // add a single modifier -- should turn article to "an"
+ np.addPreModifier(this.phraseFactory.createAdjectivePhrase("eccentric"));
+ Assert.assertEquals("there is an eccentric stenosis", this.realiser
+ .realise(s).getRealisation());
+ }
+
+ /**
+ * Test for comma separation between premodifers
+ */
+ @Test
+ public void multipleAdjPremodifiersTest() {
+ NPPhraseSpec np = this.phraseFactory.createNounPhrase("a", "stenosis");
+ np.addPreModifier(this.phraseFactory.createAdjectivePhrase("eccentric"));
+ np.addPreModifier(this.phraseFactory.createAdjectivePhrase("discrete"));
+ Assert.assertEquals("an eccentric, discrete stenosis", this.realiser
+ .realise(np).getRealisation());
+ }
+
+ /**
+ * Test for comma separation between verb premodifiers
+ */
+ @Test
+ public void multipleAdvPremodifiersTest() {
+ AdvPhraseSpec adv1 = this.phraseFactory.createAdverbPhrase("slowly");
+ AdvPhraseSpec adv2 = this.phraseFactory
+ .createAdverbPhrase("discretely");
+
+ // case 1: concatenated premods: should have comma
+ VPPhraseSpec vp = this.phraseFactory.createVerbPhrase("run");
+ vp.addPreModifier(adv1);
+ vp.addPreModifier(adv2);
+ Assert.assertEquals("slowly, discretely runs", this.realiser
+ .realise(vp).getRealisation());
+
+ // case 2: coordinated premods: no comma
+ VPPhraseSpec vp2 = this.phraseFactory.createVerbPhrase("eat");
+ vp2.addPreModifier(this.phraseFactory.createCoordinatedPhrase(adv1,
+ adv2));
+ Assert.assertEquals("slowly and discretely eats", this.realiser
+ .realise(vp2).getRealisation());
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/PrepositionalPhraseTest.java b/SharpSimpleNLGUnitTests/syntax/english/PrepositionalPhraseTest.java
new file mode 100644
index 0000000..647998d
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/PrepositionalPhraseTest.java
@@ -0,0 +1,113 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.framework.CoordinatedPhraseElement;
+
+// TODO: Auto-generated Javadoc
+/**
+ * This class groups together some tests for prepositional phrases and
+ * coordinate prepositional phrases.
+ * @author agatt
+ */
+public class PrepositionalPhraseTest extends SimpleNLG4Test {
+
+ /**
+ * Instantiates a new pP test.
+ *
+ * @param name
+ * the name
+ */
+ public PrepositionalPhraseTest(String name) {
+ super(name);
+ }
+
+ @Override
+ @After
+ public void tearDown() {
+ super.tearDown();
+ }
+
+ /**
+ * Basic test for the pre-set PP fixtures.
+ */
+ @Test
+ public void testBasic() {
+ Assert.assertEquals("in the room", this.realiser //$NON-NLS-1$
+ .realise(this.inTheRoom).getRealisation());
+ Assert.assertEquals("behind the curtain", this.realiser //$NON-NLS-1$
+ .realise(this.behindTheCurtain).getRealisation());
+ Assert.assertEquals("on the rock", this.realiser //$NON-NLS-1$
+ .realise(this.onTheRock).getRealisation());
+ }
+
+ /**
+ * Test for coordinate NP complements of PPs.
+ */
+ @Test
+ public void testComplementation() {
+ this.inTheRoom.clearComplements();
+ this.inTheRoom.addComplement(new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("the", "room"), //$NON-NLS-1$ //$NON-NLS-2$
+ this.phraseFactory.createNounPhrase("a", "car"))); //$NON-NLS-1$//$NON-NLS-2$
+ Assert.assertEquals("in the room and a car", this.realiser //$NON-NLS-1$
+ .realise(this.inTheRoom).getRealisation());
+ }
+
+ /**
+ * Test for PP coordination.
+ */
+ public void testCoordination() {
+ // simple coordination
+
+ CoordinatedPhraseElement coord1 = new CoordinatedPhraseElement(
+ this.inTheRoom, this.behindTheCurtain);
+ Assert.assertEquals("in the room and behind the curtain", this.realiser //$NON-NLS-1$
+ .realise(coord1).getRealisation());
+
+ // change the conjunction
+ coord1.setFeature(Feature.CONJUNCTION, "or"); //$NON-NLS-1$
+ Assert.assertEquals("in the room or behind the curtain", this.realiser //$NON-NLS-1$
+ .realise(coord1).getRealisation());
+
+ // new coordinate
+ CoordinatedPhraseElement coord2 = new CoordinatedPhraseElement(
+ this.onTheRock, this.underTheTable);
+ coord2.setFeature(Feature.CONJUNCTION, "or"); //$NON-NLS-1$
+ Assert.assertEquals("on the rock or under the table", this.realiser //$NON-NLS-1$
+ .realise(coord2).getRealisation());
+
+ // coordinate two coordinates
+ CoordinatedPhraseElement coord3 = new CoordinatedPhraseElement(coord1,
+ coord2);
+
+ String text = this.realiser.realise(coord3).getRealisation();
+ Assert
+ .assertEquals(
+ "in the room or behind the curtain and on the rock or under the table", //$NON-NLS-1$
+ text);
+ }
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/SimpleNLG4Test.java b/SharpSimpleNLGUnitTests/syntax/english/SimpleNLG4Test.java
new file mode 100644
index 0000000..d8b3cd8
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/SimpleNLG4Test.java
@@ -0,0 +1,145 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.syntax.english;
+
+import junit.framework.TestCase;
+
+import org.junit.After;
+import org.junit.Before;
+
+
+import simplenlg.framework.NLGFactory;
+import simplenlg.framework.PhraseElement;
+import simplenlg.lexicon.XMLLexicon;
+import simplenlg.lexicon.Lexicon;
+import simplenlg.phrasespec.VPPhraseSpec;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * This class is the base class for all JUnit simplenlg.test cases for
+ * simplenlg. It sets up a a JUnit fixture, i.e. the basic objects (basic
+ * constituents) that all other tests can use.
+ * @author agatt
+ */
+public abstract class SimpleNLG4Test extends TestCase {
+
+ /** The realiser. */
+ protected Realiser realiser;
+
+ protected NLGFactory phraseFactory;
+
+ protected Lexicon lexicon;
+
+ /** The pro test2. */
+ protected PhraseElement man, woman, dog, boy, np4, np5, np6, proTest1, proTest2;
+
+ /** The salacious. */
+ protected PhraseElement beautiful, stunning, salacious;
+
+ /** The under the table. */
+ protected PhraseElement onTheRock, behindTheCurtain, inTheRoom, underTheTable;
+
+ /** The say. */
+ protected VPPhraseSpec kick, kiss, walk, talk, getUp, fallDown, give, say;
+
+ /**
+ * Instantiates a new simplenlg test.
+ *
+ * @param name
+ * the name
+ */
+ public SimpleNLG4Test(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up the variables we'll need for this simplenlg.test to run (Called
+ * automatically by JUnit)
+ */
+ @Override
+ @Before
+ protected void setUp() {
+ lexicon = new XMLLexicon(); // built in lexicon
+
+ this.phraseFactory = new NLGFactory(this.lexicon);
+ this.realiser = new Realiser(this.lexicon);
+
+ this.man = this.phraseFactory.createNounPhrase("the", "man"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.woman = this.phraseFactory.createNounPhrase("the", "woman"); //$NON-NLS-1$//$NON-NLS-2$
+ this.dog = this.phraseFactory.createNounPhrase("the", "dog"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.boy = this.phraseFactory.createNounPhrase("the", "boy"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ this.beautiful = this.phraseFactory.createAdjectivePhrase("beautiful"); //$NON-NLS-1$
+ this.stunning = this.phraseFactory.createAdjectivePhrase("stunning"); //$NON-NLS-1$
+ this.salacious = this.phraseFactory.createAdjectivePhrase("salacious"); //$NON-NLS-1$
+
+ this.onTheRock = this.phraseFactory.createPrepositionPhrase("on"); //$NON-NLS-1$
+ this.np4 = this.phraseFactory.createNounPhrase("the", "rock"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.onTheRock.addComplement(this.np4);
+
+ this.behindTheCurtain = this.phraseFactory.createPrepositionPhrase("behind"); //$NON-NLS-1$
+ this.np5 = this.phraseFactory.createNounPhrase("the", "curtain"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.behindTheCurtain.addComplement(this.np5);
+
+ this.inTheRoom = this.phraseFactory.createPrepositionPhrase("in"); //$NON-NLS-1$
+ this.np6 = this.phraseFactory.createNounPhrase("the", "room"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.inTheRoom.addComplement(this.np6);
+
+ this.underTheTable = this.phraseFactory.createPrepositionPhrase("under"); //$NON-NLS-1$
+ this.underTheTable.addComplement(this.phraseFactory.createNounPhrase("the", "table")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ this.proTest1 = this.phraseFactory.createNounPhrase("the", "singer"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.proTest2 = this.phraseFactory.createNounPhrase("some", "person"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ this.kick = this.phraseFactory.createVerbPhrase("kick"); //$NON-NLS-1$
+ this.kiss = this.phraseFactory.createVerbPhrase("kiss"); //$NON-NLS-1$
+ this.walk = this.phraseFactory.createVerbPhrase("walk"); //$NON-NLS-1$
+ this.talk = this.phraseFactory.createVerbPhrase("talk"); //$NON-NLS-1$
+ this.getUp = this.phraseFactory.createVerbPhrase("get up"); //$NON-NLS-1$
+ this.fallDown = this.phraseFactory.createVerbPhrase("fall down"); //$NON-NLS-1$
+ this.give = this.phraseFactory.createVerbPhrase("give"); //$NON-NLS-1$
+ this.say = this.phraseFactory.createVerbPhrase("say"); //$NON-NLS-1$
+ }
+
+ @Override
+ @After
+ public void tearDown() {
+ this.realiser = null;
+
+ this.phraseFactory = null;
+
+ if(null != lexicon) {
+ lexicon = null;
+ }
+
+ this.man = null; this.woman = null; this.dog = null; this.boy = null;
+ this.np4 = null; this.np5 = null; this.np6 = null; this.proTest1 = null;
+ this.proTest2 = null;
+
+ this.beautiful = null; this.stunning = null; this.salacious = null;
+
+ this.onTheRock = null; this.behindTheCurtain= null;
+ this.inTheRoom = null; this.underTheTable = null;
+
+ this.kick = null; this.kiss = null; this.walk = null; this.talk = null;
+ this.getUp = null; this.fallDown = null; this.give = null; this.say = null;
+ }
+
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/StandAloneExample.java b/SharpSimpleNLGUnitTests/syntax/english/StandAloneExample.java
new file mode 100644
index 0000000..14e01d1
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/StandAloneExample.java
@@ -0,0 +1,123 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+package simplenlg.syntax.english;
+
+import org.junit.Ignore;
+
+import simplenlg.features.Feature;
+import simplenlg.features.Tense;
+import simplenlg.framework.DocumentElement;
+import simplenlg.framework.InflectedWordElement;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.NLGElement;
+import simplenlg.framework.NLGFactory;
+import simplenlg.framework.StringElement;
+import simplenlg.framework.WordElement;
+import simplenlg.lexicon.Lexicon;
+import simplenlg.lexicon.XMLLexicon;
+import simplenlg.phrasespec.AdjPhraseSpec;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.PPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * @author Dave Westwater, Data2Text Ltd
+ *
+ */
+@Ignore
+public class StandAloneExample {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+
+ // below is a simple complete example of using simplenlg V4
+ // afterwards is an example of using simplenlg just for morphology
+
+ // set up
+ Lexicon lexicon = new XMLLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+
+ // create sentences
+ // "John did not go to the bigger park. He played football there."
+ NPPhraseSpec thePark = nlgFactory.createNounPhrase("the", "park"); // create an NP
+ AdjPhraseSpec bigp = nlgFactory.createAdjectivePhrase("big"); // create AdjP
+ bigp.setFeature(Feature.IS_COMPARATIVE, true); // use comparative form ("bigger")
+ thePark.addModifier(bigp); // add adj as modifier in NP
+ // above relies on default placement rules. You can force placement as a premodifier
+ // (before head) by using addPreModifier
+ PPPhraseSpec toThePark = nlgFactory.createPrepositionPhrase("to"); // create a PP
+ toThePark.setObject(thePark); // set PP object
+ // could also just say nlgFactory.createPrepositionPhrase("to", the Park);
+
+ SPhraseSpec johnGoToThePark = nlgFactory.createClause("John", // create sentence
+ "go", toThePark);
+
+ johnGoToThePark.setFeature(Feature.TENSE,Tense.PAST); // set tense
+ johnGoToThePark.setFeature(Feature.NEGATED, true); // set negated
+
+ // note that constituents (such as subject and object) are set with setXXX methods
+ // while features are set with setFeature
+
+ DocumentElement sentence = nlgFactory // create a sentence DocumentElement from SPhraseSpec
+ .createSentence(johnGoToThePark);
+
+ // below creates a sentence DocumentElement by concatenating strings
+ StringElement hePlayed = new StringElement("he played");
+ StringElement there = new StringElement("there");
+ WordElement football = new WordElement("football");
+
+ DocumentElement sentence2 = nlgFactory.createSentence();
+ sentence2.addComponent(hePlayed);
+ sentence2.addComponent(football);
+ sentence2.addComponent(there);
+
+ // now create a paragraph which contains these sentences
+ DocumentElement paragraph = nlgFactory.createParagraph();
+ paragraph.addComponent(sentence);
+ paragraph.addComponent(sentence2);
+
+ // create a realiser. Note that a lexicon is specified, this should be
+ // the same one used by the NLGFactory
+ Realiser realiser = new Realiser(lexicon);
+ //realiser.setDebugMode(true); // uncomment this to print out debug info during realisation
+ NLGElement realised = realiser.realise(paragraph);
+
+ System.out.println(realised.getRealisation());
+
+ // end of main example
+
+ // second example - using simplenlg just for morphology
+ // below is clumsy as direct access to morphology isn't properly supported in V4.2
+ // hopefully will be better supported in later versions
+
+ // get word element for "child"
+ WordElement word = (WordElement) nlgFactory.createWord("child", LexicalCategory.NOUN);
+ // create InflectedWordElement from word element
+ InflectedWordElement inflectedWord = new InflectedWordElement(word);
+ // set the inflected word to plural
+ inflectedWord.setPlural(true);
+ // realise the inflected word
+ String result = realiser.realise(inflectedWord).getRealisation();
+
+ System.out.println(result);
+ }
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/StringElementTest.java b/SharpSimpleNLGUnitTests/syntax/english/StringElementTest.java
new file mode 100644
index 0000000..07c40f7
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/StringElementTest.java
@@ -0,0 +1,407 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import static org.junit.Assert.*;
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import simplenlg.framework.CoordinatedPhraseElement;
+import simplenlg.framework.DocumentElement;
+import simplenlg.framework.LexicalCategory;
+import simplenlg.framework.NLGElement;
+import simplenlg.framework.NLGFactory;
+import simplenlg.framework.StringElement;
+import simplenlg.lexicon.Lexicon;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * Tests for string elements as parts of larger phrases
+ *
+ * @author bertugatt
+ *
+ */
+public class StringElementTest {
+
+ private Lexicon lexicon = null;
+ private NLGFactory phraseFactory = null;
+ private Realiser realiser = null;
+
+ @Before
+ public void setup() {
+ lexicon = Lexicon.getDefaultLexicon();
+ phraseFactory = new NLGFactory(lexicon);
+ realiser = new Realiser(lexicon);
+ }
+
+ @After
+ public void tearDown() {
+ lexicon = null;
+ phraseFactory = null;
+ realiser = null;
+ }
+
+ /**
+ * Test that string elements can be used as heads of NP
+ */
+ @Test
+ public void stringElementAsHeadTest() {
+ NPPhraseSpec np = this.phraseFactory.createNounPhrase();
+ np.setHead(phraseFactory.createStringElement("dogs and cats"));
+ np.setSpecifier(phraseFactory.createWord("the",
+ LexicalCategory.DETERMINER));
+ assertEquals("the dogs and cats", this.realiser.realise(np)
+ .getRealisation());
+ }
+
+ /**
+ * Sentences whose VP is a canned string
+ */
+ @Test
+ public void stringElementAsVPTest() {
+ SPhraseSpec s = this.phraseFactory.createClause();
+ s.setVerbPhrase(this.phraseFactory.createStringElement("eats and drinks"));
+ s.setSubject(this.phraseFactory.createStringElement("the big fat man"));
+ assertEquals("the big fat man eats and drinks", this.realiser
+ .realise(s).getRealisation());
+ }
+
+ /**
+ * Test for when the SPhraseSpec has a NPSpec added directly after it:
+ * "Mary loves NP[the cow]."
+ */
+ @Test
+ public void tailNPStringElementTest() {
+ SPhraseSpec senSpec = this.phraseFactory.createClause();
+ senSpec.addComplement((this.phraseFactory.createStringElement("mary loves")));
+ NPPhraseSpec np = this.phraseFactory.createNounPhrase();
+ np.setHead("cow");
+ np.setDeterminer("the");
+ senSpec.addComplement(np);
+ DocumentElement completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ assertEquals("Mary loves the cow.", this.realiser.realise(completeSen).getRealisation());
+ }
+
+ /**
+ * Test for a NP followed by a canned text: "NP[A cat] loves a dog".
+ */
+ @Test
+ public void frontNPStringElementTest() {
+ SPhraseSpec senSpec = this.phraseFactory.createClause();
+ NPPhraseSpec np = this.phraseFactory.createNounPhrase();
+ np.setHead("cat");
+ np.setDeterminer("the");
+ senSpec.addComplement(np);
+ senSpec.addComplement(this.phraseFactory.createStringElement("loves a dog"));
+ DocumentElement completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ assertEquals("The cat loves a dog.", this.realiser.realise(completeSen).getRealisation());
+ }
+
+
+ /**
+ * Test for a StringElement followed by a NP followed by a StringElement
+ * "The world loves NP[ABBA] but not a sore loser."
+ */
+ @Test
+ public void mulitpleStringElementsTest() {
+ SPhraseSpec senSpec = this.phraseFactory.createClause();
+ senSpec.addComplement(this.phraseFactory.createStringElement("the world loves"));
+ NPPhraseSpec np = this.phraseFactory.createNounPhrase();
+ np.setHead("ABBA");
+ senSpec.addComplement(np);
+ senSpec.addComplement(this.phraseFactory.createStringElement("but not a sore loser"));
+ DocumentElement completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ assertEquals("The world loves ABBA but not a sore loser.", this.realiser.realise(completeSen).getRealisation());
+ }
+
+ /**
+ * Test for multiple NP phrases with a single StringElement phrase:
+ * "NP[John is] a trier NP[for cheese]."
+ */
+ @Test
+ public void mulitpleNPElementsTest() {
+ SPhraseSpec senSpec = this.phraseFactory.createClause();
+ NPPhraseSpec frontNoun = this.phraseFactory.createNounPhrase();
+ frontNoun.setHead("john");
+ senSpec.addComplement(frontNoun);
+ senSpec.addComplement(this.phraseFactory.createStringElement("is a trier"));
+ NPPhraseSpec backNoun = this.phraseFactory.createNounPhrase();
+ backNoun.setDeterminer("for");
+ backNoun.setNoun("cheese");
+ senSpec.addComplement(backNoun);
+ DocumentElement completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ assertEquals("John is a trier for cheese.", this.realiser.realise(completeSen).getRealisation());
+
+ }
+
+
+ /**
+ * White space check: Test to see how SNLG deals with additional whitespaces:
+ *
+ * NP[The Nasdaq] rose steadily during NP[early trading], however it plummeted due to NP[a shock] after NP[IBM] announced poor
+ * NP[first quarter results].
+ */
+ @Test
+ public void whiteSpaceNPTest() {
+ SPhraseSpec senSpec = this.phraseFactory.createClause();
+ NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase();
+ firstNoun.setDeterminer("the");
+ firstNoun.setNoun("Nasdaq");
+ senSpec.addComplement(firstNoun);
+ senSpec.addComplement(this.phraseFactory.createStringElement(" rose steadily during "));
+ NPPhraseSpec secondNoun = this.phraseFactory.createNounPhrase();
+ secondNoun.setSpecifier("early");
+ secondNoun.setNoun("trading");
+ senSpec.addComplement(secondNoun);
+ senSpec.addComplement(this.phraseFactory.createStringElement(" , however it plummeted due to"));
+ NPPhraseSpec thirdNoun = this.phraseFactory.createNounPhrase();
+ thirdNoun.setSpecifier("a");
+ thirdNoun.setNoun("shock");
+ senSpec.addComplement(thirdNoun);
+ senSpec.addComplement(this.phraseFactory.createStringElement(" after "));
+ NPPhraseSpec fourthNoun = this.phraseFactory.createNounPhrase();
+ fourthNoun.setNoun("IBM");
+ senSpec.addComplement(fourthNoun);
+ senSpec.addComplement(this.phraseFactory.createStringElement("announced poor "));
+ NPPhraseSpec fifthNoun = this.phraseFactory.createNounPhrase();
+ fifthNoun.setSpecifier("first quarter");
+ fifthNoun.setNoun("results");
+ fifthNoun.setPlural(true);
+ senSpec.addComplement(fifthNoun);
+ DocumentElement completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ assertEquals("The Nasdaq rose steadily during early trading, however it plummeted due to a shock after IBM announced poor first quarter results.",
+ this.realiser.realise(completeSen).getRealisation());
+ }
+
+ /**
+ * Point absorption test: Check to see if SNLG respects abbreviations at the end of a sentence.
+ * "NP[Yahya] was sleeping his own and dreaming etc."
+ */
+
+ public void pointAbsorptionTest() {
+ SPhraseSpec senSpec = this.phraseFactory.createClause();
+ NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase();
+ firstNoun.setNoun("yaha");
+ senSpec.addComplement(firstNoun);
+ senSpec.addComplement("was sleeping on his own and dreaming etc.");
+ DocumentElement completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ assertEquals("Yaha was sleeping on his own and dreaming etc.",
+ this.realiser.realise(completeSen).getRealisation());
+
+
+ }
+
+ /**
+ * Point absorption test: As above, but with trailing white space.
+ * "NP[Yaha] was sleeping his own and dreaming etc. "
+ */
+ public void pointAbsorptionTrailingWhiteSpaceTest() {
+ SPhraseSpec senSpec = this.phraseFactory.createClause();
+ NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase();
+ firstNoun.setNoun("yaha");
+ senSpec.addComplement(firstNoun);
+ senSpec.addComplement("was sleeping on his own and dreaming etc. ");
+ DocumentElement completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ assertEquals("Yaha was sleeping on his own and dreaming etc.",
+ this.realiser.realise(completeSen).getRealisation());
+ }
+
+ /**
+ * Abbreviation test: Check to see how SNLG deals with abbreviations in the middle of a sentence.
+ *
+ * "NP[Yahya] and friends etc. went to NP[the park] to play."
+ */
+ @Test
+ public void middleAbbreviationTest() {
+ SPhraseSpec senSpec = this.phraseFactory.createClause();
+ NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase();
+ firstNoun.setNoun("yahya");
+ senSpec.addComplement(firstNoun);
+ senSpec.addComplement(this.phraseFactory.createStringElement("and friends etc. went to"));
+ NPPhraseSpec secondNoun = this.phraseFactory.createNounPhrase();
+ secondNoun.setDeterminer("the");
+ secondNoun.setNoun("park");
+ senSpec.addComplement(secondNoun);
+ senSpec.addComplement("to play");
+ DocumentElement completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ assertEquals("Yahya and friends etc. went to the park to play.",
+ this.realiser.realise(completeSen).getRealisation());
+ }
+
+
+ /**
+ * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
+ * "I see an NP[elephant]"
+ */
+ @Test
+ public void stringIndefiniteArticleInflectionVowelTest() {
+ SPhraseSpec senSpec = this.phraseFactory.createClause();
+ senSpec.addComplement(this.phraseFactory.createStringElement("I see a"));
+ NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase("elephant");
+ senSpec.addComplement(firstNoun);
+ DocumentElement completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ assertEquals("I see an elephant.",
+ this.realiser.realise(completeSen).getRealisation());
+
+ }
+
+ /**
+ * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
+ * "I see NP[a elephant]" -->
+ */
+ @Test
+ public void NPIndefiniteArticleInflectionVowelTest() {
+ SPhraseSpec senSpec = this.phraseFactory.createClause();
+ senSpec.addComplement(this.phraseFactory.createStringElement("I see"));
+ NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase("elephant");
+ firstNoun.setDeterminer("a");
+ senSpec.addComplement(firstNoun);
+ DocumentElement completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ assertEquals("I see an elephant.",
+ this.realiser.realise(completeSen).getRealisation());
+
+ }
+
+
+ /**
+ * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
+ * "I see an NP[cow]"
+ */
+ @Test
+ public void stringIndefiniteArticleInflectionConsonantTest() {
+ SPhraseSpec senSpec = this.phraseFactory.createClause();
+ senSpec.addComplement(this.phraseFactory.createStringElement("I see an"));
+ NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase("cow");
+ senSpec.addComplement(firstNoun);
+ DocumentElement completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ // Do not attempt "an" -> "a"
+ assertNotSame("I see an cow.",
+ this.realiser.realise(completeSen).getRealisation());
+ }
+
+ /**
+ * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
+ * "I see NP[an cow]" -->
+ */
+ @Test
+ public void NPIndefiniteArticleInflectionConsonantTest() {
+ SPhraseSpec senSpec = this.phraseFactory.createClause();
+ senSpec.addComplement(this.phraseFactory.createStringElement("I see"));
+ NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase("cow");
+ firstNoun.setDeterminer("an");
+ senSpec.addComplement(firstNoun);
+ DocumentElement completeSen = this.phraseFactory.createSentence();
+ completeSen.addComponent(senSpec);
+ // Do not attempt "an" -> "a"
+ assertEquals("I see an cow.",
+ this.realiser.realise(completeSen).getRealisation());
+ }
+
+
+ /**
+ * aggregationStringElementTest: Test to see if we can aggregate two StringElements in a CoordinatedPhraseElement.
+ */
+ @Test
+ public void aggregationStringElementTest() {
+
+ CoordinatedPhraseElement coordinate =
+ phraseFactory.createCoordinatedPhrase(new StringElement("John is going to Tesco"),
+ new StringElement("Mary is going to Sainsburys"));
+ SPhraseSpec sentence = phraseFactory.createClause();
+ sentence.addComplement(coordinate);
+
+ assertEquals("John is going to Tesco and Mary is going to Sainsburys.",
+ realiser.realiseSentence(sentence));
+ }
+
+
+ /**
+ * Tests that no empty space is added when a StringElement is instantiated with an empty string
+ * or null object.
+ */
+ @Test
+ public void nullAndEmptyStringElementTest() {
+
+ NLGElement nullStringElement = this.phraseFactory.createStringElement(null);
+ NLGElement emptyStringElement = this.phraseFactory.createStringElement("");
+ NLGElement beautiful = this.phraseFactory.createStringElement("beautiful");
+ NLGElement horseLike = this.phraseFactory.createStringElement("horse-like");
+ NLGElement creature = this.phraseFactory.createStringElement("creature");
+
+ // Test1: null or empty at beginning
+ SPhraseSpec test1 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
+ test1.addPostModifier(emptyStringElement);
+ test1.addPostModifier(beautiful);
+ test1.addPostModifier(horseLike);
+ test1.addPostModifier(creature);
+ System.out.println(realiser.realiseSentence(test1));
+ Assert.assertEquals("A unicorn is regarded as a beautiful horse-like creature.",
+ realiser.realiseSentence(test1));
+
+ // Test2: empty or null at end
+ SPhraseSpec test2 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
+ test2.addPostModifier(beautiful);
+ test2.addPostModifier(horseLike);
+ test2.addPostModifier(creature);
+ test2.addPostModifier(nullStringElement);
+ System.out.println(realiser.realiseSentence(test2));
+ Assert.assertEquals("A unicorn is regarded as a beautiful horse-like creature.",
+ realiser.realiseSentence(test2));
+
+ // Test3: empty or null in the middle
+ SPhraseSpec test3 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
+ test3.addPostModifier("beautiful");
+ test3.addPostModifier("horse-like");
+ test3.addPostModifier("");
+ test3.addPostModifier("creature");
+ System.out.println(realiser.realiseSentence(test3));
+ Assert.assertEquals("A unicorn is regarded as a beautiful horse-like creature.",
+ realiser.realiseSentence(test3));
+
+ // Test4: empty or null in the middle with empty or null at beginning
+ SPhraseSpec test4 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
+ test4.addPostModifier("");
+ test4.addPostModifier("beautiful");
+ test4.addPostModifier("horse-like");
+ test4.addPostModifier(nullStringElement);
+ test4.addPostModifier("creature");
+ System.out.println(realiser.realiseSentence(test4));
+ Assert.assertEquals("A unicorn is regarded as a beautiful horse-like creature.",
+ realiser.realiseSentence(test4));
+
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/TutorialTest.java b/SharpSimpleNLGUnitTests/syntax/english/TutorialTest.java
new file mode 100644
index 0000000..153bd8c
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/TutorialTest.java
@@ -0,0 +1,450 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+
+import org.junit.Test;
+
+import simplenlg.features.Feature;
+import simplenlg.features.InterrogativeType;
+import simplenlg.features.Tense;
+import simplenlg.framework.CoordinatedPhraseElement;
+import simplenlg.framework.DocumentElement;
+import simplenlg.framework.NLGElement;
+import simplenlg.framework.NLGFactory;
+import simplenlg.lexicon.Lexicon;
+import simplenlg.phrasespec.NPPhraseSpec;
+import simplenlg.phrasespec.PPPhraseSpec;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.phrasespec.VPPhraseSpec;
+import simplenlg.realiser.english.Realiser;
+
+/**
+ * Tests from SimpleNLG tutorial
+ *
+ *
+ *
+ * Copyright (C) 2011, University of Aberdeen
+ *
+ *
+ * @author Ehud Reiter
+ *
+ */
+public class TutorialTest {
+
+
+ // no code in sections 1 and 2
+
+ /**
+ * test section 3 code
+ */
+ @Test
+ public void section3_Test() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+
+ NLGElement s1 = nlgFactory.createSentence("my dog is happy");
+
+ Realiser r = new Realiser(lexicon);
+
+ String output = r.realiseSentence(s1);
+
+ assertEquals("My dog is happy.", output);
+ }
+
+ /**
+ * test section 5 code
+ */
+ @Test
+ public void section5_Test() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+ Realiser realiser = new Realiser(lexicon);
+
+ SPhraseSpec p = nlgFactory.createClause();
+ p.setSubject("my dog");
+ p.setVerb("chase");
+ p.setObject("George");
+
+ String output = realiser.realiseSentence(p);
+ assertEquals("My dog chases George.", output);
+ }
+
+ /**
+ * test section 6 code
+ */
+ @Test
+ public void section6_Test() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+ Realiser realiser = new Realiser(lexicon);
+
+ SPhraseSpec p = nlgFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("chase");
+ p.setObject("George");
+
+ p.setFeature(Feature.TENSE, Tense.PAST);
+ String output = realiser.realiseSentence(p);
+ assertEquals("Mary chased George.", output);
+
+ p.setFeature(Feature.TENSE, Tense.FUTURE);
+ output = realiser.realiseSentence(p);
+ assertEquals("Mary will chase George.", output);
+
+ p.setFeature(Feature.NEGATED, true);
+ output = realiser.realiseSentence(p);
+ assertEquals("Mary will not chase George.", output);
+
+ p = nlgFactory.createClause();
+ p.setSubject("Mary");
+ p.setVerb("chase");
+ p.setObject("George");
+
+ p.setFeature(Feature.INTERROGATIVE_TYPE,
+ InterrogativeType.YES_NO);
+ output = realiser.realiseSentence(p);
+ assertEquals("Does Mary chase George?", output);
+
+ p.setSubject("Mary");
+ p.setVerb("chase");
+ p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
+ output = realiser.realiseSentence(p);
+ assertEquals("Who does Mary chase?", output);
+
+ p = nlgFactory.createClause();
+ p.setSubject("the dog");
+ p.setVerb("wake up");
+ output = realiser.realiseSentence(p);
+ assertEquals("The dog wakes up.", output);
+
+ }
+
+ /**
+ * test ability to use variant words
+ */
+ @Test
+ public void variantsTest() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
+ Realiser realiser = new Realiser(lexicon);
+
+ SPhraseSpec p = nlgFactory.createClause();
+ p.setSubject("my dog");
+ p.setVerb("is"); // variant of be
+ p.setObject("George");
+
+ String output = realiser.realiseSentence(p);
+ assertEquals("My dog is George.", output);
+
+ p = nlgFactory.createClause();
+ p.setSubject("my dog");
+ p.setVerb("chases"); // variant of chase
+ p.setObject("George");
+
+ output = realiser.realiseSentence(p);
+ assertEquals("My dog chases George.", output);
+
+
+ p = nlgFactory.createClause();
+ p.setSubject(nlgFactory.createNounPhrase("the", "dogs")); // variant of "dog"
+ p.setVerb("is"); // variant of be
+ p.setObject("happy"); // variant of happy
+ output = realiser.realiseSentence(p);
+ assertEquals("The dog is happy.", output);
+
+ p = nlgFactory.createClause();
+ p.setSubject(nlgFactory.createNounPhrase("the", "children")); // variant of "child"
+ p.setVerb("is"); // variant of be
+ p.setObject("happy"); // variant of happy
+ output = realiser.realiseSentence(p);
+ assertEquals("The child is happy.", output);
+
+ // following functionality is enabled
+ p = nlgFactory.createClause();
+ p.setSubject(nlgFactory.createNounPhrase("the", "dogs")); // variant of "dog"
+ p.setVerb("is"); // variant of be
+ p.setObject("happy"); // variant of happy
+ output = realiser.realiseSentence(p);
+ assertEquals("The dog is happy.", output); //corrected automatically
+ }
+
+ /* Following code tests the section 5 to 15
+ * sections 5 & 6 are repeated here in order to match the simplenlg tutorial version 4
+ * James Christie
+ * June 2011
+ */
+
+ /**
+ * test section 5 to match simplenlg tutorial version 4's code
+ */
+ @Test
+ public void section5A_Test() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
+ Realiser realiser = new Realiser( lexicon );
+
+ SPhraseSpec p = nlgFactory.createClause();
+ p.setSubject( "Mary" );
+ p.setVerb( "chase" );
+ p.setObject( "the monkey" );
+
+ String output = realiser.realiseSentence( p );
+ assertEquals( "Mary chases the monkey.", output );
+ } // testSection5A
+
+ /**
+ * test section 6 to match simplenlg tutorial version 4' code
+ */
+ @Test
+ public void section6A_Test() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
+ Realiser realiser = new Realiser( lexicon );
+
+ SPhraseSpec p = nlgFactory.createClause();
+ p.setSubject( "Mary" );
+ p.setVerb( "chase" );
+ p.setObject( "the monkey" );
+
+ p.setFeature( Feature.TENSE, Tense.PAST );
+ String output = realiser.realiseSentence( p );
+ assertEquals( "Mary chased the monkey.", output );
+
+ p.setFeature( Feature.TENSE, Tense.FUTURE );
+ output = realiser.realiseSentence( p );
+ assertEquals( "Mary will chase the monkey.", output );
+
+ p.setFeature( Feature.NEGATED, true );
+ output = realiser.realiseSentence( p );
+ assertEquals( "Mary will not chase the monkey.", output );
+
+ p = nlgFactory.createClause();
+ p.setSubject( "Mary" );
+ p.setVerb( "chase" );
+ p.setObject( "the monkey" );
+
+ p.setFeature( Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO );
+ output = realiser.realiseSentence( p );
+ assertEquals( "Does Mary chase the monkey?", output );
+
+ p.setSubject( "Mary" );
+ p.setVerb( "chase" );
+ p.setFeature( Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT );
+ output = realiser.realiseSentence( p );
+ assertEquals( "Who does Mary chase?", output );
+ }
+
+ /**
+ * test section 7 code
+ */
+ @Test
+ public void section7_Test() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
+ Realiser realiser = new Realiser( lexicon );
+
+ SPhraseSpec p = nlgFactory.createClause();
+ p.setSubject( "Mary" );
+ p.setVerb( "chase" );
+ p.setObject( "the monkey" );
+ p.addComplement( "very quickly" );
+ p.addComplement( "despite her exhaustion" );
+
+ String output = realiser.realiseSentence( p );
+ assertEquals( "Mary chases the monkey very quickly despite her exhaustion.", output );
+ }
+
+ /**
+ * test section 8 code
+ */
+ @Test
+ public void section8_Test() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
+ Realiser realiser = new Realiser( lexicon );
+
+ NPPhraseSpec subject = nlgFactory.createNounPhrase( "Mary" );
+ NPPhraseSpec object = nlgFactory.createNounPhrase( "the monkey" );
+ VPPhraseSpec verb = nlgFactory.createVerbPhrase( "chase" );;
+ subject.addModifier( "fast" );
+
+ SPhraseSpec p = nlgFactory.createClause();
+ p.setSubject( subject );
+ p.setVerb( verb );
+ p.setObject( object );
+
+ String outputA = realiser.realiseSentence( p );
+ assertEquals( "Fast Mary chases the monkey.", outputA );
+
+ verb.addModifier( "quickly" );
+
+ String outputB = realiser.realiseSentence( p );
+ assertEquals( "Fast Mary quickly chases the monkey.", outputB );
+ }
+
+ // there is no code specified in section 9
+
+ /**
+ * test section 10 code
+ */
+ @Test
+ public void section10_Test() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
+ Realiser realiser = new Realiser( lexicon );
+
+ NPPhraseSpec subject1 = nlgFactory.createNounPhrase( "Mary" );
+ NPPhraseSpec subject2 = nlgFactory.createNounPhrase( "your", "giraffe" );
+
+ // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API
+ CoordinatedPhraseElement subj = nlgFactory.createCoordinatedPhrase( subject1, subject2 );
+
+ VPPhraseSpec verb = nlgFactory.createVerbPhrase( "chase" );;
+
+ SPhraseSpec p = nlgFactory.createClause();
+ p.setSubject( subj );
+ p.setVerb( verb );
+ p.setObject( "the monkey" );
+
+ String outputA = realiser.realiseSentence( p );
+ assertEquals( "Mary and your giraffe chase the monkey.", outputA );
+
+ NPPhraseSpec object1 = nlgFactory.createNounPhrase( "the monkey" );
+ NPPhraseSpec object2 = nlgFactory.createNounPhrase( "George" );
+
+ // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API
+ CoordinatedPhraseElement obj = nlgFactory.createCoordinatedPhrase( object1, object2 );
+ obj.addCoordinate( "Martha" );
+ p.setObject( obj );
+
+ String outputB = realiser.realiseSentence( p );
+ assertEquals( "Mary and your giraffe chase the monkey, George and Martha.", outputB );
+
+ obj.setFeature( Feature.CONJUNCTION, "or" );
+
+ String outputC = realiser.realiseSentence( p );
+ assertEquals( "Mary and your giraffe chase the monkey, George or Martha.", outputC );
+ }
+
+ /**
+ * test section 11 code
+ */
+ @Test
+ public void section11_Test() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
+
+ Realiser realiser = new Realiser( lexicon );
+
+ SPhraseSpec pA = nlgFactory.createClause( "Mary", "chase", "the monkey" );
+ pA.addComplement( "in the park" );
+
+ String outputA = realiser.realiseSentence( pA );
+ assertEquals( "Mary chases the monkey in the park.", outputA );
+
+ // alternative build paradigm
+ NPPhraseSpec place = nlgFactory.createNounPhrase( "park" );
+ SPhraseSpec pB = nlgFactory.createClause( "Mary", "chase", "the monkey" );
+
+ // next line is depreciated ~ may be corrected in the API
+ place.setDeterminer( "the" );
+ PPPhraseSpec pp = nlgFactory.createPrepositionPhrase();
+ pp.addComplement( place );
+ pp.setPreposition( "in" );
+
+ pB.addComplement( pp );
+
+ String outputB = realiser.realiseSentence( pB );
+ assertEquals( "Mary chases the monkey in the park.", outputB );
+
+ place.addPreModifier( "leafy" );
+
+ String outputC = realiser.realiseSentence( pB );
+ assertEquals( "Mary chases the monkey in the leafy park.", outputC );
+ } // testSection11
+
+ // section12 only has a code table as illustration
+
+ /**
+ * test section 13 code
+ */
+ @Test
+ public void section13_Test() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
+
+ Realiser realiser = new Realiser( lexicon );
+
+ SPhraseSpec s1 = nlgFactory.createClause( "my cat", "like", "fish" );
+ SPhraseSpec s2 = nlgFactory.createClause( "my dog", "like", "big bones" );
+ SPhraseSpec s3 = nlgFactory.createClause( "my horse", "like", "grass" );
+
+ CoordinatedPhraseElement c = nlgFactory.createCoordinatedPhrase();
+ c.addCoordinate( s1 );
+ c.addCoordinate( s2 );
+ c.addCoordinate( s3 );
+
+ String outputA = realiser.realiseSentence( c );
+ assertEquals( "My cat likes fish, my dog likes big bones and my horse likes grass.", outputA );
+
+ SPhraseSpec p = nlgFactory.createClause( "I", "be", "happy" );
+ SPhraseSpec q = nlgFactory.createClause( "I", "eat", "fish" );
+ q.setFeature( Feature.COMPLEMENTISER, "because" );
+ q.setFeature( Feature.TENSE, Tense.PAST );
+ p.addComplement( q );
+
+ String outputB = realiser.realiseSentence( p );
+ assertEquals( "I am happy because I ate fish.", outputB );
+ }
+
+ /**
+ * test section 14 code
+ */
+ @Test
+ public void section14_Test() {
+ Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
+ NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
+
+ Realiser realiser = new Realiser( lexicon );
+
+ SPhraseSpec p1 = nlgFactory.createClause( "Mary", "chase", "the monkey" );
+ SPhraseSpec p2 = nlgFactory.createClause( "The monkey", "fight back" );
+ SPhraseSpec p3 = nlgFactory.createClause( "Mary", "be", "nervous" );
+
+ DocumentElement s1 = nlgFactory.createSentence( p1 );
+ DocumentElement s2 = nlgFactory.createSentence( p2 );
+ DocumentElement s3 = nlgFactory.createSentence( p3 );
+
+ DocumentElement par1 = nlgFactory.createParagraph( Arrays.asList( s1, s2, s3 ) );
+
+ String output14a = realiser.realise( par1 ).getRealisation();
+ assertEquals( "Mary chases the monkey. The monkey fights back. Mary is nervous.\n\n", output14a );
+
+ DocumentElement section = nlgFactory.createSection( "The Trials and Tribulation of Mary and the Monkey" );
+ section.addComponent( par1 );
+ String output14b = realiser.realise( section ).getRealisation();
+ assertEquals( "The Trials and Tribulation of Mary and the Monkey\nMary chases the monkey. The monkey fights back. Mary is nervous.\n\n", output14b );
+ }
+
+}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/VerbPhraseTest.java b/SharpSimpleNLGUnitTests/syntax/english/VerbPhraseTest.java
new file mode 100644
index 0000000..f5029a5
--- /dev/null
+++ b/SharpSimpleNLGUnitTests/syntax/english/VerbPhraseTest.java
@@ -0,0 +1,461 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is "Simplenlg".
+ *
+ * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
+ * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
+ *
+ * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
+ */
+
+package simplenlg.syntax.english;
+
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Test;
+
+import simplenlg.features.DiscourseFunction;
+import simplenlg.features.Feature;
+import simplenlg.features.Form;
+import simplenlg.features.InternalFeature;
+import simplenlg.features.NumberAgreement;
+import simplenlg.features.Person;
+import simplenlg.features.Tense;
+import simplenlg.framework.CoordinatedPhraseElement;
+import simplenlg.framework.NLGElement;
+import simplenlg.framework.PhraseElement;
+import simplenlg.framework.WordElement;
+import simplenlg.phrasespec.SPhraseSpec;
+import simplenlg.phrasespec.VPPhraseSpec;
+
+/**
+ * These are tests for the verb phrase and coordinate VP classes.
+ * @author agatt
+ */
+public class VerbPhraseTest extends SimpleNLG4Test {
+
+ /**
+ * Instantiates a new vP test.
+ *
+ * @param name
+ * the name
+ */
+ public VerbPhraseTest(String name) {
+ super(name);
+ }
+
+
+ @Override
+ @After
+ public void tearDown() {
+ super.tearDown();
+ }
+
+
+ /**
+ * Some tests to check for an early bug which resulted in reduplication of
+ * verb particles in the past tense e.g. "fall down down" or "creep up up"
+ */
+ @Test
+ public void testVerbParticle() {
+ VPPhraseSpec v = this.phraseFactory.createVerbPhrase("fall down"); //$NON-NLS-1$
+
+ assertEquals(
+ "down", v.getFeatureAsString(Feature.PARTICLE)); //$NON-NLS-1$
+
+ assertEquals(
+ "fall", ((WordElement) v.getVerb()).getBaseForm()); //$NON-NLS-1$
+
+ v.setFeature(Feature.TENSE,Tense.PAST);
+ v.setFeature(Feature.PERSON, Person.THIRD);
+ v.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+
+ assertEquals(
+ "fell down", this.realiser.realise(v).getRealisation()); //$NON-NLS-1$
+
+ v.setFeature(Feature.FORM, Form.PAST_PARTICIPLE);
+ assertEquals(
+ "fallen down", this.realiser.realise(v).getRealisation()); //$NON-NLS-1$
+ }
+
+ /**
+ * Tests for the tense and aspect.
+ */
+ @Test
+ public void simplePastTest() {
+ // "fell down"
+ this.fallDown.setFeature(Feature.TENSE,Tense.PAST);
+ assertEquals(
+ "fell down", this.realiser.realise(this.fallDown).getRealisation()); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Test tense aspect.
+ */
+ @Test
+ public void tenseAspectTest() {
+ // had fallen down
+ this.realiser.setLexicon(this.lexicon);
+ this.fallDown.setFeature(Feature.TENSE,Tense.PAST);
+ this.fallDown.setFeature(Feature.PERFECT, true);
+
+ assertEquals("had fallen down", this.realiser.realise( //$NON-NLS-1$
+ this.fallDown).getRealisation());
+
+ // had been falling down
+ this.fallDown.setFeature(Feature.PROGRESSIVE, true);
+ assertEquals("had been falling down", this.realiser.realise( //$NON-NLS-1$
+ this.fallDown).getRealisation());
+
+ // will have been kicked
+ this.kick.setFeature(Feature.PASSIVE, true);
+ this.kick.setFeature(Feature.PERFECT, true);
+ this.kick.setFeature(Feature.TENSE,Tense.FUTURE);
+ assertEquals("will have been kicked", this.realiser.realise( //$NON-NLS-1$
+ this.kick).getRealisation());
+
+ // will have been being kicked
+ this.kick.setFeature(Feature.PROGRESSIVE, true);
+ assertEquals("will have been being kicked", this.realiser //$NON-NLS-1$
+ .realise(this.kick).getRealisation());
+
+ // will not have been being kicked
+ this.kick.setFeature(Feature.NEGATED, true);
+ assertEquals("will not have been being kicked", this.realiser //$NON-NLS-1$
+ .realise(this.kick).getRealisation());
+
+ // passivisation should suppress the complement
+ this.kick.clearComplements();
+ this.kick.addComplement(this.man);
+ assertEquals("will not have been being kicked", this.realiser //$NON-NLS-1$
+ .realise(this.kick).getRealisation());
+
+ // de-passivisation should now give us "will have been kicking the man"
+ this.kick.setFeature(Feature.PASSIVE, false);
+ assertEquals("will not have been kicking the man", this.realiser //$NON-NLS-1$
+ .realise(this.kick).getRealisation());
+
+ // remove the future tense --
+ // this is a test of an earlier bug that would still realise "will"
+ this.kick.setFeature(Feature.TENSE,Tense.PRESENT);
+ assertEquals("has not been kicking the man", this.realiser //$NON-NLS-1$
+ .realise(this.kick).getRealisation());
+ }
+
+ /**
+ * Test for realisation of VP complements.
+ */
+ @Test
+ public void complementationTest() {
+
+ // was kissing Mary
+ PhraseElement mary = this.phraseFactory.createNounPhrase("Mary"); //$NON-NLS-1$
+ mary.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.OBJECT);
+ this.kiss.clearComplements();
+ this.kiss.addComplement(mary);
+ this.kiss.setFeature(Feature.PROGRESSIVE, true);
+ this.kiss.setFeature(Feature.TENSE,Tense.PAST);
+
+ assertEquals("was kissing Mary", this.realiser //$NON-NLS-1$
+ .realise(this.kiss).getRealisation());
+
+ CoordinatedPhraseElement mary2 = new CoordinatedPhraseElement(mary,
+ this.phraseFactory.createNounPhrase("Susan")); //$NON-NLS-1$
+ // add another complement -- should come out as "Mary and Susan"
+ this.kiss.clearComplements();
+ this.kiss.addComplement(mary2);
+ assertEquals("was kissing Mary and Susan", this.realiser //$NON-NLS-1$
+ .realise(this.kiss).getRealisation());
+
+ // passivise -- should make the direct object complement disappear
+ // Note: The verb doesn't come out as plural because agreement
+ // is determined by the sentential subjects and this VP isn't inside a
+ // sentence
+ this.kiss.setFeature(Feature.PASSIVE, true);
+ assertEquals("was being kissed", this.realiser //$NON-NLS-1$
+ .realise(this.kiss).getRealisation());
+
+ // make it plural (this is usually taken care of in SPhraseSpec)
+ this.kiss.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ assertEquals("were being kissed", this.realiser.realise( //$NON-NLS-1$
+ this.kiss).getRealisation());
+
+ // depassivise and add post-mod: yields "was kissing Mary in the room"
+ this.kiss.addPostModifier(this.inTheRoom);
+ this.kiss.setFeature(Feature.PASSIVE, false);
+ this.kiss.setFeature(Feature.NUMBER, NumberAgreement.SINGULAR);
+ assertEquals("was kissing Mary and Susan in the room", //$NON-NLS-1$
+ this.realiser.realise(this.kiss).getRealisation());
+
+ // passivise again: should make direct object disappear, but not postMod
+ // ="was being kissed in the room"
+ this.kiss.setFeature(Feature.PASSIVE, true);
+ this.kiss.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
+ assertEquals("were being kissed in the room", this.realiser //$NON-NLS-1$
+ .realise(this.kiss).getRealisation());
+ }
+
+ /**
+ * This tests for the default complement ordering, relative to pre and
+ * postmodifiers.
+ */
+ @Test
+ public void complementationTest_2() {
+ // give the woman the dog
+ this.woman.setFeature(InternalFeature.DISCOURSE_FUNCTION,
+ DiscourseFunction.INDIRECT_OBJECT);
+ this.dog.setFeature(InternalFeature.DISCOURSE_FUNCTION,
+ DiscourseFunction.OBJECT);
+ this.give.clearComplements();
+ this.give.addComplement(this.dog);
+ this.give.addComplement(this.woman);
+ assertEquals("gives the woman the dog", this.realiser.realise( //$NON-NLS-1$
+ this.give).getRealisation());
+
+ // add a few premodifiers and postmodifiers
+ this.give.addPreModifier("slowly"); //$NON-NLS-1$
+ this.give.addPostModifier(this.behindTheCurtain);
+ this.give.addPostModifier(this.inTheRoom);
+ assertEquals(
+ "slowly gives the woman the dog behind the curtain in the room", //$NON-NLS-1$
+ this.realiser.realise(this.give).getRealisation());
+
+ // reset the arguments
+ this.give.clearComplements();
+ this.give.addComplement(this.dog);
+ CoordinatedPhraseElement womanBoy = new CoordinatedPhraseElement(
+ this.woman, this.boy);
+ womanBoy.setFeature(InternalFeature.DISCOURSE_FUNCTION,
+ DiscourseFunction.INDIRECT_OBJECT);
+ this.give.addComplement(womanBoy);
+
+ // if we unset the passive, we should get the indirect objects
+ // they won't be coordinated
+ this.give.setFeature(Feature.PASSIVE, false);
+ assertEquals(
+ "slowly gives the woman and the boy the dog behind the curtain in the room", //$NON-NLS-1$
+ this.realiser.realise(this.give).getRealisation());
+
+ // set them to a coordinate instead
+ // set ONLY the complement INDIRECT_OBJECT, leaves OBJECT intact
+ this.give.clearComplements();
+ this.give.addComplement(womanBoy);
+ this.give.addComplement(this.dog);
+ List complements = this.give
+ .getFeatureAsElementList(InternalFeature.COMPLEMENTS);
+
+ int indirectCount = 0;
+ for (NLGElement eachElement : complements) {
+ if (DiscourseFunction.INDIRECT_OBJECT.equals(eachElement
+ .getFeature(InternalFeature.DISCOURSE_FUNCTION))) {
+ indirectCount++;
+ }
+ }
+ assertEquals(1, indirectCount); // only one indirect object
+ // where
+ // there were two before
+
+ assertEquals(
+ "slowly gives the woman and the boy the dog behind the curtain in the room", //$NON-NLS-1$
+ this.realiser.realise(this.give).getRealisation());
+ }
+
+ /**
+ * Test for complements raised in the passive case.
+ */
+ @Test
+ public void passiveComplementTest() {
+ // add some arguments
+ this.dog.setFeature(InternalFeature.DISCOURSE_FUNCTION,
+ DiscourseFunction.OBJECT);
+ this.woman.setFeature(InternalFeature.DISCOURSE_FUNCTION,
+ DiscourseFunction.INDIRECT_OBJECT);
+ this.give.addComplement(this.dog);
+ this.give.addComplement(this.woman);
+ assertEquals("gives the woman the dog", this.realiser.realise( //$NON-NLS-1$
+ this.give).getRealisation());
+
+ // add a few premodifiers and postmodifiers
+ this.give.addPreModifier("slowly"); //$NON-NLS-1$
+ this.give.addPostModifier(this.behindTheCurtain);
+ this.give.addPostModifier(this.inTheRoom);
+ assertEquals(
+ "slowly gives the woman the dog behind the curtain in the room", //$NON-NLS-1$
+ this.realiser.realise(this.give).getRealisation());
+
+ // passivise: This should suppress "the dog"
+ this.give.clearComplements();
+ this.give.addComplement(this.dog);
+ this.give.addComplement(this.woman);
+ this.give.setFeature(Feature.PASSIVE, true);
+
+ assertEquals(
+ "is slowly given the woman behind the curtain in the room", //$NON-NLS-1$
+ this.realiser.realise(this.give).getRealisation());
+ }
+
+ /**
+ * Test VP with sentential complements. This tests for structures like "said
+ * that John was walking"
+ */
+ @Test
+ public void clausalComplementTest() {
+ this.phraseFactory.setLexicon(this.lexicon);
+ SPhraseSpec s = this.phraseFactory.createClause();
+
+ s.setSubject(this.phraseFactory
+ .createNounPhrase("John")); //$NON-NLS-1$
+
+ // Create a sentence first
+ CoordinatedPhraseElement maryAndSusan = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Mary"), //$NON-NLS-1$
+ this.phraseFactory.createNounPhrase("Susan")); //$NON-NLS-1$
+
+ this.kiss.clearComplements();
+ s.setVerbPhrase(this.kiss);
+ s.setObject(maryAndSusan);
+ s.setFeature(Feature.PROGRESSIVE, true);
+ s.setFeature(Feature.TENSE,Tense.PAST);
+ s.addPostModifier(this.inTheRoom);
+ assertEquals("John was kissing Mary and Susan in the room", //$NON-NLS-1$
+ this.realiser.realise(s).getRealisation());
+
+ // make the main VP past
+ this.say.setFeature(Feature.TENSE,Tense.PAST);
+ assertEquals("said", this.realiser.realise(this.say) //$NON-NLS-1$
+ .getRealisation());
+
+ // now add the sentence as complement of "say". Should make the sentence
+ // subordinate
+ // note that sentential punctuation is suppressed
+ this.say.addComplement(s);
+ assertEquals(
+ "said that John was kissing Mary and Susan in the room", //$NON-NLS-1$
+ this.realiser.realise(this.say).getRealisation());
+
+ // add a postModifier to the main VP
+ // yields [says [that John was kissing Mary and Susan in the room]
+ // [behind the curtain]]
+ this.say.addPostModifier(this.behindTheCurtain);
+ assertEquals(
+ "said that John was kissing Mary and Susan in the room behind the curtain", //$NON-NLS-1$
+ this.realiser.realise(this.say).getRealisation());
+
+ // create a new sentential complement
+ PhraseElement s2 = this.phraseFactory.createClause(this.phraseFactory
+ .createNounPhrase("all"), //$NON-NLS-1$
+ "be", //$NON-NLS-1$
+ this.phraseFactory.createAdjectivePhrase("fine")); //$NON-NLS-1$
+
+ s2.setFeature(Feature.TENSE,Tense.FUTURE);
+ assertEquals("all will be fine", this.realiser.realise(s2) //$NON-NLS-1$
+ .getRealisation());
+
+ // add the new complement to the VP
+ // yields [said [that John was kissing Mary and Susan in the room and
+ // all will be fine] [behind the curtain]]
+ CoordinatedPhraseElement s3 = new CoordinatedPhraseElement(s, s2);
+ this.say.clearComplements();
+ this.say.addComplement(s3);
+
+ // first with outer complementiser suppressed
+ s3.setFeature(Feature.SUPRESSED_COMPLEMENTISER, true);
+ assertEquals(
+ "said that John was kissing Mary and Susan in the room " //$NON-NLS-1$
+ + "and all will be fine behind the curtain", //$NON-NLS-1$
+ this.realiser.realise(this.say).getRealisation());
+
+ setUp();
+ s = this.phraseFactory.createClause();
+
+ s.setSubject(this.phraseFactory
+ .createNounPhrase("John")); //$NON-NLS-1$
+
+ // Create a sentence first
+ maryAndSusan = new CoordinatedPhraseElement(
+ this.phraseFactory.createNounPhrase("Mary"), //$NON-NLS-1$
+ this.phraseFactory.createNounPhrase("Susan")); //$NON-NLS-1$
+
+ s.setVerbPhrase(this.kiss);
+ s.setObject(maryAndSusan);
+ s.setFeature(Feature.PROGRESSIVE, true);
+ s.setFeature(Feature.TENSE,Tense.PAST);
+ s.addPostModifier(this.inTheRoom);
+ s2 = this.phraseFactory.createClause(this.phraseFactory
+ .createNounPhrase("all"), //$NON-NLS-1$
+ "be", //$NON-NLS-1$
+ this.phraseFactory.createAdjectivePhrase("fine")); //$NON-NLS-1$
+
+ s2.setFeature(Feature.TENSE,Tense.FUTURE);
+ // then with complementiser not suppressed and not aggregated
+ s3 = new CoordinatedPhraseElement(s, s2);
+ this.say.addComplement(s3);
+ this.say.setFeature(Feature.TENSE,Tense.PAST);
+ this.say.addPostModifier(this.behindTheCurtain);
+
+ assertEquals(
+ "said that John was kissing Mary and Susan in the room and " //$NON-NLS-1$
+ + "that all will be fine behind the curtain", //$NON-NLS-1$
+ this.realiser.realise(this.say).getRealisation());
+
+ }
+
+ /**
+ * Test VP coordination and aggregation:
+ *
+ * If the simplenlg.features of a coordinate VP are set, they should be
+ * inherited by its daughter VP;
+ * 2. We can aggregate the coordinate VP so it's realised with one
+ * wide-scope auxiliary
+ */
+ @Test
+ public void coordinationTest() {
+ // simple case
+ this.kiss.addComplement(this.dog);
+ this.kick.addComplement(this.boy);
+
+ CoordinatedPhraseElement coord1 = new CoordinatedPhraseElement(
+ this.kiss, this.kick);
+
+ coord1.setFeature(Feature.PERSON, Person.THIRD);
+ coord1.setFeature(Feature.TENSE,Tense.PAST);
+ assertEquals("kissed the dog and kicked the boy", this.realiser //$NON-NLS-1$
+ .realise(coord1).getRealisation());
+
+ // with negation: should be inherited by all components
+ coord1.setFeature(Feature.NEGATED, true);
+ this.realiser.setLexicon(this.lexicon);
+ assertEquals("did not kiss the dog and did not kick the boy", //$NON-NLS-1$
+ this.realiser.realise(coord1).getRealisation());
+
+ // set a modal
+ coord1.setFeature(Feature.MODAL, "could"); //$NON-NLS-1$
+ assertEquals(
+ "could not have kissed the dog and could not have kicked the boy", //$NON-NLS-1$
+ this.realiser.realise(coord1).getRealisation());
+
+ // set perfect and progressive
+ coord1.setFeature(Feature.PERFECT, true);
+ coord1.setFeature(Feature.PROGRESSIVE, true);
+ assertEquals("could not have been kissing the dog and " //$NON-NLS-1$
+ + "could not have been kicking the boy", this.realiser.realise( //$NON-NLS-1$
+ coord1).getRealisation());
+
+ // now aggregate
+ coord1.setFeature(Feature.AGGREGATE_AUXILIARY, true);
+ assertEquals(
+ "could not have been kissing the dog and kicking the boy", //$NON-NLS-1$
+ this.realiser.realise(coord1).getRealisation());
+ }
+}
From c7255dba71c70734f6cfbeb139af063e49c7ca41 Mon Sep 17 00:00:00 2001
From: Arash Sabet
Date: Fri, 7 Jul 2017 10:40:20 -0400
Subject: [PATCH 03/10] Added NUnitTestAdapter to SharpSimpleNLGDotNet45
project.
---
SharpSimpleNLGTests/packages.config | 1 +
1 file changed, 1 insertion(+)
diff --git a/SharpSimpleNLGTests/packages.config b/SharpSimpleNLGTests/packages.config
index c9b7034..476c8cd 100644
--- a/SharpSimpleNLGTests/packages.config
+++ b/SharpSimpleNLGTests/packages.config
@@ -2,5 +2,6 @@
+
\ No newline at end of file
From 1e2ff6185953f6dabe4ca3eb3ee45c4ea11e0e5d Mon Sep 17 00:00:00 2001
From: Arash Sabet
Date: Fri, 7 Jul 2017 12:37:31 -0400
Subject: [PATCH 04/10] Removed packages.config file from the test project due
to its redudancy in VS 2017.
---
SharpSimpleNLGTests/packages.config | 7 -------
SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj | 6 +-----
2 files changed, 1 insertion(+), 12 deletions(-)
delete mode 100644 SharpSimpleNLGTests/packages.config
diff --git a/SharpSimpleNLGTests/packages.config b/SharpSimpleNLGTests/packages.config
deleted file mode 100644
index 476c8cd..0000000
--- a/SharpSimpleNLGTests/packages.config
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj b/SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj
index 31598bd..7be4c13 100644
--- a/SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj
+++ b/SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj
@@ -2,11 +2,6 @@
netstandard1.6
-
-
-
-
- 1.0
@@ -19,6 +14,7 @@
+
From c999c3c4d22ee628ffe8e02b547e96e33d99e540 Mon Sep 17 00:00:00 2001
From: Arash Sabet
Date: Fri, 7 Jul 2017 14:56:40 -0400
Subject: [PATCH 05/10] Added required packages by nuget to fix build server's
compile issue.
---
SharpSimpleNLGTests/packages.config | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 SharpSimpleNLGTests/packages.config
diff --git a/SharpSimpleNLGTests/packages.config b/SharpSimpleNLGTests/packages.config
new file mode 100644
index 0000000..c9b7034
--- /dev/null
+++ b/SharpSimpleNLGTests/packages.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
From 009e2f7d42abdb02c15c544c23b25a002ffdc12e Mon Sep 17 00:00:00 2001
From: Arash Sabet
Date: Fri, 7 Jul 2017 16:13:38 -0400
Subject: [PATCH 06/10] Added appveyor.yml for CI on appveyor. Updated version
info in README markdown.
---
README.md | 2 ++
appveyor.yml | 15 +++++++++++++++
2 files changed, 17 insertions(+)
create mode 100644 appveyor.yml
diff --git a/README.md b/README.md
index 906d4e6..1968dab 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,8 @@ Install-Package SharpSimpleNLG
```
## Version News
+Version 1.2.0
+* Now supports .net standard 1.6 and full .net 4.6.2. Added to Nuget package.
Version 1.1.1:
* Thanks to [PR from Andriy Svyrd](https://github.com/nickhodge/SharpSimpleNLG/pull/2) now supports .NET Standard 1.3. Added to NuGet package (I hope my packaging is OK!)
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..9e7d7a9
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,15 @@
+version: 1.0.{build}
+image: Visual Studio 2017
+before_build:
+- cmd: >-
+ dotnet restore
+
+ nuget restore
+build:
+ publish_nuget: true
+ publish_nuget_symbols: true
+ include_nuget_references: true
+ verbosity: minimal
+before_package:
+- cmd: nuget spec
+test: off
\ No newline at end of file
From 05736e2cd106fff874f333e06bb09f1c0336b42a Mon Sep 17 00:00:00 2001
From: Arash Sabet
Date: Fri, 7 Jul 2017 21:28:13 -0400
Subject: [PATCH 07/10] Added appveyor CI status badge.
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 1968dab..e2efe74 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
+[![Build status](https://ci.appveyor.com/api/projects/status/yu970w2evwwkx0vt?svg=true)](https://ci.appveyor.com/project/Arash-Sabet/sharpsimplenlg)
# SharpSimpleNLG
SharpSimpleNLG is a C# port of the [University of Aberdeen *simplenlg* project](https://github.com/simplenlg/simplenlg). All thanks and acknowledgement for hard work goes to this team.
From e3ff0dadb1411e8717c5ff25d7dc255450bf9936 Mon Sep 17 00:00:00 2001
From: Arash Sabet
Date: Sat, 8 Jul 2017 06:39:16 -0400
Subject: [PATCH 08/10] .Net standard version of unit test library removed from
the solution
The reason for this change is that the reference to the full .net version of SharpSimpleNLG library removed from SharpSimpleNLGTests and a reference to its .net standard version added.
---
.../SharpSimpleNLGTests.csproj | 9 +-
.../morphology/DeterminerAgrHelper.cs | 0
.../morphology/MorphologyProcessor.cs | 0
.../morphology/MorphologyRules.cs | 0
.../SharpSimpleNLGUnitTests.csproj | 31 -
.../external/ExternalTest.cs | 562 -----------
.../format/EnumeratedListTest.cs | 101 --
.../format/NumberedPrefixTest.cs | 111 ---
.../format/TextFormatterTest.cs | 161 ---
.../format/english/EnumeratedListTest.java | 98 --
.../format/english/NumberedPrefixTest.java | 75 --
.../format/english/TextFormatterTest.java | 157 ---
.../helpers/ExtensionHelpersTest.cs | 336 -------
.../helpers/RegexExercises.cs | 151 ---
.../lexicon/LexicalVariantsTest.java | 285 ------
.../lexicon/MultipleLexiconTest.java | 103 --
.../lexicon/NIHDBLexiconTest.java | 251 -----
.../lexicon/SharedLexiconTests.java | 137 ---
.../lexicon/XMLLexiconTest.cs | 155 ---
.../lexicon/english/LexicalVariantsTest.java | 285 ------
.../lexicon/english/MultipleLexiconTest.java | 103 --
.../lexicon/english/NIHDBLexiconTest.java | 251 -----
.../lexicon/english/SharedLexiconTests.java | 137 ---
.../lexicon/english/XMLLexiconTest.java | 108 --
.../morphology/DeterminerAgrHelperTest.cs | 103 --
.../english/DeterminerAgrHelperTest.java | 75 --
.../realiser/RealiserTest.cs | 173 ----
.../realiser/english/RealiserTest.java | 173 ----
.../syntax/AdjectivePhraseTest.cs | 160 ---
.../syntax/ClauseAggregationTest.cs | 259 -----
SharpSimpleNLGUnitTests/syntax/ClauseTest.cs | 886 -----------------
.../syntax/CoordinationTest.cs | 200 ----
.../syntax/DeterminerTest.cs | 400 --------
.../syntax/DocumentElementTest.cs | 209 ----
SharpSimpleNLGUnitTests/syntax/ElisionTest.cs | 97 --
SharpSimpleNLGUnitTests/syntax/FeatureTest.cs | 346 -------
.../syntax/HTMLFormatterTest.cs | 138 ---
.../syntax/InterrogativeTest.cs | 847 ----------------
.../syntax/NounPhraseTest.cs | 643 ------------
.../syntax/OrthographyFormatTest.cs | 195 ----
.../syntax/PhraseSpecTest.cs | 92 --
.../syntax/PremodifierTest.cs | 101 --
.../syntax/PrepositionalPhraseTest.cs | 105 --
.../syntax/SimpleNLG4Test.cs | 245 -----
.../syntax/StandAloneExample.cs | 117 ---
.../syntax/StringElementTest.cs | 413 --------
.../syntax/TutorialTest.cs | 465 ---------
.../syntax/VerbPhraseTest.cs | 472 ---------
.../syntax/english/AdjectivePhraseTest.java | 168 ----
.../syntax/english/ClauseAggregationTest.java | 273 ------
.../syntax/english/ClauseTest.java | 926 ------------------
.../syntax/english/CoordinationTest.java | 201 ----
.../syntax/english/DeterminerTest.java | 388 --------
.../syntax/english/DocumentElementTest.java | 209 ----
.../syntax/english/ElisionTest.java | 105 --
.../syntax/english/FeatureTest.java | 368 -------
.../syntax/english/HTMLFormatterTest.java | 138 ---
.../syntax/english/InterrogativeTest.java | 836 ----------------
.../syntax/english/NounPhraseTest.java | 617 ------------
.../syntax/english/OrthographyFormatTest.java | 205 ----
.../syntax/english/PhraseSpecTest.java | 120 ---
.../syntax/english/PremodifierTest.java | 114 ---
.../english/PrepositionalPhraseTest.java | 113 ---
.../syntax/english/SimpleNLG4Test.java | 145 ---
.../syntax/english/StandAloneExample.java | 123 ---
.../syntax/english/StringElementTest.java | 407 --------
.../syntax/english/TutorialTest.java | 450 ---------
.../syntax/english/VerbPhraseTest.java | 461 ---------
68 files changed, 6 insertions(+), 16882 deletions(-)
rename {SharpSimpleNLGUnitTests => SharpSimpleNLGTests}/morphology/DeterminerAgrHelper.cs (100%)
rename {SharpSimpleNLGUnitTests => SharpSimpleNLGTests}/morphology/MorphologyProcessor.cs (100%)
rename {SharpSimpleNLGUnitTests => SharpSimpleNLGTests}/morphology/MorphologyRules.cs (100%)
delete mode 100644 SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj
delete mode 100644 SharpSimpleNLGUnitTests/external/ExternalTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/format/EnumeratedListTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/format/NumberedPrefixTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/format/TextFormatterTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/format/english/EnumeratedListTest.java
delete mode 100644 SharpSimpleNLGUnitTests/format/english/NumberedPrefixTest.java
delete mode 100644 SharpSimpleNLGUnitTests/format/english/TextFormatterTest.java
delete mode 100644 SharpSimpleNLGUnitTests/helpers/ExtensionHelpersTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/helpers/RegexExercises.cs
delete mode 100644 SharpSimpleNLGUnitTests/lexicon/LexicalVariantsTest.java
delete mode 100644 SharpSimpleNLGUnitTests/lexicon/MultipleLexiconTest.java
delete mode 100644 SharpSimpleNLGUnitTests/lexicon/NIHDBLexiconTest.java
delete mode 100644 SharpSimpleNLGUnitTests/lexicon/SharedLexiconTests.java
delete mode 100644 SharpSimpleNLGUnitTests/lexicon/XMLLexiconTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/lexicon/english/LexicalVariantsTest.java
delete mode 100644 SharpSimpleNLGUnitTests/lexicon/english/MultipleLexiconTest.java
delete mode 100644 SharpSimpleNLGUnitTests/lexicon/english/NIHDBLexiconTest.java
delete mode 100644 SharpSimpleNLGUnitTests/lexicon/english/SharedLexiconTests.java
delete mode 100644 SharpSimpleNLGUnitTests/lexicon/english/XMLLexiconTest.java
delete mode 100644 SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelperTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/morphology/english/DeterminerAgrHelperTest.java
delete mode 100644 SharpSimpleNLGUnitTests/realiser/RealiserTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/realiser/english/RealiserTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/AdjectivePhraseTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/ClauseAggregationTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/ClauseTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/CoordinationTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/DeterminerTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/DocumentElementTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/ElisionTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/FeatureTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/HTMLFormatterTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/InterrogativeTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/NounPhraseTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/OrthographyFormatTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/PhraseSpecTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/PremodifierTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/PrepositionalPhraseTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/SimpleNLG4Test.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/StandAloneExample.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/StringElementTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/TutorialTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/VerbPhraseTest.cs
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/AdjectivePhraseTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/ClauseAggregationTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/ClauseTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/CoordinationTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/DeterminerTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/DocumentElementTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/ElisionTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/FeatureTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/HTMLFormatterTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/InterrogativeTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/NounPhraseTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/OrthographyFormatTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/PhraseSpecTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/PremodifierTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/PrepositionalPhraseTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/SimpleNLG4Test.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/StandAloneExample.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/StringElementTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/TutorialTest.java
delete mode 100644 SharpSimpleNLGUnitTests/syntax/english/VerbPhraseTest.java
diff --git a/SharpSimpleNLGTests/SharpSimpleNLGTests.csproj b/SharpSimpleNLGTests/SharpSimpleNLGTests.csproj
index f1369ac..febe16b 100644
--- a/SharpSimpleNLGTests/SharpSimpleNLGTests.csproj
+++ b/SharpSimpleNLGTests/SharpSimpleNLGTests.csproj
@@ -66,6 +66,9 @@
+
+
+
@@ -106,9 +109,9 @@
-
- {fd418a41-a46e-4fd7-a6db-ff3ebb4afa29}
- SharpSimpleNLGDotNet45
+
+ {16f344a8-b688-4d95-8da6-2e207d47aecb}
+ SharpSimpleNLG
diff --git a/SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelper.cs b/SharpSimpleNLGTests/morphology/DeterminerAgrHelper.cs
similarity index 100%
rename from SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelper.cs
rename to SharpSimpleNLGTests/morphology/DeterminerAgrHelper.cs
diff --git a/SharpSimpleNLGUnitTests/morphology/MorphologyProcessor.cs b/SharpSimpleNLGTests/morphology/MorphologyProcessor.cs
similarity index 100%
rename from SharpSimpleNLGUnitTests/morphology/MorphologyProcessor.cs
rename to SharpSimpleNLGTests/morphology/MorphologyProcessor.cs
diff --git a/SharpSimpleNLGUnitTests/morphology/MorphologyRules.cs b/SharpSimpleNLGTests/morphology/MorphologyRules.cs
similarity index 100%
rename from SharpSimpleNLGUnitTests/morphology/MorphologyRules.cs
rename to SharpSimpleNLGTests/morphology/MorphologyRules.cs
diff --git a/SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj b/SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj
deleted file mode 100644
index 7be4c13..0000000
--- a/SharpSimpleNLGUnitTests/SharpSimpleNLGUnitTests.csproj
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
- netstandard1.6
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/external/ExternalTest.cs b/SharpSimpleNLGUnitTests/external/ExternalTest.cs
deleted file mode 100644
index f4624d1..0000000
--- a/SharpSimpleNLGUnitTests/external/ExternalTest.cs
+++ /dev/null
@@ -1,562 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using System;
-using System.Collections.Generic;
-using NUnit.Framework;
-using SimpleNLG;
-using SimpleNLG.Extensions;
-
-namespace SimpleNLGTests.external
-{
- /**
- * Tests from third parties
- * @author ereiter
- *
- */
-
-
- public class ExternalTest
- {
- [SetUpFixture]
- public class SetupForExternalTest
- {
- public static Lexicon lexicon = Lexicon.getDefaultLexicon();
- public static NLGFactory phraseFactory = new NLGFactory(lexicon);
- public static Realiser realiser = new Realiser(lexicon);
- }
-
- [Test]
- public void forcherTest()
- {
- // Bjorn Forcher's tests
- SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);
- SPhraseSpec s1 = SetupForExternalTest.phraseFactory.createClause(null, "associate", "Marie");
- s1.setFeature(Feature.PASSIVE.ToString(), true);
- PPPhraseSpec pp1 = SetupForExternalTest.phraseFactory.createPrepositionPhrase("with");
- pp1.addComplement("Peter");
- pp1.addComplement("Paul");
- s1.addPostModifier(pp1);
-
-
- SetupForExternalTest.realiser.setDebugMode(true);
- var r = SetupForExternalTest.realiser.realise(s1).getRealisation();
-
- Assert.AreEqual("Marie is associated with Peter and Paul", r);
-
-
- SPhraseSpec s2 = SetupForExternalTest.phraseFactory.createClause();
- s2.setSubject((NPPhraseSpec)SetupForExternalTest.phraseFactory.createNounPhrase("Peter"));
- s2.setVerb("have");
- s2.setObject("something to do");
- s2.addPostModifier((PPPhraseSpec)SetupForExternalTest.phraseFactory.createPrepositionPhrase(
- "with", "Paul"));
-
-
- Assert.AreEqual("Peter has something to do with Paul",
- SetupForExternalTest.realiser.realise(s2).getRealisation());
- }
-
- [Test]
- public void luTest()
- {
- // Xin Lu's test
- SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);
- SPhraseSpec s1 = SetupForExternalTest.phraseFactory.createClause("we",
- "consider",
- "John");
- s1.addPostModifier("a friend");
-
- Assert.AreEqual("we consider John a friend", SetupForExternalTest.realiser
- .realise(s1).getRealisation());
- }
-
-
- [Test]
- public void dwightTest()
- {
- // Rachel Dwight's test
- SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);
-
- NPPhraseSpec noun4 = SetupForExternalTest.phraseFactory
- .createNounPhrase("FGFR3 gene in every cell");
-
- noun4.setSpecifier("the");
-
- PPPhraseSpec prep1 = SetupForExternalTest.phraseFactory.createPrepositionPhrase(
- "of", noun4);
-
- NPPhraseSpec noun1 = SetupForExternalTest.phraseFactory.createNounPhrase(
- "the", "patient's mother");
-
- NPPhraseSpec noun2 = SetupForExternalTest.phraseFactory.createNounPhrase(
- "the", "patient's father");
-
- NPPhraseSpec noun3 = SetupForExternalTest.phraseFactory
- .createNounPhrase("changed copy");
- noun3.addPreModifier("one");
- noun3.addComplement(prep1);
-
- var coordNoun1 = new CoordinatedPhraseElement(
- noun1, noun2);
- coordNoun1.setConjunction("or");
-
- VPPhraseSpec verbPhrase1 = SetupForExternalTest.phraseFactory.createVerbPhrase("have");
- verbPhrase1.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
-
- SPhraseSpec sentence1 = SetupForExternalTest.phraseFactory.createClause(coordNoun1,
- verbPhrase1, noun3);
-
- Assert
- .AreEqual(
- "the patient's mother or the patient's father has one changed copy of the FGFR3 gene in every cell",
-
- SetupForExternalTest.realiser.realise(sentence1).getRealisation());
-
- // Rachel's second test
- noun3 = SetupForExternalTest.phraseFactory.createNounPhrase("a", "gene test");
- noun2 = SetupForExternalTest.phraseFactory.createNounPhrase("an", "LDL test");
- noun1 = SetupForExternalTest.phraseFactory.createNounPhrase("the", "clinic");
- verbPhrase1 = SetupForExternalTest.phraseFactory.createVerbPhrase("perform");
-
- var coord1 = new CoordinatedPhraseElement(noun2,
- noun3);
- sentence1 = SetupForExternalTest.phraseFactory.createClause(noun1, verbPhrase1, coord1);
- sentence1.setFeature(Feature.TENSE.ToString(), Tense.PAST);
-
- Assert
- .AreEqual(
- "the clinic performed an LDL test and a gene test", SetupForExternalTest.realiser
- .realise(sentence1).getRealisation());
- }
-
-
- [Test]
- public void novelliTest()
- {
- // Nicole Novelli's test
- SPhraseSpec p = SetupForExternalTest.phraseFactory.createClause(
- "Mary", "chase", "George");
-
- PPPhraseSpec pp = SetupForExternalTest.phraseFactory.createPrepositionPhrase(
- "in", "the park");
- p.addPostModifier(pp);
-
- Assert.AreEqual("Mary chases George in the park", SetupForExternalTest.realiser
- .realise(p).getRealisation());
-
- // another question from Nicole
- SPhraseSpec run = SetupForExternalTest.phraseFactory.createClause(
- "you", "go", "running");
- run.setFeature(Feature.MODAL.ToString(), "should");
- run.addPreModifier("really");
- SPhraseSpec think = SetupForExternalTest.phraseFactory.createClause("I", "think");
- think.setObject(run);
- run.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true);
-
- var text = SetupForExternalTest.realiser.realise(think).getRealisation();
- Assert.AreEqual("I think you should really go running", text);
- }
-
-
- [Test]
- public void piotrekTest()
- {
- // Piotrek Smulikowski's test
- SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);
- SPhraseSpec sent = SetupForExternalTest.phraseFactory.createClause(
- "I", "shoot", "the duck");
- sent.setFeature(Feature.TENSE.ToString(), Tense.PAST);
-
- PPPhraseSpec loc = SetupForExternalTest.phraseFactory.createPrepositionPhrase(
- "at", "the Shooting Range");
- sent.addPostModifier(loc);
- sent.setFeature(Feature.CUE_PHRASE.ToString(), "then");
-
- Assert.AreEqual("then I shot the duck at the Shooting Range",
- SetupForExternalTest.realiser.realise(sent).getRealisation());
- }
-
-
- [Test]
- public void prescottTest()
- {
- // Michael Prescott's test
- SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);
- var embedded = SetupForExternalTest.phraseFactory.createClause(
- "Jill", "prod", "Spot");
- var sent = SetupForExternalTest.phraseFactory.createClause(
- "Jack", "see", embedded);
- embedded.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true);
- embedded.setFeature(Feature.FORM.ToString(), Form.BARE_INFINITIVE.ToString());
-
- Assert.AreEqual("Jack sees Jill prod Spot", SetupForExternalTest.realiser
- .realise(sent).getRealisation());
- }
-
-
- [Test]
- public void wissnerTest()
- {
- // Michael Wissner's text
- var p = SetupForExternalTest.phraseFactory.createClause("a wolf", "eat");
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
- Assert.AreEqual("what does a wolf eat", SetupForExternalTest.realiser.realise(p)
- .getRealisation());
-
- }
-
-
- [Test]
- public void phanTest()
- {
- // Thomas Phan's text
- var subjectElement = SetupForExternalTest.phraseFactory.createNounPhrase("I");
- var verbElement = SetupForExternalTest.phraseFactory.createVerbPhrase("run");
-
- var prepPhrase = SetupForExternalTest.phraseFactory.createPrepositionPhrase("from");
- prepPhrase.addComplement("home");
-
- verbElement.addComplement(prepPhrase);
- var newSentence = SetupForExternalTest.phraseFactory.createClause();
- newSentence.setSubject(subjectElement);
- newSentence.setVerbPhrase(verbElement);
-
- Assert.AreEqual("I run from home", SetupForExternalTest.realiser.realise(newSentence)
- .getRealisation());
-
- }
-
-
- [Test]
- public void kerberTest()
- {
- // Frederic Kerber's tests
- var sp = SetupForExternalTest.phraseFactory.createClause("he", "need");
- var secondSp = SetupForExternalTest.phraseFactory.createClause();
- secondSp.setVerb("build");
- secondSp.setObject("a house");
- secondSp.setFeature(Feature.FORM.ToString(), Form.INFINITIVE);
- sp.setObject("stone");
- sp.addComplement(secondSp);
- Assert.AreEqual("he needs stone to build a house", SetupForExternalTest.realiser.realise(sp).getRealisation());
-
- var sp2 = SetupForExternalTest.phraseFactory.createClause("he", "give");
- sp2.setIndirectObject("I");
- sp2.setObject("the book");
- Assert.AreEqual("he gives me the book", SetupForExternalTest.realiser.realise(sp2).getRealisation());
-
- }
-
-
- [Test]
- public void stephensonTest()
- {
- // Bruce Stephenson's test
- var qs2 = SetupForExternalTest.phraseFactory.createClause();
- qs2 = SetupForExternalTest.phraseFactory.createClause();
- qs2.setSubject("moles of Gold");
- qs2.setVerb("are");
- qs2.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
- qs2.setFeature(Feature.PASSIVE.ToString(), false);
- qs2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.HOW_MANY);
- qs2.setObject("in a 2.50 g sample of pure Gold");
- var sentence = SetupForExternalTest.phraseFactory.createSentence(qs2);
- Assert.AreEqual("How many moles of Gold are in a 2.50 g sample of pure Gold?",
- SetupForExternalTest.realiser.realise(sentence).getRealisation());
- }
-
-
- [Test]
- public void pierreTest()
- {
- // John Pierre's test
- var p = SetupForExternalTest.phraseFactory.createClause("Mary", "chase", "George");
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
- Assert.AreEqual("What does Mary chase?", SetupForExternalTest.realiser.realiseSentence(p));
-
- p = SetupForExternalTest.phraseFactory.createClause("Mary", "chase", "George");
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- Assert.AreEqual("Does Mary chase George?", SetupForExternalTest.realiser.realiseSentence(p));
-
- p = SetupForExternalTest.phraseFactory.createClause("Mary", "chase", "George");
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHERE);
- Assert.AreEqual("Where does Mary chase George?", SetupForExternalTest.realiser.realiseSentence(p));
-
- p = SetupForExternalTest.phraseFactory.createClause("Mary", "chase", "George");
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
- Assert.AreEqual("Why does Mary chase George?", SetupForExternalTest.realiser.realiseSentence(p));
-
- p = SetupForExternalTest.phraseFactory.createClause("Mary", "chase", "George");
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.HOW);
- Assert.AreEqual("How does Mary chase George?", SetupForExternalTest.realiser.realiseSentence(p));
-
-
- }
-
- [Test]
- public void data2TextTest()
- {
- // Data2Text tests
- // test OK to have number at end of sentence
- SPhraseSpec p = SetupForExternalTest.phraseFactory.createClause("the dog", "weigh", "12");
- Assert.AreEqual("The dog weighs 12.", SetupForExternalTest.realiser.realiseSentence(p));
-
- // test OK to have "there be" sentence with "there" as a StringElement
- var dataDropout2 = SetupForExternalTest.phraseFactory.createNLGElement("data dropouts");
- dataDropout2.setPlural(true);
- var sentence2 = SetupForExternalTest.phraseFactory.createClause();
- sentence2.setSubject(SetupForExternalTest.phraseFactory.createStringElement("there"));
- sentence2.setVerb("be");
- sentence2.setObject(dataDropout2);
- Assert.AreEqual("There are data dropouts.", SetupForExternalTest.realiser.realiseSentence(sentence2));
-
- // test OK to have gerund form verb
- SPhraseSpec weather1 = SetupForExternalTest.phraseFactory.createClause("SE 10-15", "veer", "S 15-20");
- weather1.setFeature(Feature.FORM.ToString(), Form.GERUND);
- Assert.AreEqual("SE 10-15 veering S 15-20.", SetupForExternalTest.realiser.realiseSentence(weather1));
-
- // test OK to have subject only
- SPhraseSpec weather2 = SetupForExternalTest.phraseFactory.createClause("cloudy and misty", "be", "XXX");
- weather2.getVerbPhrase().setFeature(Feature.ELIDED.ToString(), true);
- Assert.AreEqual("Cloudy and misty.", SetupForExternalTest.realiser.realiseSentence(weather2));
-
- // test OK to have VP only
- SPhraseSpec weather3 = SetupForExternalTest.phraseFactory.createClause("S 15-20", "increase", "20-25");
- weather3.setFeature(Feature.FORM.ToString(), Form.GERUND);
- weather3.getSubject().setFeature(Feature.ELIDED.ToString(), true);
- Assert.AreEqual("Increasing 20-25.", SetupForExternalTest.realiser.realiseSentence(weather3));
-
- // conjoined test
- SPhraseSpec weather4 = SetupForExternalTest.phraseFactory.createClause("S 20-25", "back", "SSE");
- weather4.setFeature(Feature.FORM.ToString(), Form.GERUND);
- weather4.getSubject().setFeature(Feature.ELIDED.ToString(), true);
-
- var coord = new CoordinatedPhraseElement();
- coord.addCoordinate(weather1);
- coord.addCoordinate(weather3);
- coord.addCoordinate(weather4);
- coord.setConjunction("then");
- Assert.AreEqual("SE 10-15 veering S 15-20, increasing 20-25 then backing SSE.",
- SetupForExternalTest.realiser.realiseSentence(coord));
-
-
- // no verb
- SPhraseSpec weather5 = SetupForExternalTest.phraseFactory.createClause("rain", null, "likely");
- Assert.AreEqual("Rain likely.", SetupForExternalTest.realiser.realiseSentence(weather5));
-
- }
-
-
- /*[Test]
- public void rafaelTest()
- {
- // Rafael Valle's tests
- List ss = new List();
- ClauseCoordinationRule coord = new ClauseCoordinationRule();
- coord.setFactory(SetupForPassive.phraseFactory);
-
- ss.add(SetupForPassive.agreePhrase("John Lennon")); // john lennon agreed with it
- ss.add(SetupForPassive.disagreePhrase("Geri Halliwell")); // Geri Halliwell disagreed with it
- ss.add(SetupForPassive.commentPhrase("Melanie B")); // Mealnie B commented on it
- ss.add(SetupForPassive.agreePhrase("you")); // you agreed with it
- ss.add(SetupForPassive.commentPhrase("Emma Bunton")); //Emma Bunton commented on it
-
- List results = coord.apply(ss);
- List ret = SetupForPassive.realizeAll(results);
- Assert.AreEqual(
- "[John Lennon and you agreed with it, Geri Halliwell disagreed with it, Melanie B and Emma Bunton commented on it]",
- ret.toString());
- }
- */
- private NLGElement commentPhrase(String name)
- {
- // used by testRafael
- var s = SetupForExternalTest.phraseFactory.createClause();
- s.setSubject(SetupForExternalTest.phraseFactory.createNounPhrase(name));
- s.setVerbPhrase(SetupForExternalTest.phraseFactory.createVerbPhrase("comment on"));
- s.setObject("it");
- s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- return s;
- }
-
- private NLGElement agreePhrase(String name)
- {
- // used by testRafael
- var s = SetupForExternalTest.phraseFactory.createClause();
- s.setSubject(SetupForExternalTest.phraseFactory.createNounPhrase(name));
- s.setVerbPhrase(SetupForExternalTest.phraseFactory.createVerbPhrase("agree with"));
- s.setObject("it");
- s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- return s;
- }
-
- private NLGElement disagreePhrase(String name)
- {
- // used by testRafael
- var s = SetupForExternalTest.phraseFactory.createClause();
- s.setSubject(SetupForExternalTest.phraseFactory.createNounPhrase(name));
- s.setVerbPhrase(SetupForExternalTest.phraseFactory.createVerbPhrase("disagree with"));
- s.setObject("it");
- s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- return s;
- }
-
- private List realizeAll(List results)
- {
- // used by testRafael
- var ret = new List();
- foreach (var e in results)
- {
- var r = SetupForExternalTest.realiser.realise(e).getRealisation();
- ret.add(r);
- }
- return ret;
- }
-
- [Test]
- public void wikipediaTest()
- {
- // test code fragments in wikipedia
- // realisation
- var subject = SetupForExternalTest.phraseFactory.createNounPhrase("the", "woman");
- subject.setPlural(true);
- var sentence = SetupForExternalTest.phraseFactory.createClause(subject, "smoke");
- sentence.setFeature(Feature.NEGATED.ToString(), true);
- Assert.AreEqual("The women do not smoke.", SetupForExternalTest.realiser.realiseSentence(sentence));
-
- // aggregation
- var s1 = SetupForExternalTest.phraseFactory.createClause("the man", "be", "hungry");
- var s2 = SetupForExternalTest.phraseFactory.createClause("the man", "buy", "an apple");
- var subject2 = SetupForExternalTest.phraseFactory.createCoordinatedPhrase(s1, s2);
- Assert.AreEqual("The man is hungry and buys an apple.", SetupForExternalTest.realiser.realiseSentence(subject2));
-
- }
-
- [Test]
- public void leanTest()
- {
- // A Lean's test
- var sentence = SetupForExternalTest.phraseFactory.createClause();
- sentence.setVerb("be");
- sentence.setObject("a ball");
- sentence.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
- Assert.AreEqual("What is a ball?", SetupForExternalTest.realiser.realiseSentence(sentence));
-
- sentence = SetupForExternalTest.phraseFactory.createClause();
- sentence.setVerb("be");
- var o = SetupForExternalTest.phraseFactory.createNounPhrase("example");
- o.setPlural(true);
- o.addModifier("of jobs");
- sentence.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
- sentence.setObject(o);
- Assert.AreEqual("What are examples of jobs?", SetupForExternalTest.realiser.realiseSentence(sentence));
-
- var p = SetupForExternalTest.phraseFactory.createClause();
- var sub1 = SetupForExternalTest.phraseFactory.createNounPhrase("Mary");
-
- sub1.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
- sub1.setFeature(Feature.PRONOMINAL.ToString(), true);
- sub1.setFeature(Feature.PERSON.ToString(), Person.FIRST);
- p.setSubject(sub1);
- p.setVerb("chase");
- p.setObject("the monkey");
-
-
- var output2 = SetupForExternalTest.realiser.realiseSentence(p); // Realiser created earlier.
- Assert.AreEqual("I chase the monkey.", output2);
-
- var test = SetupForExternalTest.phraseFactory.createClause();
- var subject = SetupForExternalTest.phraseFactory.createNounPhrase("Mary");
-
- subject.setFeature(Feature.PRONOMINAL.ToString(), true);
- subject.setFeature(Feature.PERSON.ToString(), Person.SECOND);
- test.setSubject(subject);
- test.setVerb("cry");
-
- test.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
- test.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
- Assert.AreEqual("Why do you cry?", SetupForExternalTest.realiser.realiseSentence(test));
-
- test = SetupForExternalTest.phraseFactory.createClause();
- subject = SetupForExternalTest.phraseFactory.createNounPhrase("Mary");
-
- subject.setFeature(Feature.PRONOMINAL.ToString(), true);
- subject.setFeature(Feature.PERSON.ToString(), Person.SECOND);
- test.setSubject(subject);
- test.setVerb("be");
- test.setObject("crying");
-
- test.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
- test.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
- Assert.AreEqual("Why are you crying?", SetupForExternalTest.realiser.realiseSentence(test));
-
-
- }
-
- [Test]
- public void kalijurandTest()
- {
- // K Kalijurand's test
- var lemma = "walk";
-
-
- var word = SetupForExternalTest.lexicon.lookupWord(lemma, new LexicalCategory_VERB());
- var inflectedWord = new InflectedWordElement(word);
-
- inflectedWord.setFeature(Feature.FORM.ToString(), Form.PAST_PARTICIPLE);
- var form = SetupForExternalTest.realiser.realise(inflectedWord).getRealisation();
- Assert.AreEqual("walked", form);
-
-
- inflectedWord = new InflectedWordElement(word);
-
- inflectedWord.setFeature(Feature.PERSON.ToString(), Person.THIRD);
- form = SetupForExternalTest.realiser.realise(inflectedWord).getRealisation();
- Assert.AreEqual("walks", form);
-
- }
-
- [Test]
- public void layTest()
- {
- // Richard Lay's test
- var lemma = "slap";
-
- var word = SetupForExternalTest.lexicon.lookupWord(lemma,new LexicalCategory_VERB());
- var inflectedWord = new InflectedWordElement(word);
- inflectedWord.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE);
- var form = SetupForExternalTest.realiser.realise(inflectedWord).getRealisation();
- Assert.AreEqual("slapping", form);
-
-
- var v = SetupForExternalTest.phraseFactory.createVerbPhrase("slap");
- v.setFeature(Feature.PROGRESSIVE.ToString(), true);
- var progressive = SetupForExternalTest.realiser.realise(v).getRealisation();
- Assert.AreEqual("is slapping", progressive);
- }
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/format/EnumeratedListTest.cs b/SharpSimpleNLGUnitTests/format/EnumeratedListTest.cs
deleted file mode 100644
index 110a0e8..0000000
--- a/SharpSimpleNLGUnitTests/format/EnumeratedListTest.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.morphology
-{
-
- /**
- * This tests that two sentences are realised as a list.
- * @author Rodrigo de Oliveira - Data2Text Ltd
- *
- */
-
- public class EnumeratedListTest
- {
-
- [Test]
- public void bulletList()
- {
- var lexicon = Lexicon.getDefaultLexicon();
- var nlgFactory = new NLGFactory(lexicon);
- var realiser = new Realiser(lexicon);
- realiser.setFormatter(new HTMLFormatter());
- var document = nlgFactory.createDocument("Document");
- var paragraph = nlgFactory.createParagraph();
- var list = nlgFactory.createList();
- var item1 = nlgFactory.createListItem();
- var item2 = nlgFactory.createListItem();
- // NB: a list item employs orthographical operations only until sentence level;
- // nest clauses within a sentence to generate more than 1 clause per list item.
- var sentence1 = nlgFactory.createSentence("this", "be", "the first sentence");
- var sentence2 = nlgFactory.createSentence("this", "be", "the second sentence");
- item1.addComponent(sentence1);
- item2.addComponent(sentence2);
- list.addComponent(item1);
- list.addComponent(item2);
- paragraph.addComponent(list);
- document.addComponent(paragraph);
- var expectedOutput = "Document " + "" + "
" + "This is the first sentence. "
- + "This is the second sentence. " + " " + "";
-
- var realisedOutput = realiser.realise(document).getRealisation();
- Assert.AreEqual(expectedOutput, realisedOutput);
- }
-
- [Test]
- public void enumeratedList()
- {
- var lexicon = Lexicon.getDefaultLexicon();
- var nlgFactory = new NLGFactory(lexicon);
- var realiser = new Realiser(lexicon);
- realiser.setFormatter(new HTMLFormatter());
- var document = nlgFactory.createDocument("Document");
- var paragraph = nlgFactory.createParagraph();
- var list = nlgFactory.createEnumeratedList();
- var item1 = nlgFactory.createListItem();
- var item2 = nlgFactory.createListItem();
- // NB: a list item employs orthographical operations only until sentence level;
- // nest clauses within a sentence to generate more than 1 clause per list item.
- var sentence1 = nlgFactory.createSentence("this", "be", "the first sentence");
- var sentence2 = nlgFactory.createSentence("this", "be", "the second sentence");
- item1.addComponent(sentence1);
- item2.addComponent(sentence2);
- list.addComponent(item1);
- list.addComponent(item2);
- paragraph.addComponent(list);
- document.addComponent(paragraph);
- var expectedOutput = "Document " + "" + "
" + "This is the first sentence. "
- + "This is the second sentence. " + " " + "";
-
- var realisedOutput = realiser.realise(document).getRealisation();
- Assert.AreEqual(expectedOutput, realisedOutput);
- }
-
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/format/NumberedPrefixTest.cs b/SharpSimpleNLGUnitTests/format/NumberedPrefixTest.cs
deleted file mode 100644
index adb7be2..0000000
--- a/SharpSimpleNLGUnitTests/format/NumberedPrefixTest.cs
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.morphology
-{
- public class NumberedPrefixTest
- {
-
- [Test]
- public void testNewInstancePrefixIsZero()
- {
- NumberedPrefix prefix = new NumberedPrefix();
- Assert.AreEqual("0", prefix.getPrefix());
- }
-
- [Test]
- public void testIncrementFromNewInstanceIsOne()
- {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.increment();
- Assert.AreEqual("1", prefix.getPrefix());
- }
-
- [Test]
- public void testIncrementForTwoPointTwoIsTwoPointThree()
- {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.setPrefix("2.2");
- prefix.increment();
- Assert.AreEqual("2.3", prefix.getPrefix());
- }
-
- [Test]
- public void testIncrementForThreePointFourPointThreeIsThreePointFourPointFour()
- {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.setPrefix("3.4.3");
- prefix.increment();
- Assert.AreEqual("3.4.4", prefix.getPrefix());
- }
-
- [Test]
- public void testUpALevelForNewInstanceIsOne()
- {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.upALevel();
- Assert.AreEqual("1", prefix.getPrefix());
- }
-
- [Test]
- public void testDownALevelForNewInstanceIsZero()
- {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.downALevel();
- Assert.AreEqual("0", prefix.getPrefix());
- }
-
- [Test]
- public void testDownALevelForSevenIsZero()
- {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.setPrefix("7");
- prefix.downALevel();
- Assert.AreEqual("0", prefix.getPrefix());
- }
-
- [Test]
- public void testDownALevelForTwoPointSevenIsTwo()
- {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.setPrefix("2.7");
- prefix.downALevel();
- Assert.AreEqual("2", prefix.getPrefix());
- }
-
- [Test]
- public void testDownALevelForThreePointFourPointThreeIsThreePointFour()
- {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.setPrefix("3.4.3");
- prefix.downALevel();
- Assert.AreEqual("3.4", prefix.getPrefix());
- }
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/format/TextFormatterTest.cs b/SharpSimpleNLGUnitTests/format/TextFormatterTest.cs
deleted file mode 100644
index 617304f..0000000
--- a/SharpSimpleNLGUnitTests/format/TextFormatterTest.cs
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.morphology
-{
- /**
- * TextFormatterTest -- Test's the TextFormatter.
- * @author Daniel Paiva -- Arria NLG plc.
- */
- public class TextFormatterTest {
-
- [Test]
- public void testEnumeratedList() {
- var lexicon = Lexicon.getDefaultLexicon();
- var nlgFactory = new NLGFactory(lexicon);
- var realiser = new Realiser(lexicon);
- realiser.setFormatter(new TextFormatter());
- var document = nlgFactory.createDocument("Document");
- var paragraph = nlgFactory.createParagraph();
-
-
- var subListItem1 = nlgFactory.createListItem();
- var subListSentence1 = nlgFactory.createSentence("this", "be", "sub-list sentence 1");
- subListItem1.addComponent(subListSentence1);
-
- var subListItem2 = nlgFactory.createListItem();
- var subListSentence2 = nlgFactory.createSentence("this", "be", "sub-list sentence 2");
- subListItem2.addComponent(subListSentence2);
-
- var subList = nlgFactory.createEnumeratedList();
- subList.addComponent(subListItem1);
- subList.addComponent(subListItem2);
-
- var item1 = nlgFactory.createListItem();
- var sentence1 = nlgFactory.createSentence("this", "be", "the first sentence");
- item1.addComponent(sentence1);
-
- var item2 = nlgFactory.createListItem();
- var sentence2 = nlgFactory.createSentence("this", "be", "the second sentence");
- item2.addComponent(sentence2);
-
- var list = nlgFactory.createEnumeratedList();
- list.addComponent(subList);
- list.addComponent(item1);
- list.addComponent(item2);
- paragraph.addComponent(list);
- document.addComponent(paragraph);
- var expectedOutput = "Document\n" +
- "\n" +
- "1.1 - This is sub-list sentence 1.\n" +
- "1.2 - This is sub-list sentence 2.\n"+
- "2 - This is the first sentence.\n" +
- "3 - This is the second sentence.\n" +
- "\n\n"; // for the end of a paragraph
-
- var realisedOutput = realiser.realise(document).getRealisation();
- Assert.AreEqual(expectedOutput, realisedOutput);
- }
-
- [Test]
- public void testEnumeratedListWithSeveralLevelsOfNesting() {
- var lexicon = Lexicon.getDefaultLexicon();
- var nlgFactory = new NLGFactory(lexicon);
- var realiser = new Realiser(lexicon);
- realiser.setFormatter(new TextFormatter());
- var document = nlgFactory.createDocument("Document");
- var paragraph = nlgFactory.createParagraph();
-
- // sub item 1
- var subList1Item1 = nlgFactory.createListItem();
- var subList1Sentence1 = nlgFactory.createSentence("sub-list item 1");
- subList1Item1.addComponent(subList1Sentence1);
-
- // sub sub item 1
- var subSubList1Item1 = nlgFactory.createListItem();
- var subSubList1Sentence1 = nlgFactory.createSentence("sub-sub-list item 1");
- subSubList1Item1.addComponent(subSubList1Sentence1);
-
- // sub sub item 2
- var subSubList1Item2 = nlgFactory.createListItem();
- var subSubList1Sentence2 = nlgFactory.createSentence("sub-sub-list item 2");
- subSubList1Item2.addComponent(subSubList1Sentence2);
-
- // sub sub list
- var subSubList1 = nlgFactory.createEnumeratedList();
- subSubList1.addComponent(subSubList1Item1);
- subSubList1.addComponent(subSubList1Item2);
-
- // sub item 2
- var subList1Item2 = nlgFactory.createListItem();
- var subList1Sentence2 = nlgFactory.createSentence("sub-list item 3");
- subList1Item2.addComponent(subList1Sentence2);
-
- // sub list 1
- var subList1 = nlgFactory.createEnumeratedList();
- subList1.addComponent(subList1Item1);
- subList1.addComponent(subSubList1);
- subList1.addComponent(subList1Item2);
-
- // item 2
- var item2 = nlgFactory.createListItem();
- var sentence2 = nlgFactory.createSentence("item 2");
- item2.addComponent(sentence2);
-
- // item 3
- var item3 = nlgFactory.createListItem();
- var sentence3 = nlgFactory.createSentence("item 3");
- item3.addComponent(sentence3);
-
- // list
- var list = nlgFactory.createEnumeratedList();
- list.addComponent(subList1);
- list.addComponent(item2);
- list.addComponent(item3);
-
- paragraph.addComponent(list);
-
- document.addComponent(paragraph);
-
- var expectedOutput = "Document\n" +
- "\n" +
- "1.1 - Sub-list item 1.\n" +
- "1.2.1 - Sub-sub-list item 1.\n" +
- "1.2.2 - Sub-sub-list item 2.\n" +
- "1.3 - Sub-list item 3.\n"+
- "2 - Item 2.\n" +
- "3 - Item 3.\n" +
- "\n\n";
-
- var realisedOutput = realiser.realise(document).getRealisation();
- Assert.AreEqual(expectedOutput, realisedOutput);
- }
-
-}
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/format/english/EnumeratedListTest.java b/SharpSimpleNLGUnitTests/format/english/EnumeratedListTest.java
deleted file mode 100644
index e88dd9e..0000000
--- a/SharpSimpleNLGUnitTests/format/english/EnumeratedListTest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.format.english;
-
-import junit.framework.Assert;
-
-import org.junit.Test;
-
-import simplenlg.framework.DocumentElement;
-import simplenlg.framework.NLGFactory;
-import simplenlg.lexicon.Lexicon;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * This tests that two sentences are realised as a list.
- * @author Rodrigo de Oliveira - Data2Text Ltd
- *
- */
-public class EnumeratedListTest {
-
- @Test
- public void bulletList() {
- Lexicon lexicon = Lexicon.getDefaultLexicon();
- NLGFactory nlgFactory = new NLGFactory(lexicon);
- Realiser realiser = new Realiser(lexicon);
- realiser.setFormatter(new HTMLFormatter());
- DocumentElement document = nlgFactory.createDocument("Document");
- DocumentElement paragraph = nlgFactory.createParagraph();
- DocumentElement list = nlgFactory.createList();
- DocumentElement item1 = nlgFactory.createListItem();
- DocumentElement item2 = nlgFactory.createListItem();
- // NB: a list item employs orthographical operations only until sentence level;
- // nest clauses within a sentence to generate more than 1 clause per list item.
- DocumentElement sentence1 = nlgFactory.createSentence("this", "be", "the first sentence");
- DocumentElement sentence2 = nlgFactory.createSentence("this", "be", "the second sentence");
- item1.addComponent(sentence1);
- item2.addComponent(sentence2);
- list.addComponent(item1);
- list.addComponent(item2);
- paragraph.addComponent(list);
- document.addComponent(paragraph);
- String expectedOutput = "Document " + "" + "
" + "This is the first sentence. "
- + "This is the second sentence. " + " " + "";
-
- String realisedOutput = realiser.realise(document).getRealisation();
- // System.out.println(expectedOutput);
- // System.out.println(realisedOutput);
- Assert.assertEquals(expectedOutput, realisedOutput);
- }
-
- @Test
- public void enumeratedList() {
- Lexicon lexicon = Lexicon.getDefaultLexicon();
- NLGFactory nlgFactory = new NLGFactory(lexicon);
- Realiser realiser = new Realiser(lexicon);
- realiser.setFormatter(new HTMLFormatter());
- DocumentElement document = nlgFactory.createDocument("Document");
- DocumentElement paragraph = nlgFactory.createParagraph();
- DocumentElement list = nlgFactory.createEnumeratedList();
- DocumentElement item1 = nlgFactory.createListItem();
- DocumentElement item2 = nlgFactory.createListItem();
- // NB: a list item employs orthographical operations only until sentence level;
- // nest clauses within a sentence to generate more than 1 clause per list item.
- DocumentElement sentence1 = nlgFactory.createSentence("this", "be", "the first sentence");
- DocumentElement sentence2 = nlgFactory.createSentence("this", "be", "the second sentence");
- item1.addComponent(sentence1);
- item2.addComponent(sentence2);
- list.addComponent(item1);
- list.addComponent(item2);
- paragraph.addComponent(list);
- document.addComponent(paragraph);
- String expectedOutput = "Document " + "" + "
" + "This is the first sentence. "
- + "This is the second sentence. " + " " + "";
-
- String realisedOutput = realiser.realise(document).getRealisation();
- // System.out.println(expectedOutput);
- // System.out.println(realisedOutput);
- Assert.assertEquals(expectedOutput, realisedOutput);
- }
-
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/format/english/NumberedPrefixTest.java b/SharpSimpleNLGUnitTests/format/english/NumberedPrefixTest.java
deleted file mode 100644
index 85d3912..0000000
--- a/SharpSimpleNLGUnitTests/format/english/NumberedPrefixTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package simplenlg.format.english;
-
-import junit.framework.Assert;
-import org.junit.Test;
-
-
-public class NumberedPrefixTest {
-
- @Test
- public void testNewInstancePrefixIsZero() {
- NumberedPrefix prefix = new NumberedPrefix();
- Assert.assertEquals("0", prefix.getPrefix());
- }
-
- @Test
- public void testIncrementFromNewInstanceIsOne() {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.increment();
- Assert.assertEquals("1", prefix.getPrefix());
- }
-
- @Test
- public void testIncrementForTwoPointTwoIsTwoPointThree() {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.setPrefix("2.2");
- prefix.increment();
- Assert.assertEquals("2.3", prefix.getPrefix());
- }
-
- @Test
- public void testIncrementForThreePointFourPointThreeIsThreePointFourPointFour() {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.setPrefix("3.4.3");
- prefix.increment();
- Assert.assertEquals("3.4.4", prefix.getPrefix());
- }
-
- @Test
- public void testUpALevelForNewInstanceIsOne() {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.upALevel();
- Assert.assertEquals("1", prefix.getPrefix());
- }
-
- @Test
- public void testDownALevelForNewInstanceIsZero() {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.downALevel();
- Assert.assertEquals("0", prefix.getPrefix());
- }
-
- @Test
- public void testDownALevelForSevenIsZero() {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.setPrefix("7");
- prefix.downALevel();
- Assert.assertEquals("0", prefix.getPrefix());
- }
-
- @Test
- public void testDownALevelForTwoPointSevenIsTwo() {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.setPrefix("2.7");
- prefix.downALevel();
- Assert.assertEquals("2", prefix.getPrefix());
- }
-
- @Test
- public void testDownALevelForThreePointFourPointThreeIsThreePointFour() {
- NumberedPrefix prefix = new NumberedPrefix();
- prefix.setPrefix("3.4.3");
- prefix.downALevel();
- Assert.assertEquals("3.4", prefix.getPrefix());
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/format/english/TextFormatterTest.java b/SharpSimpleNLGUnitTests/format/english/TextFormatterTest.java
deleted file mode 100644
index 42c036d..0000000
--- a/SharpSimpleNLGUnitTests/format/english/TextFormatterTest.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.format.english;
-
-import junit.framework.Assert;
-import org.junit.Test;
-import simplenlg.framework.DocumentElement;
-import simplenlg.framework.NLGFactory;
-import simplenlg.lexicon.Lexicon;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * TextFormatterTest -- Test's the TextFormatter.
- * @author Daniel Paiva -- Arria NLG plc.
- */
-public class TextFormatterTest {
-
- @Test
- public void testEnumeratedList() {
- Lexicon lexicon = Lexicon.getDefaultLexicon();
- NLGFactory nlgFactory = new NLGFactory(lexicon);
- Realiser realiser = new Realiser(lexicon);
- realiser.setFormatter(new TextFormatter());
- DocumentElement document = nlgFactory.createDocument("Document");
- DocumentElement paragraph = nlgFactory.createParagraph();
-
-
- DocumentElement subListItem1 = nlgFactory.createListItem();
- DocumentElement subListSentence1 = nlgFactory.createSentence("this", "be", "sub-list sentence 1");
- subListItem1.addComponent(subListSentence1);
-
- DocumentElement subListItem2 = nlgFactory.createListItem();
- DocumentElement subListSentence2 = nlgFactory.createSentence("this", "be", "sub-list sentence 2");
- subListItem2.addComponent(subListSentence2);
-
- DocumentElement subList = nlgFactory.createEnumeratedList();
- subList.addComponent(subListItem1);
- subList.addComponent(subListItem2);
-
- DocumentElement item1 = nlgFactory.createListItem();
- DocumentElement sentence1 = nlgFactory.createSentence("this", "be", "the first sentence");
- item1.addComponent(sentence1);
-
- DocumentElement item2 = nlgFactory.createListItem();
- DocumentElement sentence2 = nlgFactory.createSentence("this", "be", "the second sentence");
- item2.addComponent(sentence2);
-
- DocumentElement list = nlgFactory.createEnumeratedList();
- list.addComponent(subList);
- list.addComponent(item1);
- list.addComponent(item2);
- paragraph.addComponent(list);
- document.addComponent(paragraph);
- String expectedOutput = "Document\n" +
- "\n" +
- "1.1 - This is sub-list sentence 1.\n" +
- "1.2 - This is sub-list sentence 2.\n"+
- "2 - This is the first sentence.\n" +
- "3 - This is the second sentence.\n" +
- "\n\n"; // for the end of a paragraph
-
- String realisedOutput = realiser.realise(document).getRealisation();
- Assert.assertEquals(expectedOutput, realisedOutput);
- }
-
- @Test
- public void testEnumeratedListWithSeveralLevelsOfNesting() {
- Lexicon lexicon = Lexicon.getDefaultLexicon();
- NLGFactory nlgFactory = new NLGFactory(lexicon);
- Realiser realiser = new Realiser(lexicon);
- realiser.setFormatter(new TextFormatter());
- DocumentElement document = nlgFactory.createDocument("Document");
- DocumentElement paragraph = nlgFactory.createParagraph();
-
- // sub item 1
- DocumentElement subList1Item1 = nlgFactory.createListItem();
- DocumentElement subList1Sentence1 = nlgFactory.createSentence("sub-list item 1");
- subList1Item1.addComponent(subList1Sentence1);
-
- // sub sub item 1
- DocumentElement subSubList1Item1 = nlgFactory.createListItem();
- DocumentElement subSubList1Sentence1 = nlgFactory.createSentence("sub-sub-list item 1");
- subSubList1Item1.addComponent(subSubList1Sentence1);
-
- // sub sub item 2
- DocumentElement subSubList1Item2 = nlgFactory.createListItem();
- DocumentElement subSubList1Sentence2 = nlgFactory.createSentence("sub-sub-list item 2");
- subSubList1Item2.addComponent(subSubList1Sentence2);
-
- // sub sub list
- DocumentElement subSubList1 = nlgFactory.createEnumeratedList();
- subSubList1.addComponent(subSubList1Item1);
- subSubList1.addComponent(subSubList1Item2);
-
- // sub item 2
- DocumentElement subList1Item2 = nlgFactory.createListItem();
- DocumentElement subList1Sentence2 = nlgFactory.createSentence("sub-list item 3");
- subList1Item2.addComponent(subList1Sentence2);
-
- // sub list 1
- DocumentElement subList1 = nlgFactory.createEnumeratedList();
- subList1.addComponent(subList1Item1);
- subList1.addComponent(subSubList1);
- subList1.addComponent(subList1Item2);
-
- // item 2
- DocumentElement item2 = nlgFactory.createListItem();
- DocumentElement sentence2 = nlgFactory.createSentence("item 2");
- item2.addComponent(sentence2);
-
- // item 3
- DocumentElement item3 = nlgFactory.createListItem();
- DocumentElement sentence3 = nlgFactory.createSentence("item 3");
- item3.addComponent(sentence3);
-
- // list
- DocumentElement list = nlgFactory.createEnumeratedList();
- list.addComponent(subList1);
- list.addComponent(item2);
- list.addComponent(item3);
-
- paragraph.addComponent(list);
-
- document.addComponent(paragraph);
-
- String expectedOutput = "Document\n" +
- "\n" +
- "1.1 - Sub-list item 1.\n" +
- "1.2.1 - Sub-sub-list item 1.\n" +
- "1.2.2 - Sub-sub-list item 2.\n" +
- "1.3 - Sub-list item 3.\n"+
- "2 - Item 2.\n" +
- "3 - Item 3.\n" +
- "\n\n";
-
- String realisedOutput = realiser.realise(document).getRealisation();
- Assert.assertEquals(expectedOutput, realisedOutput);
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/helpers/ExtensionHelpersTest.cs b/SharpSimpleNLGUnitTests/helpers/ExtensionHelpersTest.cs
deleted file mode 100644
index da0523c..0000000
--- a/SharpSimpleNLGUnitTests/helpers/ExtensionHelpersTest.cs
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using System.Collections.Generic;
-using NUnit.Framework;
-using Shouldly;
-using SimpleNLG.Extensions;
-
-namespace SimpleNLGTests.helpers
-{
-
- /**
- * @author Nick Hodge, nhodge@mungr.com
- *
- */
-
- public class ExtensionHelpersTests
- {
- // String and Char ones first
-
-
- //ref: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isDigit(char)
- [TestCase(' ', ExpectedResult = false, TestName = "isDigit: space case")]
- [TestCase('a', ExpectedResult = false, TestName = "isDigit: single char a")]
- [TestCase('0', ExpectedResult = true, TestName = "isDigit: single char 0")]
- [TestCase('1', ExpectedResult = true, TestName = "isDigit: single char 1")]
- [TestCase('2', ExpectedResult = true, TestName = "isDigit: single char 2")]
- [TestCase('3', ExpectedResult = true, TestName = "isDigit: single char 3")]
- [TestCase('4', ExpectedResult = true, TestName = "isDigit: single char 4")]
- [TestCase('5', ExpectedResult = true, TestName = "isDigit: single char 5")]
- [TestCase('6', ExpectedResult = true, TestName = "isDigit: single char 6")]
- [TestCase('7', ExpectedResult = true, TestName = "isDigit: single char 7")]
- [TestCase('8', ExpectedResult = true, TestName = "isDigit: single char 8")]
- [TestCase('9', ExpectedResult = true, TestName = "isDigit: single char 9")]
- [TestCase('\u0660', ExpectedResult = true, TestName = "isDigit: arabic/indic start")]
- [TestCase('\u0669', ExpectedResult = true, TestName = "isDigit: arabic/indic end")]
- [TestCase('\u06F0', ExpectedResult = true, TestName = "isDigit: arabic extended start")]
- [TestCase('\u06F9', ExpectedResult = true, TestName = "isDigit: arabic extended end")]
- [TestCase('\u0966', ExpectedResult = true, TestName = "isDigit: Devanagari extended start")]
- [TestCase('\u096F', ExpectedResult = true, TestName = "isDigit: Devanagari extended end")]
- [TestCase('\uFF10', ExpectedResult = true, TestName = "isDigit: Fullwidth extended start")]
- [TestCase('\uFF19', ExpectedResult = true, TestName = "isDigit: Fullwidth extended end")]
- public bool isDigit_ToCsharp(char c)
- {
- return c.isDigit();
- }
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#length()
- [TestCase("", ExpectedResult = 0, TestName = "length: null case")]
- [TestCase(" ", ExpectedResult = 1, TestName = "length: 1")]
- [TestCase(" ", ExpectedResult = 2, TestName = "length: 2")]
- [TestCase("cat", ExpectedResult = 3, TestName = "length: 3")]
- [TestCase("\uFF19cat", ExpectedResult = 4, TestName = "length: 4 with Unicode")]
- public int length_ToCsharp(string s)
- {
- return s.length();
- }
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#trim()
- [TestCase("", ExpectedResult = "", TestName = "trim: null case")]
- [TestCase("cat", ExpectedResult = "cat", TestName = "trim: 3 chars")]
- [TestCase(" \uFF19cat", ExpectedResult = "\uFF19cat", TestName = "trim: 4 chars with Unicode, leading only")]
- [TestCase(" cat", ExpectedResult = "cat", TestName = "trim: 4 chars with leading space")]
- [TestCase("cat ", ExpectedResult = "cat", TestName = "trim: 4 chars with trailing space")]
- [TestCase(" cat ", ExpectedResult = "cat", TestName = "trim: 4 chars leading and trailing space")]
- [TestCase("\uFF19cat", ExpectedResult = "\uFF19cat", TestName = "trim: 4 chars with Unicode, leading spcae")]
- [TestCase(" \uFF19cat", ExpectedResult = "\uFF19cat",
- TestName = "trim: 4 chars with Unicode, leading")]
- [TestCase("\uFF19cat ", ExpectedResult = "\uFF19cat",
- TestName = "trim: 4 chars with Unicode, leading and trailing")]
- [TestCase(" \uFF19cat ", ExpectedResult = "\uFF19cat", TestName = "trim: 4 chars with Unicode")]
- [TestCase("\r\uFF19cat ", ExpectedResult = "\uFF19cat",
- TestName = "trim: 4 chars with Unicode, return char at start")]
- [TestCase("\r\uFF19cat \n", ExpectedResult = "\uFF19cat",
- TestName = "trim: 4 chars with Unicode, return at start, new line char at end")]
- public string trim_ToCsharp(string s)
- {
- return s.trim();
- }
-
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#toLowerCase()
- [TestCase("", ExpectedResult = "", TestName = "toLower: null")]
- [TestCase("cat", ExpectedResult = "cat", TestName = "toLower: simple")]
- [TestCase("CAT", ExpectedResult = "cat", TestName = "toLower: all caps")]
- [TestCase("cAt", ExpectedResult = "cat", TestName = "toLower: mixed caps")]
- public string tolower_ToCsharp(string s)
- {
- return s.toLowerCase();
- }
-
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#toUpperCase()
- [TestCase("", ExpectedResult = "", TestName = "toUpper: null")]
- [TestCase("cat", ExpectedResult = "CAT", TestName = "toUpper: simple")]
- [TestCase("CAT", ExpectedResult = "CAT", TestName = "toUpper: all caps")]
- [TestCase("cAt", ExpectedResult = "CAT", TestName = "toUpper: mixed caps")]
- public string toupper_ToCsharp(string s)
- {
- return s.toUpperCase();
- }
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#equalsIgnoreCase(java.lang.String)
- [TestCase("cat", ExpectedResult = true, TestName = "equalsIgnoreCase: lower, true")]
- [TestCase("dog", ExpectedResult = false, TestName = "equalsIgnoreCase: lower, false")]
- [TestCase("Cat", ExpectedResult = true, TestName = "equalsIgnoreCase: mixed 1, true")]
- [TestCase("Dog", ExpectedResult = false, TestName = "equalsIgnoreCase: mixed, false")]
- [TestCase("CAT", ExpectedResult = true, TestName = "equalsIgnoreCase: tupper, rue")]
- [TestCase("CaT", ExpectedResult = true, TestName = "equalsIgnoreCase: mixed 2,true")]
- public bool equalsIgnoreCase_ToCsharp(string s)
- {
- return s.equalsIgnoreCase("cat");
- }
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(int)
- [TestCase("", ExpectedResult = -1, TestName = "indexOf string: null is negative")]
- [TestCase("CaT", ExpectedResult = 1, TestName = "indexOf string: in cat 1")]
- [TestCase("dog", ExpectedResult = -1, TestName = "indexOf string: in dog negative")]
- [TestCase("cta", ExpectedResult = 2, TestName = "indexOf string: in cat end")]
- [TestCase("atac", ExpectedResult = 0, TestName = "indexOf string: in cat beginning")]
- public int indexOf_string_ToCsharp(string s)
- {
- return s.indexOf("a");
- }
-
- [TestCase("", ExpectedResult = -1, TestName = "indexOf char: null is negative")]
- [TestCase("CaT", ExpectedResult = 1, TestName = "indexOf char: in cat 1")]
- public int indexOf_char_ToCsharp(string s)
- {
- return s.indexOf('a');
- }
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#charAt(int)
- [TestCase(0, ExpectedResult = 'c', TestName = "charAt: in cat 1")]
- [TestCase(1, ExpectedResult = 'a', TestName = "charAt: in cat 2")]
- [TestCase(2, ExpectedResult = 't', TestName = "charAt: in cat 3")]
- [TestCase(3, ExpectedResult = '\uFF19', TestName = "charAt: in cat 4")]
- public char charAt_ToCsharp(int i)
- {
- return "cat\uFF19".charAt(i);
- }
-
- [TestCase("\uFF19", ExpectedResult = true, TestName = "endsWith: 1 in cat Unicode")]
- [TestCase("t\uFF19", ExpectedResult = true, TestName = "endsWith: 2 in cat Unicode")]
- [TestCase("at\uFF19", ExpectedResult = true, TestName = "endsWith: 3 in cat Unicode")]
- [TestCase("cat\uFF19", ExpectedResult = true, TestName = "endsWith: 4 in cat Unicode")]
- [TestCase("dog", ExpectedResult = false, TestName = "endsWith: false")]
- public bool endsWith_ToCsharp(string s)
- {
- return "cat\uFF19".endsWith(s);
- }
-
-
- [TestCase("dog", ExpectedResult = false, TestName = "contains: false")]
- [TestCase("cat", ExpectedResult = true, TestName = "contains: true cat")]
- [TestCase("\uFF19", ExpectedResult = true, TestName = "contains: true Unicode")]
- public bool contains_ToCsharp(string s)
- {
- return "cat\uFF19".contains(s);
- }
-
-
- [TestCase("c", ExpectedResult = true, TestName = "startsWith: 1 in cat Unicode")]
- [TestCase("ca", ExpectedResult = true, TestName = "startsWith: 2 in cat Unicode")]
- [TestCase("cat", ExpectedResult = true, TestName = "startsWith: 3 in cat Unicode")]
- [TestCase("cat\uFF19", ExpectedResult = true, TestName = "startsWith: 4 in cat Unicode")]
- [TestCase("dog", ExpectedResult = false, TestName = "startsWith: false")]
- public bool startsWith_ToCsharp(string s)
- {
- return "cat\uFF19".startsWith(s);
- }
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#substring(int,%20int)
- // and contrast: https://msdn.microsoft.com/en-us/library/aka44szs(v=vs.110).aspx
- [Test]
- public void substring_ToCsharp()
- {
- // NOTE Java semantics: public String substring(int beginIndex, int endIndex) base 1
- // NOTE C# semantics:
-
- "hamburger".substring(4, 8).ShouldBe("urge");
- "smiles".substring(1, 5).ShouldBe("mile");
-
- var s = "the cat sat on the matz";
- s.substring(0, 1).ShouldBe("t");
- s.substring(0, 2).ShouldBe("th");
- s.substring((s.Length - 1), (s.Length)).ShouldBe("z"); // just the last char
- s.substring(0, (s.Length - 1)).ShouldBe("the cat sat on the mat"); // all except last char
- }
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#isEmpty()
- [TestCase("", ExpectedResult = true, TestName = "isEmpty: true")]
- [TestCase(" ", ExpectedResult = false, TestName = "isEmpty: false")]
- [TestCase("\uFF19", ExpectedResult = false, TestName = "isEmpty: with Unicode false")]
- public bool isEmpty_ToCsharp(string s)
- {
- return s.isEmpty();
- }
-
-
- [TestCase("", ExpectedResult = false, TestName = "matches: false")]
- [TestCase("word", ExpectedResult = true, TestName = "matches: true")]
- public bool matches_ToCsharp(string s)
- {
- return s.matches(@"[\w]+");
- }
-
- [TestCase("word", ExpectedResult = "nerd", TestName = "replaceAll: nerd")]
- [TestCase("wordwo", ExpectedResult = "nerdne", TestName = "replaceAll: nerdier")]
- [TestCase("rd", ExpectedResult = "rd", TestName = "replaceAll: rd")]
- public string replaceAll_ToCsharp(string s)
- {
- return s.replaceAll(@"wo", "ne");
- }
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html
- [Test]
- public void Lists_ToCsharp()
- {
- var one = new List();
- var two = new List() {"cat", "dog"};
- var three = new List() {"cat", "dog", "cat"};
-
- one.isEmpty().ShouldBe(true);
- two.isEmpty().ShouldBe(false);
-
- one.size().ShouldBe(0);
- two.size().ShouldBe(2);
-
- two.get(0).ShouldBe(two[0]);
- two.get(0).ShouldBe("cat");
-
- two.get(1).ShouldBe(two[1]);
- two.get(1).ShouldBe("dog");
-
- three.indexOf("cat").ShouldBe(0);
-
- one.contains("cat").ShouldBe(false);
- two.contains("dog").ShouldBe(true);
- two.contains("tree").ShouldBe(false);
-
- three.remove("cat").ShouldBe(true); // remove first
- three.remove("cat").ShouldBe(true); // remove second
- three.remove("cat").ShouldBe(false); // no more to remove, so should return false
-
- three = new List() {"cat", "dog", "cat"};
- three.removeAll(new List {"cat"}).ShouldBe(true); // remove second
- three.remove("cat").ShouldBe(false); // no more to remove, so should return false
-
-
- two.clear();
- two.size().ShouldBe(0);
- two.isEmpty().ShouldBe(true);
-
- // now two is empty, let's continue
- two.add("horse").ShouldBe(true);
- two.size().ShouldBe(1);
-
- two.addAll(new List {"cat", "dog"}).ShouldBe(true);
- two.size().ShouldBe(3);
-
- two.set(0, "cow").ShouldBe("cow");
- two[0].ShouldBe("cow");
- two[1].ShouldBe("cat");
-
- }
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html
- [Test]
- public void Hashset_ToCsharp()
- {
- var two = new HashSet() {"cat", "dog"};
- two.add("horse").ShouldBe(true);
- two.add("cat").ShouldBe(false);
- }
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/util/Stack.html
- [Test]
- public void Stack_ToCsharp()
- {
- var two = new Stack();
- two.push("cat").ShouldBe("cat");
- two.push("dog").ShouldBe("dog");
- two.isEmpty().ShouldBe(false);
- two.pop().ShouldBe("dog"); // LIFO
- two.pop().ShouldBe("cat");
- two.isEmpty().ShouldBe(true);
- }
-
-
- // Dictionary ones
-
- // ref: https://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html
- [Test]
- public void HashMap_ToCsharp_Dictionary()
- {
- var two = new Dictionary();
- two.put("cat","lucy").ShouldBe("lucy");
- two.put("dog", "benny").ShouldBe("benny");
-
- two.Keys.Count.ShouldBe(2);
- two["cat"].ShouldBe("lucy");
-
- two.put("cat", "emi").ShouldBe("emi");
- two["cat"].ShouldBe("emi");
-
- two.containsKey("dog").ShouldBe(true);
- two.containsKey("camel").ShouldBe(false);
-
- }
-
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/helpers/RegexExercises.cs b/SharpSimpleNLGUnitTests/helpers/RegexExercises.cs
deleted file mode 100644
index a12dcec..0000000
--- a/SharpSimpleNLGUnitTests/helpers/RegexExercises.cs
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using Shouldly;
-
-namespace SimpleNLG.Extensions
-{
- /**
- * @author Nick Hodge, nhodge@mungr.com
- */
-
- public class RegexExercises
- {
- // The Regex engine in Java is different to .NET, and there are a couple of
- // idioms/semantic difference "exercised" and tested here.
- // ref: MorphologyRules.cs
-
- // this checks the "matches" and "replaceAll" extension methods as found
- [Test]
- public void TestDotNetRegex_vsJava_Nouns()
- {
- // Firstly, Noun Plural Morpholology
-
- var baseForm1 = "carry away";
- if (baseForm1.matches(@".*[b-z-[eiou]]y\\b"))
- {
- baseForm1.replaceAll(@"y\b", @"ies").ShouldBe("carried away");
- }
-
- var baseForm1a = "cazy away";
- if (baseForm1a.matches(@".*[b-z-[eiou]]y\\b"))
- {
- baseForm1a.replaceAll(@"y\b", @"ies").ShouldBe("cazies away");
- }
-
- var baseForm2 = "cash";
- if (baseForm2.matches(@".*([szx]|[cs]h)\\b"))
- {
- (baseForm2 + "es").ShouldBe("cashes");
- }
-
- var baseForm2a = "cax";
- if (baseForm2a.matches(@".*([szx]|[cs]h)\\b"))
- {
- (baseForm2a + "es").ShouldBe("caxes");
- }
-
- var baseForm3 = "documentus impartum";
- if (baseForm3.endsWith("us"))
- {
- baseForm3.replaceAll(@"us\b", "i").ShouldBe("documenti impartum");
-
- }
-
- var baseForm4 = "documentus impartum onton";
- if (baseForm4.matches(@".*[(um)(on)]\\b"))
- {
- baseForm4.replaceAll(@"[(um)(on)]\\b", "a").ShouldBe("documentus imparta onta");
- }
-
- var baseForm5 = "sepsis";
- if (baseForm5.endsWith("sis"))
- {
- baseForm5.replaceAll(@"sis\b", "ses").ShouldBe("sepses");
- }
-
- var baseForm6 = "markis";
- if (baseForm6.endsWith("is"))
- {
- baseForm6.replaceAll(@"is\b", "ides").ShouldBe("markides");
- }
-
- var baseForm7 = "cognomen";
- if (baseForm7.endsWith("men"))
- {
- baseForm7.replaceAll(@"men\b", "mina").ShouldBe("cognomina");
- }
-
- var baseForm8 = "index";
- if (baseForm8.endsWith("ex"))
- {
- baseForm8.replaceAll(@"ex\b", "ices").ShouldBe("indices");
- }
-
- var baseForm9 = "wax";
- if (baseForm9.endsWith("x"))
- {
- baseForm9.replaceAll(@"x\b", "ces").ShouldBe("waces");
- }
-
- }
-
- [Test]
- public void TestDotNetRegex_vsJava_Verbs()
- {
- var baseForm1 = "come";
- if (baseForm1.matches(@".*[^iyeo]e\\b"))
- {
- baseForm1.replaceAll(@"e\b", "ing").ShouldBe("coming");
- }
-
- var baseForm1a = "cooee";
- if (baseForm1a.matches(@".*[^iyeo]e\\b"))
- {
- // actually shouldnt match so want fall through to here
- baseForm1a.replaceAll(@"e\b", "ing").ShouldBe("banana");
- }
-
- var baseForm2 = "carry";
- if (baseForm2.matches(@".*[b-z-[eiou]]y\\b"))
- {
- baseForm2.replaceAll(@"y\b", "ied").ShouldBe("carried");
- }
- }
-
- [Test]
- public void AN_AGREEMENT_DeterminierAgrHelper()
- {
- var AN_AGREEMENT = @"\A(a|e|i|o|u).*";
- var lowercaseInput = "enormous".toLowerCase();
-
- lowercaseInput.matches(AN_AGREEMENT).ShouldBeTrue();
-
-
- }
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/lexicon/LexicalVariantsTest.java b/SharpSimpleNLGUnitTests/lexicon/LexicalVariantsTest.java
deleted file mode 100644
index 04ca697..0000000
--- a/SharpSimpleNLGUnitTests/lexicon/LexicalVariantsTest.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.lexicon.english;
-
-import java.util.List;
-import java.util.Properties;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.features.Inflection;
-import simplenlg.features.LexicalFeature;
-import simplenlg.features.NumberAgreement;
-import simplenlg.features.Tense;
-import simplenlg.framework.InflectedWordElement;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.NLGFactory;
-import simplenlg.framework.WordElement;
-import simplenlg.lexicon.NIHDBLexicon;
-import simplenlg.lexicon.XMLLexicon;
-import simplenlg.lexicon.Lexicon;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * Tests on the use of spelling and inflectional variants, using the
- * NIHDBLexicon.
- *
- * @author bertugatt
- *
- */
-public class LexicalVariantsTest {
-
- // lexicon object -- an instance of Lexicon
- Lexicon lexicon = null;
-
- // factory for phrases
- NLGFactory factory;
-
- // realiser
- Realiser realiser;
-
- // DB location -- change this to point to the lex access data dir
- static String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
-
- @Before
- /*
- * * Sets up the accessor and runs it -- takes ca. 26 sec
- */
- public void setUp() {
- // use property file for the lexicon
- try {
- Properties prop = new Properties();
- prop.load(getClass().getClassLoader().
- getResourceAsStream("lexicon.properties"));
-
- String type = prop.getProperty("LexiconType");
-
- // the XML lexicon is used by default
- if (type == null)
- type = "XML";
-
- if ("NIH".AreEqual(type)) {
- // NIH lexicon
- lexicon = new NIHDBLexicon(prop.getProperty("DB_FILENAME"));
- } else {
- // XML lexicon
- lexicon = new XMLLexicon(prop.getProperty("XML_FILENAME"));
- }
- } catch (Exception e) {
- this.lexicon = new NIHDBLexicon(DB_FILENAME);
- }
-
- this.factory = new NLGFactory(lexicon);
- this.realiser = new Realiser(this.lexicon);
- }
-
- /**
- * Close the lexicon
- */
- @After
- public void tearDown() throws Exception {
-
- if (lexicon != null)
- lexicon.close();
- }
-
- /**
- * check that spelling variants are properly set
- */
- [Test]
- public void spellingVariantsTest() {
- WordElement asd = lexicon.getWord("Adams-Stokes disease");
- List spellVars = asd
- .getFeatureAsStringList(LexicalFeature.SPELL_VARS);
- Assert.assertTrue(spellVars.contains("Adams Stokes disease"));
- Assert.assertTrue(spellVars.contains("Adam-Stokes disease"));
- Assert.AreEqual(2, spellVars.size());
- Assert.AreEqual(asd.getBaseForm(), asd
- .getFeatureAsString(LexicalFeature.DEFAULT_SPELL));
-
- // default spell variant is baseform
- Assert.AreEqual("Adams-Stokes disease", asd
- .getDefaultSpellingVariant());
-
- // default spell variant changes
- asd.setDefaultSpellingVariant("Adams Stokes disease");
- Assert.AreEqual("Adams Stokes disease", asd
- .getDefaultSpellingVariant());
- }
-
- /**
- * Test spelling/orthographic variants with different inflections
- */
- [Test]
- public void spellingVariantWithInflectionTest() {
- WordElement word = lexicon.getWord("formalization");
- List spellVars = word
- .getFeatureAsStringList(LexicalFeature.SPELL_VARS);
- Assert.assertTrue(spellVars.contains("formalisation"));
- Assert.AreEqual(Inflection.REGULAR, word
- .getDefaultInflectionalVariant());
-
- // create with default spelling
- NPPhraseSpec np = factory.createNounPhrase("the", word);
- np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- Assert.AreEqual("the formalizations", this.realiser.realise(np)
- .getRealisation());
-
- // reset spell var
- word.setDefaultSpellingVariant("formalisation");
- Assert.AreEqual("the formalisations", this.realiser.realise(np)
- .getRealisation());
- }
-
- /**
- * Test the inflectional variants for a verb.
- */
- [Test]
- public void verbInflectionalVariantsTest() {
- WordElement word = lexicon.getWord("lie", LexicalCategory.VERB);
- Assert.AreEqual(Inflection.REGULAR, word
- .getDefaultInflectionalVariant());
-
- // default past is "lied"
- InflectedWordElement infl = new InflectedWordElement(word);
- infl.setFeature(Feature.TENSE, Tense.PAST);
- String past = realiser.realise(infl).getRealisation();
- Assert.AreEqual("lied", past);
-
- // switch to irregular
- word.setDefaultInflectionalVariant(Inflection.IRREGULAR);
- infl = new InflectedWordElement(word);
- infl.setFeature(Feature.TENSE, Tense.PAST);
- past = realiser.realise(infl).getRealisation();
- Assert.AreEqual("lay", past);
-
- // switch back to regular
- word.setDefaultInflectionalVariant(Inflection.REGULAR);
- Assert.AreEqual(null, word.getFeature(LexicalFeature.PAST));
- infl = new InflectedWordElement(word);
- infl.setFeature(Feature.TENSE, Tense.PAST);
- past = realiser.realise(infl).getRealisation();
- Assert.AreEqual("lied", past);
- }
-
- /**
- * Test inflectional variants for nouns
- */
- [Test]
- public void nounInflectionalVariantsTest() {
- WordElement word = lexicon.getWord("sanctum", LexicalCategory.NOUN);
- Assert.AreEqual(Inflection.REGULAR, word
- .getDefaultInflectionalVariant());
-
- // reg plural shouldn't be stored
- Assert.AreEqual(null, word.getFeature(LexicalFeature.PLURAL));
- InflectedWordElement infl = new InflectedWordElement(word);
- infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- String plur = realiser.realise(infl).getRealisation();
- Assert.AreEqual("sanctums", plur);
-
- // switch to glreg
- word.setDefaultInflectionalVariant(Inflection.GRECO_LATIN_REGULAR);
- infl = new InflectedWordElement(word);
- infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- plur = realiser.realise(infl).getRealisation();
- Assert.AreEqual("sancta", plur);
-
- // and back to reg
- word.setDefaultInflectionalVariant(Inflection.REGULAR);
- infl = new InflectedWordElement(word);
- infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- plur = realiser.realise(infl).getRealisation();
- Assert.AreEqual("sanctums", plur);
- }
-
- /**
- * Check that spelling variants are preserved during realisation of NPs
- */
- [Test]
- public void spellingVariantsInNPTest() {
- WordElement asd = lexicon.getWord("Adams-Stokes disease");
- Assert.AreEqual("Adams-Stokes disease", asd
- .getDefaultSpellingVariant());
- NPPhraseSpec np = this.factory.createNounPhrase(asd);
- np.setSpecifier(lexicon.getWord("the"));
- Assert.AreEqual("the Adams-Stokes disease", this.realiser.realise(
- np).getRealisation());
-
- // change spelling var
- asd.setDefaultSpellingVariant("Adams Stokes disease");
- Assert.AreEqual("Adams Stokes disease", asd
- .getDefaultSpellingVariant());
- Assert.AreEqual("the Adams Stokes disease", this.realiser.realise(
- np).getRealisation());
-
- //default infl for this word is uncount
- np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- Assert.AreEqual("the Adams Stokes disease", this.realiser.realise(
- np).getRealisation());
-
- //change default infl for this word
- asd.setDefaultInflectionalVariant(Inflection.REGULAR);
- Assert.AreEqual("the Adams Stokes diseases", this.realiser.realise(
- np).getRealisation());
- }
-
- /**
- * Check that spelling variants are preserved during realisation of VPs
- */
- [Test]
- public void spellingVariantsInVPTest() {
- WordElement eth = (WordElement) factory.createWord("etherise",
- LexicalCategory.VERB);
- Assert.AreEqual("etherize", eth.getDefaultSpellingVariant());
- eth.setDefaultSpellingVariant("etherise");
- Assert.AreEqual("etherise", eth.getDefaultSpellingVariant());
- SPhraseSpec s = this.factory.createClause(this.factory
- .createNounPhrase("the", "doctor"), eth, this.factory.createNounPhrase("the patient"));
- Assert.AreEqual("the doctor etherises the patient", this.realiser.realise(s).getRealisation());
- }
-
- /**
- * Test the difference between an uncount and a count noun
- */
- [Test]
- public void uncountInflectionalVariantTest() {
- WordElement calc = (WordElement) factory.createWord("calcification", LexicalCategory.NOUN);
- NPPhraseSpec theCalc = this.factory.createNounPhrase("the", calc);
- theCalc.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
-
- String r1 = this.realiser.realise(theCalc).getRealisation();
- Assert.AreEqual("the calcifications", r1);
-
- calc.setDefaultInflectionalVariant(Inflection.UNCOUNT);
- NPPhraseSpec theCalc2 = this.factory.createNounPhrase("the", calc);
- theCalc2.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- String r2 = this.realiser.realise(theCalc2).getRealisation();
- Assert.AreEqual("the calcification", r2);
-
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/lexicon/MultipleLexiconTest.java b/SharpSimpleNLGUnitTests/lexicon/MultipleLexiconTest.java
deleted file mode 100644
index 73425bc..0000000
--- a/SharpSimpleNLGUnitTests/lexicon/MultipleLexiconTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.lexicon.english;
-
-import java.io.File;
-import java.io.FileReader;
-import java.util.Properties;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.features.LexicalFeature;
-import simplenlg.framework.WordElement;
-import simplenlg.lexicon.MultipleLexicon;
-import simplenlg.lexicon.NIHDBLexicon;
-import simplenlg.lexicon.XMLLexicon;
-
-/**
- * @author Dave Westwater, Data2Text Ltd
- *
- */
-public class MultipleLexiconTest {
-
- // NIH, XML lexicon location
- static String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
- static String XML_FILENAME = "src/main/resources/default-lexicon.xml";
-
- // multi lexicon
- MultipleLexicon lexicon;
-
-
- @Before
- public void setUp() throws Exception {
- try {
- Properties prop = new Properties();
- FileReader reader = new FileReader(new File("./src/main/resources/lexicon.properties"));
- prop.load(reader);
-
- String xmlFile = prop.getProperty("XML_FILENAME");
- String dbFile = prop.getProperty("DB_FILENAME");
-
- this.lexicon = new MultipleLexicon(new XMLLexicon(xmlFile),
- new NIHDBLexicon(dbFile));
- } catch (Exception e) {
- e.printStackTrace();
- this.lexicon = new MultipleLexicon(new XMLLexicon(XML_FILENAME),
- new NIHDBLexicon(DB_FILENAME));
- }
- }
-
- @After
- public void tearDown() throws Exception {
- lexicon.close();
- }
-
- [Test]
- public void basicLexiconTests() {
- SharedLexiconTests tests = new SharedLexiconTests();
- tests.doBasicTests(lexicon);
- }
-
- [Test]
- public void multipleSpecificsTests() {
- // try to get word which is only in NIH lexicon
- WordElement UK = lexicon.getWord("UK");
-
- Assert.AreEqual(true, UK.getFeatureAsString(LexicalFeature.ACRONYM_OF).contains("United Kingdom"));
-
- // test alwaysSearchAll flag
- boolean alwaysSearchAll = lexicon.isAlwaysSearchAll();
-
- // tree as noun exists in both, but as verb only in NIH
- lexicon.setAlwaysSearchAll(true);
- Assert.AreEqual(3, lexicon.getWords("tree").size()); // 3 = once in XML plus twice in NIH
-
- lexicon.setAlwaysSearchAll(false);
- Assert.AreEqual(1, lexicon.getWords("tree").size());
-
- // restore flag to original state
- lexicon.setAlwaysSearchAll(alwaysSearchAll);
- }
-
-
-}
diff --git a/SharpSimpleNLGUnitTests/lexicon/NIHDBLexiconTest.java b/SharpSimpleNLGUnitTests/lexicon/NIHDBLexiconTest.java
deleted file mode 100644
index 838e844..0000000
--- a/SharpSimpleNLGUnitTests/lexicon/NIHDBLexiconTest.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.lexicon.english;
-
-import java.util.List;
-import java.util.Properties;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.features.LexicalFeature;
-import simplenlg.features.NumberAgreement;
-import simplenlg.features.Person;
-import simplenlg.features.Tense;
-import simplenlg.framework.InflectedWordElement;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.NLGElement;
-import simplenlg.framework.WordElement;
-import simplenlg.lexicon.NIHDBLexicon;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * Tests for NIHDBLexicon
- *
- * @author Ehud Reiter, Albert Gatt
- */
-public class NIHDBLexiconTest {
-
- // lexicon object -- an instance of Lexicon
- NIHDBLexicon lexicon = null;
-
- // DB location -- change this to point to the lex access data dir
- static String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
-
- @Before
- /*
- * * Sets up the accessor and runs it -- takes ca. 26 sec
- */
- public void setUp() {
- // use property file for the lexicon
- try {
- Properties prop = new Properties();
- prop.load(getClass().getClassLoader().
- getResourceAsStream("lexicon.properties"));
-
- String lexiconPath = prop.getProperty("DB_FILENAME");
-
- if (null != lexiconPath)
- this.lexicon = new NIHDBLexicon(lexiconPath);
- } catch (Exception e) {
- this.lexicon = new NIHDBLexicon(DB_FILENAME);
- }
- }
-
- /**
- * Close the lexicon
- */
- @After
- public void tearDown() throws Exception {
- if (lexicon != null)
- lexicon.close();
- }
-
- /**
- * Runs basic Lexicon Tests.
- */
- [Test]
- public void basicLexiconTests() {
- SharedLexiconTests tests = new SharedLexiconTests();
- tests.doBasicTests(lexicon);
- }
-
- /**
- * Verb 'be' conjugation tests.
- */
- public void beInflectionTest() {
- Realiser r = new Realiser();
- WordElement word = lexicon.getWord("be", LexicalCategory.VERB);
- InflectedWordElement inflWord = new InflectedWordElement(word);
-
- //1st person sg past
- inflWord.setFeature(Feature.PERSON, Person.FIRST);
- inflWord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.AreEqual("was", r.realise(inflWord).toString());
-
- //2nd person sg past
- inflWord.setFeature(Feature.PERSON, Person.SECOND);
- inflWord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.AreEqual("were", r.realise(inflWord).toString());
-
- //3rd person sg past
- inflWord.setFeature(Feature.PERSON, Person.THIRD);
- inflWord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.AreEqual("was", r.realise(inflWord).toString());
-
- //1st person sg present
- inflWord.setFeature(Feature.PERSON, Person.FIRST);
- inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
- Assert.AreEqual("am", r.realise(inflWord).toString());
-
- //2nd person sg present
- inflWord.setFeature(Feature.PERSON, Person.SECOND);
- inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
- Assert.AreEqual("are", r.realise(inflWord).toString());
-
- //3rd person sg present
- inflWord.setFeature(Feature.PERSON, Person.THIRD);
- inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
- Assert.AreEqual("is", r.realise(inflWord).toString());
-
- inflWord.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
-
- //1st person pl past
- inflWord.setFeature(Feature.PERSON, Person.FIRST);
- inflWord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.AreEqual("were", r.realise(inflWord).toString());
-
- //2nd person pl past
- inflWord.setFeature(Feature.PERSON, Person.SECOND);
- inflWord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.AreEqual("were", r.realise(inflWord).toString());
-
- //3rd person pl past
- inflWord.setFeature(Feature.PERSON, Person.THIRD);
- inflWord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.AreEqual("were", r.realise(inflWord).toString());
-
- //1st person pl present
- inflWord.setFeature(Feature.PERSON, Person.FIRST);
- inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
- Assert.AreEqual("are", r.realise(inflWord).toString());
-
- //2nd person pl present
- inflWord.setFeature(Feature.PERSON, Person.SECOND);
- inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
- Assert.AreEqual("are", r.realise(inflWord).toString());
-
- //3rd person pl present
- inflWord.setFeature(Feature.PERSON, Person.THIRD);
- inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
- Assert.AreEqual("are", r.realise(inflWord).toString());
-
- }
-
- /**
- * Tests the lexicon for recall of Acryonms.
- */
- [Test]
- public void acronymsTests() {
- WordElement uk = lexicon.getWord("UK");
- WordElement unitedKingdom = lexicon.getWord("United Kingdom");
- List fullForms = uk
- .getFeatureAsElementList(LexicalFeature.ACRONYM_OF);
-
- // "uk" is an acronym of 3 full forms
- Assert.AreEqual(3, fullForms.size());
- Assert.assertTrue(fullForms.contains(unitedKingdom));
- }
-
- /**
- * Tests the lexicon for recall of baseforms with their standard inflected forms.
- */
- [Test]
- public void standardInflectionsTest() {
- // test keepStandardInflection flag
- boolean keepInflectionsFlag = lexicon.isKeepStandardInflections();
-
- lexicon.setKeepStandardInflections(true);
- WordElement dog = lexicon.getWord("dog", LexicalCategory.NOUN);
- Assert.AreEqual("dogs", dog
- .getFeatureAsString(LexicalFeature.PLURAL));
-
- lexicon.setKeepStandardInflections(false);
- WordElement cat = lexicon.getWord("cat", LexicalCategory.NOUN);
- Assert
- .AreEqual(null, cat
- .getFeatureAsString(LexicalFeature.PLURAL));
-
- // restore flag to original state
- lexicon.setKeepStandardInflections(keepInflectionsFlag);
- }
-
- /**
- * Test for NIHDBLexicon functionality when several threads are using the
- * same Lexicon
- */
- @SuppressWarnings("static-access")
- public void multiThreadAppAccessTest() {
-
- LexThread runner1 = new LexThread("lie");
- LexThread runner2 = new LexThread("bark");
-
- // schedule them and run them
- ScheduledExecutorService service = Executors.newScheduledThreadPool(2);
- service.schedule(runner1, 0, TimeUnit.MILLISECONDS);
- service.schedule(runner2, 0, TimeUnit.MILLISECONDS);
-
- try {
- Thread.currentThread().sleep(500);
- } catch (InterruptedException ie) {
- ;// do nothing
- }
-
- service.shutdownNow();
-
- // check that the right words have been retrieved
- Assert.AreEqual("lie", runner1.word.getBaseForm());
- Assert.AreEqual("bark", runner2.word.getBaseForm());
- }
-
- /*
- * Class that implements a thread from which a lexical item can be retrieved
- */
- private class LexThread extends Thread {
- WordElement word;
- String base;
-
- public LexThread(String base) {
- this.base = base;
- }
-
- public void run() {
- word = lexicon.getWord(base, LexicalCategory.VERB);
- }
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/lexicon/SharedLexiconTests.java b/SharpSimpleNLGUnitTests/lexicon/SharedLexiconTests.java
deleted file mode 100644
index 413b6ce..0000000
--- a/SharpSimpleNLGUnitTests/lexicon/SharedLexiconTests.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.lexicon.english;
-
-import junit.framework.Assert;
-import simplenlg.features.Inflection;
-import simplenlg.features.LexicalFeature;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.WordElement;
-import simplenlg.lexicon.Lexicon;
-
-/**
- * @author Dave Westwater, Data2Text Ltd
- *
- */
-public class SharedLexiconTests {
-
- public void doBasicTests(Lexicon lexicon) {
- // test getWords. Should be 2 "can" (of any cat), 1 noun tree, 0 adj
- // trees
- Assert.AreEqual(3, lexicon.getWords("can").size());
- Assert.AreEqual(1, lexicon.getWords("can", LexicalCategory.NOUN)
- .size());
- Assert.AreEqual(0, lexicon.getWords("can",
- LexicalCategory.ADJECTIVE).size());
-
- // below test removed as standard morph variants no longer recorded in
- // lexicon
- // WordElement early = lexicon.getWord("early",
- // LexicalCategory.ADJECTIVE);
- // Assert.AreEqual("earlier",
- // early.getFeatureAsString(Feature.COMPARATIVE));
-
- // test getWord. Comparative of ADJ "good" is "better", superlative is
- // "best", this is a qualitative and predicative adjective
- WordElement good = lexicon.getWord("good", LexicalCategory.ADJECTIVE);
- Assert.AreEqual("better", good
- .getFeatureAsString(LexicalFeature.COMPARATIVE));
- Assert.AreEqual("best", good
- .getFeatureAsString(LexicalFeature.SUPERLATIVE));
- Assert.AreEqual(true, good.getFeatureAsBoolean(
- LexicalFeature.QUALITATIVE).booleanValue());
- Assert.AreEqual(true, good.getFeatureAsBoolean(
- LexicalFeature.PREDICATIVE).booleanValue());
- Assert.AreEqual(false, good.getFeatureAsBoolean(
- LexicalFeature.COLOUR).booleanValue());
- Assert.AreEqual(false, good.getFeatureAsBoolean(
- LexicalFeature.CLASSIFYING).booleanValue());
-
- // test getWord. There is only one "woman", and its plural is "women".
- // It is not an acronym, not proper, and countable
- WordElement woman = lexicon.getWord("woman");
-
- Assert.AreEqual("women", woman
- .getFeatureAsString(LexicalFeature.PLURAL));
- Assert.AreEqual(null, woman
- .getFeatureAsString(LexicalFeature.ACRONYM_OF));
- Assert.AreEqual(false, woman.getFeatureAsBoolean(
- LexicalFeature.PROPER).booleanValue());
- Assert.assertFalse(woman.hasInflectionalVariant(Inflection.UNCOUNT));
-
- // NB: This fails if the lexicon is XMLLexicon. No idea why.
- // Assert.AreEqual("irreg",
- // woman.getFeatureAsString(LexicalFeature.DEFAULT_INFL));
-
- // test getWord. Noun "sand" is non-count
- WordElement sand = lexicon.getWord("sand", LexicalCategory.NOUN);
- Assert.AreEqual(true, sand.hasInflectionalVariant(Inflection.UNCOUNT));
- Assert.AreEqual(Inflection.UNCOUNT, sand.getDefaultInflectionalVariant());
-
- // test hasWord
- Assert.AreEqual(true, lexicon.hasWord("tree")); // "tree" exists
- Assert.AreEqual(false, lexicon.hasWord("tree",
- LexicalCategory.ADVERB)); // but not as an adverb
-
- // test getWordByID; quickly, also check that this is a verb_modifier
- WordElement quickly = lexicon.getWordByID("E0051632");
- Assert.AreEqual("quickly", quickly.getBaseForm());
- Assert.AreEqual(LexicalCategory.ADVERB, quickly.getCategory());
- Assert.AreEqual(true, quickly.getFeatureAsBoolean(
- LexicalFeature.VERB_MODIFIER).booleanValue());
- Assert.AreEqual(false, quickly.getFeatureAsBoolean(
- LexicalFeature.SENTENCE_MODIFIER).booleanValue());
- Assert.AreEqual(false, quickly.getFeatureAsBoolean(
- LexicalFeature.INTENSIFIER).booleanValue());
-
- // test getWordFromVariant, verb type (tran or intran, not ditran)
- WordElement eat = lexicon.getWordFromVariant("eating");
- Assert.AreEqual("eat", eat.getBaseForm());
- Assert.AreEqual(LexicalCategory.VERB, eat.getCategory());
- Assert.AreEqual(true, eat.getFeatureAsBoolean(
- LexicalFeature.INTRANSITIVE).booleanValue());
- Assert.AreEqual(true, eat.getFeatureAsBoolean(
- LexicalFeature.TRANSITIVE).booleanValue());
- Assert.AreEqual(false, eat.getFeatureAsBoolean(
- LexicalFeature.DITRANSITIVE).booleanValue());
-
- // test BE is handled OK
- Assert.AreEqual("been", lexicon.getWordFromVariant("is",
- LexicalCategory.VERB).getFeatureAsString(
- LexicalFeature.PAST_PARTICIPLE));
-
- // test modal
- WordElement can = lexicon.getWord("can", LexicalCategory.MODAL);
- Assert.AreEqual("could", can
- .getFeatureAsString(LexicalFeature.PAST));
-
- // test non-existent word
- Assert.AreEqual(0, lexicon.getWords("akjmchsgk").size());
-
- // test lookup word method
- Assert.AreEqual(lexicon.lookupWord("say", LexicalCategory.VERB)
- .getBaseForm(), "say");
- Assert.AreEqual(lexicon.lookupWord("said", LexicalCategory.VERB)
- .getBaseForm(), "say");
- Assert.AreEqual(lexicon
- .lookupWord("E0054448", LexicalCategory.VERB).getBaseForm(),
- "say");
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/lexicon/XMLLexiconTest.cs b/SharpSimpleNLGUnitTests/lexicon/XMLLexiconTest.cs
deleted file mode 100644
index fd4267a..0000000
--- a/SharpSimpleNLGUnitTests/lexicon/XMLLexiconTest.cs
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using System;
-using System.Diagnostics;
-using FluentAssertions;
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.lexicon
-{
-
- /**
- * @author D. Westwater, Data2Text Ltd
- *
- */
-
- public class XMLLexiconTest
- {
-
- // lexicon object -- an instance of Lexicon
- XMLLexicon lexicon = null;
-
-
- [Test]
- public void setUp_from_EmbeddedResource()
- {
- var timer = new Stopwatch();
- timer.Start();
- this.lexicon = new XMLLexicon();
- timer.Stop();
- Console.WriteLine($"Loading Lexicon took: {timer.ElapsedMilliseconds}ms");
- }
-
-
- [Test]
- public void setUp_from_Filepath()
- {
- var timer = new Stopwatch();
- timer.Start();
- this.lexicon = new XMLLexicon(@"C:\work\SharpSimpleNLG\SharpSimpleNLGDotNetCore\lexicon\default-lexicon.xml");
- timer.Stop();
- Console.WriteLine($"Loading Lexicon took: {timer.ElapsedMilliseconds}ms");
- }
-
-
- /**
- * Tests the immutability of the XMLLexicon by checking to make sure features
- * are not inadvertently propagated to the canonical XMLLexicon WordElement object.
- */
-
- [Test]
- public void xmlLexiconImmutabilityTest()
- {
- this.lexicon = new XMLLexicon();
- NLGFactory factory = new NLGFactory(lexicon);
- Realiser realiser = new Realiser(lexicon);
-
- // "wall" is singular.
- NPPhraseSpec wall = factory.createNounPhrase("the", "wall");
- Assert.AreEqual(NumberAgreement.SINGULAR, wall.getFeature(Feature.NUMBER.ToString()));
-
- // Realise a sentence with plural form of "wall"
- wall.setPlural(true);
- SPhraseSpec sentence = factory.createClause("motion", "observe");
- sentence.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- PPPhraseSpec pp = factory.createPrepositionPhrase("in", wall);
- sentence.addPostModifier(pp);
- var r = realiser.realiseSentence(sentence);
-
- Assert.AreEqual(r, "Motion observed in the walls.");
-
- // Create a new 'the wall' NP and check to make sure that the syntax processor has
- // not propagated plurality to the canonical XMLLexicon WordElement object.
- wall = factory.createNounPhrase("the", "wall");
- Assert.AreEqual(NumberAgreement.SINGULAR, wall.getFeature(Feature.NUMBER.ToString()));
- }
-
- [Test]
- public void xmlLexiconLookupTests()
- {
- this.lexicon = new XMLLexicon();
-
- var w = lexicon.getWords("man");
- w.Count.ShouldBeEquivalentTo(1);
- w[0].getBaseForm().ShouldBeEquivalentTo("man");
- w[0].features.Count.ShouldBeEquivalentTo(2);
- w[0].getId().ShouldBeEquivalentTo("E0038767");
- }
-
- [Test]
- public void xmlLexiconLookupWord()
- {
- this.lexicon = new XMLLexicon();
- var w = lexicon.lookupWord("man", new LexicalCategory_NOUN());
- var id = w.getId();
- Assert.IsNotNull(id);
- Assert.IsNotEmpty(id);
- id.ShouldBeEquivalentTo("E0038767");
- }
-
- [Test]
- public void xmlLexiconLookupWord_plurals()
- {
- this.lexicon = new XMLLexicon();
- var w1 = lexicon.lookupWord("man", new LexicalCategory_NOUN());
- var w2 = w1.getFeature(LexicalFeature.PLURAL.ToString());
- w2.ShouldBeEquivalentTo("men");
- }
-
-
- [Test]
- public void xmlLexiconGetWordVariants()
- {
- this.lexicon = new XMLLexicon();
- var w = lexicon.getWordsFromVariant("did");
- var resw = w[0];
- Assert.IsNotNull(resw);
- resw.getAllFeatures().Count.ShouldBeEquivalentTo(8);
- var form1 = resw.getFeature(LexicalFeature.PAST);
- form1.ShouldBeEquivalentTo("did");
- var form2 = resw.getFeature(LexicalFeature.PRESENT3S);
- form2.ShouldBeEquivalentTo("does");
- var form3 = resw.getFeature(LexicalFeature.PAST_PARTICIPLE);
- form3.ShouldBeEquivalentTo("done");
- var form4 = resw.getFeature(LexicalFeature.PRESENT_PARTICIPLE);
- form4.ShouldBeEquivalentTo("doing");
- }
-
- }
-
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/lexicon/english/LexicalVariantsTest.java b/SharpSimpleNLGUnitTests/lexicon/english/LexicalVariantsTest.java
deleted file mode 100644
index e316e16..0000000
--- a/SharpSimpleNLGUnitTests/lexicon/english/LexicalVariantsTest.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.lexicon.english;
-
-import java.util.List;
-import java.util.Properties;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.features.Inflection;
-import simplenlg.features.LexicalFeature;
-import simplenlg.features.NumberAgreement;
-import simplenlg.features.Tense;
-import simplenlg.framework.InflectedWordElement;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.NLGFactory;
-import simplenlg.framework.WordElement;
-import simplenlg.lexicon.NIHDBLexicon;
-import simplenlg.lexicon.XMLLexicon;
-import simplenlg.lexicon.Lexicon;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * Tests on the use of spelling and inflectional variants, using the
- * NIHDBLexicon.
- *
- * @author bertugatt
- *
- */
-public class LexicalVariantsTest {
-
- // lexicon object -- an instance of Lexicon
- Lexicon lexicon = null;
-
- // factory for phrases
- NLGFactory factory;
-
- // realiser
- Realiser realiser;
-
- // DB location -- change this to point to the lex access data dir
- static String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
-
- @Before
- /*
- * * Sets up the accessor and runs it -- takes ca. 26 sec
- */
- public void setUp() {
- // use property file for the lexicon
- try {
- Properties prop = new Properties();
- prop.load(getClass().getClassLoader().
- getResourceAsStream("lexicon.properties"));
-
- String type = prop.getProperty("LexiconType");
-
- // the XML lexicon is used by default
- if (type == null)
- type = "XML";
-
- if ("NIH".equals(type)) {
- // NIH lexicon
- lexicon = new NIHDBLexicon(prop.getProperty("DB_FILENAME"));
- } else {
- // XML lexicon
- lexicon = new XMLLexicon(prop.getProperty("XML_FILENAME"));
- }
- } catch (Exception e) {
- this.lexicon = new NIHDBLexicon(DB_FILENAME);
- }
-
- this.factory = new NLGFactory(lexicon);
- this.realiser = new Realiser(this.lexicon);
- }
-
- /**
- * Close the lexicon
- */
- @After
- public void tearDown() throws Exception {
-
- if (lexicon != null)
- lexicon.close();
- }
-
- /**
- * check that spelling variants are properly set
- */
- @Test
- public void spellingVariantsTest() {
- WordElement asd = lexicon.getWord("Adams-Stokes disease");
- List spellVars = asd
- .getFeatureAsStringList(LexicalFeature.SPELL_VARS);
- Assert.assertTrue(spellVars.contains("Adams Stokes disease"));
- Assert.assertTrue(spellVars.contains("Adam-Stokes disease"));
- Assert.assertEquals(2, spellVars.size());
- Assert.assertEquals(asd.getBaseForm(), asd
- .getFeatureAsString(LexicalFeature.DEFAULT_SPELL));
-
- // default spell variant is baseform
- Assert.assertEquals("Adams-Stokes disease", asd
- .getDefaultSpellingVariant());
-
- // default spell variant changes
- asd.setDefaultSpellingVariant("Adams Stokes disease");
- Assert.assertEquals("Adams Stokes disease", asd
- .getDefaultSpellingVariant());
- }
-
- /**
- * Test spelling/orthographic variants with different inflections
- */
- @Test
- public void spellingVariantWithInflectionTest() {
- WordElement word = lexicon.getWord("formalization");
- List spellVars = word
- .getFeatureAsStringList(LexicalFeature.SPELL_VARS);
- Assert.assertTrue(spellVars.contains("formalisation"));
- Assert.assertEquals(Inflection.REGULAR, word
- .getDefaultInflectionalVariant());
-
- // create with default spelling
- NPPhraseSpec np = factory.createNounPhrase("the", word);
- np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- Assert.assertEquals("the formalizations", this.realiser.realise(np)
- .getRealisation());
-
- // reset spell var
- word.setDefaultSpellingVariant("formalisation");
- Assert.assertEquals("the formalisations", this.realiser.realise(np)
- .getRealisation());
- }
-
- /**
- * Test the inflectional variants for a verb.
- */
- @Test
- public void verbInflectionalVariantsTest() {
- WordElement word = lexicon.getWord("lie", LexicalCategory.VERB);
- Assert.assertEquals(Inflection.REGULAR, word
- .getDefaultInflectionalVariant());
-
- // default past is "lied"
- InflectedWordElement infl = new InflectedWordElement(word);
- infl.setFeature(Feature.TENSE, Tense.PAST);
- String past = realiser.realise(infl).getRealisation();
- Assert.assertEquals("lied", past);
-
- // switch to irregular
- word.setDefaultInflectionalVariant(Inflection.IRREGULAR);
- infl = new InflectedWordElement(word);
- infl.setFeature(Feature.TENSE, Tense.PAST);
- past = realiser.realise(infl).getRealisation();
- Assert.assertEquals("lay", past);
-
- // switch back to regular
- word.setDefaultInflectionalVariant(Inflection.REGULAR);
- Assert.assertEquals(null, word.getFeature(LexicalFeature.PAST));
- infl = new InflectedWordElement(word);
- infl.setFeature(Feature.TENSE, Tense.PAST);
- past = realiser.realise(infl).getRealisation();
- Assert.assertEquals("lied", past);
- }
-
- /**
- * Test inflectional variants for nouns
- */
- @Test
- public void nounInflectionalVariantsTest() {
- WordElement word = lexicon.getWord("sanctum", LexicalCategory.NOUN);
- Assert.assertEquals(Inflection.REGULAR, word
- .getDefaultInflectionalVariant());
-
- // reg plural shouldn't be stored
- Assert.assertEquals(null, word.getFeature(LexicalFeature.PLURAL));
- InflectedWordElement infl = new InflectedWordElement(word);
- infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- String plur = realiser.realise(infl).getRealisation();
- Assert.assertEquals("sanctums", plur);
-
- // switch to glreg
- word.setDefaultInflectionalVariant(Inflection.GRECO_LATIN_REGULAR);
- infl = new InflectedWordElement(word);
- infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- plur = realiser.realise(infl).getRealisation();
- Assert.assertEquals("sancta", plur);
-
- // and back to reg
- word.setDefaultInflectionalVariant(Inflection.REGULAR);
- infl = new InflectedWordElement(word);
- infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- plur = realiser.realise(infl).getRealisation();
- Assert.assertEquals("sanctums", plur);
- }
-
- /**
- * Check that spelling variants are preserved during realisation of NPs
- */
- @Test
- public void spellingVariantsInNPTest() {
- WordElement asd = lexicon.getWord("Adams-Stokes disease");
- Assert.assertEquals("Adams-Stokes disease", asd
- .getDefaultSpellingVariant());
- NPPhraseSpec np = this.factory.createNounPhrase(asd);
- np.setSpecifier(lexicon.getWord("the"));
- Assert.assertEquals("the Adams-Stokes disease", this.realiser.realise(
- np).getRealisation());
-
- // change spelling var
- asd.setDefaultSpellingVariant("Adams Stokes disease");
- Assert.assertEquals("Adams Stokes disease", asd
- .getDefaultSpellingVariant());
- Assert.assertEquals("the Adams Stokes disease", this.realiser.realise(
- np).getRealisation());
-
- //default infl for this word is uncount
- np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- Assert.assertEquals("the Adams Stokes disease", this.realiser.realise(
- np).getRealisation());
-
- //change default infl for this word
- asd.setDefaultInflectionalVariant(Inflection.REGULAR);
- Assert.assertEquals("the Adams Stokes diseases", this.realiser.realise(
- np).getRealisation());
- }
-
- /**
- * Check that spelling variants are preserved during realisation of VPs
- */
- @Test
- public void spellingVariantsInVPTest() {
- WordElement eth = (WordElement) factory.createWord("etherise",
- LexicalCategory.VERB);
- Assert.assertEquals("etherize", eth.getDefaultSpellingVariant());
- eth.setDefaultSpellingVariant("etherise");
- Assert.assertEquals("etherise", eth.getDefaultSpellingVariant());
- SPhraseSpec s = this.factory.createClause(this.factory
- .createNounPhrase("the", "doctor"), eth, this.factory.createNounPhrase("the patient"));
- Assert.assertEquals("the doctor etherises the patient", this.realiser.realise(s).getRealisation());
- }
-
- /**
- * Test the difference between an uncount and a count noun
- */
- @Test
- public void uncountInflectionalVariantTest() {
- WordElement calc = (WordElement) factory.createWord("calcification", LexicalCategory.NOUN);
- NPPhraseSpec theCalc = this.factory.createNounPhrase("the", calc);
- theCalc.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
-
- String r1 = this.realiser.realise(theCalc).getRealisation();
- Assert.assertEquals("the calcifications", r1);
-
- calc.setDefaultInflectionalVariant(Inflection.UNCOUNT);
- NPPhraseSpec theCalc2 = this.factory.createNounPhrase("the", calc);
- theCalc2.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- String r2 = this.realiser.realise(theCalc2).getRealisation();
- Assert.assertEquals("the calcification", r2);
-
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/lexicon/english/MultipleLexiconTest.java b/SharpSimpleNLGUnitTests/lexicon/english/MultipleLexiconTest.java
deleted file mode 100644
index 3b9df74..0000000
--- a/SharpSimpleNLGUnitTests/lexicon/english/MultipleLexiconTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.lexicon.english;
-
-import java.io.File;
-import java.io.FileReader;
-import java.util.Properties;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.features.LexicalFeature;
-import simplenlg.framework.WordElement;
-import simplenlg.lexicon.MultipleLexicon;
-import simplenlg.lexicon.NIHDBLexicon;
-import simplenlg.lexicon.XMLLexicon;
-
-/**
- * @author Dave Westwater, Data2Text Ltd
- *
- */
-public class MultipleLexiconTest {
-
- // NIH, XML lexicon location
- static String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
- static String XML_FILENAME = "src/main/resources/default-lexicon.xml";
-
- // multi lexicon
- MultipleLexicon lexicon;
-
-
- @Before
- public void setUp() throws Exception {
- try {
- Properties prop = new Properties();
- FileReader reader = new FileReader(new File("./src/main/resources/lexicon.properties"));
- prop.load(reader);
-
- String xmlFile = prop.getProperty("XML_FILENAME");
- String dbFile = prop.getProperty("DB_FILENAME");
-
- this.lexicon = new MultipleLexicon(new XMLLexicon(xmlFile),
- new NIHDBLexicon(dbFile));
- } catch (Exception e) {
- e.printStackTrace();
- this.lexicon = new MultipleLexicon(new XMLLexicon(XML_FILENAME),
- new NIHDBLexicon(DB_FILENAME));
- }
- }
-
- @After
- public void tearDown() throws Exception {
- lexicon.close();
- }
-
- @Test
- public void basicLexiconTests() {
- SharedLexiconTests tests = new SharedLexiconTests();
- tests.doBasicTests(lexicon);
- }
-
- @Test
- public void multipleSpecificsTests() {
- // try to get word which is only in NIH lexicon
- WordElement UK = lexicon.getWord("UK");
-
- Assert.assertEquals(true, UK.getFeatureAsString(LexicalFeature.ACRONYM_OF).contains("United Kingdom"));
-
- // test alwaysSearchAll flag
- boolean alwaysSearchAll = lexicon.isAlwaysSearchAll();
-
- // tree as noun exists in both, but as verb only in NIH
- lexicon.setAlwaysSearchAll(true);
- Assert.assertEquals(3, lexicon.getWords("tree").size()); // 3 = once in XML plus twice in NIH
-
- lexicon.setAlwaysSearchAll(false);
- Assert.assertEquals(1, lexicon.getWords("tree").size());
-
- // restore flag to original state
- lexicon.setAlwaysSearchAll(alwaysSearchAll);
- }
-
-
-}
diff --git a/SharpSimpleNLGUnitTests/lexicon/english/NIHDBLexiconTest.java b/SharpSimpleNLGUnitTests/lexicon/english/NIHDBLexiconTest.java
deleted file mode 100644
index 232aba8..0000000
--- a/SharpSimpleNLGUnitTests/lexicon/english/NIHDBLexiconTest.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.lexicon.english;
-
-import java.util.List;
-import java.util.Properties;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.features.LexicalFeature;
-import simplenlg.features.NumberAgreement;
-import simplenlg.features.Person;
-import simplenlg.features.Tense;
-import simplenlg.framework.InflectedWordElement;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.NLGElement;
-import simplenlg.framework.WordElement;
-import simplenlg.lexicon.NIHDBLexicon;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * Tests for NIHDBLexicon
- *
- * @author Ehud Reiter, Albert Gatt
- */
-public class NIHDBLexiconTest {
-
- // lexicon object -- an instance of Lexicon
- NIHDBLexicon lexicon = null;
-
- // DB location -- change this to point to the lex access data dir
- static String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
-
- @Before
- /*
- * * Sets up the accessor and runs it -- takes ca. 26 sec
- */
- public void setUp() {
- // use property file for the lexicon
- try {
- Properties prop = new Properties();
- prop.load(getClass().getClassLoader().
- getResourceAsStream("lexicon.properties"));
-
- String lexiconPath = prop.getProperty("DB_FILENAME");
-
- if (null != lexiconPath)
- this.lexicon = new NIHDBLexicon(lexiconPath);
- } catch (Exception e) {
- this.lexicon = new NIHDBLexicon(DB_FILENAME);
- }
- }
-
- /**
- * Close the lexicon
- */
- @After
- public void tearDown() throws Exception {
- if (lexicon != null)
- lexicon.close();
- }
-
- /**
- * Runs basic Lexicon Tests.
- */
- @Test
- public void basicLexiconTests() {
- SharedLexiconTests tests = new SharedLexiconTests();
- tests.doBasicTests(lexicon);
- }
-
- /**
- * Verb 'be' conjugation tests.
- */
- public void beInflectionTest() {
- Realiser r = new Realiser();
- WordElement word = lexicon.getWord("be", LexicalCategory.VERB);
- InflectedWordElement inflWord = new InflectedWordElement(word);
-
- //1st person sg past
- inflWord.setFeature(Feature.PERSON, Person.FIRST);
- inflWord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals("was", r.realise(inflWord).toString());
-
- //2nd person sg past
- inflWord.setFeature(Feature.PERSON, Person.SECOND);
- inflWord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals("were", r.realise(inflWord).toString());
-
- //3rd person sg past
- inflWord.setFeature(Feature.PERSON, Person.THIRD);
- inflWord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals("was", r.realise(inflWord).toString());
-
- //1st person sg present
- inflWord.setFeature(Feature.PERSON, Person.FIRST);
- inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
- Assert.assertEquals("am", r.realise(inflWord).toString());
-
- //2nd person sg present
- inflWord.setFeature(Feature.PERSON, Person.SECOND);
- inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
- Assert.assertEquals("are", r.realise(inflWord).toString());
-
- //3rd person sg present
- inflWord.setFeature(Feature.PERSON, Person.THIRD);
- inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
- Assert.assertEquals("is", r.realise(inflWord).toString());
-
- inflWord.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
-
- //1st person pl past
- inflWord.setFeature(Feature.PERSON, Person.FIRST);
- inflWord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals("were", r.realise(inflWord).toString());
-
- //2nd person pl past
- inflWord.setFeature(Feature.PERSON, Person.SECOND);
- inflWord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals("were", r.realise(inflWord).toString());
-
- //3rd person pl past
- inflWord.setFeature(Feature.PERSON, Person.THIRD);
- inflWord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals("were", r.realise(inflWord).toString());
-
- //1st person pl present
- inflWord.setFeature(Feature.PERSON, Person.FIRST);
- inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
- Assert.assertEquals("are", r.realise(inflWord).toString());
-
- //2nd person pl present
- inflWord.setFeature(Feature.PERSON, Person.SECOND);
- inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
- Assert.assertEquals("are", r.realise(inflWord).toString());
-
- //3rd person pl present
- inflWord.setFeature(Feature.PERSON, Person.THIRD);
- inflWord.setFeature(Feature.TENSE, Tense.PRESENT);
- Assert.assertEquals("are", r.realise(inflWord).toString());
-
- }
-
- /**
- * Tests the lexicon for recall of Acryonms.
- */
- @Test
- public void acronymsTests() {
- WordElement uk = lexicon.getWord("UK");
- WordElement unitedKingdom = lexicon.getWord("United Kingdom");
- List fullForms = uk
- .getFeatureAsElementList(LexicalFeature.ACRONYM_OF);
-
- // "uk" is an acronym of 3 full forms
- Assert.assertEquals(3, fullForms.size());
- Assert.assertTrue(fullForms.contains(unitedKingdom));
- }
-
- /**
- * Tests the lexicon for recall of baseforms with their standard inflected forms.
- */
- @Test
- public void standardInflectionsTest() {
- // test keepStandardInflection flag
- boolean keepInflectionsFlag = lexicon.isKeepStandardInflections();
-
- lexicon.setKeepStandardInflections(true);
- WordElement dog = lexicon.getWord("dog", LexicalCategory.NOUN);
- Assert.assertEquals("dogs", dog
- .getFeatureAsString(LexicalFeature.PLURAL));
-
- lexicon.setKeepStandardInflections(false);
- WordElement cat = lexicon.getWord("cat", LexicalCategory.NOUN);
- Assert
- .assertEquals(null, cat
- .getFeatureAsString(LexicalFeature.PLURAL));
-
- // restore flag to original state
- lexicon.setKeepStandardInflections(keepInflectionsFlag);
- }
-
- /**
- * Test for NIHDBLexicon functionality when several threads are using the
- * same Lexicon
- */
- @SuppressWarnings("static-access")
- public void multiThreadAppAccessTest() {
-
- LexThread runner1 = new LexThread("lie");
- LexThread runner2 = new LexThread("bark");
-
- // schedule them and run them
- ScheduledExecutorService service = Executors.newScheduledThreadPool(2);
- service.schedule(runner1, 0, TimeUnit.MILLISECONDS);
- service.schedule(runner2, 0, TimeUnit.MILLISECONDS);
-
- try {
- Thread.currentThread().sleep(500);
- } catch (InterruptedException ie) {
- ;// do nothing
- }
-
- service.shutdownNow();
-
- // check that the right words have been retrieved
- Assert.assertEquals("lie", runner1.word.getBaseForm());
- Assert.assertEquals("bark", runner2.word.getBaseForm());
- }
-
- /*
- * Class that implements a thread from which a lexical item can be retrieved
- */
- private class LexThread extends Thread {
- WordElement word;
- String base;
-
- public LexThread(String base) {
- this.base = base;
- }
-
- public void run() {
- word = lexicon.getWord(base, LexicalCategory.VERB);
- }
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/lexicon/english/SharedLexiconTests.java b/SharpSimpleNLGUnitTests/lexicon/english/SharedLexiconTests.java
deleted file mode 100644
index 9ba975b..0000000
--- a/SharpSimpleNLGUnitTests/lexicon/english/SharedLexiconTests.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.lexicon.english;
-
-import junit.framework.Assert;
-import simplenlg.features.Inflection;
-import simplenlg.features.LexicalFeature;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.WordElement;
-import simplenlg.lexicon.Lexicon;
-
-/**
- * @author Dave Westwater, Data2Text Ltd
- *
- */
-public class SharedLexiconTests {
-
- public void doBasicTests(Lexicon lexicon) {
- // test getWords. Should be 2 "can" (of any cat), 1 noun tree, 0 adj
- // trees
- Assert.assertEquals(3, lexicon.getWords("can").size());
- Assert.assertEquals(1, lexicon.getWords("can", LexicalCategory.NOUN)
- .size());
- Assert.assertEquals(0, lexicon.getWords("can",
- LexicalCategory.ADJECTIVE).size());
-
- // below test removed as standard morph variants no longer recorded in
- // lexicon
- // WordElement early = lexicon.getWord("early",
- // LexicalCategory.ADJECTIVE);
- // Assert.assertEquals("earlier",
- // early.getFeatureAsString(Feature.COMPARATIVE));
-
- // test getWord. Comparative of ADJ "good" is "better", superlative is
- // "best", this is a qualitative and predicative adjective
- WordElement good = lexicon.getWord("good", LexicalCategory.ADJECTIVE);
- Assert.assertEquals("better", good
- .getFeatureAsString(LexicalFeature.COMPARATIVE));
- Assert.assertEquals("best", good
- .getFeatureAsString(LexicalFeature.SUPERLATIVE));
- Assert.assertEquals(true, good.getFeatureAsBoolean(
- LexicalFeature.QUALITATIVE).booleanValue());
- Assert.assertEquals(true, good.getFeatureAsBoolean(
- LexicalFeature.PREDICATIVE).booleanValue());
- Assert.assertEquals(false, good.getFeatureAsBoolean(
- LexicalFeature.COLOUR).booleanValue());
- Assert.assertEquals(false, good.getFeatureAsBoolean(
- LexicalFeature.CLASSIFYING).booleanValue());
-
- // test getWord. There is only one "woman", and its plural is "women".
- // It is not an acronym, not proper, and countable
- WordElement woman = lexicon.getWord("woman");
-
- Assert.assertEquals("women", woman
- .getFeatureAsString(LexicalFeature.PLURAL));
- Assert.assertEquals(null, woman
- .getFeatureAsString(LexicalFeature.ACRONYM_OF));
- Assert.assertEquals(false, woman.getFeatureAsBoolean(
- LexicalFeature.PROPER).booleanValue());
- Assert.assertFalse(woman.hasInflectionalVariant(Inflection.UNCOUNT));
-
- // NB: This fails if the lexicon is XMLLexicon. No idea why.
- // Assert.assertEquals("irreg",
- // woman.getFeatureAsString(LexicalFeature.DEFAULT_INFL));
-
- // test getWord. Noun "sand" is non-count
- WordElement sand = lexicon.getWord("sand", LexicalCategory.NOUN);
- Assert.assertEquals(true, sand.hasInflectionalVariant(Inflection.UNCOUNT));
- Assert.assertEquals(Inflection.UNCOUNT, sand.getDefaultInflectionalVariant());
-
- // test hasWord
- Assert.assertEquals(true, lexicon.hasWord("tree")); // "tree" exists
- Assert.assertEquals(false, lexicon.hasWord("tree",
- LexicalCategory.ADVERB)); // but not as an adverb
-
- // test getWordByID; quickly, also check that this is a verb_modifier
- WordElement quickly = lexicon.getWordByID("E0051632");
- Assert.assertEquals("quickly", quickly.getBaseForm());
- Assert.assertEquals(LexicalCategory.ADVERB, quickly.getCategory());
- Assert.assertEquals(true, quickly.getFeatureAsBoolean(
- LexicalFeature.VERB_MODIFIER).booleanValue());
- Assert.assertEquals(false, quickly.getFeatureAsBoolean(
- LexicalFeature.SENTENCE_MODIFIER).booleanValue());
- Assert.assertEquals(false, quickly.getFeatureAsBoolean(
- LexicalFeature.INTENSIFIER).booleanValue());
-
- // test getWordFromVariant, verb type (tran or intran, not ditran)
- WordElement eat = lexicon.getWordFromVariant("eating");
- Assert.assertEquals("eat", eat.getBaseForm());
- Assert.assertEquals(LexicalCategory.VERB, eat.getCategory());
- Assert.assertEquals(true, eat.getFeatureAsBoolean(
- LexicalFeature.INTRANSITIVE).booleanValue());
- Assert.assertEquals(true, eat.getFeatureAsBoolean(
- LexicalFeature.TRANSITIVE).booleanValue());
- Assert.assertEquals(false, eat.getFeatureAsBoolean(
- LexicalFeature.DITRANSITIVE).booleanValue());
-
- // test BE is handled OK
- Assert.assertEquals("been", lexicon.getWordFromVariant("is",
- LexicalCategory.VERB).getFeatureAsString(
- LexicalFeature.PAST_PARTICIPLE));
-
- // test modal
- WordElement can = lexicon.getWord("can", LexicalCategory.MODAL);
- Assert.assertEquals("could", can
- .getFeatureAsString(LexicalFeature.PAST));
-
- // test non-existent word
- Assert.assertEquals(0, lexicon.getWords("akjmchsgk").size());
-
- // test lookup word method
- Assert.assertEquals(lexicon.lookupWord("say", LexicalCategory.VERB)
- .getBaseForm(), "say");
- Assert.assertEquals(lexicon.lookupWord("said", LexicalCategory.VERB)
- .getBaseForm(), "say");
- Assert.assertEquals(lexicon
- .lookupWord("E0054448", LexicalCategory.VERB).getBaseForm(),
- "say");
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/lexicon/english/XMLLexiconTest.java b/SharpSimpleNLGUnitTests/lexicon/english/XMLLexiconTest.java
deleted file mode 100644
index 1152bc7..0000000
--- a/SharpSimpleNLGUnitTests/lexicon/english/XMLLexiconTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.lexicon.english;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.features.NumberAgreement;
-import simplenlg.features.Tense;
-import simplenlg.framework.NLGFactory;
-import simplenlg.lexicon.XMLLexicon;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.PPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * @author D. Westwater, Data2Text Ltd
- *
- */
-public class XMLLexiconTest {
-
- // lexicon object -- an instance of Lexicon
- XMLLexicon lexicon = null;
-
-
- @Before
- /*
- * * Sets up the accessor and runs it -- takes ca. 26 sec
- */
- public void setUp() {
- long startTime = System.currentTimeMillis();
- //this.lexicon = new XMLLexicon(XML_FILENAME); // omit, use default
- // lexicon instead
- this.lexicon = new XMLLexicon();
- long stopTime = System.currentTimeMillis();
-
- System.out.format("Loading XML lexicon took %d ms%n",
- stopTime - startTime);
-
- }
-
- /**
- * Close the lexicon and cleanup.
- */
- @After
- public void tearDown() throws Exception {
- if (lexicon != null)
- lexicon.close();
- }
-
- /**
- * Runs basic Lexicon tests.
- */
- @Test
- public void basicLexiconTests() {
- SharedLexiconTests tests = new SharedLexiconTests();
- tests.doBasicTests(lexicon);
- }
-
- /**
- * Tests the immutability of the XMLLexicon by checking to make sure features
- * are not inadvertently propagated to the canonical XMLLexicon WordElement object.
- */
- @Test
- public void xmlLexiconImmutabilityTest() {
- NLGFactory factory = new NLGFactory(lexicon);
- Realiser realiser = new Realiser(lexicon);
-
- // "wall" is singular.
- NPPhraseSpec wall = factory.createNounPhrase("the", "wall");
- Assert.assertEquals(NumberAgreement.SINGULAR, wall.getFeature(Feature.NUMBER));
-
- // Realise a sentence with plural form of "wall"
- wall.setPlural(true);
- SPhraseSpec sentence = factory.createClause("motion", "observe");
- sentence.setFeature(Feature.TENSE, Tense.PAST);
- PPPhraseSpec pp = factory.createPrepositionPhrase("in", wall);
- sentence.addPostModifier(pp);
- realiser.realiseSentence(sentence);
-
- // Create a new 'the wall' NP and check to make sure that the syntax processor has
- // not propagated plurality to the canonical XMLLexicon WordElement object.
- wall = factory.createNounPhrase("the", "wall");
- Assert.assertEquals(NumberAgreement.SINGULAR, wall.getFeature(Feature.NUMBER));
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelperTest.cs b/SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelperTest.cs
deleted file mode 100644
index dbed2bc..0000000
--- a/SharpSimpleNLGUnitTests/morphology/DeterminerAgrHelperTest.cs
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SharpNLG.Extensions;
-
-namespace SimpleNLGTests.external
-{
-
- public class DeterminerAgrHelperTest
- {
-
- [Test]
- public void testRequiresAn()
- {
-
- Assert.IsTrue(DeterminerAgrHelper.requiresAn("elephant"));
-
- Assert.IsFalse(DeterminerAgrHelper.requiresAn("cow"));
-
- // Does not hand phonetics
- Assert.IsFalse(DeterminerAgrHelper.requiresAn("hour"));
-
- // But does have exceptions for some numerals
- Assert.IsFalse(DeterminerAgrHelper.requiresAn("one"));
-
- Assert.IsFalse(DeterminerAgrHelper.requiresAn("100"));
-
- }
-
- [Test]
- public void testCheckEndsWithIndefiniteArticle1()
- {
-
- var cannedText = "I see a";
-
- var np = "elephant";
-
- var expected = "I see an";
-
- var actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np);
-
- Assert.AreEqual(expected, actual);
-
- }
-
- [Test]
- public void testCheckEndsWithIndefiniteArticle2()
- {
-
- var cannedText = "I see a";
-
- var np = "cow";
-
- var expected = "I see a";
-
- var actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np);
-
- Assert.AreEqual(expected, actual);
-
- }
-
- [Test]
- public void testCheckEndsWithIndefiniteArticle3()
- {
-
- var cannedText = "I see an";
-
- var np = "cow";
-
- // Does not handle "an" -> "a"
- var expected = "I see an";
-
- var actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np);
-
- Assert.AreEqual(expected, actual);
-
- }
- }
-}
diff --git a/SharpSimpleNLGUnitTests/morphology/english/DeterminerAgrHelperTest.java b/SharpSimpleNLGUnitTests/morphology/english/DeterminerAgrHelperTest.java
deleted file mode 100644
index 42b4160..0000000
--- a/SharpSimpleNLGUnitTests/morphology/english/DeterminerAgrHelperTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package simplenlg.morphology.english;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-public class DeterminerAgrHelperTest {
-
- @Test
- public void testRequiresAn() {
-
- assertTrue(DeterminerAgrHelper.requiresAn("elephant"));
-
- assertFalse(DeterminerAgrHelper.requiresAn("cow"));
-
- // Does not hand phonetics
- assertFalse(DeterminerAgrHelper.requiresAn("hour"));
-
- // But does have exceptions for some numerals
- assertFalse(DeterminerAgrHelper.requiresAn("one"));
-
- assertFalse(DeterminerAgrHelper.requiresAn("100"));
-
- }
-
- @Test
- public void testCheckEndsWithIndefiniteArticle1() {
-
- String cannedText = "I see a";
-
- String np = "elephant";
-
- String expected = "I see an";
-
- String actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np);
-
- assertEquals(expected, actual);
-
- }
-
- @Test
- public void testCheckEndsWithIndefiniteArticle2() {
-
- String cannedText = "I see a";
-
- String np = "cow";
-
- String expected = "I see a";
-
- String actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np);
-
- assertEquals(expected, actual);
-
- }
-
- @Test
- public void testCheckEndsWithIndefiniteArticle3() {
-
- String cannedText = "I see an";
-
- String np = "cow";
-
- // Does not handle "an" -> "a"
- String expected = "I see an";
-
- String actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np);
-
- assertEquals(expected, actual);
-
- }
-
-
-
-
-}
diff --git a/SharpSimpleNLGUnitTests/realiser/RealiserTest.cs b/SharpSimpleNLGUnitTests/realiser/RealiserTest.cs
deleted file mode 100644
index 2e22846..0000000
--- a/SharpSimpleNLGUnitTests/realiser/RealiserTest.cs
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using System.Collections.Generic;
-using NUnit.Framework;
-using SimpleNLG;
-using SimpleNLG.Extensions;
-
-namespace SimpleNLGTests.realiser
-{
- /**
- * JUnit test class for the {@link Realiser} class.
- *
- * @author Saad Mahamood
- */
-
- public class RealiserTest
- {
-
- [SetUpFixture]
- public class SetupForRealiserTest
- {
- public static Lexicon lexicon = Lexicon.getDefaultLexicon();
- public static NLGFactory phraseFactory = new NLGFactory(lexicon);
- public static Realiser realiser = new Realiser(lexicon);
- }
-
-
-
- /**
- * Test the realization of List of NLGElements that is null
- */
- [Test]
- public void emptyNLGElementRealiserTest()
- {
- List elements = new List();
- List realisedElements = SetupForRealiserTest.realiser.realise(elements);
- // Expect emtpy listed returned:
- Assert.IsNotNull(realisedElements);
- Assert.AreEqual(0, realisedElements.size());
- }
-
-
- /**
- * Test the realization of List of NLGElements that is null
- */
- [Test]
- public void nullNLGElementRealiserTest()
- {
- List elements = null;
- List realisedElements = SetupForRealiserTest.realiser.realise(elements);
- // Expect emtpy listed returned:
- Assert.IsNotNull(realisedElements);
- Assert.AreEqual(0, realisedElements.size());
-
- }
-
- /**
- * Tests the realization of multiple NLGElements in a list.
- */
- [Test]
- public void multipleNLGElementListRealiserTest()
- {
- List elements = new List();
- // Create test NLGElements to realize:
-
- // "The cat jumping on the counter."
- DocumentElement sentence1 = SetupForRealiserTest.phraseFactory.createSentence();
- NPPhraseSpec subject_1 = SetupForRealiserTest.phraseFactory.createNounPhrase("the", "cat");
- VPPhraseSpec verb_1 = SetupForRealiserTest.phraseFactory.createVerbPhrase("jump");
- verb_1.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE);
- PPPhraseSpec prep_1 = SetupForRealiserTest.phraseFactory.createPrepositionPhrase();
- NPPhraseSpec object_1 = SetupForRealiserTest.phraseFactory.createNounPhrase();
- object_1.setDeterminer("the");
- object_1.setNoun("counter");
- prep_1.addComplement(object_1);
- prep_1.setPreposition("on");
- SPhraseSpec clause_1 = SetupForRealiserTest.phraseFactory.createClause();
- clause_1.setSubject(subject_1);
- clause_1.setVerbPhrase(verb_1);
- clause_1.setObject(prep_1);
- sentence1.addComponent(clause_1);
-
- // "The dog running on the counter."
- DocumentElement sentence2 = SetupForRealiserTest.phraseFactory.createSentence();
- NPPhraseSpec subject_2 = SetupForRealiserTest.phraseFactory.createNounPhrase("the", "dog");
- VPPhraseSpec verb_2 = SetupForRealiserTest.phraseFactory.createVerbPhrase("run");
- verb_2.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE);
- PPPhraseSpec prep_2 = SetupForRealiserTest.phraseFactory.createPrepositionPhrase();
- NPPhraseSpec object_2 = SetupForRealiserTest.phraseFactory.createNounPhrase();
- object_2.setDeterminer("the");
- object_2.setNoun("counter");
- prep_2.addComplement(object_2);
- prep_2.setPreposition("on");
- SPhraseSpec clause_2 = SetupForRealiserTest.phraseFactory.createClause();
- clause_2.setSubject(subject_2);
- clause_2.setVerbPhrase(verb_2);
- clause_2.setObject(prep_2);
- sentence2.addComponent(clause_2);
-
-
- elements.add(sentence1);
- elements.add(sentence2);
-
- List realisedElements = SetupForRealiserTest.realiser.realise(elements);
-
- Assert.IsNotNull(realisedElements);
- Assert.AreEqual(2, realisedElements.size());
- Assert.AreEqual("The cat jumping on the counter.", realisedElements.get(0).getRealisation());
- Assert.AreEqual("The dog running on the counter.", realisedElements.get(1).getRealisation());
-
- }
-
- /**
- * Tests the correct pluralization with possessives (GitHub issue #9)
- */
- [Test]
- public void correctPluralizationWithPossessives()
- {
- NPPhraseSpec sisterNP = SetupForRealiserTest.phraseFactory.createNounPhrase("sister");
- INLGElement word = SetupForRealiserTest.phraseFactory.createInflectedWord("Albert Einstein",
- new LexicalCategory_NOUN());
- word.setFeature(LexicalFeature.PROPER, true);
- NPPhraseSpec possNP = SetupForRealiserTest.phraseFactory.createNounPhrase(word);
- possNP.setFeature(Feature.POSSESSIVE.ToString(), true);
- sisterNP.setSpecifier(possNP);
-
-
- Assert.AreEqual("Albert Einstein's sister",
- SetupForRealiserTest.realiser.realise(sisterNP).getRealisation());
-
- sisterNP.setPlural(true);
-
- SetupForRealiserTest.realiser.setDebugMode(true);
- Assert.AreEqual("Albert Einstein's sisters",
- SetupForRealiserTest.realiser.realise(sisterNP).getRealisation());
-
- sisterNP.setPlural(false);
-
- possNP.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
- possNP.setFeature(Feature.PRONOMINAL.ToString(), true);
- Assert.AreEqual("his sister",
- SetupForRealiserTest.realiser.realise(sisterNP).getRealisation());
- sisterNP.setPlural(true);
- Assert.AreEqual("his sisters",
- SetupForRealiserTest.realiser.realise(sisterNP).getRealisation());
- }
-
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/realiser/english/RealiserTest.java b/SharpSimpleNLGUnitTests/realiser/english/RealiserTest.java
deleted file mode 100644
index 7dd58c1..0000000
--- a/SharpSimpleNLGUnitTests/realiser/english/RealiserTest.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.realiser.english;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.Assert;
-
-import org.junit.Before;
-import org.junit.Test;
-
-
-import simplenlg.features.Feature;
-import simplenlg.features.Form;
-import simplenlg.features.LexicalFeature;
-import simplenlg.features.Gender;
-import simplenlg.framework.DocumentElement;
-import simplenlg.framework.NLGElement;
-import simplenlg.framework.NLGFactory;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.lexicon.Lexicon;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.PPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.phrasespec.VPPhraseSpec;
-
-/**
- * JUnit test class for the {@link Realiser} class.
- *
- * @author Saad Mahamood
- */
-public class RealiserTest {
-
- private Lexicon lexicon;
- private NLGFactory nlgFactory;
- private Realiser realiser = null;
-
-
- @Before
- public void setup() {
- lexicon = Lexicon.getDefaultLexicon();
- nlgFactory = new NLGFactory(lexicon);
- realiser = new Realiser(lexicon);
- }
-
-
- /**
- * Test the realization of List of NLGElements that is null
- */
- @Test
- public void emptyNLGElementRealiserTest() {
- ArrayList elements = new ArrayList();
- List realisedElements = realiser.realise(elements);
- // Expect emtpy listed returned:
- Assert.assertNotNull(realisedElements);
- Assert.assertEquals(0, realisedElements.size());
-
- }
-
-
- /**
- * Test the realization of List of NLGElements that is null
- */
- @Test
- public void nullNLGElementRealiserTest() {
- ArrayList elements = null;
- List realisedElements = realiser.realise(elements);
- // Expect emtpy listed returned:
- Assert.assertNotNull(realisedElements);
- Assert.assertEquals(0, realisedElements.size());
-
- }
-
- /**
- * Tests the realization of multiple NLGElements in a list.
- */
- @Test
- public void multipleNLGElementListRealiserTest() {
- ArrayList elements = new ArrayList();
- // Create test NLGElements to realize:
-
- // "The cat jumping on the counter."
- DocumentElement sentence1 = nlgFactory.createSentence();
- NPPhraseSpec subject_1 = nlgFactory.createNounPhrase("the", "cat");
- VPPhraseSpec verb_1 = nlgFactory.createVerbPhrase("jump");
- verb_1.setFeature(Feature.FORM, Form.PRESENT_PARTICIPLE);
- PPPhraseSpec prep_1 = nlgFactory.createPrepositionPhrase();
- NPPhraseSpec object_1 = nlgFactory.createNounPhrase();
- object_1.setDeterminer("the");
- object_1.setNoun("counter");
- prep_1.addComplement(object_1);
- prep_1.setPreposition("on");
- SPhraseSpec clause_1 = nlgFactory.createClause();
- clause_1.setSubject(subject_1);
- clause_1.setVerbPhrase(verb_1);
- clause_1.setObject(prep_1);
- sentence1.addComponent(clause_1);
-
- // "The dog running on the counter."
- DocumentElement sentence2 = nlgFactory.createSentence();
- NPPhraseSpec subject_2 = nlgFactory.createNounPhrase("the", "dog");
- VPPhraseSpec verb_2 = nlgFactory.createVerbPhrase("run");
- verb_2.setFeature(Feature.FORM, Form.PRESENT_PARTICIPLE);
- PPPhraseSpec prep_2 = nlgFactory.createPrepositionPhrase();
- NPPhraseSpec object_2 = nlgFactory.createNounPhrase();
- object_2.setDeterminer("the");
- object_2.setNoun("counter");
- prep_2.addComplement(object_2);
- prep_2.setPreposition("on");
- SPhraseSpec clause_2 = nlgFactory.createClause();
- clause_2.setSubject(subject_2);
- clause_2.setVerbPhrase(verb_2);
- clause_2.setObject(prep_2);
- sentence2.addComponent(clause_2);
-
-
- elements.add(sentence1);
- elements.add(sentence2);
-
- List realisedElements = realiser.realise(elements);
-
- Assert.assertNotNull(realisedElements);
- Assert.assertEquals(2, realisedElements.size());
- Assert.assertEquals("The cat jumping on the counter.", realisedElements.get(0).getRealisation());
- Assert.assertEquals("The dog running on the counter.", realisedElements.get(1).getRealisation());
-
- }
-
- /**
- * Tests the correct pluralization with possessives (GitHub issue #9)
- */
- @Test
- public void correctPluralizationWithPossessives() {
- NPPhraseSpec sisterNP = nlgFactory.createNounPhrase("sister");
- NLGElement word = nlgFactory.createInflectedWord("Albert Einstein",
- LexicalCategory.NOUN);
- word.setFeature(LexicalFeature.PROPER, true);
- NPPhraseSpec possNP = nlgFactory.createNounPhrase(word);
- possNP.setFeature(Feature.POSSESSIVE, true);
- sisterNP.setSpecifier(possNP);
- Assert.assertEquals("Albert Einstein's sister",
- realiser.realise(sisterNP).getRealisation());
- sisterNP.setPlural(true);
- Assert.assertEquals("Albert Einstein's sisters",
- realiser.realise(sisterNP).getRealisation());
- sisterNP.setPlural(false);
- possNP.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
- possNP.setFeature(Feature.PRONOMINAL, true);
- Assert.assertEquals("his sister",
- realiser.realise(sisterNP).getRealisation());
- sisterNP.setPlural(true);
- Assert.assertEquals("his sisters",
- realiser.realise(sisterNP).getRealisation());
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/AdjectivePhraseTest.cs b/SharpSimpleNLGUnitTests/syntax/AdjectivePhraseTest.cs
deleted file mode 100644
index 3c9c705..0000000
--- a/SharpSimpleNLGUnitTests/syntax/AdjectivePhraseTest.cs
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
- /**
- * JUnit test class for the {@link Realiser} class.
- *
- * @author Saad Mahamood
- */
-
- public class AdjectivePhraseTest : SimpleNLG4TestBase
- {
-
-
- /**
- * Test premodification & coordination of Adjective Phrases (Not much else
- * to simplenlg.test)
- */
- [Test]
- public void testAdj()
- {
-
- // form the adjphrase "incredibly salacious"
- this.salacious.addPreModifier(this.phraseFactory
- .createAdverbPhrase("incredibly"));
- Assert.AreEqual("incredibly salacious", this.realiser
- .realise(this.salacious).getRealisation());
-
- // form the adjphrase "incredibly beautiful"
- this.beautiful.addPreModifier("amazingly");
- Assert.AreEqual("amazingly beautiful", this.realiser
- .realise(this.beautiful).getRealisation());
-
- // coordinate the two aps
- var coordap = new CoordinatedPhraseElement(
- this.salacious, this.beautiful);
- Assert.AreEqual("incredibly salacious and amazingly beautiful",
- this.realiser.realise(coordap).getRealisation());
-
- // changing the inner conjunction
- coordap.setFeature(Feature.CONJUNCTION.ToString(), "or");
- Assert.AreEqual("incredibly salacious or amazingly beautiful",
- this.realiser.realise(coordap).getRealisation());
-
- // coordinate this with a new AdjPhraseSpec
- var coord2 = new CoordinatedPhraseElement(coordap,
- this.stunning);
- //this.realiser.setDebugMode(true);
- Assert.AreEqual(
- "incredibly salacious or amazingly beautiful and stunning",
- this.realiser.realise(coord2).getRealisation());
-
- // add a premodifier the coordinate phrase, yielding
- // "seriously and undeniably incredibly salacious or amazingly beautiful
- // and stunning"
- var preMod = new CoordinatedPhraseElement(
- new StringElement("seriously"), new StringElement("undeniably"));
-
- coord2.addPreModifier(preMod);
- Assert.AreEqual(
- "seriously and undeniably incredibly salacious or amazingly beautiful and stunning",
- this.realiser.realise(coord2).getRealisation());
-
- // adding a coordinate rather than coordinating should give a different
- // result
- coordap.addCoordinate(this.stunning);
- Assert.AreEqual(
- "incredibly salacious, amazingly beautiful or stunning",
- this.realiser.realise(coordap).getRealisation());
-
- }
-
- /**
- * Simple test of adverbials
- */
- [Test]
-
- public void testAdv()
- {
-
- var sent = this.phraseFactory.createClause("John", "eat");
-
- var adv = this.phraseFactory.createAdverbPhrase("quickly");
-
- sent.addPreModifier(adv);
-
- Assert.AreEqual("John quickly eats", this.realiser.realise(sent)
- .getRealisation());
-
- adv.addPreModifier("very");
-
- Assert.AreEqual("John very quickly eats", this.realiser.realise(
- sent).getRealisation());
-
- }
-
- /**
- * Test participles as adjectives
- */
- [Test]
-
- public void testParticipleAdj()
- {
- var ap = this.phraseFactory
- .createAdjectivePhrase(this.lexicon.getWord("associated",
- new LexicalCategory_ADJECTIVE()));
- Assert.AreEqual("associated", this.realiser.realise(ap)
- .getRealisation());
- }
-
- /**
- * Test for multiple adjective modifiers with comma-separation. Example courtesy of William Bradshaw (Data2Text Ltd).
- */
- [Test]
- public void testMultipleModifiers()
- {
- var np = this.phraseFactory
- .createNounPhrase(this.lexicon.getWord("message",
- new LexicalCategory_NOUN()));
- np.addPreModifier(this.lexicon.getWord("active",
- new LexicalCategory_ADJECTIVE()));
- np.addPreModifier(this.lexicon.getWord("temperature",
- new LexicalCategory_ADJECTIVE()));
- Assert.AreEqual("active, temperature message", this.realiser.realise(np).getRealisation());
-
- //now we set the realiser not to separate using commas
- this.realiser.setCommaSepPremodifiers(false);
- Assert.AreEqual("active temperature message", this.realiser.realise(np).getRealisation());
-
- }
-
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/ClauseAggregationTest.cs b/SharpSimpleNLGUnitTests/syntax/ClauseAggregationTest.cs
deleted file mode 100644
index 98e8388..0000000
--- a/SharpSimpleNLGUnitTests/syntax/ClauseAggregationTest.cs
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using System.Collections.Generic;
-using NUnit.Framework;
-using SimpleNLG;
-using SimpleNLG.Extensions;
-
-namespace SimpleNLGTests.syntax
-{
-/**
- * Some tests for aggregation.
- *
- * @author Albert Gatt, University of Malta & University of Aberdeen
- *
- */
-
- public class ClauseAggregationTest : SimpleNLG4TestBase
- {
- // set up a few more fixtures
- /** The s4. */
- public SPhraseSpec s5, s6;
- public Aggregator aggregator = new Aggregator();
- public ClauseCoordinationRule coord = new ClauseCoordinationRule();
- public ForwardConjunctionReductionRule fcr = new ForwardConjunctionReductionRule();
- public BackwardConjunctionReductionRule bcr = new BackwardConjunctionReductionRule();
-
- /**
- * Instantiates a new clause aggregation test.
- *
- * @param name
- * the name
- */
-
- [SetUp]
- protected override void setUp()
- {
- aggregator.initialise();
-
- // the woman kissed the man behind the curtain
- s1 = this.phraseFactory.createClause();
- s1.setSubject(this.woman);
- s1.setVerbPhrase(this.phraseFactory.createVerbPhrase("kiss"));
- s1.setObject(this.man);
- s1.addPostModifier(this.phraseFactory
- .createPrepositionPhrase("behind", this.phraseFactory
- .createNounPhrase("the", "curtain")));
-
- // the woman kicked the dog on the rock
- s2 = this.phraseFactory.createClause();
- s2.setSubject(this.phraseFactory.createNounPhrase("the", "woman"));
- s2.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick"));
- s2.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
- s2.addPostModifier(this.onTheRock);
-
- // the woman kicked the dog behind the curtain
- s3 = this.phraseFactory.createClause();
- s3.setSubject(this.phraseFactory.createNounPhrase("the", "woman"));
- s3.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick"));
- s3.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
- s3.addPostModifier(this.phraseFactory
- .createPrepositionPhrase("behind", this.phraseFactory
- .createNounPhrase("the", "curtain")));
-
- // the man kicked the dog behind the curtain
- s4 = this.phraseFactory.createClause();
- s4.setSubject(this.man);
- s4.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick"));
- s4.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
- s4.addPostModifier(this.behindTheCurtain);
-
- // the girl kicked the dog behind the curtain
- s5 = this.phraseFactory.createClause();
- s5.setSubject(this.phraseFactory.createNounPhrase("the", "girl"));
- s5.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick"));
- s5.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
- s5.addPostModifier(this.behindTheCurtain);
-
- // the woman kissed the dog behind the curtain
- s6 = this.phraseFactory.createClause();
- s6.setSubject(this.phraseFactory.createNounPhrase("the", "woman"));
- s6.setVerbPhrase(this.phraseFactory.createVerbPhrase("kiss"));
- s6.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
- s6.addPostModifier(this.phraseFactory
- .createPrepositionPhrase("behind", this.phraseFactory
- .createNounPhrase("the", "curtain")));
- }
-
-
- [TearDown]
- public void tearDown()
- {
- s1 = null;
- s2 = null;
- s3 = null;
- s4 = null;
- s5 = null;
- s6 = null;
-
- }
- /**
- * Test clause coordination with two sentences with same subject but
- * different postmodifiers: fails
- */
- [Test]
- public void testCoordinationSameSubjectFail()
- {
- var elements = new List { this.s1, this.s2};
- var result = this.coord.apply(elements);
- Assert.AreEqual(1, result.size());
- }
-
- /**
- * Test clause coordination with two sentences one of which is passive:
- * fails
- */
- [Test]
- public void testCoordinationPassiveFail()
- {
- s1.setFeature(Feature.PASSIVE.ToString(), true);
- var elements = new List {s1, s2};
- var result = coord.apply(elements);
- Assert.AreEqual(2, result.size());
- }
-
- // /**
- // * Test clause coordination with 2 sentences with same subject: succeeds
- // */
- // [Test]
- // public void testCoordinationSameSubjectSuccess() {
- // List elements = Arrays.asList((NLGElement) this.s1,
- // (NLGElement) this.s3);
- // List result = this.coord.apply(elements);
- // Assert.assertTrue(result.size() == 1); // should only be one sentence
- // NLGElement aggregated = result.get(0);
- // Assert
- // .AreEqual(
- // "the woman kisses the man and kicks the dog behind the curtain",
- // this.realiser.realise(aggregated).getRealisation());
- // }
-
- /**
- * Test clause coordination with 2 sentences with same VP: succeeds
- */
- [Test]
- public void testCoordinationSameVP()
- {
- var elements = new List { s3, s4 };
- var result = coord.apply(elements);
- Assert.IsTrue(result.size() == 1); // should only be one sentence
- var aggregated = result.get(0);
- Assert.AreEqual(
- "the woman kicks the dog behind the curtain",
- this.realiser.realise(aggregated).getRealisation());
- }
-
- [Test]
- public void testCoordinationWithModifiers()
- {
- // now add a couple of front modifiers
- s3.addFrontModifier(this.phraseFactory
- .createAdverbPhrase("however"));
- s4.addFrontModifier(this.phraseFactory
- .createAdverbPhrase("however"));
- var elements = new List { s3, s4 };
- var result = coord.apply(elements);
- Assert.IsTrue(result.size() == 1); // should only be one sentence
- var aggregated = result.get(0);
- Assert
- .AreEqual(
- "however the woman kicks the dog behind the curtain",
- this.realiser.realise(aggregated).getRealisation());
- }
-
- /**
- * Test coordination of 3 sentences with the same VP
- */
- // [Test]
- public void testCoordinationSameVP2()
- {
- var elements = new List { s3, s4, s5 };
- var result = coord.apply(elements);
- Assert.IsTrue(result.size() == 1); // should only be one sentence
- var aggregated = result.get(0);
- Assert
- .AreEqual(
- "the woman and the man and the girl kick the dog behind the curtain",
- this.realiser.realise(aggregated).getRealisation());
- }
-
- /**
- * Forward conjunction reduction test
- */
- [Test]
- public void testForwardConjReduction()
- {
- var aggregated = fcr.apply(s2, s3);
- Assert
- .AreEqual(
- "the woman kicks the dog on the rock and kicks the dog behind the curtain",
- this.realiser.realise(aggregated).getRealisation());
- }
-
- /**
- * Backward conjunction reduction test
- */
- [Test]
- public void testBackwardConjunctionReduction()
- {
- var aggregated = bcr.apply(s3, s6);
- Assert
- .AreEqual(
- "the woman kicks and the woman kisses the dog behind the curtain",
- this.realiser.realise(aggregated).getRealisation());
- }
-
- /**
- * Test multiple aggregation procedures in a single aggregator.
- */
-// [Test]
-// public void testForwardBackwardConjunctionReduction() {
-// this.aggregator.addRule(this.fcr);
-// this.aggregator.addRule(this.bcr);
-// realiser.setDebugMode(true);
-// List result = this.aggregator.realise(Arrays.asList((NLGElement) this.s2, (NLGElement) this.s3));
-// Assert.assertTrue(result.size() == 1); // should only be one sentence
-// NLGElement aggregated = result.get(0);
-// NLGElement aggregated = this.phraseFactory.createdCoordinatedPhrase(this.s2, this.s3);
-// Assert
-// .AreEqual(
-// "the woman kicks the dog on the rock and behind the curtain",
-// this.realiser.realise(aggregated).getRealisation());
-// }
-
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/ClauseTest.cs b/SharpSimpleNLGUnitTests/syntax/ClauseTest.cs
deleted file mode 100644
index 159292e..0000000
--- a/SharpSimpleNLGUnitTests/syntax/ClauseTest.cs
+++ /dev/null
@@ -1,886 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-using SimpleNLG.Extensions;
-
-namespace SimpleNLGTests.syntax
-{
- // TODO: Auto-generated Javadoc
- /**
- * The Class STest.
- */
-
- public class ClauseTest : SimpleNLG4TestBase
- {
- /** The realiser. */
-
- /**
- * Initial test for basic sentences.
- */
-
- [Test]
- public void testBasic()
- {
- Assert.AreEqual("the woman kisses the man", this.realiser
- .realise(s1).getRealisation());
- Assert.AreEqual("there is the dog on the rock", this.realiser
- .realise(s2).getRealisation());
-
- setUp();
- Assert.AreEqual("the man gives the woman John's flower",
- this.realiser.realise(s3).getRealisation());
- this.realiser.setDebugMode(true);
- Assert
- .AreEqual(
- "however tomorrow Jane and Andrew will pick up the balls in the shop",
- this.realiser.realise(s4).getRealisation());
- }
-
- /**
- * Test did not
- */
-
- [Test]
- public void testDidNot()
- {
- SPhraseSpec o = this.phraseFactory.createClause("John", "eat");
- o.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- o.setFeature(Feature.NEGATED.ToString(), true);
- this.realiser.setLexicon(this.lexicon);
- Assert.AreEqual("John did not eat", this.realiser.realise(o).getRealisation());
- }
-
- /**
- * Test did not
- */
-
- [Test]
- public void testVPNegation()
- {
- // negate the VP
- var vp = this.phraseFactory.createVerbPhrase("lie");
- vp.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- vp.setFeature(Feature.NEGATED.ToString(), true);
- var compl = this.phraseFactory.createVerbPhrase("etherize");
- compl.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- vp.setComplement(compl);
-
- var s = this.phraseFactory.createClause(this.phraseFactory
- .createNounPhrase("the", "patient"), vp);
-
- Assert.AreEqual("the patient did not lie etherized",
- this.realiser.realise(s).getRealisation());
-
- }
-
- /**
- * Test that pronominal args are being correctly cast as NPs.
- */
-
- [Test]
- public void testPronounArguments()
- {
- // the subject of s2 should have been cast into a pronominal NP
- var subj = s2.getFeatureAsElementList(
- InternalFeature.SUBJECTS.ToString()).get(0);
- Assert.IsTrue(subj.isA(PhraseCategoryEnum.NOUN_PHRASE));
- // Assert.assertTrue(LexicalCategory.PRONOUN.AreEqual(((PhraseElement)
- // subj)
- // .getCategory()));
- }
-
- /**
- * Tests for setting tense, aspect and passive from the sentence interface.
- */
-
- [Test]
- public void testTenses()
- {
- // simple past
- s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- Assert.AreEqual("the man gave the woman John's flower",
- this.realiser.realise(s3).getRealisation());
-
- // perfect
- s3.setFeature(Feature.PERFECT.ToString(), true);
- Assert.AreEqual("the man had given the woman John's flower",
- this.realiser.realise(s3).getRealisation());
-
- // negation
- s3.setFeature(Feature.NEGATED.ToString(), true);
- Assert.AreEqual("the man had not given the woman John's flower",
- this.realiser.realise(s3).getRealisation());
-
- s3.setFeature(Feature.PROGRESSIVE.ToString(), true);
- Assert.AreEqual(
- "the man had not been giving the woman John's flower",
- this.realiser.realise(s3).getRealisation());
-
- // passivisation with direct and indirect object
- // s3.setFeature(Feature.PASSIVE.ToString(), true);
- // Assert.AreEqual(
- // "John's flower had not been being given the woman by the man",
- // realiser.realise(s3).getRealisation());
- }
-
- /**
- * Test what happens when a sentence is subordinated as complement of a
- * verb.
- */
-
- [Test]
- public void testSubordination()
- {
-
- // subordinate sentence by setting it as complement of a verb
- this.say.addComplement(s3);
-
- // check the getter
- Assert.AreEqual(ClauseStatus.SUBORDINATE, s3
- .getFeature(InternalFeature.CLAUSE_STATUS.ToString()));
-
- // check realisation
- Assert.AreEqual("says that the man gives the woman John's flower",
- this.realiser.realise(this.say).getRealisation());
- }
-
- /**
- * Test the various forms of a sentence, including subordinates.
- */
- /**
- *
- */
-
- [Test]
- public void testForm()
- {
-
- // check the getter method
- Assert.AreEqual(Form.NORMAL, s1.getFeatureAsElement(
- InternalFeature.VERB_PHRASE.ToString()).getFeature(Feature.FORM.ToString()));
-
- // infinitive
- s1.setFeature(Feature.FORM.ToString(), Form.INFINITIVE);
- Assert
- .AreEqual(
- "to kiss the man", this.realiser.realise(s1).getRealisation());
-
- // gerund with "there"
- s2.setFeature(Feature.FORM.ToString(), Form.GERUND);
- Assert.AreEqual("there being the dog on the rock", this.realiser
- .realise(s2).getRealisation());
-
- // gerund with possessive
- s3.setFeature(Feature.FORM.ToString(), Form.GERUND);
- Assert.AreEqual("the man's giving the woman John's flower",
- this.realiser.realise(s3).getRealisation());
-
- // imperative
- // the man gives the woman John's flower
- s3 = this.phraseFactory.createClause();
-
- s3.setVerbPhrase(this.give);
- s3.setFeature(Feature.FORM.ToString(), Form.IMPERATIVE);
-
- Assert.AreEqual("give the woman John's flower", this.realiser
- .realise(s3).getRealisation());
-
-
-
- this.say = this.phraseFactory.createVerbPhrase("say");
- this.say.addComplement(s3);
- this.realiser.setDebugMode(true);
- Assert.AreEqual("says to give the woman John's flower",
- this.realiser.realise(this.say).getRealisation());
-
- // imperative -- case II
- s4.setFeature(Feature.FORM.ToString(), Form.IMPERATIVE);
- Assert.AreEqual("however tomorrow pick up the balls in the shop",
- this.realiser.realise(s4).getRealisation());
-
- // infinitive -- case II
- s4 = this.phraseFactory.createClause();
- s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
- s4.addFrontModifier("tomorrow");
-
- var subject = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"), this.phraseFactory
- .createNounPhrase("Andrew"));
-
- s4.setFeature(InternalFeature.SUBJECTS.ToString(), subject);
-
- var pick = this.phraseFactory.createVerbPhrase("pick up");
- s4.setFeature(InternalFeature.VERB_PHRASE.ToString(), pick);
- s4.setObject("the balls");
- s4.addPostModifier("in the shop");
- s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- s4.setFeature(Feature.FORM.ToString(), Form.INFINITIVE);
- Assert.AreEqual(
- "however to pick up the balls in the shop tomorrow",
- this.realiser.realise(s4).getRealisation());
- }
-
- /**
- * Slightly more complex tests for forms.
- */
-
- [Test]
- public void testForm2()
- {
- // set s4 as subject of a new sentence
- var temp = this.phraseFactory.createClause(s4, "be",
- "recommended");
-
- Assert.AreEqual(
- "however tomorrow Jane and Andrew's picking up the " +
- "balls in the shop is recommended",
- this.realiser.realise(temp).getRealisation());
-
- // compose this with a new sentence
- // ER - switched direct and indirect object in sentence
- var temp2 = this.phraseFactory.createClause("I", "tell", temp);
- temp2.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
-
- var indirectObject = this.phraseFactory
- .createNounPhrase("John");
-
- temp2.setIndirectObject(indirectObject);
-
- Assert.AreEqual("I will tell John that however tomorrow Jane and " +
- "Andrew's picking up the balls in the shop is " +
- "recommended",
- this.realiser.realise(temp2).getRealisation());
-
- // turn s4 to imperative and put it in indirect object position
-
- s4 = this.phraseFactory.createClause();
- s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
- s4.addFrontModifier("tomorrow");
-
- var subject = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"), this.phraseFactory
- .createNounPhrase("Andrew"));
-
- s4.setSubject(subject);
-
- var pick = this.phraseFactory.createVerbPhrase("pick up");
- s4.setVerbPhrase(pick);
- s4.setObject("the balls");
- s4.addPostModifier("in the shop");
- s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- s4.setFeature(Feature.FORM.ToString(), Form.IMPERATIVE);
-
- temp2 = this.phraseFactory.createClause("I", "tell", s4);
- indirectObject = this.phraseFactory.createNounPhrase("John");
- temp2.setIndirectObject(indirectObject);
- temp2.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
-
- Assert.AreEqual("I will tell John however to pick up the balls "
- + "in the shop tomorrow", this.realiser.realise(temp2)
- .getRealisation());
- }
-
- /**
- * Tests for gerund forms and genitive subjects.
- */
-
- [Test]
- public void testGerundsubject()
- {
-
- // the man's giving the woman John's flower upset Peter
- var _s4 = this.phraseFactory.createClause();
- _s4.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset"));
- _s4.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- _s4.setObject(this.phraseFactory.createNounPhrase("Peter"));
- s3.setFeature(Feature.PERFECT.ToString(), true);
-
- // set the sentence as subject of another: makes it a gerund
- _s4.setSubject(s3);
-
- // suppress the genitive realisation of the NP subject in gerund
- // sentences
- s3.setFeature(Feature.SUPPRESS_GENITIVE_IN_GERUND.ToString(), true);
-
- // check the realisation: subject should not be genitive
- Assert.AreEqual(
- "the man having given the woman John's flower upset Peter",
- this.realiser.realise(_s4).getRealisation());
-
- }
-
- /**
- * Some tests for multiple embedded sentences.
- */
-
- [Test]
- public void testComplexSentence1()
- {
- setUp();
- // the man's giving the woman John's flower upset Peter
- var complexS = this.phraseFactory.createClause();
- complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset"));
- complexS.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- complexS.setObject(this.phraseFactory.createNounPhrase("Peter"));
- s3.setFeature(Feature.PERFECT.ToString(), true);
- complexS.setSubject(s3);
-
- // check the realisation: subject should be genitive
- Assert.AreEqual(
- "the man's having given the woman John's flower upset Peter",
- this.realiser.realise(complexS).getRealisation());
-
- setUp();
- // coordinate sentences in subject position
- var s5 = this.phraseFactory.createClause();
- s5.setSubject(this.phraseFactory.createNounPhrase("some", "person"));
- s5.setVerbPhrase(this.phraseFactory.createVerbPhrase("stroke"));
- s5.setObject(this.phraseFactory.createNounPhrase("the", "cat"));
-
- var coord = new CoordinatedPhraseElement(s3,
- s5);
- complexS = this.phraseFactory.createClause();
- complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset"));
- complexS.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- complexS.setObject(this.phraseFactory.createNounPhrase("Peter"));
- complexS.setSubject(coord);
- s3.setFeature(Feature.PERFECT.ToString(), true);
-
- Assert.AreEqual("the man's having given the woman John's flower "
- + "and some person's stroking the cat upset Peter",
- this.realiser.realise(complexS).getRealisation());
-
- setUp();
- // now subordinate the complex sentence
- // coord.setClauseStatus(SPhraseSpec.ClauseType.MAIN);
- var s6 = this.phraseFactory.createClause();
- s6.setVerbPhrase(this.phraseFactory.createVerbPhrase("tell"));
- s6.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- s6.setSubject(this.phraseFactory.createNounPhrase("the", "boy"));
- // ER - switched indirect and direct object
- var indirect = this.phraseFactory.createNounPhrase("every",
- "girl");
- s6.setIndirectObject(indirect);
- complexS = this.phraseFactory.createClause();
- complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset"));
- complexS.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- complexS.setObject(this.phraseFactory.createNounPhrase("Peter"));
- s6.setObject(complexS);
- coord = new CoordinatedPhraseElement(s3, s5);
- complexS.setSubject(coord);
- s3.setFeature(Feature.PERFECT.ToString(), true);
- Assert.AreEqual(
- "the boy told every girl that the man's having given the woman "
- + "John's flower and some person's stroking the cat "
- + "upset Peter",
- this.realiser.realise(s6).getRealisation());
-
- }
-
- /**
- * More coordination tests.
- */
-
- [Test]
- public void testComplexSentence3()
- {
- setUp();
-
- s1 = this.phraseFactory.createClause();
- s1.setSubject(this.woman);
- s1.setVerb("kiss");
- s1.setObject(this.man);
-
- var _man = this.phraseFactory.createNounPhrase("the", "man");
- s3 = this.phraseFactory.createClause();
- s3.setSubject(_man);
- s3.setVerb("give");
-
- var flower = this.phraseFactory.createNounPhrase("flower");
- var john = this.phraseFactory.createNounPhrase("John");
- john.setFeature(Feature.POSSESSIVE.ToString(), true);
- flower.setSpecifier(john);
- s3.setObject(flower);
-
- var _woman = this.phraseFactory.createNounPhrase(
- "the", "woman");
- s3.setIndirectObject(_woman);
-
- // the coordinate sentence allows us to raise and lower complementiser
- var coord2 = new CoordinatedPhraseElement(s1,
- s3);
- coord2.setFeature(Feature.TENSE.ToString(), Tense.PAST);
-
- this.realiser.setDebugMode(true);
- Assert
- .AreEqual(
- "the woman kissed the man and the man gave the woman John's flower",
- this.realiser.realise(coord2).getRealisation());
- }
-
- // /**
- // * Sentence with clausal subject with verb "be" and a progressive feature
- // */
- // public void testComplexSentence2() {
- // SPhraseSpec subject = phraseFactory.createClause(
- // phraseFactory.createNounPhrase("the", "child"),
- // phraseFactory.createVerbPhrase("be"), phraseFactory
- // .createWord("difficult", LexicalCategory.ADJECTIVE));
- // subject.setFeature(Feature.PROGRESSIVE, true);
- // }
-
- /**
- * Tests recogition of strings in API.
- */
-
- [Test]
- public void testStringRecognition()
- {
-
- // test recognition of forms of "be"
- var _s1 = this.phraseFactory.createClause(
- "my cat", "be", "sad");
- Assert.AreEqual(
- "my cat is sad", this.realiser.realise(_s1).getRealisation());
-
- // test recognition of pronoun for afreement
- var _s2 = this.phraseFactory
- .createClause("I", "want", "Mary");
-
- Assert.AreEqual(
- "I want Mary", this.realiser.realise(_s2).getRealisation());
-
- // test recognition of pronoun for correct form
- var subject = this.phraseFactory.createNounPhrase("dog");
- subject.setFeature(InternalFeature.SPECIFIER.ToString(), "a");
- subject.addPostModifier("from next door");
- var obj = this.phraseFactory.createNounPhrase("I");
- var s = this.phraseFactory.createClause(subject,
- "chase", obj);
- s.setFeature(Feature.PROGRESSIVE.ToString(), true);
- Assert.AreEqual("a dog from next door is chasing me",
- this.realiser.realise(s).getRealisation());
- }
-
- /**
- * Tests complex agreement.
- */
-
- [Test]
- public void testAgreement()
- {
-
- // basic agreement
- var np = this.phraseFactory.createNounPhrase("dog");
- np.setSpecifier("the");
- np.addPreModifier("angry");
- var _s1 = this.phraseFactory
- .createClause(np, "chase", "John");
- Assert.AreEqual("the angry dog chases John", this.realiser
- .realise(_s1).getRealisation());
-
- // plural
- np = this.phraseFactory.createNounPhrase("dog");
- np.setSpecifier("the");
- np.addPreModifier("angry");
- np.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
- _s1 = this.phraseFactory.createClause(np, "chase", "John");
- Assert.AreEqual("the angry dogs chase John", this.realiser
- .realise(_s1).getRealisation());
-
- // test agreement with "there is"
- np = this.phraseFactory.createNounPhrase("dog");
- np.addPreModifier("angry");
- np.setFeature(Feature.NUMBER.ToString(), NumberAgreement.SINGULAR);
- np.setSpecifier("a");
- var _s2 = this.phraseFactory.createClause("there", "be", np);
- Assert.AreEqual("there is an angry dog", this.realiser
- .realise(_s2).getRealisation());
-
- // plural with "there"
- np = this.phraseFactory.createNounPhrase("dog");
- np.addPreModifier("angry");
- np.setSpecifier("a");
- np.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
- _s2 = this.phraseFactory.createClause("there", "be", np);
- Assert.AreEqual("there are some angry dogs", this.realiser
- .realise(_s2).getRealisation());
- }
-
- /**
- * Tests passive.
- */
-
- [Test]
- public void testPassive()
- {
- // passive with just complement
- var _s1 = this.phraseFactory.createClause(null,
- "intubate", this.phraseFactory.createNounPhrase("the", "baby"));
-
- _s1.setFeature(Feature.PASSIVE.ToString(), true);
-
- Assert.AreEqual("the baby is intubated", this.realiser
- .realise(_s1).getRealisation());
-
- // passive with subject and complement
- _s1 = this.phraseFactory.createClause(null,
- "intubate", this.phraseFactory.createNounPhrase("the", "baby"));
-
- _s1.setSubject(this.phraseFactory.createNounPhrase("the nurse"));
- _s1.setFeature(Feature.PASSIVE.ToString(), true);
- Assert.AreEqual("the baby is intubated by the nurse",
- this.realiser.realise(_s1).getRealisation());
-
- // passive with subject and indirect object
- var _s2 = this.phraseFactory.createClause(null, "give",
- this.phraseFactory.createNounPhrase("the", "baby"));
-
- var morphine = this.phraseFactory
- .createNounPhrase("50ug of morphine");
- _s2.setIndirectObject(morphine);
- _s2.setFeature(Feature.PASSIVE.ToString(), true);
- Assert.AreEqual("the baby is given 50ug of morphine",
- this.realiser.realise(_s2).getRealisation());
-
- // passive with subject, complement and indirect object
- _s2 = this.phraseFactory.createClause(this.phraseFactory
- .createNounPhrase("the", "nurse"), "give",
- this.phraseFactory.createNounPhrase("the", "baby"));
-
- morphine = this.phraseFactory.createNounPhrase("50ug of morphine");
- _s2.setIndirectObject(morphine);
- _s2.setFeature(Feature.PASSIVE.ToString(), true);
- Assert.AreEqual("the baby is given 50ug of morphine by the nurse",
- this.realiser.realise(_s2).getRealisation());
-
- // test agreement in passive
- var _s3 = this.phraseFactory.createClause(
- new CoordinatedPhraseElement("my dog", "your cat"), "chase",
- "George");
- _s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- _s3.addFrontModifier("yesterday");
- Assert.AreEqual("yesterday my dog and your cat chased George",
- this.realiser.realise(_s3).getRealisation());
-
- _s3 = this.phraseFactory.createClause(new CoordinatedPhraseElement(
- "my dog", "your cat"), "chase",
- this.phraseFactory.createNounPhrase("George"));
- _s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- _s3.addFrontModifier("yesterday");
- _s3.setFeature(Feature.PASSIVE.ToString(), true);
- Assert.AreEqual(
- "yesterday George was chased by my dog and your cat",
- this.realiser.realise(_s3).getRealisation());
-
- // test correct pronoun forms
- var _s4 = this.phraseFactory.createClause(this.phraseFactory
- .createNounPhrase("he"), "chase",
- this.phraseFactory.createNounPhrase("I"));
- Assert.AreEqual("he chases me", this.realiser.realise(_s4)
- .getRealisation());
- _s4 = this.phraseFactory
- .createClause(
- this.phraseFactory.createNounPhrase("he"), "chase", this.phraseFactory.createNounPhrase("me"));
-
- _s4.setFeature(Feature.PASSIVE.ToString(), true);
- Assert
- .AreEqual(
- "I am chased by him", this.realiser.realise(_s4).getRealisation());
-
- // same thing, but giving the S constructor "me". Should recognise
- // correct pro
- // anyway
- var _s5 = this.phraseFactory
- .createClause("him", "chase", "I");
- Assert.AreEqual(
- "he chases me", this.realiser.realise(_s5).getRealisation());
-
- _s5 = this.phraseFactory.createClause("him", "chase", "I");
- _s5.setFeature(Feature.PASSIVE.ToString(), true);
- Assert
- .AreEqual(
- "I am chased by him", this.realiser.realise(_s5).getRealisation());
- }
-
- /**
- * Test that complements set within the VP are raised when sentence is
- * passivised.
- */
-
- [Test]
- public void testPassiveWithInternalVPComplement()
- {
- var vp = this.phraseFactory.createVerbPhrase(this.phraseFactory
- .createWord("upset", new LexicalCategory_VERB()));
- vp.addComplement(this.phraseFactory.createNounPhrase("the", "man"));
- var _s6 = this.phraseFactory.createClause(this.phraseFactory
- .createNounPhrase("the", "child"), vp);
- _s6.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- Assert.AreEqual("the child upset the man", this.realiser.realise(
- _s6).getRealisation());
-
- _s6.setFeature(Feature.PASSIVE.ToString(), true);
- Assert.AreEqual("the man was upset by the child", this.realiser
- .realise(_s6).getRealisation());
- }
-
- /**
- * Tests tenses with modals.
- */
-
- [Test]
- public void testModal()
- {
-
- setUp();
- // simple modal in present tense
- s3.setFeature(Feature.MODAL.ToString(), "should");
- Assert.AreEqual("the man should give the woman John's flower",
- this.realiser.realise(s3).getRealisation());
-
- // modal + future -- uses present
- setUp();
- s3.setFeature(Feature.MODAL.ToString(), "should");
- s3.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- Assert.AreEqual("the man should give the woman John's flower",
- this.realiser.realise(s3).getRealisation());
-
- // modal + present progressive
- setUp();
- s3.setFeature(Feature.MODAL.ToString(), "should");
- s3.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- s3.setFeature(Feature.PROGRESSIVE.ToString(), true);
- Assert.AreEqual("the man should be giving the woman John's flower",
- this.realiser.realise(s3).getRealisation());
-
- // modal + past tense
- setUp();
- s3.setFeature(Feature.MODAL.ToString(), "should");
- s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- Assert.AreEqual(
- "the man should have given the woman John's flower",
- this.realiser.realise(s3).getRealisation());
-
- // modal + past progressive
- setUp();
- s3.setFeature(Feature.MODAL.ToString(), "should");
- s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- s3.setFeature(Feature.PROGRESSIVE.ToString(), true);
-
- Assert.AreEqual(
- "the man should have been giving the woman John's flower",
- this.realiser.realise(s3).getRealisation());
-
- }
-
- /**
- * Test for passivisation with mdoals
- */
-
- [Test]
- public void testModalWithPassive()
- {
- var obj = this.phraseFactory.createNounPhrase("the",
- "pizza");
- var post = this.phraseFactory.createAdjectivePhrase("good");
- var aso = this.phraseFactory.createAdverbPhrase("as");
- aso.addComplement(post);
- var verb = this.phraseFactory.createVerbPhrase("classify");
- verb.addPostModifier( aso );
- verb.addComplement(obj);
- var s = this.phraseFactory.createClause();
- s.setVerbPhrase(verb);
- s.setFeature(Feature.MODAL.ToString(), "can");
- // s.setFeature(Feature.FORM, Form.INFINITIVE);
- s.setFeature(Feature.PASSIVE.ToString(), true);
- Assert.AreEqual("the pizza can be classified as good",
- this.realiser.realise(s).getRealisation());
- }
-
- [Test]
- public void testPassiveWithPPCompl()
- {
- // passive with just complement
- var subject = this.phraseFactory.createNounPhrase("wave");
- subject.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
- var obj = this.phraseFactory.createNounPhrase("surfer");
- obj.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
-
- var _s1 = this.phraseFactory.createClause(subject,
- "carry", obj);
-
- // add a PP complement
- var pp = this.phraseFactory.createPrepositionPhrase("to",
- this.phraseFactory.createNounPhrase("the", "shore"));
- pp.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
- DiscourseFunction.INDIRECT_OBJECT);
- _s1.addComplement(pp);
-
- _s1.setFeature(Feature.PASSIVE.ToString(), true);
- this.realiser.setDebugMode(true);
- Assert.AreEqual(
- "surfers are carried to the shore by waves", this.realiser
- .realise(_s1).getRealisation());
- }
-
- [Test]
- public void testPassiveWithPPMod()
- {
- // passive with just complement
- var subject = this.phraseFactory.createNounPhrase("wave");
- subject.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
- var obj = this.phraseFactory.createNounPhrase("surfer");
- obj.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
-
- var _s1 = this.phraseFactory.createClause(subject,
- "carry", obj);
-
- // add a PP complement
- var pp = this.phraseFactory.createPrepositionPhrase("to",
- this.phraseFactory.createNounPhrase("the", "shore"));
- _s1.addPostModifier(pp);
-
- _s1.setFeature(Feature.PASSIVE.ToString(), true);
-
- Assert.AreEqual(
- "surfers are carried to the shore by waves", this.realiser
- .realise(_s1).getRealisation());
- }
-
- [Test]
- public void testCuePhrase()
- {
- var subject = this.phraseFactory.createNounPhrase("wave");
- subject.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
- var obj = this.phraseFactory.createNounPhrase("surfer");
- obj.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
-
- var _s1 = this.phraseFactory.createClause(subject,
- "carry", obj);
-
- // add a PP complement
- var pp = this.phraseFactory.createPrepositionPhrase("to",
- this.phraseFactory.createNounPhrase("the", "shore"));
- _s1.addPostModifier(pp);
-
- _s1.setFeature(Feature.PASSIVE.ToString(), true);
-
- _s1.addFrontModifier("however");
-
-
- //without comma separation of cue phrase
- Assert.AreEqual(
- "however surfers are carried to the shore by waves", this.realiser
- .realise(_s1).getRealisation());
-
- //with comma separation
- this.realiser.setCommaSepCuephrase(true);
- Assert.AreEqual(
- "however, surfers are carried to the shore by waves", this.realiser
- .realise(_s1).getRealisation());
- }
-
-
- /**
- * Check that setComplement replaces earlier complements
- */
-
- [Test]
- public void setComplementTest()
- {
- var s = this.phraseFactory.createClause();
- s.setSubject("I");
- s.setVerb("see");
- s.setObject("a dog");
-
- Assert.AreEqual("I see a dog", this.realiser.realise(s)
- .getRealisation());
-
- s.setObject("a cat");
- Assert.AreEqual("I see a cat", this.realiser.realise(s)
- .getRealisation());
-
- s.setObject("a wolf");
- Assert.AreEqual("I see a wolf", this.realiser.realise(s)
- .getRealisation());
-
- }
-
-
- /**
- * Test for subclauses involving WH-complements Based on a query by Owen
- * Bennett
- */
-
- [Test]
- public void subclausesTest()
- {
- // Once upon a time, there was an Accountant, called Jeff, who lived in
- // a forest.
-
- // main sentence
- var acct = this.phraseFactory.createNounPhrase("a",
- "accountant");
-
- // first postmodifier of "an accountant"
- var sub1 = this.phraseFactory.createVerbPhrase("call");
- sub1.addComplement("Jeff");
- sub1.setFeature(Feature.FORM.ToString(), Form.PAST_PARTICIPLE);
- // this is an appositive modifier, which makes simplenlg put it between
- // commas
- sub1.setFeature(Feature.APPOSITIVE.ToString(), true);
- acct.addPostModifier(sub1);
-
- // second postmodifier of "an accountant" is "who lived in a forest"
- var sub2 = this.phraseFactory.createClause();
- var subvp = this.phraseFactory.createVerbPhrase("live");
- subvp.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- subvp.setComplement(this.phraseFactory.createPrepositionPhrase("in",
- this.phraseFactory.createNounPhrase("a", "forest")));
- sub2.setVerbPhrase(subvp);
- // simplenlg can't yet handle wh-clauses in NPs, so we need to hack it
- // by setting the subject to "who"
- sub2.setSubject("who");
- acct.addPostModifier(sub2);
-
- // main sentence
- var s = this.phraseFactory.createClause("there", "be", acct);
- s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
-
- // add front modifier "once upon a time"
- s.addFrontModifier("once upon a time");
-
- Assert.AreEqual(
- "once upon a time there was an accountant, called Jeff, who lived in a forest",
- this.realiser.realise(s).getRealisation());
-
- }
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/CoordinationTest.cs b/SharpSimpleNLGUnitTests/syntax/CoordinationTest.cs
deleted file mode 100644
index ad1a7f9..0000000
--- a/SharpSimpleNLGUnitTests/syntax/CoordinationTest.cs
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
- /**
- * Some tests for coordination, especially of coordinated VPs with modifiers.
- *
- * @author Albert Gatt
- *
- */
-
- public class CoordinationTest : SimpleNLG4TestBase
- {
-
-
-
- /**
- * Check that empty coordinate phrases are not realised as "null"
- */
- [Test]
-
- public void emptyCoordinationTest()
- {
- //this.realiser.setDebugMode(true);
- // first a simple phrase with no coordinates
- var coord = this.phraseFactory.createCoordinatedPhrase();
- //Assert.AreEqual("", this.realiser.realise(coord).getRealisation());
-
- // now one with a premodifier and nothing else
- coord.addPreModifier(this.phraseFactory.createAdjectivePhrase("nice"));
- Assert.AreEqual("nice", this.realiser.realise(coord)
- .getRealisation());
- }
-
- /**
- * Test pre and post-modification of coordinate VPs inside a sentence.
- */
- [Test]
-
- public void testModifiedCoordVP()
- {
- var coord = this.phraseFactory
- .createCoordinatedPhrase(this.getUp, this.fallDown);
- coord.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- Assert.AreEqual("got up and fell down", this.realiser
- .realise(coord).getRealisation());
-
- // add a premodifier
- coord.addPreModifier("slowly");
- Assert.AreEqual("slowly got up and fell down", this.realiser
- .realise(coord).getRealisation());
-
- // adda postmodifier
- coord.addPostModifier(this.behindTheCurtain);
- Assert.AreEqual("slowly got up and fell down behind the curtain",
- this.realiser.realise(coord).getRealisation());
-
- // put within the context of a sentence
- var s = this.phraseFactory.createClause("Jake", coord);
- s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- Assert.AreEqual(
- "Jake slowly got up and fell down behind the curtain",
- this.realiser.realise(s).getRealisation());
-
- // add premod to the sentence
- s.addPreModifier(this.lexicon
- .getWord("however", new LexicalCategory_ADVERB()));
- Assert.AreEqual(
- "Jake however slowly got up and fell down behind the curtain",
- this.realiser.realise(s).getRealisation());
-
- // add postmod to the sentence
- s.addPostModifier(this.inTheRoom);
- Assert.AreEqual(
- "Jake however slowly got up and fell down behind the curtain in the room",
- this.realiser.realise(s).getRealisation());
- }
-
- /**
- * Test due to Chris Howell -- create a complex sentence with front modifier
- * and coordinateVP. this is a version in which we create the coordinate
- * phrase directly.
- */
- [Test]
-
- public void testCoordinateVPComplexSubject()
- {
- // "As a result of the procedure the patient had an adverse contrast media reaction and went into cardiogenic shock."
- var s = this.phraseFactory.createClause();
-
- s.setSubject(this.phraseFactory.createNounPhrase("the", "patient"));
-
- // first VP
- var vp1 = this.phraseFactory.createVerbPhrase(this.lexicon
- .getWord("have", new LexicalCategory_VERB()));
- var np1 = this.phraseFactory.createNounPhrase("a",
- this.lexicon.getWord("contrast media reaction",
- new LexicalCategory_NOUN()));
- np1.addPreModifier(this.lexicon.getWord("adverse",
- new LexicalCategory_ADJECTIVE()));
- vp1.addComplement(np1);
-
- // second VP
- var vp2 = this.phraseFactory.createVerbPhrase(this.lexicon
- .getWord("go", new LexicalCategory_VERB()));
- var pp = this.phraseFactory
- .createPrepositionPhrase("into", this.lexicon.getWord(
- "cardiogenic shock", new LexicalCategory_NOUN()));
- vp2.addComplement(pp);
-
- // coordinate
- var coord = this.phraseFactory
- .createCoordinatedPhrase(vp1, vp2);
- coord.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- Assert.AreEqual(
- "had an adverse contrast media reaction and went into cardiogenic shock",
- this.realiser.realise(coord).getRealisation());
-
- // now put this in the sentence
- s.setVerbPhrase(coord);
- s.addFrontModifier("As a result of the procedure");
- Assert.AreEqual(
- "As a result of the procedure the patient had an adverse contrast media reaction and went into cardiogenic shock",
- this.realiser.realise(s).getRealisation());
-
- }
-
- /**
- * Test setting a conjunction to null
- */
-
- public void testNullConjunction()
- {
- var p = this.phraseFactory.createClause("I", "be", "happy");
- var q = this.phraseFactory.createClause("I", "eat", "fish");
- var pq = this.phraseFactory
- .createCoordinatedPhrase();
- pq.addCoordinate(p);
- pq.addCoordinate(q);
- pq.setFeature(Feature.CONJUNCTION.ToString(), "");
-
- // should come out without conjunction
- Assert.AreEqual("I am happy I eat fish", this.realiser.realise(pq)
- .getRealisation());
-
- // should come out without conjunction
- pq.setFeature(Feature.CONJUNCTION.ToString(), null);
- Assert.AreEqual("I am happy I eat fish", this.realiser.realise(pq)
- .getRealisation());
-
- }
-
- /**
- * Check that the negation feature on a child of a coordinate phrase remains
- * as set, unless explicitly set otherwise at the parent level.
- */
- [Test]
-
- public void testNegationFeature()
- {
- var s1 = this.phraseFactory
- .createClause("he", "have", "asthma");
- var s2 = this.phraseFactory.createClause("he", "have",
- "diabetes");
- s1.setFeature(Feature.NEGATED.ToString(), true);
- var coord = this.phraseFactory
- .createCoordinatedPhrase(s1, s2);
- var realisation = this.realiser.realise(coord).getRealisation();
- Assert.AreEqual("he does not have asthma and he has diabetes",
- realisation);
- }
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/DeterminerTest.cs b/SharpSimpleNLGUnitTests/syntax/DeterminerTest.cs
deleted file mode 100644
index 61d20b4..0000000
--- a/SharpSimpleNLGUnitTests/syntax/DeterminerTest.cs
+++ /dev/null
@@ -1,400 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-
-namespace SimpleNLGTests.syntax
-{
-
- /**
- * Some determiner tests -- in particular for indefinite articles like "a" or "an".
- *
- * @author Saad Mahamood, Data2Text Limited.
- *
- */
-
- public class DeterminerTest : SimpleNLG4TestBase
- {
-
- /**
- * testLowercaseConstant - Test for when there is a lower case constant
- */
-
- [Test]
- public void testLowercaseConstant()
- {
-
- var sentence = this.phraseFactory.createClause();
-
- var subject = this.phraseFactory.createNounPhrase("a", "dog");
- sentence.setSubject(subject);
-
- var output = this.realiser.realiseSentence(sentence);
-
- Assert.AreEqual("A dog.", output);
- }
-
- /**
- * testLowercaseVowel - Test for "an" as a specifier.
- */
-
- [Test]
- public void testLowercaseVowel()
- {
- var sentence = this.phraseFactory.createClause();
-
- var subject = this.phraseFactory.createNounPhrase("a", "owl");
- sentence.setSubject(subject);
-
- var output = this.realiser.realiseSentence(sentence);
-
- Assert.AreEqual("An owl.", output);
- }
-
- /**
- * testUppercaseConstant - Test for when there is a upper case constant
- */
-
- [Test]
- public void testUppercaseConstant()
- {
-
- var sentence = this.phraseFactory.createClause();
-
- var subject = this.phraseFactory.createNounPhrase("a", "Cat");
- sentence.setSubject(subject);
-
- var output = this.realiser.realiseSentence(sentence);
-
- Assert.AreEqual("A Cat.", output);
- }
-
- /**
- * testUppercaseVowel - Test for "an" as a specifier for upper subjects.
- */
-
- [Test]
- public void testUppercaseVowel()
- {
- var sentence = this.phraseFactory.createClause();
-
- var subject = this.phraseFactory.createNounPhrase("a", "Emu");
- sentence.setSubject(subject);
-
- var output = this.realiser.realiseSentence(sentence);
-
- Assert.AreEqual("An Emu.", output);
- }
-
- /**
- * testNumericA - Test for "a" specifier with a numeric subject
- */
-
- [Test]
- public void testNumericA()
- {
- var sentence = this.phraseFactory.createClause();
-
- var subject = this.phraseFactory.createNounPhrase("a", "7");
- sentence.setSubject(subject);
-
- var output = this.realiser.realiseSentence(sentence);
-
- Assert.AreEqual("A 7.", output);
- }
-
- /**
- * testNumericAn - Test for "an" specifier with a numeric subject
- */
-
- [Test]
- public void testNumericAn()
- {
- var sentence = this.phraseFactory.createClause();
-
- var subject = this.phraseFactory.createNounPhrase("a", "11");
- sentence.setSubject(subject);
-
- var output = this.realiser.realiseSentence(sentence);
-
- Assert.AreEqual("An 11.", output);
- }
-
- /**
- * testIrregularSubjects - Test irregular subjects that don't conform to the
- * vowel vs. constant divide.
- */
-
- [Test]
- public void testIrregularSubjects()
- {
- var sentence = this.phraseFactory.createClause();
-
- var subject = this.phraseFactory.createNounPhrase("a", "one");
- sentence.setSubject(subject);
-
- var output = this.realiser.realiseSentence(sentence);
-
- Assert.AreEqual("A one.", output);
- }
-
- /**
- * testSingluarThisDeterminerNPObject - Test for "this" when used in the singular form as a determiner in a NP Object
- */
-
- [Test]
- public void testSingluarThisDeterminerNPObject()
- {
- var sentence_1 = this.phraseFactory.createClause();
-
- var nounPhrase_1 = this.phraseFactory.createNounPhrase("this", "monkey");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.AreEqual("This monkey.", this.realiser.realiseSentence(sentence_1));
- }
-
- /**
- * testPluralThisDeterminerNPObject - Test for "this" when used in the plural form as a determiner in a NP Object
- */
-
- [Test]
- public void testPluralThisDeterminerNPObject()
- {
- var sentence_1 = this.phraseFactory.createClause();
-
- var nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(true);
- nounPhrase_1.setDeterminer("this");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.AreEqual("These monkeys.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testSingluarThatDeterminerNPObject - Test for "that" when used in the singular form as a determiner in a NP Object
- */
-
- [Test]
- public void testSingluarThatDeterminerNPObject()
- {
- var sentence_1 = this.phraseFactory.createClause();
-
- var nounPhrase_1 = this.phraseFactory.createNounPhrase("that", "monkey");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.AreEqual("That monkey.", this.realiser.realiseSentence(sentence_1));
- }
-
- /**
- * testPluralThatDeterminerNPObject - Test for "that" when used in the plural form as a determiner in a NP Object
- */
-
- [Test]
- public void testPluralThatDeterminerNPObject()
- {
- var sentence_1 = this.phraseFactory.createClause();
-
- var nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(true);
- nounPhrase_1.setDeterminer("that");
- sentence_1.setObject(nounPhrase_1);
-
- this.realiser.setDebugMode(true);
- Assert.AreEqual("Those monkeys.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testSingularThoseDeterminerNPObject - Test for "those" when used in the singular form as a determiner in a NP Object
- */
-
- [Test]
- public void testSingularThoseDeterminerNPObject()
- {
- var sentence_1 = this.phraseFactory.createClause();
-
- var nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(false);
- nounPhrase_1.setDeterminer("those");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.AreEqual("That monkey.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testSingularTheseDeterminerNPObject - Test for "these" when used in the singular form as a determiner in a NP Object
- */
-
- [Test]
- public void testSingularTheseDeterminerNPObject()
- {
- var sentence_1 = this.phraseFactory.createClause();
-
- var nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(false);
- nounPhrase_1.setDeterminer("these");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.AreEqual("This monkey.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testPluralThoseDeterminerNPObject - Test for "those" when used in the plural form as a determiner in a NP Object
- */
-
- [Test]
- public void testPluralThoseDeterminerNPObject()
- {
- var sentence_1 = this.phraseFactory.createClause();
-
- var nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(true);
- nounPhrase_1.setDeterminer("those");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.AreEqual("Those monkeys.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testPluralTheseDeterminerNPObject - Test for "these" when used in the plural form as a determiner in a NP Object
- */
-
- [Test]
- public void testPluralTheseDeterminerNPObject()
- {
- var sentence_1 = this.phraseFactory.createClause();
-
- var nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(true);
- nounPhrase_1.setDeterminer("these");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.AreEqual("These monkeys.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testSingularTheseDeterminerNPObject - Test for "these" when used in the singular form as a determiner in a NP Object
- * using the NIHDB Lexicon.
- */
-
-/*
- public void testSingularTheseDeterminerNPObject_NIHDBLexicon()
- {
- this.lexicon = new NIHDBLexicon(DB_FILENAME);
- this.phraseFactory = new NLGFactory(this.lexicon);
- this.realiser = new Realiser(this.lexicon);
-
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(false);
- nounPhrase_1.setDeterminer("these");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.AreEqual("This monkey.", this.realiser.realiseSentence(sentence_1));
-
- }
- */
-
- /**
- * testSingularThoseDeterminerNPObject - Test for "those" when used in the singular form as a determiner in a NP Object
- * using the NIHDB Lexicon
- */
-
-/*
- public void testSingularThoseDeterminerNPObject_NIHDBLexicon()
- {
- this.lexicon = new NIHDBLexicon(DB_FILENAME);
- this.phraseFactory = new NLGFactory(this.lexicon);
- this.realiser = new Realiser(this.lexicon);
-
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(false);
- nounPhrase_1.setDeterminer("those");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.AreEqual("That monkey.", this.realiser.realiseSentence(sentence_1));
-
- }
- */
-
-
- /**
- * testPluralThatDeterminerNPObject - Test for "that" when used in the plural form as a determiner in a NP Object
- * using the NIHDB Lexicon.
- */
-
- /*
- public void testPluralThatDeterminerNPObject_NIHDBLexicon()
- {
- this.lexicon = new NIHDBLexicon(DB_FILENAME);
- this.phraseFactory = new NLGFactory(this.lexicon);
- this.realiser = new Realiser(this.lexicon);
-
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(true);
- nounPhrase_1.setDeterminer("that");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.AreEqual("Those monkeys.", this.realiser.realiseSentence(sentence_1));
-
- }
- */
-
- /**
- * testPluralThisDeterminerNPObject - Test for "this" when used in the plural form as a determiner in a NP Object
- * using the NIHDBLexicon.
- */
-
- /*
- public void testPluralThisDeterminerNPObject_NIHDBLexicon()
- {
- this.lexicon = new NIHDBLexicon(DB_FILENAME);
- this.phraseFactory = new NLGFactory(this.lexicon);
- this.realiser = new Realiser(this.lexicon);
-
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(true);
- nounPhrase_1.setDeterminer("this");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.AreEqual("These monkeys.", this.realiser.realiseSentence(sentence_1));
-
- }
- */
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/DocumentElementTest.cs b/SharpSimpleNLGUnitTests/syntax/DocumentElementTest.cs
deleted file mode 100644
index 6d526f5..0000000
--- a/SharpSimpleNLGUnitTests/syntax/DocumentElementTest.cs
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using System.Collections.Generic;
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
-
- /**
- * Tests for the DocumentElement class.
- *
- * @author ereiter
- */
-
- public class DocumentElementTest : SimpleNLG4TestBase
- {
-
- private SPhraseSpec p1, p2, p3;
-
- /**
- * Instantiates a new document element test.
- *
- * @param name
- * the name
- */
-
- [SetUp]
- protected override void setUp()
- {
- p1 = this.phraseFactory.createClause("you", "be", "happy");
- p2 = this.phraseFactory.createClause("I", "be", "sad");
- p3 = this.phraseFactory.createClause("they", "be", "nervous");
- }
-
-
- /**
- * Basic tests.
- */
-
- [Test]
- public void testBasics()
- {
- var s1 = this.phraseFactory.createSentence(p1);
- var s2 = this.phraseFactory.createSentence(p2);
- var s3 = this.phraseFactory.createSentence(p3);
-
- var par1 = this.phraseFactory.createParagraph(new List { s1, s2, s3});
-
- Assert.AreEqual("You are happy. I am sad. They are nervous.\n\n",
- this.realiser.realise(par1).getRealisation());
-
- }
-
- /**
- * Ensure that no extra whitespace is inserted into a realisation if a
- * constituent is empty. (This is to check for a bug fix for addition of
- * spurious whitespace).
- */
-
- public void testExtraWhitespace()
- {
- var np1 = this.phraseFactory.createNounPhrase("a", "vessel");
-
- // empty coordinate as premod
- np1.setPreModifier(this.phraseFactory.createCoordinatedPhrase());
- Assert.AreEqual("a vessel", this.realiser.realise(np1)
- .getRealisation());
-
- // empty adjP as premod
- np1.setPreModifier(this.phraseFactory.createAdjectivePhrase());
- Assert.AreEqual("a vessel", this.realiser.realise(np1)
- .getRealisation());
-
- // empty string
- np1.setPreModifier("");
- Assert.AreEqual("a vessel", this.realiser.realise(np1)
- .getRealisation());
-
- }
-
- /**
- * test whether sents can be embedded in a section without intervening paras
- */
-
- [Test]
- public void testEmbedding()
- {
- var sent = this.phraseFactory.createSentence("This is a test");
- var sent2 = this.phraseFactory.createSentence(this.phraseFactory
- .createClause("John", "be", "missing"));
- var section = this.phraseFactory.createSection("SECTION TITLE");
- section.addComponent(sent);
- section.addComponent(sent2);
-
- Assert.AreEqual(
- "SECTION TITLE\nThis is a test.\n\nJohn is missing.\n\n",
- this.realiser.realise(section).getRealisation());
- }
-
- [Test]
- public void testSections()
- {
- // doc which contains a section, and two paras
- var doc = this.phraseFactory
- .createDocument("Test Document");
-
- var section = this.phraseFactory
- .createSection("Test Section");
- doc.addComponent(section);
-
- var para1 = this.phraseFactory.createParagraph();
- var sent1 = this.phraseFactory
- .createSentence("This is the first test paragraph");
- para1.addComponent(sent1);
- section.addComponent(para1);
-
- var para2 = this.phraseFactory.createParagraph();
- var sent2 = this.phraseFactory
- .createSentence("This is the second test paragraph");
- para2.addComponent(sent2);
- section.addComponent(para2);
-
- Assert
- .AreEqual(
- "Test Document\n\nTest Section\nThis is the first test paragraph.\n\nThis is the second test paragraph.\n\n",
- this.realiser.realise(doc).getRealisation());
- //
- // Realiser htmlRealiser = new Realiser();
- // htmlRealiser.setHTML(true);
- // Assert
- // .AreEqual(
- // "Test Document \r\nTest Section \r\nTest Subsection \r\nThis is the first test paragraph. \r\nThis is the second test paragraph. \r\n \r\n\r\n",
- // htmlRealiser.realise(doc));
- //
- // // now lets try a doc with a header, header-less section and
- // subsection,
- // // and 2 paras (no list)
- // doc = new TextSpec();
- // doc.setDocument();
- // doc.setHeading("Test Document2");
- //
- // section = new TextSpec();
- // section.setDocStructure(DocStructure.SECTION);
- // ;
- // doc.addSpec(section);
- //
- // subsection = new TextSpec();
- // subsection.setDocStructure(DocStructure.SUBSECTION);
- // section.addSpec(subsection);
- //
- // // use list from above, with indent
- // subsection.addChild(list);
- // list.setIndentedList(false);
- //
- // Assert
- // .AreEqual(
- // "Test Document2\r\n\r\nThis is the first test paragraph.\r\n\r\nThis is the second test paragraph.\r\n",
- // this.realiser.realise(doc));
- //
- // Assert
- // .AreEqual(
- // "Test Document2 \r\nThis is the first test paragraph.
\r\nThis is the second test paragraph.
\r\n\r\n",
- // htmlRealiser.realise(doc));
-
- }
-
- /**
- * Tests for lists and embedded lists
- */
-
- public void testListItems()
- {
- var list = this.phraseFactory.createList();
- list.addComponent(this.phraseFactory.createListItem(p1));
- list.addComponent(this.phraseFactory.createListItem(p2));
- list.addComponent(this.phraseFactory.createListItem(this.phraseFactory
- .createCoordinatedPhrase(p1, p2)));
- var realisation = this.realiser.realise(list).getRealisation();
- Assert.AreEqual(
- "* you are happy\n* I am sad\n* you are happy and I am sad\n",
- realisation);
- }
- }
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/ElisionTest.cs b/SharpSimpleNLGUnitTests/syntax/ElisionTest.cs
deleted file mode 100644
index 59a64f5..0000000
--- a/SharpSimpleNLGUnitTests/syntax/ElisionTest.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
- public class ElisionTest : SimpleNLG4TestBase
- {
-
-
- /**
- * Test elision of phrases in various places in the sentence
- */
-// public void testPhraseElision() {
-// SPhraseSpec s1 = this.phraseFactory.createClause();
-// s1.setSubject(this.np4); //the rock
-// this.kiss.setComplement(this.np5);//kiss the curtain
-// s1.setVerbPhrase(this.kiss);
-//
-// Assert.AreEqual("the rock kisses the curtain", this.realiser.realise(s1).getRealisation());
-//
-// //elide subject np
-// this.np4.setFeature(Feature.ELIDED, true);
-// Assert.AreEqual("kisses the curtain", this.realiser.realise(s1).getRealisation());
-//
-// //elide vp
-// this.np4.setFeature(Feature.ELIDED, false);
-// this.kiss.setFeature(Feature.ELIDED, true);
-// Assert.AreEqual("the rock", this.realiser.realise(s1).getRealisation());
-//
-// //elide complement only
-// this.kiss.setFeature(Feature.ELIDED, false);
-// this.np5.setFeature(Feature.ELIDED, true);
-// Assert.AreEqual("the rock kisses", this.realiser.realise(s1).getRealisation());
-// }
-
-/* DISABLED here as this test doesnt pass in current build of Java SimpleNLG */
- /**
- * Test for elision of specific words rather than phrases
- */
-
- //[Test]
- public void wordElisionTest()
- {
- this.realiser.setDebugMode(true);
- var s1 = this.phraseFactory.createClause();
- s1.setSubject(this.np4); //the rock
- this.kiss.setComplement(this.np5); //kiss the curtain
- s1.setVerbPhrase(this.kiss);
-
- this.np5.setFeature(Feature.ELIDED.ToString(), true);
- Assert.AreEqual("the rock kisses", this.realiser.realise(s1).getRealisation());
- }
-
-
-
- /**
- * Test for elision of specific words rather than phrases
- *
- [Test]
- public void testWordElision() {
- this.realiser.setDebugMode(true);
- SPhraseSpec s1 = this.phraseFactory.createClause();
- s1.setSubject(this.np4); //the rock
- this.kiss.setComplement(this.np5);//kiss the curtain
- s1.setVerbPhrase(this.kiss);
-
- this.kiss.getHead().setFeature(Feature.ELIDED, true);
- Assert.AreEqual("the rock kisses the curtain", this.realiser.realise(s1).getRealisation());
- } */
- }
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/FeatureTest.cs b/SharpSimpleNLGUnitTests/syntax/FeatureTest.cs
deleted file mode 100644
index 61916ac..0000000
--- a/SharpSimpleNLGUnitTests/syntax/FeatureTest.cs
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
- /**
- * Tests that check that realization of different Features against NLGElements.
- *
- * @author François Portet
- */
-
- public class FeatureTest : SimpleNLG4TestBase
- {
-
- /**
- * Tests use of the Possessive Feature.
- */
-
- [Test]
- public void testPossessiveFeature_PastTense()
- {
- // Create the pronoun 'she'
- var she = this.phraseFactory.createWord("she", new LexicalCategory_PRONOUN());
-
- // Set possessive on the pronoun to make it 'her'
- she.setFeature(Feature.POSSESSIVE.ToString(), true);
-
- // Create a noun phrase with the subject lover and the determiner
- // as she
- var herLover = this.phraseFactory.createNounPhrase(she, "lover");
-
- // Create a clause to say 'he be her lover'
- var clause = this.phraseFactory.createClause("he", "be", herLover);
-
- // Add the cue phrase need the comma as orthography
- // currently doesn't handle this.
- // This could be expanded to be a noun phrase with determiner
- // 'two' and noun 'week', set to plural and with a premodifier of
- // 'after'
- clause.setFeature(Feature.CUE_PHRASE.ToString(), "after two weeks,");
-
- // Add the 'for a fortnight' as a post modifier. Alternatively
- // this could be added as a prepositional phrase 'for' with a
- // complement of a noun phrase ('a' 'fortnight')
- clause.addPostModifier("for a fortnight");
-
- // Set 'be' to 'was' as past tense
- clause.setFeature(Feature.TENSE.ToString(), Tense.PAST);
-
- // Add the clause to a sentence.
- var sentence1 = this.phraseFactory.createSentence(clause);
-
- // Realise the sentence
- var realised = this.realiser.realise(sentence1);
-
- Assert.AreEqual("After two weeks, he was her lover for a fortnight.",
- realised.getRealisation());
- }
-
- /**
- * Basic tests.
- */
-
- [Test]
- public void testTwoPossessiveFeature_PastTense()
- {
- // Create the pronoun 'she'
- var she = this.phraseFactory.createWord("she", new LexicalCategory_PRONOUN());
-
- // Set possessive on the pronoun to make it 'her'
- she.setFeature(Feature.POSSESSIVE.ToString(), true);
-
- // Create a noun phrase with the subject lover and the determiner
- // as she
- var herLover = this.phraseFactory.createNounPhrase(she, "lover");
- herLover.setPlural(true);
-
- // Create the pronoun 'he'
- NLGElement he = this.phraseFactory.createNounPhrase(new LexicalCategory_PRONOUN(), "he");
- he.setPlural(true);
-
- // Create a clause to say 'they be her lovers'
- var clause = this.phraseFactory.createClause(he, "be", herLover);
- clause.setFeature(Feature.POSSESSIVE.ToString(), true);
-
- // Add the cue phrase need the comma as orthography
- // currently doesn't handle this.
- // This could be expanded to be a noun phrase with determiner
- // 'two' and noun 'week', set to plural and with a premodifier of
- // 'after'
- clause.setFeature(Feature.CUE_PHRASE.ToString(), "after two weeks,");
-
- // Add the 'for a fortnight' as a post modifier. Alternatively
- // this could be added as a prepositional phrase 'for' with a
- // complement of a noun phrase ('a' 'fortnight')
- clause.addPostModifier("for a fortnight");
-
- // Set 'be' to 'was' as past tense
- clause.setFeature(Feature.TENSE.ToString(), Tense.PAST);
-
- // Add the clause to a sentence.
- var sentence1 = this.phraseFactory.createSentence(clause);
-
- // Realise the sentence
- var realised = this.realiser.realise(sentence1);
-
- Assert.AreEqual("After two weeks, they were her lovers for a fortnight.",
- realised.getRealisation());
- }
-
- /**
- * Test use of the Complementiser feature by combining two S's using cue phrase and gerund.
- */
-
- [Test]
- public void testComplementiserFeature_PastTense()
- {
- var born = this.phraseFactory.createClause("Dave Bus", "be", "born");
- born.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- born.addPostModifier("in");
- born.setFeature(Feature.COMPLEMENTISER.ToString(), "which");
-
- var theHouse = this.phraseFactory.createNounPhrase("the", "house");
- theHouse.addComplement(born);
-
- var clause = this.phraseFactory.createClause(theHouse, "be",
- this.phraseFactory.createPrepositionPhrase("in", "Edinburgh"));
- var sentence = this.phraseFactory.createSentence(clause);
- var realised = this.realiser.realise(sentence);
-
- // Retrieve the realisation and dump it to the console
- Assert.AreEqual("The house which Dave Bus was born in is in Edinburgh.",
- realised.getRealisation());
- }
-
- /**
- * Test use of the Complementiser feature in a {@link CoordinatedPhraseElement} by combine two S's using cue phrase and gerund.
- */
-
- [Test]
- public void testComplementiserFeatureInACoordinatePhrase_PastTense()
- {
- var dave = this.phraseFactory.createWord("Dave Bus", new LexicalCategory_NOUN());
- var albert = this.phraseFactory.createWord("Albert", new LexicalCategory_NOUN());
-
- var coord1 = new CoordinatedPhraseElement(
- dave, albert);
-
- var born = this.phraseFactory.createClause(coord1, "be", "born");
- born.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- born.addPostModifier("in");
- born.setFeature(Feature.COMPLEMENTISER.ToString(), "which");
-
- var theHouse = this.phraseFactory.createNounPhrase("the", "house");
- theHouse.addComplement(born);
-
- var clause = this.phraseFactory.createClause(theHouse, "be",
- this.phraseFactory.createPrepositionPhrase("in", "Edinburgh"));
- var sentence = this.phraseFactory.createSentence(clause);
-
- var realised = this.realiser.realise(sentence);
-
- // Retrieve the realisation and dump it to the console
- Assert.AreEqual("The house which Dave Bus and Albert were born in is in Edinburgh.",
- realised.getRealisation());
- }
-
- /**
- * Test the use of the Progressive and Complementiser Features in future tense.
- */
-
- [Test]
- public void testProgressiveAndComplementiserFeatures_FutureTense()
- {
- // Inner clause is 'I' 'make' 'sentence' 'for'.
- var inner = this.phraseFactory.createClause("I", "make", "sentence for");
- // Inner clause set to progressive.
- inner.setFeature(Feature.PROGRESSIVE.ToString(), true);
-
- //Complementiser on inner clause is 'whom'
- inner.setFeature(Feature.COMPLEMENTISER.ToString(), "whom");
-
- // create the engineer and add the inner clause as post modifier
- var engineer = this.phraseFactory.createNounPhrase("the engineer");
- engineer.addComplement(inner);
-
- // Outer clause is: 'the engineer' 'go' (preposition 'to' 'holidays')
- var outer = this.phraseFactory.createClause(engineer, "go",
- this.phraseFactory.createPrepositionPhrase("to", "holidays"));
-
- // Outer clause tense is Future.
- outer.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
-
- // Possibly progressive as well not sure.
- outer.setFeature(Feature.PROGRESSIVE.ToString(), true);
-
- //Outer clause postmodifier would be 'tomorrow'
- outer.addPostModifier("tomorrow");
- var sentence = this.phraseFactory.createSentence(outer);
- var realised = this.realiser.realise(sentence);
-
- // Retrieve the realisation and dump it to the console
- Assert.AreEqual("The engineer whom I am making sentence for will be going to holidays tomorrow.",
- realised.getRealisation());
- }
-
-
- /**
- * Tests the use of the Complementiser, Passive, Perfect features in past tense.
- */
-
- [Test]
- public void testComplementiserPassivePerfectFeatures_PastTense()
- {
- var inner = this.phraseFactory.createClause("I", "play", "poker");
- inner.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- inner.setFeature(Feature.COMPLEMENTISER.ToString(), "where");
-
- var house = this.phraseFactory.createNounPhrase("the", "house");
- house.addComplement(inner);
-
- var outer = this.phraseFactory.createClause(null, "abandon", house);
-
- outer.addPostModifier("since 1986");
-
- outer.setFeature(Feature.PASSIVE.ToString(), true);
- outer.setFeature(Feature.PERFECT.ToString(), true);
-
- var sentence = this.phraseFactory.createSentence(outer);
- var realised = this.realiser.realise(sentence);
-
- // Retrieve the realisation and dump it to the console
- Assert.AreEqual("The house where I played poker has been abandoned since 1986.",
- realised.getRealisation());
- }
-
- /**
- * Tests the user of the progressive and complementiser featuers in past tense.
- */
-
- [Test]
- public void testProgressiveComplementiserFeatures_PastTense()
- {
- var sandwich = this.phraseFactory.createNounPhrase(new LexicalCategory_NOUN(), "sandwich");
- sandwich.setPlural(true);
- //
- var first = this.phraseFactory.createClause("I", "make", sandwich);
- first.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- first.setFeature(Feature.PROGRESSIVE.ToString(), true);
- first.setPlural(false);
-
- var second = this.phraseFactory.createClause("the mayonnaise", "run out");
- second.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- //
- second.setFeature(Feature.COMPLEMENTISER.ToString(), "when");
-
- first.addComplement(second);
-
- var sentence = this.phraseFactory.createSentence(first);
- var realised = this.realiser.realise(sentence);
-
- // Retrieve the realisation and dump it to the console
- Assert.AreEqual("I was making sandwiches when the mayonnaise ran out.",
- realised.getRealisation());
- }
-
- /**
- * Test the use of Passive in creating a Passive sentence structure: + [be] + + [by] + [Subject].
- */
-
- [Test]
- public void testPassiveFeature()
- {
- var phrase = this.phraseFactory.createClause("recession", "affect", "value");
- phrase.setFeature(Feature.PASSIVE.ToString(), true);
- var sentence = this.phraseFactory.createSentence(phrase);
- var realised = this.realiser.realise(sentence);
-
- Assert.AreEqual("Value is affected by recession.", realised.getRealisation());
- }
-
-
- /**
- * Test for repetition of the future auxiliary "will", courtesy of Luxor
- * Vlonjati
- */
-
- [Test]
- public void testFutureTense()
- {
- var test = this.phraseFactory.createClause();
-
- var subj = this.phraseFactory.createNounPhrase("I");
-
- var verb = this.phraseFactory.createVerbPhrase("go");
-
- var adverb = this.phraseFactory
- .createAdverbPhrase("tomorrow");
-
- test.setSubject(subj);
- test.setVerbPhrase(verb);
- test.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- test.addPostModifier(adverb);
- var sentence = this.realiser.realiseSentence(test);
- Assert.AreEqual("I will go tomorrow.", sentence);
-
- var test2 = this.phraseFactory.createClause();
- var vb = this.phraseFactory.createWord("go", new LexicalCategory_VERB());
- test2.setSubject(subj);
- test2.setVerb(vb);
- test2.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- test2.addPostModifier(adverb);
- var sentence2 = this.realiser.realiseSentence(test);
- Assert.AreEqual("I will go tomorrow.", sentence2);
-
- }
-
-
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/HTMLFormatterTest.cs b/SharpSimpleNLGUnitTests/syntax/HTMLFormatterTest.cs
deleted file mode 100644
index 6306455..0000000
--- a/SharpSimpleNLGUnitTests/syntax/HTMLFormatterTest.cs
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.After;
-import org.junit.Test;
-
-import simplenlg.format.english.HTMLFormatter;
-import simplenlg.framework.DocumentElement;
-import simplenlg.framework.NLGElement;
-import simplenlg.phrasespec.SPhraseSpec;
-
-// HTMLFormatter and HTMLFormatterTest ~ author James Christie, but taken from TextFormatter and TextFormatterTest
-
-public class HTMLFormatterTest extends SimpleNLG4Test {
-
- /**
- * Instantiates a new document element test.
- *
- * @param name
- * the name
- */
- public HTMLFormatterTest(String name) {
- super(name);
- }
-
- @Override
- @After
- public void tearDown() {
- super.tearDown();
- }
-
-
- /**
- * Check the correct [part] web page contents are being generated
- */
- [Test]
- public final void testWebPageContent( ) {
- // now build a document ...
- DocumentElement document = phraseFactory.createDocument( "This is a title" ) ;
-
- DocumentElement section = phraseFactory.createSection( "This is a section" ) ;
-
- DocumentElement paragraph1 = phraseFactory.createParagraph( ) ;
- DocumentElement sentence11 = phraseFactory.createSentence( "This is the first sentence of paragraph 1" ) ;
- paragraph1.addComponent( sentence11 ) ;
- DocumentElement sentence12 = phraseFactory.createSentence( "This is the second sentence of paragraph 1" ) ;
- paragraph1.addComponent( sentence12 ) ;
- section.addComponent( paragraph1 ) ;
- document.addComponent( section ) ;
-
- DocumentElement paragraph2 = phraseFactory.createParagraph( ) ;
- DocumentElement sentence2 = phraseFactory.createSentence( "This is the first sentence of paragraph 2" ) ;
- paragraph2.addComponent( sentence2 ) ;
- document.addComponent( paragraph2 ) ;
-
- DocumentElement paragraph3 = phraseFactory.createParagraph( ) ;
- DocumentElement sentence3 = phraseFactory.createSentence( "This is the first sentence of paragraph 3" ) ;
- paragraph3.addComponent( sentence3 ) ;
- document.addComponent( paragraph3 ) ;
-
- // now for a second section with three sentences in one paragraph using arrays.asList function
- SPhraseSpec p1 = phraseFactory.createClause( "Mary", "chase", "the monkey" ) ;
- SPhraseSpec p2 = phraseFactory.createClause( "the monkey", "fight back" ) ;
- SPhraseSpec p3 = phraseFactory.createClause( "Mary", "be", "nervous" ) ;
-
- DocumentElement s1 = phraseFactory.createSentence( p1 ) ;
- DocumentElement s2 = phraseFactory.createSentence( p2 ) ;
- DocumentElement s3 = phraseFactory.createSentence( p3 ) ;
-
- DocumentElement para1x3 = phraseFactory.createParagraph( Arrays.asList( s1, s2, s3 ) ) ;
-
- DocumentElement sectionList = phraseFactory.createSection( "This section contains lists" ) ;
- sectionList.addComponent( para1x3 ) ;
- document.addComponent( sectionList ) ;
-
- // from David Westwater 4-10-11
- DocumentElement element = phraseFactory.createList( ) ;
- List < NLGElement > list = new ArrayList < NLGElement > ( ) ;
- list.add( phraseFactory.createListItem( phraseFactory.createStringElement( "Item 1" ) ) ) ;
- list.add( phraseFactory.createListItem( phraseFactory.createStringElement( "Item 2" ) ) ) ;
- list.add( phraseFactory.createListItem( phraseFactory.createStringElement( "Item 3" ) ) ) ;
-
- element.addComponents( list ) ;
- document.addComponent( element ) ;
-
- // ... finally produce some output with HMTL tags ...
- System.out.println( "HTML realisation ~ \n=============================\n" ) ;
-
- String output = "" ;
-
- // this.realiser.setFormatter( new TextFormatter( ) ) ;
- this.realiser.setFormatter( new HTMLFormatter( ) ) ;
- // realiser.setDebugMode( true ) ; // hide after testing
- output += realiser.realise( document ).getRealisation( ) ;
-
- System.out.println( output ) ; // just to visually check what is being produced
-
- String expectedResults =
- "This is a title " +
- "This is a section " +
- "This is the first sentence of paragraph 1. This is the second sentence of paragraph 1.
" +
- "This is the first sentence of paragraph 2.
" +
- "This is the first sentence of paragraph 3.
" +
- "This section contains lists " +
- "Mary chases the monkey. The monkey fights back. Mary is nervous.
" +
- "" +
- "Item 1 " +
- "Item 2 " +
- "Item 3 " +
- " " ;
-
- Equals( expectedResults, output ) ; // when realisation is working then complete this test
- } // testWebPageContents
-} // class
-
-
diff --git a/SharpSimpleNLGUnitTests/syntax/InterrogativeTest.cs b/SharpSimpleNLGUnitTests/syntax/InterrogativeTest.cs
deleted file mode 100644
index 38190b2..0000000
--- a/SharpSimpleNLGUnitTests/syntax/InterrogativeTest.cs
+++ /dev/null
@@ -1,847 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
- /**
- * JUnit test case for interrogatives.
- *
- * @author agatt
- */
-
- public class InterrogativeTest : SimpleNLG4TestBase
- {
-
- // set up a few more fixtures
- /** The s5. */
-
-
- [SetUp]
- protected override void setUp()
- {
-
- // // the man gives the woman John's flower
- var john = this.phraseFactory.createNounPhrase("John");
- john.setFeature(Feature.POSSESSIVE.ToString(), true);
- var flower = this.phraseFactory.createNounPhrase(john,
- "flower");
- var _woman = this.phraseFactory.createNounPhrase(
- "the", "woman");
- s3 = this.phraseFactory.createClause(this.man, this.give, flower);
- s3.setIndirectObject(_woman);
-
- var subjects = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"),
- this.phraseFactory.createNounPhrase("Andrew"));
- s4 = this.phraseFactory.createClause(subjects, "pick up",
- "the balls");
- s4.addPostModifier("in the shop");
- s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
- s4.addFrontModifier("tomorrow");
- s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- // s5 = new SPhraseSpec();
- // s5.setSubject(new NPPhraseSpec("the", "dog"));
- // s5.setHead("be");
- // s5.setComplement(new NPPhraseSpec("the", "rock"),
- // DiscourseFunction.OBJECT);
-
- }
-
- /**
- * Tests a couple of fairly simple questions.
- */
-
- [Test]
- public void testSimpleQuestions()
- {
- setUp();
- this.phraseFactory.setLexicon(this.lexicon);
- this.realiser.setLexicon(this.lexicon);
-
- // simple present
- s1 = this.phraseFactory.createClause(this.woman, this.kiss,
- this.man);
- s1.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
- s1.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
-
- var docFactory = new NLGFactory(this.lexicon);
- var sent = docFactory.createSentence(s1);
- Assert.AreEqual("Does the woman kiss the man?", this.realiser
- .realise(sent).getRealisation());
-
- // simple past
- // sentence: "the woman kissed the man"
- s1 = this.phraseFactory.createClause(this.woman, this.kiss,
- this.man);
- s1.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- s1.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- Assert.AreEqual("did the woman kiss the man", this.realiser
- .realise(s1).getRealisation());
-
- // copular/existential: be-fronting
- // sentence = "there is the dog on the rock"
- s2 = this.phraseFactory.createClause("there", "be", this.dog);
- s2.addPostModifier(this.onTheRock);
- s2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- Assert.AreEqual("is there the dog on the rock", this.realiser
- .realise(s2).getRealisation());
-
- // perfective
- // sentence -- "there has been the dog on the rock"
- s2 = this.phraseFactory.createClause("there", "be", this.dog);
- s2.addPostModifier(this.onTheRock);
- s2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- s2.setFeature(Feature.PERFECT.ToString(), true);
- Assert.AreEqual("has there been the dog on the rock",
- this.realiser.realise(s2).getRealisation());
-
- // progressive
- // sentence: "the man was giving the woman John's flower"
- var john = this.phraseFactory.createNounPhrase("John");
- john.setFeature(Feature.POSSESSIVE.ToString(), true);
- var flower = this.phraseFactory.createNounPhrase(john,
- "flower");
- var _woman = this.phraseFactory.createNounPhrase(
- "the", "woman");
- s3 = this.phraseFactory.createClause(this.man, this.give, flower);
- s3.setIndirectObject(_woman);
- s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- s3.setFeature(Feature.PROGRESSIVE.ToString(), true);
- s3.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- var realised = this.realiser.realise(s3);
- Assert.AreEqual("was the man giving the woman John's flower",
- realised.getRealisation());
-
- // modal
- // sentence: "the man should be giving the woman John's flower"
- setUp();
- john = this.phraseFactory.createNounPhrase("John");
- john.setFeature(Feature.POSSESSIVE.ToString(), true);
- flower = this.phraseFactory.createNounPhrase(john, "flower");
- _woman = this.phraseFactory.createNounPhrase("the", "woman");
- s3 = this.phraseFactory.createClause(this.man, this.give, flower);
- s3.setIndirectObject(_woman);
- s3.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- s3.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- s3.setFeature(Feature.MODAL.ToString(), "should");
- Assert.AreEqual(
- "should the man have given the woman John's flower",
- this.realiser.realise(s3).getRealisation());
-
- // complex case with cue phrases
- // sentence: "however, tomorrow, Jane and Andrew will pick up the balls
- // in the shop"
- // this gets the front modifier "tomorrow" shifted to the end
- setUp();
- var subjects = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"),
- this.phraseFactory.createNounPhrase("Andrew"));
- s4 = this.phraseFactory.createClause(subjects, "pick up",
- "the balls");
- s4.addPostModifier("in the shop");
- s4.setFeature(Feature.CUE_PHRASE.ToString(), "however,");
- s4.addFrontModifier("tomorrow");
- s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- Assert.AreEqual(
- "however, will Jane and Andrew pick up the balls in the shop tomorrow",
- this.realiser.realise(s4).getRealisation());
- }
-
- /**
- * Test for sentences with negation.
- */
-
- [Test]
- public void testNegatedQuestions()
- {
- setUp();
- this.phraseFactory.setLexicon(this.lexicon);
- this.realiser.setLexicon(this.lexicon);
-
- // sentence: "the woman did not kiss the man"
- s1 = this.phraseFactory.createClause(this.woman, "kiss", this.man);
- s1.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- s1.setFeature(Feature.NEGATED.ToString(), true);
- s1.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- Assert.AreEqual("did the woman not kiss the man", this.realiser
- .realise(s1).getRealisation());
-
- // sentence: however, tomorrow, Jane and Andrew will not pick up the
- // balls in the shop
- var subjects = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"),
- this.phraseFactory.createNounPhrase("Andrew"));
- s4 = this.phraseFactory.createClause(subjects, "pick up",
- "the balls");
- s4.addPostModifier("in the shop");
- s4.setFeature(Feature.CUE_PHRASE.ToString(), "however,");
- s4.addFrontModifier("tomorrow");
- s4.setFeature(Feature.NEGATED.ToString(), true);
- s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- Assert.AreEqual(
- "however, will Jane and Andrew not pick up the balls in the shop tomorrow",
- this.realiser.realise(s4).getRealisation());
- }
-
- /**
- * Tests for coordinate VPs in question form.
- */
-
- // Disabled due to test setup issues [Test]
- public void testCoordinateVPQuestions()
- {
-
- // create a complex vp: "kiss the dog and walk in the room"
- reset();
- var complex = new CoordinatedPhraseElement(this.kiss, this.walk);
- this.kiss.addComplement(this.dog);
- this.walk.addComplement(this.inTheRoom);
-
- // sentence: "However, tomorrow, Jane and Andrew will kiss the dog and
- // will walk in the room"
- var subjects = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"),
- this.phraseFactory.createNounPhrase("Andrew"));
- s4 = this.phraseFactory.createClause(subjects, complex);
- s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
- s4.addFrontModifier("tomorrow");
- s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
-
- Assert.AreEqual(
- "however tomorrow Jane and Andrew will kiss the dog and will walk in the room",
- this.realiser.realise(s4).getRealisation());
-
- // setting to interrogative should automatically give us a single,
- // wide-scope aux
- reset();
- subjects = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"),
- this.phraseFactory.createNounPhrase("Andrew"));
- complex = new CoordinatedPhraseElement(this.kiss, this.walk);
- s4 = this.phraseFactory.createClause(subjects, complex);
- s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
- s4.addFrontModifier("tomorrow");
- s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
-
- Assert.AreEqual(
- "however will Jane and Andrew kiss the dog and walk in the room tomorrow",
- this.realiser.realise(s4).getRealisation());
-
- // slightly more complex -- perfective
- reset();
- this.realiser.setLexicon(this.lexicon);
- subjects = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"),
- this.phraseFactory.createNounPhrase("Andrew"));
- complex = new CoordinatedPhraseElement(this.kiss, this.walk);
- this.kiss.addComplement(this.dog);
- this.walk.addComplement(this.inTheRoom);
- s4 = this.phraseFactory.createClause(subjects, complex);
- s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
- s4.addFrontModifier("tomorrow");
- s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- s4.setFeature(Feature.PERFECT.ToString(), true);
-
- Assert.AreEqual(
- "however will Jane and Andrew have kissed the dog and walked in the room tomorrow",
- this.realiser.realise(s4).getRealisation());
- }
-
- /**
- * Test for simple WH questions in present tense.
- */
-
- [Test]
- public void testSimpleQuestions2()
- {
- setUp();
- this.realiser.setLexicon(this.lexicon);
- var s = this.phraseFactory.createClause("the woman", "kiss",
- "the man");
-
- // try with the simple yes/no type first
- s.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- Assert.AreEqual("does the woman kiss the man", this.realiser
- .realise(s).getRealisation());
-
- // now in the passive
- s = this.phraseFactory.createClause("the woman", "kiss",
- "the man");
- s.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- s.setFeature(Feature.PASSIVE.ToString(), true);
- Assert.AreEqual("is the man kissed by the woman", this.realiser
- .realise(s).getRealisation());
-
- // // subject interrogative with simple present
- // // sentence: "the woman kisses the man"
- s = this.phraseFactory.createClause("the woman", "kiss",
- "the man");
- s.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
-
- Assert.AreEqual("who kisses the man", this.realiser.realise(s)
- .getRealisation());
-
- // object interrogative with simple present
- s = this.phraseFactory.createClause("the woman", "kiss",
- "the man");
- s.setFeature(Feature.INTERROGATIVE_TYPE.ToString().ToString(), InterrogativeType.WHO_OBJECT);
- Assert.AreEqual("who does the woman kiss", this.realiser
- .realise(s).getRealisation());
-
- // subject interrogative with passive
- s = this.phraseFactory.createClause("the woman", "kiss",
- "the man");
- s.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
- s.setFeature(Feature.PASSIVE.ToString(), true);
- Assert.AreEqual("who is the man kissed by", this.realiser
- .realise(s).getRealisation());
- }
-
- /**
- * Test for wh questions.
- */
-
- [Test]
- public void testWHQuestions()
- {
-
- // subject interrogative
- setUp();
- this.realiser.setLexicon(this.lexicon);
- s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
- InterrogativeType.WHO_SUBJECT);
- Assert.AreEqual(
- "however who will pick up the balls in the shop tomorrow",
- this.realiser.realise(s4).getRealisation());
-
- // subject interrogative in passive
- setUp();
- s4.setFeature(Feature.PASSIVE.ToString(), true);
- s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
- InterrogativeType.WHO_SUBJECT);
-
- Assert.AreEqual(
- "however who will the balls be picked up in the shop by tomorrow",
- this.realiser.realise(s4).getRealisation());
-
- // object interrogative
- setUp();
- s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
- InterrogativeType.WHAT_OBJECT);
- Assert.AreEqual(
- "however what will Jane and Andrew pick up in the shop tomorrow",
- this.realiser.realise(s4).getRealisation());
-
- // object interrogative with passive
- setUp();
- s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
- InterrogativeType.WHAT_OBJECT);
- s4.setFeature(Feature.PASSIVE.ToString(), true);
-
- Assert.AreEqual(
- "however what will be picked up in the shop by Jane and Andrew tomorrow",
- this.realiser.realise(s4).getRealisation());
-
- // how-question + passive
- setUp();
- s4.setFeature(Feature.PASSIVE.ToString(), true);
- s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.HOW);
- Assert.AreEqual(
- "however how will the balls be picked up in the shop by Jane and Andrew tomorrow",
- this.realiser.realise(s4).getRealisation());
-
- // // why-question + passive
- setUp();
- s4.setFeature(Feature.PASSIVE.ToString(), true);
- s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
- Assert.AreEqual(
- "however why will the balls be picked up in the shop by Jane and Andrew tomorrow",
- this.realiser.realise(s4).getRealisation());
-
- // how question with modal
- setUp();
- s4.setFeature(Feature.PASSIVE.ToString(), true);
- s4.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.HOW);
- s4.setFeature(Feature.MODAL.ToString(), "should");
- Assert.AreEqual(
- "however how should the balls be picked up in the shop by Jane and Andrew tomorrow",
- this.realiser.realise(s4).getRealisation());
-
- // indirect object
- setUp();
- this.realiser.setLexicon(this.lexicon);
- s3.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
- InterrogativeType.WHO_INDIRECT_OBJECT);
- Assert.AreEqual("who does the man give John's flower to",
- this.realiser.realise(s3).getRealisation());
- }
-
- /**
- * WH movement in the progressive
- */
-
- [Test]
- public void testProgrssiveWHSubjectQuestions()
- {
- var p = this.phraseFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("eat");
- p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
- p.setFeature(Feature.PROGRESSIVE.ToString(), true);
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
- Assert.AreEqual("who is eating the pie",
- this.realiser.realise(p).getRealisation());
- }
-
- /**
- * WH movement in the progressive
- */
-
- [Test]
- public void testProgrssiveWHObjectQuestions()
- {
- var p = this.phraseFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("eat");
- p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
- p.setFeature(Feature.PROGRESSIVE.ToString(), true);
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
- Assert.AreEqual("what is Mary eating",
- this.realiser.realise(p).getRealisation());
-
- // AG -- need to check this; it doesn't work
- // p.setFeature(Feature.NEGATED, true);
- // Assert.AreEqual("what is Mary not eating",
- // this.realiser.realise(p).getRealisation());
-
- }
-
- /**
- * Negation with WH movement for subject
- */
-
- [Test]
- public void testNegatedWHSubjQuestions()
- {
- var p = this.phraseFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("eat");
- p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
- p.setFeature(Feature.NEGATED.ToString(), true);
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
- Assert.AreEqual("who does not eat the pie",
- this.realiser.realise(p).getRealisation());
- }
-
- /**
- * Negation with WH movement for object
- */
-
- [Test]
- public void testNegatedWHObjQuestions()
- {
- var p = this.phraseFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("eat");
- p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
- p.setFeature(Feature.NEGATED.ToString(), true);
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
- var realisation = this.realiser.realise(p);
- Assert.AreEqual("what does Mary not eat",
- realisation.getRealisation());
- }
-
- /**
- * Test questyions in the tutorial.
- */
-
- [Test]
- public void testTutorialQuestions()
- {
- setUp();
- this.realiser.setLexicon(this.lexicon);
-
- var p = this.phraseFactory.createClause("Mary", "chase",
- "George");
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- Assert.AreEqual("does Mary chase George", this.realiser.realise(p)
- .getRealisation());
-
- p = this.phraseFactory.createClause("Mary", "chase",
- "George");
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
- Assert.AreEqual("who does Mary chase", this.realiser.realise(p)
- .getRealisation());
-
- }
-
- /**
- * Subject WH Questions with modals
- */
-
- [Test]
- public void testModalWHSubjectQuestion()
- {
- var p = this.phraseFactory.createClause(this.dog, "upset",
- this.man);
- p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- Assert.AreEqual("the dog upset the man", this.realiser.realise(p)
- .getRealisation());
-
- // first without modal
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
- Assert.AreEqual("who upset the man", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
- Assert.AreEqual("what upset the man", this.realiser.realise(p)
- .getRealisation());
-
- // now with modal auxiliary
- p.setFeature(Feature.MODAL.ToString(), "may");
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
- Assert.AreEqual("who may have upset the man", this.realiser
- .realise(p).getRealisation());
-
- p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- Assert.AreEqual("who may upset the man", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
- Assert.AreEqual("what may have upset the man", this.realiser
- .realise(p).getRealisation());
-
- p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- Assert.AreEqual("what may upset the man", this.realiser.realise(p)
- .getRealisation());
- }
-
- /**
- * Subject WH Questions with modals
- */
-
- [Test]
- public void testModalWHObjectQuestion()
- {
- var p = this.phraseFactory.createClause(this.dog, "upset",
- this.man);
- p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
-
- Assert.AreEqual("who did the dog upset", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.MODAL.ToString(), "may");
- Assert.AreEqual("who may the dog have upset", this.realiser
- .realise(p).getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
- Assert.AreEqual("what may the dog have upset", this.realiser
- .realise(p).getRealisation());
-
- p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
- Assert.AreEqual("who may the dog upset", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
- Assert.AreEqual("what may the dog upset", this.realiser.realise(p)
- .getRealisation());
- }
-
- /**
- * Questions with tenses requiring auxiliaries + subject WH
- */
-
- [Test]
- public void testAuxWHSubjectQuestion()
- {
- var p = this.phraseFactory.createClause(this.dog, "upset",
- this.man);
- p.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
- p.setFeature(Feature.PERFECT.ToString(), true);
- Assert.AreEqual("the dog has upset the man",
- this.realiser.realise(p).getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
- Assert.AreEqual("who has upset the man", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
- Assert.AreEqual("what has upset the man", this.realiser.realise(p)
- .getRealisation());
- }
-
- /**
- * Questions with tenses requiring auxiliaries + subject WH
- */
-
- [Test]
- public void testAuxWHObjectQuestion()
- {
- var p = this.phraseFactory.createClause(this.dog, "upset",
- this.man);
-
- // first without any aux
- p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
- Assert.AreEqual("what did the dog upset", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
- Assert.AreEqual("who did the dog upset", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
- p.setFeature(Feature.PERFECT.ToString().ToString(), true);
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
- Assert.AreEqual("who has the dog upset", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
- Assert.AreEqual("what has the dog upset", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- p.setFeature(Feature.PERFECT.ToString(), true);
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
- Assert.AreEqual("who will the dog have upset", this.realiser
- .realise(p).getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
- Assert.AreEqual("what will the dog have upset", this.realiser
- .realise(p).getRealisation());
-
- }
-
- /**
- * Test for questions with "be"
- */
-
- [Test]
- public void testBeQuestions()
- {
- var p = this.phraseFactory.createClause(
- this.phraseFactory.createNounPhrase("a", "ball"),
- this.phraseFactory.createWord("be", new LexicalCategory_VERB()),
- this.phraseFactory.createNounPhrase("a", "toy"));
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
- Assert.AreEqual("what is a ball", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- Assert.AreEqual("is a ball a toy", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
- Assert.AreEqual("what is a toy", this.realiser.realise(p)
- .getRealisation());
-
- var p2 = this.phraseFactory.createClause("Mary", "be",
- "beautiful");
- p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
- Assert.AreEqual("why is Mary beautiful", this.realiser.realise(p2)
- .getRealisation());
-
- p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHERE);
- Assert.AreEqual("where is Mary beautiful", this.realiser.realise(p2)
- .getRealisation());
-
- p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
- Assert.AreEqual("who is beautiful", this.realiser.realise(p2)
- .getRealisation());
- }
-
- /**
- * Test for questions with "be" in future tense
- */
-
- [Test]
- public void testBeQuestionsFuture()
- {
- var p = this.phraseFactory.createClause(
- this.phraseFactory.createNounPhrase("a", "ball"),
- this.phraseFactory.createWord("be", new LexicalCategory_VERB()),
- this.phraseFactory.createNounPhrase("a", "toy"));
- p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
- Assert.AreEqual("what will a ball be", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- Assert.AreEqual("will a ball be a toy", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
- Assert.AreEqual("what will be a toy", this.realiser.realise(p)
- .getRealisation());
-
- var p2 = this.phraseFactory.createClause("Mary", "be",
- "beautiful");
- p2.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
- Assert.AreEqual("why will Mary be beautiful", this.realiser
- .realise(p2).getRealisation());
-
- p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHERE);
- Assert.AreEqual("where will Mary be beautiful", this.realiser
- .realise(p2).getRealisation());
-
- p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
- Assert.AreEqual("who will be beautiful", this.realiser.realise(p2)
- .getRealisation());
- }
-
- /**
- * Tests for WH questions with be in past tense
- */
-
- [Test]
- public void testBeQuestionsPast()
- {
- var p = this.phraseFactory.createClause(
- this.phraseFactory.createNounPhrase("a", "ball"),
- this.phraseFactory.createWord("be", new LexicalCategory_VERB()),
- this.phraseFactory.createNounPhrase("a", "toy"));
- p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_OBJECT);
- Assert.AreEqual("what was a ball", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- Assert.AreEqual("was a ball a toy", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHAT_SUBJECT);
- Assert.AreEqual("what was a toy", this.realiser.realise(p)
- .getRealisation());
-
- var p2 = this.phraseFactory.createClause("Mary", "be",
- "beautiful");
- p2.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
- Assert.AreEqual("why was Mary beautiful", this.realiser.realise(p2)
- .getRealisation());
-
- p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHERE);
- Assert.AreEqual("where was Mary beautiful", this.realiser.realise(p2)
- .getRealisation());
-
- p2.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_SUBJECT);
- Assert.AreEqual("who was beautiful", this.realiser.realise(p2)
- .getRealisation());
- }
-
-
- /**
- * Test WHERE, HOW and WHY questions, with copular predicate "be"
- */
-
- public void testSimpleBeWHQuestions()
- {
- var p = this.phraseFactory.createClause("I", "be");
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHERE);
- Assert.AreEqual("Where am I?", this.realiser.realiseSentence(p));
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHY);
- Assert.AreEqual("Why am I?", this.realiser.realiseSentence(p));
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.HOW);
- Assert.AreEqual("How am I?", this.realiser.realiseSentence(p));
-
- }
-
- /**
- * Test a simple "how" question, based on query from Albi Oxa
- */
-
- [Test]
- public void testHowPredicateQuestion()
- {
- var test = this.phraseFactory.createClause();
- var subject = this.phraseFactory.createNounPhrase("You");
-
- subject.setFeature(Feature.PRONOMINAL.ToString(), true);
- subject.setFeature(Feature.PERSON.ToString(), Person.SECOND);
- test.setSubject(subject);
- test.setVerb("be");
-
- test.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
- InterrogativeType.HOW_PREDICATE);
- test.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
-
- var result = this.realiser.realiseSentence(test);
- Assert.AreEqual("How are you?", result);
-
- }
-
- /**
- * Case 1 checks that "What do you think about John?" can be generated.
- *
- * Case 2 checks that the same clause is generated, even when an object is
- * declared.
- */
-
- [Test]
- public void testWhatObjectInterrogative()
- {
- var lexicon = Lexicon.getDefaultLexicon();
- var nlg = new NLGFactory(lexicon);
- var realiser = new Realiser(lexicon);
-
- // Case 1, no object is explicitly given:
- var clause = nlg.createClause("you", "think");
- var aboutJohn = nlg.createPrepositionPhrase("about", "John");
- clause.addPostModifier(aboutJohn);
- clause.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
- InterrogativeType.WHAT_OBJECT);
- var realisation = realiser.realiseSentence(clause);
- Assert.AreEqual("What do you think about John?", realisation);
-
- // Case 2:
- // Add "bad things" as the object so the object doesn't remain null:
- clause.setObject("bad things");
- realisation = realiser.realiseSentence(clause);
- Assert.AreEqual("What do you think about John?", realisation);
- }
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/NounPhraseTest.cs b/SharpSimpleNLGUnitTests/syntax/NounPhraseTest.cs
deleted file mode 100644
index 48f52b3..0000000
--- a/SharpSimpleNLGUnitTests/syntax/NounPhraseTest.cs
+++ /dev/null
@@ -1,643 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using System;
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
- /**
- * Tests for the NPPhraseSpec and CoordinateNPPhraseSpec classes.
- *
- * @author agatt
- */
-
- public class NounPhraseTest : SimpleNLG4TestBase
- {
-
-
- /**
- * Test the setPlural() method in noun phrases.
- */
-
- [Test]
- public void testPlural()
- {
- this.np4.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
- Assert.AreEqual(
- "the rocks", this.realiser.realise(this.np4).getRealisation());
-
-
- this.np5.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
- Assert
- .AreEqual(
- "the curtains", this.realiser.realise(this.np5).getRealisation());
-
-
- this.np5.setFeature(Feature.NUMBER.ToString(), NumberAgreement.SINGULAR);
- Assert.AreEqual(NumberAgreement.SINGULAR, this.np5
- .getFeature(Feature.NUMBER.ToString()));
- Assert
- .AreEqual(
- "the curtain", this.realiser.realise(this.np5).getRealisation());
-
-
- this.np5.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
- Assert
- .AreEqual(
- "the curtains", this.realiser.realise(this.np5).getRealisation());
-
- }
-
- /**
- * Test the pronominalisation method for full NPs.
- */
-
- [Test]
- public void testPronominalisation()
- {
- // sing
- this.proTest1.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
- this.proTest1.setFeature(Feature.PRONOMINAL.ToString(), true);
- Assert.AreEqual(
- "she", this.realiser.realise(this.proTest1).getRealisation());
-
-
- // sing, possessive
- this.proTest1.setFeature(Feature.POSSESSIVE.ToString(), true);
- Assert.AreEqual(
- "her", this.realiser.realise(this.proTest1).getRealisation());
-
-
- // plural pronoun
- this.proTest2.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
- this.proTest2.setFeature(Feature.PRONOMINAL.ToString(), true);
- Assert.AreEqual(
- "they", this.realiser.realise(this.proTest2).getRealisation());
-
-
- // accusative: "them"
- this.proTest2.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
- DiscourseFunction.OBJECT);
- Assert.AreEqual(
- "them", this.realiser.realise(this.proTest2).getRealisation());
-
- }
-
- /**
- * Test the pronominalisation method for full NPs (more thorough than above)
- */
-
- [Test]
- public void testPronominalisation2()
- {
- // Ehud - added extra pronominalisation tests
- var pro = this.phraseFactory.createNounPhrase("Mary");
- pro.setFeature(Feature.PRONOMINAL.ToString(), true);
- pro.setFeature(Feature.PERSON.ToString(), Person.FIRST);
- var sent = this.phraseFactory.createClause(pro, "like", "John");
- Assert
- .AreEqual("I like John.", this.realiser
- .realiseSentence(sent));
-
- pro = this.phraseFactory.createNounPhrase("Mary");
- pro.setFeature(Feature.PRONOMINAL.ToString(), true);
- pro.setFeature(Feature.PERSON.ToString(), Person.SECOND);
- sent = this.phraseFactory.createClause(pro, "like", "John");
- Assert.AreEqual("You like John.", this.realiser
- .realiseSentence(sent));
-
- pro = this.phraseFactory.createNounPhrase("Mary");
- pro.setFeature(Feature.PRONOMINAL.ToString(), true);
- pro.setFeature(Feature.PERSON.ToString(), Person.THIRD);
- pro.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
- sent = this.phraseFactory.createClause(pro, "like", "John");
- Assert.AreEqual("She likes John.", this.realiser
- .realiseSentence(sent));
-
- pro = this.phraseFactory.createNounPhrase("Mary");
- pro.setFeature(Feature.PRONOMINAL.ToString(), true);
- pro.setFeature(Feature.PERSON.ToString(), Person.FIRST);
- pro.setPlural(true);
- sent = this.phraseFactory.createClause(pro, "like", "John");
- Assert.AreEqual("We like John.", this.realiser
- .realiseSentence(sent));
-
- pro = this.phraseFactory.createNounPhrase("Mary");
- pro.setFeature(Feature.PRONOMINAL.ToString(), true);
- pro.setFeature(Feature.PERSON.ToString(), Person.SECOND);
- pro.setPlural(true);
- sent = this.phraseFactory.createClause(pro, "like", "John");
- Assert.AreEqual("You like John.", this.realiser
- .realiseSentence(sent));
-
- pro = this.phraseFactory.createNounPhrase("Mary");
- pro.setFeature(Feature.PRONOMINAL.ToString(), true);
- pro.setFeature(Feature.PERSON.ToString(), Person.THIRD);
- pro.setPlural(true);
- pro.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
- sent = this.phraseFactory.createClause(pro, "like", "John");
- Assert.AreEqual("They like John.", this.realiser
- .realiseSentence(sent));
-
- pro = this.phraseFactory.createNounPhrase("John");
- pro.setFeature(Feature.PRONOMINAL.ToString(), true);
- pro.setFeature(Feature.PERSON.ToString(), Person.FIRST);
- sent = this.phraseFactory.createClause("Mary", "like", pro);
- Assert.AreEqual("Mary likes me.", this.realiser
- .realiseSentence(sent));
-
- pro = this.phraseFactory.createNounPhrase("John");
- pro.setFeature(Feature.PRONOMINAL.ToString(), true);
- pro.setFeature(Feature.PERSON.ToString(), Person.SECOND);
- sent = this.phraseFactory.createClause("Mary", "like", pro);
- Assert.AreEqual("Mary likes you.", this.realiser
- .realiseSentence(sent));
-
- pro = this.phraseFactory.createNounPhrase("John");
- pro.setFeature(Feature.PRONOMINAL.ToString(), true);
- pro.setFeature(Feature.PERSON.ToString(), Person.THIRD);
- pro.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
- sent = this.phraseFactory.createClause("Mary", "like", pro);
- Assert.AreEqual("Mary likes him.", this.realiser
- .realiseSentence(sent));
-
- pro = this.phraseFactory.createNounPhrase("John");
- pro.setFeature(Feature.PRONOMINAL.ToString(), true);
- pro.setFeature(Feature.PERSON.ToString(), Person.FIRST);
- pro.setPlural(true);
- sent = this.phraseFactory.createClause("Mary", "like", pro);
- Assert.AreEqual("Mary likes us.", this.realiser
- .realiseSentence(sent));
-
- pro = this.phraseFactory.createNounPhrase("John");
- pro.setFeature(Feature.PRONOMINAL.ToString(), true);
- pro.setFeature(Feature.PERSON.ToString(), Person.SECOND);
- pro.setPlural(true);
- sent = this.phraseFactory.createClause("Mary", "like", pro);
- Assert.AreEqual("Mary likes you.", this.realiser
- .realiseSentence(sent));
-
- pro = this.phraseFactory.createNounPhrase("John");
- pro.setFeature(Feature.PRONOMINAL.ToString(), true);
- pro.setFeature(Feature.PERSON.ToString(), Person.THIRD);
- pro.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
- pro.setPlural(true);
- sent = this.phraseFactory.createClause("Mary", "like", pro);
- Assert.AreEqual("Mary likes them.", this.realiser
- .realiseSentence(sent));
- }
-
- /**
- * Test premodification in NPS.
- */
-
- [Test]
- public void testPremodification()
- {
- this.man.addPreModifier(this.salacious);
- Assert.AreEqual("the salacious man", this.realiser
- .realise(this.man).getRealisation());
-
- this.woman.addPreModifier(this.beautiful);
- Assert.AreEqual("the beautiful woman", this.realiser.realise(
- this.woman).getRealisation());
-
- this.dog.addPreModifier(this.stunning);
- Assert.AreEqual("the stunning dog",
- this.realiser.realise(this.dog)
- .getRealisation());
-
- // premodification with a WordElement
- this.man.setPreModifier(this.phraseFactory.createWord("idiotic",
- new LexicalCategory_ADJECTIVE()));
- Assert.AreEqual("the idiotic man", this.realiser
- .realise(this.man).getRealisation());
-
- }
-
- /**
- * Test prepositional postmodification.
- */
-
- [Test]
- public void testPostmodification()
- {
- this.man.addPostModifier(this.onTheRock);
- Assert.AreEqual("the man on the rock", this.realiser.realise(
- this.man).getRealisation());
-
- this.woman.addPostModifier(this.behindTheCurtain);
- Assert.AreEqual("the woman behind the curtain", this.realiser
- .realise(this.woman).getRealisation());
-
- // postmodification with a WordElement
- this.man.setPostModifier(this.phraseFactory.createWord("jack",
- new LexicalCategory_NOUN()));
- Assert.AreEqual("the man jack", this.realiser.realise(
- this.man).getRealisation());
- }
-
- /**
- * Test nominal complementation
- */
-
- [Test]
- public void testComplementation()
- {
- // complementation with a WordElement
- this.man.setComplement(this.phraseFactory.createWord("jack",
- new LexicalCategory_NOUN()));
- Assert.AreEqual("the man jack", this.realiser.realise(
- this.man).getRealisation());
-
- this.woman.addComplement(this.behindTheCurtain);
- Assert.AreEqual("the woman behind the curtain", this.realiser
- .realise(this.woman).getRealisation());
- }
-
- /**
- * Test possessive constructions.
- */
-
- [Test]
- public void testPossessive()
- {
-
- // simple possessive 's: 'a man's'
- var possNP = this.phraseFactory.createNounPhrase("a", "man");
-
- possNP.setFeature(Feature.POSSESSIVE.ToString(), true);
- Assert.AreEqual("a man's", this.realiser.realise(possNP)
- .getRealisation());
-
- // now set this possessive as specifier of the NP 'the dog'
- this.dog.setFeature(InternalFeature.SPECIFIER.ToString(), possNP);
- Assert.AreEqual("a man's dog",
- this.realiser.realise(this.dog)
- .getRealisation());
-
- // convert possNP to pronoun and turn "a dog" into "his dog"
- // need to specify gender, as default is NEUTER
- possNP.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
- possNP.setFeature(Feature.PRONOMINAL.ToString(), true);
- Assert.AreEqual("his dog", this.realiser.realise(this.dog)
- .getRealisation());
-
- // make it slightly more complicated: "his dog's rock"
- this.dog.setFeature(Feature.POSSESSIVE.ToString(), true); // his dog's
-
- // his dog's rock (substituting "the"
- // for the
- // entire phrase)
- this.np4.setFeature(InternalFeature.SPECIFIER.ToString(), this.dog);
- Assert.AreEqual("his dog's rock",
- this.realiser.realise(this.np4)
- .getRealisation());
- }
-
- /**
- * Test NP coordination.
- */
-
- [Test]
- public void testCoordination()
- {
-
- var cnp1 = new CoordinatedPhraseElement(this.dog,
- this.woman);
- // simple coordination
- Assert.AreEqual("the dog and the woman", this.realiser
- .realise(cnp1).getRealisation());
-
- // simple coordination with complementation of entire coordinate NP
- cnp1.addComplement(this.behindTheCurtain);
- Assert.AreEqual("the dog and the woman behind the curtain",
- this.realiser.realise(cnp1).getRealisation());
-
- // raise the specifier in this cnp
- // Assert.AreEqual(true, cnp1.raiseSpecifier()); // should return
- // true as all
- // sub-nps have same spec
- // Equals("the dog and woman behind the curtain",
- // realiser.realise(cnp1));
- }
-
- /**
- * Another battery of tests for NP coordination.
- */
-
- [Test]
- public void testCoordination2()
- {
-
- // simple coordination of complementised nps
- this.dog.clearComplements();
- this.woman.clearComplements();
-
- var cnp1 = new CoordinatedPhraseElement(this.dog,
- this.woman);
- cnp1.setFeature(Feature.RAISE_SPECIFIER.ToString(), true);
- var realised = this.realiser.realise(cnp1);
- Assert.AreEqual("the dog and woman", realised.getRealisation());
-
- this.dog.addComplement(this.onTheRock);
- this.woman.addComplement(this.behindTheCurtain);
-
- var cnp2 = new CoordinatedPhraseElement(this.dog,
- this.woman);
-
- this.woman.setFeature(InternalFeature.RAISED.ToString(), false);
- Assert.AreEqual(
- "the dog on the rock and the woman behind the curtain",
- this.realiser.realise(cnp2).getRealisation());
-
- // complementised coordinates + outer pp modifier
- cnp2.addPostModifier(this.inTheRoom);
- Assert
- .AreEqual(
- "the dog on the rock and the woman behind the curtain in the room",
- this.realiser.realise(cnp2).getRealisation());
-
- // set the specifier for this cnp; should unset specifiers for all inner
- // coordinates
- var every = this.phraseFactory.createWord(
- "every", new LexicalCategory_DETERMINER());
-
- cnp2.setFeature(InternalFeature.SPECIFIER.ToString(), every);
-
- Assert
- .AreEqual(
- "every dog on the rock and every woman behind the curtain in the room",
- this.realiser.realise(cnp2).getRealisation());
-
- // pronominalise one of the constituents
- this.dog.setFeature(Feature.PRONOMINAL.ToString(), true); // ="it"
- this.dog.setFeature(InternalFeature.SPECIFIER.ToString(), this.phraseFactory
- .createWord("the", new LexicalCategory_DETERMINER()));
- // raising spec still returns true as spec has been set
- cnp2.setFeature(Feature.RAISE_SPECIFIER.ToString(), true);
-
- // CNP should be realised with pronominal internal const
- Assert.AreEqual(
- "it and every woman behind the curtain in the room",
- this.realiser.realise(cnp2).getRealisation());
- }
-
- /**
- * Test possessives in coordinate NPs.
- */
-
- [Test]
- public void testPossessiveCoordinate()
- {
- // simple coordination
- var cnp2 = new CoordinatedPhraseElement(this.dog,
- this.woman);
- Assert.AreEqual("the dog and the woman", this.realiser
- .realise(cnp2).getRealisation());
-
- // set possessive -- wide-scope by default
- cnp2.setFeature(Feature.POSSESSIVE.ToString(), true);
- Assert.AreEqual("the dog and the woman's", this.realiser.realise(
- cnp2).getRealisation());
-
- // set possessive with pronoun
- this.dog.setFeature(Feature.PRONOMINAL.ToString(), true);
- this.dog.setFeature(Feature.POSSESSIVE.ToString(), true);
- cnp2.setFeature(Feature.POSSESSIVE.ToString(), true);
- Assert.AreEqual("its and the woman's", this.realiser.realise(cnp2)
- .getRealisation());
-
- }
-
- /**
- * Test A vs An.
- */
-
- [Test]
- public void testAAn()
- {
- var _dog = this.phraseFactory.createNounPhrase("a", "dog");
-
- Assert.AreEqual("a dog", this.realiser.realise(_dog)
- .getRealisation());
-
- _dog.addPreModifier("enormous");
-
- Assert.AreEqual("an enormous dog", this.realiser.realise(_dog)
- .getRealisation());
-
- var elephant = this.phraseFactory.createNounPhrase(
- "a", "elephant");
- Assert.AreEqual("an elephant", this.realiser.realise(elephant)
- .getRealisation());
-
- elephant.addPreModifier("big");
- Assert.AreEqual("a big elephant", this.realiser.realise(elephant)
- .getRealisation());
-
- // test treating of plural specifiers
- _dog.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
-
- Assert.AreEqual("some enormous dogs", this.realiser.realise(_dog)
- .getRealisation());
- }
-
- /**
- * Further tests for a/an agreement with coordinated premodifiers
- */
-
- public void testAAnCoord()
- {
- var _dog = this.phraseFactory.createNounPhrase("a", "dog");
- _dog.addPreModifier(this.phraseFactory.createCoordinatedPhrase(
- "enormous", "black"));
- var realisation = this.realiser.realise(_dog).getRealisation();
- Assert.AreEqual("an enormous and black dog", realisation);
- }
-
- /**
- * Test for a/an agreement with numbers
- */
-
- public void testAAnWithNumbers()
- {
- var num = this.phraseFactory.createNounPhrase("a", "change");
- String realisation;
-
- // no an with "one"
- num.setPreModifier("one percent");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("a one percent change", realisation);
-
- // an with "eighty"
- num.setPreModifier("eighty percent");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("an eighty percent change", realisation);
-
- // an with 80
- num.setPreModifier("80%");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("an 80% change", realisation);
-
- // an with 80000
- num.setPreModifier("80000");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("an 80000 change", realisation);
-
- // an with 11,000
- num.setPreModifier("11,000");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("an 11,000 change", realisation);
-
- // an with 18
- num.setPreModifier("18%");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("an 18% change", realisation);
-
- // a with 180
- num.setPreModifier("180");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("a 180 change", realisation);
-
- // a with 1100
- num.setPreModifier("1100");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("a 1100 change", realisation);
-
- // a with 180,000
- num.setPreModifier("180,000");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("a 180,000 change", realisation);
-
- // an with 11000
- num.setPreModifier("11000");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("an 11000 change", realisation);
-
- // an with 18000
- num.setPreModifier("18000");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("an 18000 change", realisation);
-
- // an with 18.1
- num.setPreModifier("18.1%");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("an 18.1% change", realisation);
-
- // an with 11.1
- num.setPreModifier("11.1%");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.AreEqual("an 11.1% change", realisation);
-
- }
-
- /**
- * Test Modifier "guess" placement.
- */
-
- [Test]
- public void testModifier()
- {
- var _dog = this.phraseFactory.createNounPhrase("a", "dog");
-
- _dog.addPreModifier("angry");
-
- Assert.AreEqual("an angry dog", this.realiser.realise(_dog)
- .getRealisation());
-
- _dog.addPostModifier("in the park");
- Assert.AreEqual("an angry dog in the park", this.realiser.realise(
- _dog).getRealisation());
-
- var cat = this.phraseFactory.createNounPhrase("a", "cat");
-
- cat.addPreModifier(this.phraseFactory.createAdjectivePhrase("angry"));
- Assert.AreEqual("an angry cat", this.realiser.realise(cat)
- .getRealisation());
-
- cat.addPostModifier(this.phraseFactory.createPrepositionPhrase(
- "in", "the park"));
- Assert.AreEqual("an angry cat in the park", this.realiser.realise(
- cat).getRealisation());
-
- }
-
- [Test]
- public void testPluralNounsBelongingToASingular()
- {
-
- var sent = this.phraseFactory.createClause("I", "count up");
- sent.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- var obj = this.phraseFactory.createNounPhrase("digit");
- obj.setPlural(true);
- var possessor = this.phraseFactory.createNounPhrase("the", "box");
- possessor.setPlural(false);
- possessor.setFeature(Feature.POSSESSIVE.ToString(), true);
- obj.setSpecifier(possessor);
- sent.setObject(obj);
-
- Assert.AreEqual("I counted up the box's digits", this.realiser.realise(sent)
- .getRealisation());
- }
-
-
- [Test]
- public void testSingularNounsBelongingToAPlural()
- {
-
- var sent = this.phraseFactory.createClause("I", "clean");
- sent.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- var obj = this.phraseFactory.createNounPhrase("car");
- obj.setPlural(false);
- var possessor = this.phraseFactory.createNounPhrase("the", "parent");
- possessor.setPlural(true);
- possessor.setFeature(Feature.POSSESSIVE.ToString(), true);
- obj.setSpecifier(possessor);
- sent.setObject(obj);
-
- Assert.AreEqual("I cleaned the parents' car", this.realiser.realise(sent)
- .getRealisation());
- }
-
- /**
- * Test for appositive postmodifiers
- */
-
- [Test]
- public void testAppositivePostmodifier()
- {
- var _dog = this.phraseFactory.createNounPhrase("the", "dog");
- var _rott = this.phraseFactory.createNounPhrase("a", "rottweiler");
- _rott.setFeature(Feature.APPOSITIVE.ToString(), true);
- _dog.addPostModifier(_rott);
- var _sent = this.phraseFactory.createClause(_dog, "ran");
- Assert.AreEqual("The dog, a rottweiler runs.", this.realiser.realiseSentence(_sent));
- }
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/OrthographyFormatTest.cs b/SharpSimpleNLGUnitTests/syntax/OrthographyFormatTest.cs
deleted file mode 100644
index 29df4c5..0000000
--- a/SharpSimpleNLGUnitTests/syntax/OrthographyFormatTest.cs
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using System.Collections.Generic;
-using System.Text;
-using NUnit.Framework;
-using SimpleNLG;
-using SimpleNLG.Extensions;
-
-namespace SimpleNLGTests.syntax
-{
- public class OrthographyFormatTest : SimpleNLG4TestBase
- {
-
- public DocumentElement list1, list2;
- public DocumentElement listItem1, listItem2, listItem3;
- public string list1Realisation = new StringBuilder().Append("\n* behind the curtain").Append("\n").ToString();
-
- public string list2Realisation;
-
- [SetUp]
- public new void setUp()
- {
- list2Realisation = new StringBuilder("* in the room").append("\n* ").append(list1Realisation).append("\n").ToString();
-
- // need to set formatter for realiser (set to null in the test
- // superclass)
- this.realiser.setFormatter(new TextFormatter());
-
- // a couple phrases as list items
- listItem1 = this.phraseFactory.createListItem(this.inTheRoom);
- listItem2 = this.phraseFactory
- .createListItem(this.behindTheCurtain);
- listItem3 = this.phraseFactory.createListItem(this.onTheRock);
-
- // a simple depth-1 list of phrases
- list1 = this.phraseFactory
- .createList( new List
- {
- listItem1, listItem2
- });
-
- /* a list consisting of one phrase (depth-1) + a list )(depth-2)
- list2 = this.phraseFactory.createList(
- new List { new List
- {
- listItem3,
- this.phraseFactory.createListItem(list1)
- }}); */
- }
-
-
- /**
- * Test the realisation of a list with an embedded list
- */
-
- //[Test]
- public void testEmbeddedListOrthography()
- {
- var realised = this.realiser.realise(list2);
- Assert.AreEqual(list2Realisation, realised.getRealisation());
- }
-
- /**
- * Test the realisation of appositive pre-modifiers with commas around them.
- */
-
- [Test]
- public void testAppositivePreModifiers()
- {
- var subject = this.phraseFactory.createNounPhrase("I");
- var obj = this.phraseFactory.createNounPhrase("a bag");
-
- var _s1 = this.phraseFactory.createClause(subject,
- "carry", obj);
-
- // add a PP complement
- var pp = this.phraseFactory.createPrepositionPhrase("on",
- this.phraseFactory.createNounPhrase("most", "Tuesdays"));
- _s1.addPreModifier(pp);
-
- //without appositive feature on pp
- Assert.AreEqual(
- "I on most Tuesdays carry a bag", this.realiser
- .realise(_s1).getRealisation());
-
- //with appositive feature
- pp.setFeature(Feature.APPOSITIVE.ToString(), true);
- Assert.AreEqual(
- "I, on most Tuesdays, carry a bag", this.realiser
- .realise(_s1).getRealisation());
- }
-
-
- /**
- * Test the realisation of appositive pre-modifiers with commas around them.
- */
-
- [Test]
- public void testCommaSeparatedFrontModifiers()
- {
- var subject = this.phraseFactory.createNounPhrase("I");
- var obj = this.phraseFactory.createNounPhrase("a bag");
-
- var _s1 = this.phraseFactory.createClause(subject,
- "carry", obj);
-
- // add a PP complement
- var pp1 = this.phraseFactory.createPrepositionPhrase("on",
- this.phraseFactory.createNounPhrase("most", "Tuesdays"));
- _s1.addFrontModifier(pp1);
-
- var pp2 = this.phraseFactory.createPrepositionPhrase("since",
- this.phraseFactory.createNounPhrase("1991"));
- _s1.addFrontModifier(pp2);
- pp1.setFeature(Feature.APPOSITIVE.ToString(), true);
- pp2.setFeature(Feature.APPOSITIVE.ToString(), true);
-
- //without setCommaSepCuephrase
- Assert.AreEqual(
- "on most Tuesdays since 1991 I carry a bag", this.realiser
- .realise(_s1).getRealisation());
-
- //with setCommaSepCuephrase
- this.realiser.setCommaSepCuephrase(true);
- Assert.AreEqual(
- "on most Tuesdays, since 1991, I carry a bag", this.realiser
- .realise(_s1).getRealisation());
- }
-
- /**
- * Ensure we don't end up with doubled commas.
- */
-
- [Test]
- public void testNoDoubledCommas()
- {
- var subject = this.phraseFactory.createNounPhrase("I");
- var obj = this.phraseFactory.createNounPhrase("a bag");
-
- var _s1 = this.phraseFactory.createClause(subject,
- "carry", obj);
-
- var pp1 = this.phraseFactory.createPrepositionPhrase("on",
- this.phraseFactory.createNounPhrase("most", "Tuesdays"));
- _s1.addFrontModifier(pp1);
-
- var pp2 = this.phraseFactory.createPrepositionPhrase("since",
- this.phraseFactory.createNounPhrase("1991"));
- var pp3 = this.phraseFactory.createPrepositionPhrase("except",
- this.phraseFactory.createNounPhrase("yesterday"));
-
- pp2.setFeature(Feature.APPOSITIVE.ToString(), true);
- pp3.setFeature(Feature.APPOSITIVE.ToString(), true);
-
- pp1.addPostModifier(pp2);
- pp1.addPostModifier(pp3);
-
- this.realiser.setCommaSepCuephrase(true);
-
- Assert.AreEqual(
- "on most Tuesdays, since 1991, except yesterday, I carry a bag", this.realiser
- .realise(_s1).getRealisation());
- // without my fix (that we're testing here), you'd end up with
- // "on most Tuesdays, since 1991,, except yesterday, I carry a bag"
- }
-
-// <[on most Tuesdays, since 1991, except yesterday, ]I carry a bag> but was:<[]I carry a bag>
-
-
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/PhraseSpecTest.cs b/SharpSimpleNLGUnitTests/syntax/PhraseSpecTest.cs
deleted file mode 100644
index 9a26a77..0000000
--- a/SharpSimpleNLGUnitTests/syntax/PhraseSpecTest.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
-
- /**
- * test suite for simple XXXPhraseSpec classes
- * @author ereiter
- *
- */
-
- public class PhraseSpecTest : SimpleNLG4TestBase
- {
-
-
-
- /**
- * Check that empty phrases are not realised as "null"
- */
-
- [Test]
- public void emptyPhraseRealisationTest()
- {
- var emptyClause = this.phraseFactory.createClause();
- Assert.AreEqual("", this.realiser.realise(emptyClause)
- .getRealisation());
- }
-
-
- /**
- * Test SPhraseSpec
- */
-
- [Test]
- public void testSPhraseSpec()
- {
-
- // simple test of methods
- var c1 = (SPhraseSpec) this.phraseFactory.createClause();
- c1.setVerb("give");
- c1.setSubject("John");
- c1.setObject("an apple");
- c1.setIndirectObject("Mary");
- c1.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- c1.setFeature(Feature.NEGATED.ToString(), true);
-
- // check getXXX methods
- Assert.AreEqual("give", getBaseForm(c1.getVerb()));
- Assert.AreEqual("John", getBaseForm(c1.getSubject()));
- Assert.AreEqual("an apple", getBaseForm(c1.getObject()));
- Assert.AreEqual("Mary", getBaseForm(c1.getIndirectObject()));
-
- Assert.AreEqual("John did not give Mary an apple", this.realiser
- .realise(c1).getRealisation());
-
-
-
- // test modifier placement
- var c2 = this.phraseFactory.createClause();
- c2.setVerb("see");
- c2.setSubject("the man");
- c2.setObject("me");
- c2.addModifier("fortunately");
- c2.addModifier("quickly");
- c2.addModifier("in the park");
- // try setting tense directly as a feature
- c2.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- this.realiser.setDebugMode(true);
- Assert.AreEqual("fortunately the man quickly saw me in the park",
- this.realiser
- .realise(c2).getRealisation());
- }
-
- // get string for head of constituent
- private string getBaseForm(INLGElement constituent)
- {
- if (constituent == null)
- return null;
- else if (constituent is StringElement)
- return constituent.getRealisation();
- else if (constituent is WordElement)
- return ((WordElement) constituent).getBaseForm();
- else if (constituent is InflectedWordElement)
- return getBaseForm(((InflectedWordElement) constituent).getBaseWord());
- else if (constituent is PhraseElement)
- return getBaseForm(((PhraseElement) constituent).getHead());
- else
- return null;
- }
- }
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/PremodifierTest.cs b/SharpSimpleNLGUnitTests/syntax/PremodifierTest.cs
deleted file mode 100644
index 00213c8..0000000
--- a/SharpSimpleNLGUnitTests/syntax/PremodifierTest.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
- public class PremodifierTest : SimpleNLG4TestBase
- {
-
-
-
- /**
- * Test change from "a" to "an" in the presence of a premodifier with a
- * vowel
- */
-
- [Test]
- public void indefiniteWithPremodifierTest()
- {
- var s = this.phraseFactory.createClause("there", "be");
- s.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
- var np = this.phraseFactory.createNounPhrase("a", "stenosis");
- s.setObject(np);
-
- // check without modifiers -- article should be "a"
- Assert.AreEqual("there is a stenosis", this.realiser.realise(s)
- .getRealisation());
-
- // add a single modifier -- should turn article to "an"
- np.addPreModifier(this.phraseFactory.createAdjectivePhrase("eccentric"));
- Assert.AreEqual("there is an eccentric stenosis", this.realiser
- .realise(s).getRealisation());
- }
-
- /**
- * Test for comma separation between premodifers
- */
-
- [Test]
- public void multipleAdjPremodifiersTest()
- {
- var np = this.phraseFactory.createNounPhrase("a", "stenosis");
- np.addPreModifier(this.phraseFactory.createAdjectivePhrase("eccentric"));
- np.addPreModifier(this.phraseFactory.createAdjectivePhrase("discrete"));
- Assert.AreEqual("an eccentric, discrete stenosis", this.realiser
- .realise(np).getRealisation());
- }
-
- /**
- * Test for comma separation between verb premodifiers
- */
-
- [Test]
- public void multipleAdvPremodifiersTest()
- {
- var adv1 = this.phraseFactory.createAdverbPhrase("slowly");
- var adv2 = this.phraseFactory
- .createAdverbPhrase("discretely");
-
- // case 1: concatenated premods: should have comma
- var vp = this.phraseFactory.createVerbPhrase("run");
- vp.addPreModifier(adv1);
- vp.addPreModifier(adv2);
- Assert.AreEqual("slowly, discretely runs", this.realiser
- .realise(vp).getRealisation());
-
- // case 2: coordinated premods: no comma
- var vp2 = this.phraseFactory.createVerbPhrase("eat");
- vp2.addPreModifier(this.phraseFactory.createCoordinatedPhrase(adv1,
- adv2));
- Assert.AreEqual("slowly and discretely eats", this.realiser
- .realise(vp2).getRealisation());
- }
-
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/PrepositionalPhraseTest.cs b/SharpSimpleNLGUnitTests/syntax/PrepositionalPhraseTest.cs
deleted file mode 100644
index 9d19180..0000000
--- a/SharpSimpleNLGUnitTests/syntax/PrepositionalPhraseTest.cs
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
- // TODO: Auto-generated Javadoc
- /**
- * This class groups together some tests for prepositional phrases and
- * coordinate prepositional phrases.
- * @author agatt
- */
-
- public class PrepositionalPhraseTest : SimpleNLG4TestBase
- {
-
-
- [Test]
- public void testBasic()
- {
- Assert.AreEqual("in the room", this.realiser
- .realise(this.inTheRoom).getRealisation());
- Assert.AreEqual("behind the curtain", this.realiser
- .realise(this.behindTheCurtain).getRealisation());
- Assert.AreEqual("on the rock", this.realiser
- .realise(this.onTheRock).getRealisation());
- }
-
- /**
- * Test for coordinate NP complements of PPs.
- */
-
- [Test]
- public void testComplementation()
- {
- this.inTheRoom.clearComplements();
- this.inTheRoom.addComplement(new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("the", "room"),
- this.phraseFactory.createNounPhrase("a", "car")));
- Assert.AreEqual("in the room and a car", this.realiser
- .realise(this.inTheRoom).getRealisation());
- }
-
- /**
- * Test for PP coordination.
- */
-
- public void testCoordination()
- {
- // simple coordination
-
- var coord1 = new CoordinatedPhraseElement(
- this.inTheRoom, this.behindTheCurtain);
- Assert.AreEqual("in the room and behind the curtain", this.realiser
- .realise(coord1).getRealisation());
-
- // change the conjunction
- coord1.setFeature(Feature.CONJUNCTION.ToString(), "or");
- Assert.AreEqual("in the room or behind the curtain", this.realiser
- .realise(coord1).getRealisation());
-
- // new coordinate
- var coord2 = new CoordinatedPhraseElement(
- this.onTheRock, this.underTheTable);
- coord2.setFeature(Feature.CONJUNCTION.ToString(), "or");
- Assert.AreEqual("on the rock or under the table", this.realiser
- .realise(coord2).getRealisation());
-
- // coordinate two coordinates
- var coord3 = new CoordinatedPhraseElement(coord1,
- coord2);
-
- var text = this.realiser.realise(coord3).getRealisation();
- Assert
- .AreEqual(
- "in the room or behind the curtain and on the rock or under the table",
- text);
- }
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/SimpleNLG4Test.cs b/SharpSimpleNLGUnitTests/syntax/SimpleNLG4Test.cs
deleted file mode 100644
index 99f8453..0000000
--- a/SharpSimpleNLGUnitTests/syntax/SimpleNLG4Test.cs
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
- /**
- * This class is the base class for all JUnit simplenlg.test cases for
- * simplenlg. It sets up a a JUnit fixture, i.e. the basic objects (basic
- * constituents) that all other tests can use.
- * @author agatt
- */
-
- public class SimpleNLG4TestBase
- {
-
- public Realiser realiser { get; set; }
-
- public NLGFactory phraseFactory { get; set; }
-
- public Lexicon lexicon { get; set; }
-
- /** The pro test2. */
- public NPPhraseSpec man, woman, dog, boy, np4, np5, np6, proTest1, proTest2;
-
- /** The salacious. */
- public AdjPhraseSpec beautiful, stunning, salacious;
-
- /** The under the table. */
- public PPPhraseSpec onTheRock, behindTheCurtain, inTheRoom, underTheTable;
-
- /** The say. */
- public VPPhraseSpec kick, kiss, walk, talk, getUp, fallDown, give, say;
- // set up a few more fixtures
- /** The s4. */
- public SPhraseSpec s1, s2, s3, s4;
-
-
- /*
- * (non-Javadoc)
- *
- * @see simplenlg.test.SimplenlgTest#setUp()
- */
-
- [SetUp]
- protected virtual void setUp()
- {
- this.lexicon = Lexicon.getDefaultLexicon();
-
- this.phraseFactory = new NLGFactory(this.lexicon);
- this.realiser = new Realiser(this.lexicon);
-
- this.man = this.phraseFactory.createNounPhrase("the", "man");
- this.woman = this.phraseFactory.createNounPhrase("the", "woman");
- this.dog = this.phraseFactory.createNounPhrase("the", "dog");
- this.boy = this.phraseFactory.createNounPhrase("the", "boy");
-
- this.beautiful = this.phraseFactory.createAdjectivePhrase("beautiful");
- this.stunning = this.phraseFactory.createAdjectivePhrase("stunning");
- this.salacious = this.phraseFactory.createAdjectivePhrase("salacious");
-
- this.onTheRock = this.phraseFactory.createPrepositionPhrase("on");
- this.np4 = this.phraseFactory.createNounPhrase("the", "rock");
- this.onTheRock.addComplement(this.np4);
-
- this.behindTheCurtain = this.phraseFactory.createPrepositionPhrase("behind");
- this.np5 = this.phraseFactory.createNounPhrase("the", "curtain");
- this.behindTheCurtain.addComplement(this.np5);
-
- this.inTheRoom = this.phraseFactory.createPrepositionPhrase("in");
- this.np6 = this.phraseFactory.createNounPhrase("the", "room");
- this.inTheRoom.addComplement(this.np6);
-
- this.underTheTable = this.phraseFactory.createPrepositionPhrase("under");
- this.underTheTable.addComplement(this.phraseFactory.createNounPhrase("the", "table"));
-
-
- this.proTest1 = this.phraseFactory.createNounPhrase("the", "singer");
- this.proTest2 = this.phraseFactory.createNounPhrase("some", "person");
-
- this.kick = this.phraseFactory.createVerbPhrase("kick");
- this.kiss = this.phraseFactory.createVerbPhrase("kiss");
- this.walk = this.phraseFactory.createVerbPhrase("walk");
- this.talk = this.phraseFactory.createVerbPhrase("talk");
- this.getUp = this.phraseFactory.createVerbPhrase("get up");
- this.fallDown = this.phraseFactory.createVerbPhrase("fall down");
- this.give = this.phraseFactory.createVerbPhrase("give");
- this.say = this.phraseFactory.createVerbPhrase("say");
-
- // the woman kisses the man
- s1 = this.phraseFactory.createClause();
- s1.setSubject(this.woman);
- s1.setVerbPhrase(this.kiss);
- s1.setObject(this.man);
-
- // there is the dog on the rock
- s2 = this.phraseFactory.createClause();
- s2.setSubject("there");
- s2.setVerb("be");
- s2.setObject(this.dog);
- s2.addPostModifier(this.onTheRock);
-
- // the man gives the woman John's flower
- s3 = this.phraseFactory.createClause();
- s3.setSubject(this.man);
- s3.setVerbPhrase(this.give);
-
- var flower = this.phraseFactory.createNounPhrase("flower");
- var john = this.phraseFactory.createNounPhrase("John");
- john.setFeature(Feature.POSSESSIVE.ToString(), true);
- flower.setFeature(InternalFeature.SPECIFIER.ToString(), john);
- s3.setObject(flower);
- s3.setIndirectObject(this.woman);
-
- s4 = this.phraseFactory.createClause();
- s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
- s4.addFrontModifier("tomorrow");
-
- var subject = this.phraseFactory
- .createCoordinatedPhrase(this.phraseFactory
- .createNounPhrase("Jane"), this.phraseFactory
- .createNounPhrase("Andrew"));
-
- s4.setSubject(subject);
-
- var pick = this.phraseFactory.createVerbPhrase("pick up");
- s4.setVerbPhrase(pick);
- s4.setObject("the balls");
- s4.addPostModifier("in the shop");
- s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- }
-
- protected void reset()
- {
- this.phraseFactory = new NLGFactory(this.lexicon);
- this.realiser = new Realiser(this.lexicon);
-
- this.man = this.phraseFactory.createNounPhrase("the", "man");
- this.woman = this.phraseFactory.createNounPhrase("the", "woman");
- this.dog = this.phraseFactory.createNounPhrase("the", "dog");
- this.boy = this.phraseFactory.createNounPhrase("the", "boy");
-
- this.beautiful = this.phraseFactory.createAdjectivePhrase("beautiful");
- this.stunning = this.phraseFactory.createAdjectivePhrase("stunning");
- this.salacious = this.phraseFactory.createAdjectivePhrase("salacious");
-
- this.onTheRock = this.phraseFactory.createPrepositionPhrase("on");
- this.np4 = this.phraseFactory.createNounPhrase("the", "rock");
- this.onTheRock.addComplement(this.np4);
-
- this.behindTheCurtain = this.phraseFactory.createPrepositionPhrase("behind");
- this.np5 = this.phraseFactory.createNounPhrase("the", "curtain");
- this.behindTheCurtain.addComplement(this.np5);
-
- this.inTheRoom = this.phraseFactory.createPrepositionPhrase("in");
- this.np6 = this.phraseFactory.createNounPhrase("the", "room");
- this.inTheRoom.addComplement(this.np6);
-
- this.underTheTable = this.phraseFactory.createPrepositionPhrase("under");
- this.underTheTable.addComplement(this.phraseFactory.createNounPhrase("the", "table"));
-
-
- this.proTest1 = this.phraseFactory.createNounPhrase("the", "singer");
- this.proTest2 = this.phraseFactory.createNounPhrase("some", "person");
-
- this.kick = this.phraseFactory.createVerbPhrase("kick");
- this.kiss = this.phraseFactory.createVerbPhrase("kiss");
- this.walk = this.phraseFactory.createVerbPhrase("walk");
- this.talk = this.phraseFactory.createVerbPhrase("talk");
- this.getUp = this.phraseFactory.createVerbPhrase("get up");
- this.fallDown = this.phraseFactory.createVerbPhrase("fall down");
- this.give = this.phraseFactory.createVerbPhrase("give");
- this.say = this.phraseFactory.createVerbPhrase("say");
-
- // the woman kisses the man
- s1 = this.phraseFactory.createClause();
- s1.setSubject(this.woman);
- s1.setVerbPhrase(this.kiss);
- s1.setObject(this.man);
-
- // there is the dog on the rock
- s2 = this.phraseFactory.createClause();
- s2.setSubject("there");
- s2.setVerb("be");
- s2.setObject(this.dog);
- s2.addPostModifier(this.onTheRock);
-
- // the man gives the woman John's flower
- s3 = this.phraseFactory.createClause();
- s3.setSubject(this.man);
- s3.setVerbPhrase(this.give);
-
- var flower = this.phraseFactory.createNounPhrase("flower");
- var john = this.phraseFactory.createNounPhrase("John");
- john.setFeature(Feature.POSSESSIVE.ToString(), true);
- flower.setFeature(InternalFeature.SPECIFIER.ToString(), john);
- s3.setObject(flower);
- s3.setIndirectObject(this.woman);
-
- s4 = this.phraseFactory.createClause();
- s4.setFeature(Feature.CUE_PHRASE.ToString(), "however");
- s4.addFrontModifier("tomorrow");
-
- var subject = this.phraseFactory
- .createCoordinatedPhrase(this.phraseFactory
- .createNounPhrase("Jane"), this.phraseFactory
- .createNounPhrase("Andrew"));
-
- s4.setSubject(subject);
-
- var pick = this.phraseFactory.createVerbPhrase("pick up");
- s4.setVerbPhrase(pick);
- s4.setObject("the balls");
- s4.addPostModifier("in the shop");
- s4.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- }
-
- }
-
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/StandAloneExample.cs b/SharpSimpleNLGUnitTests/syntax/StandAloneExample.cs
deleted file mode 100644
index 6967f6c..0000000
--- a/SharpSimpleNLGUnitTests/syntax/StandAloneExample.cs
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using System;
-using System.Collections.Generic;
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests
-{
- /**
- * @author Dave Westwater, Data2Text Ltd
- *
- */
-
-public class StandAloneExample {
-
- /**
- * @param args
- */
- public static void (string[] args) {
-
- // below is a simple complete example of using simplenlg V4
- // afterwards is an example of using simplenlg just for morphology
-
- // set up
- Lexicon lexicon = new XMLLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
-
- // create sentences
- // "John did not go to the bigger park. He played football there."
- var thePark = nlgFactory.createNounPhrase("the", "park"); // create an NP
- var bigp = nlgFactory.createAdjectivePhrase("big"); // create AdjP
- bigp.setFeature(Feature.IS_COMPARATIVE, true); // use comparative form ("bigger")
- thePark.addModifier(bigp); // add adj as modifier in NP
- // above relies on default placement rules. You can force placement as a premodifier
- // (before head) by using addPreModifier
- var toThePark = nlgFactory.createPrepositionPhrase("to"); // create a PP
- toThePark.setObject(thePark); // set PP object
- // could also just say nlgFactory.createPrepositionPhrase("to", the Park);
-
- var johnGoToThePark = nlgFactory.createClause("John", // create sentence
- "go", toThePark);
-
- johnGoToThePark.setFeature(Feature.TENSE,Tense.PAST); // set tense
- johnGoToThePark.setFeature(Feature.NEGATED, true); // set negated
-
- // note that constituents (such as subject and object) are set with setXXX methods
- // while features are set with setFeature
-
- var sentence = nlgFactory // create a sentence DocumentElement from SPhraseSpec
- .createSentence(johnGoToThePark);
-
- // below creates a sentence DocumentElement by concatenating strings
- var hePlayed = new StringElement("he played");
- var there = new StringElement("there");
- var football = new WordElement("football");
-
- var sentence2 = nlgFactory.createSentence();
- sentence2.addComponent(hePlayed);
- sentence2.addComponent(football);
- sentence2.addComponent(there);
-
- // now create a paragraph which contains these sentences
- var paragraph = nlgFactory.createParagraph();
- paragraph.addComponent(sentence);
- paragraph.addComponent(sentence2);
-
- // create a realiser. Note that a lexicon is specified, this should be
- // the same one used by the NLGFactory
- var realiser = new Realiser(lexicon);
- //realiser.setDebugMode(true); // uncomment this to print out debug info during realisation
- var realised = realiser.realise(paragraph);
-
- System.out.println(realised.getRealisation());
-
- // end of main example
-
- // second example - using simplenlg just for morphology
- // below is clumsy as direct access to morphology isn't properly supported in V4.2
- // hopefully will be better supported in later versions
-
- // get word element for "child"
- var word = (WordElement) nlgFactory.createWord("child", LexicalCategory.NOUN);
- // create InflectedWordElement from word element
- var inflectedWord = new InflectedWordElement(word);
- // set the inflected word to plural
- inflectedWord.setPlural(true);
- // realise the inflected word
- var result = realiser.realise(inflectedWord).getRealisation();
-
- System.out.println(result);
- }
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/StringElementTest.cs b/SharpSimpleNLGUnitTests/syntax/StringElementTest.cs
deleted file mode 100644
index 9b69084..0000000
--- a/SharpSimpleNLGUnitTests/syntax/StringElementTest.cs
+++ /dev/null
@@ -1,413 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
- /**
- * Tests for string elements as parts of larger phrases
- *
- * @author bertugatt
- *
- */
-
- public class StringElementTest : SimpleNLG4TestBase
- {
-
- /**
- * Test that string elements can be used as heads of NP
- */
-
- [Test]
- public void stringElementAsHeadTest()
- {
- var np = this.phraseFactory.createNounPhrase();
- np.setHead(this.phraseFactory.createStringElement("dogs and cats"));
- np.setSpecifier(this.phraseFactory.createWord("the",
- new LexicalCategory_DETERMINER()));
- Assert.AreEqual("the dogs and cats", this.realiser.realise(np)
- .getRealisation());
- }
-
- /**
- * Sentences whose VP is a canned string
- */
-
- [Test]
- public void stringElementAsVPTest()
- {
- var s = this.phraseFactory.createClause();
- s.setVerbPhrase(this.phraseFactory.createStringElement("eats and drinks"));
- s.setSubject(this.phraseFactory.createStringElement("the big fat man"));
- Assert.AreEqual("the big fat man eats and drinks", this.realiser
- .realise(s).getRealisation());
- }
-
- /**
- * Test for when the SPhraseSpec has a NPSpec added directly after it:
- * "Mary loves NP[the cow]."
- */
-
- [Test]
- public void tailNPStringElementTest()
- {
- var senSpec = this.phraseFactory.createClause();
- senSpec.addComplement((this.phraseFactory.createStringElement("mary loves")));
- var np = this.phraseFactory.createNounPhrase();
- np.setHead("cow");
- np.setDeterminer("the");
- senSpec.addComplement(np);
- var completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- Assert.AreEqual("Mary loves the cow.", this.realiser.realise(completeSen).getRealisation());
- }
-
- /**
- * Test for a NP followed by a canned text: "NP[A cat] loves a dog".
- */
-
- [Test]
- public void frontNPStringElementTest()
- {
- var senSpec = this.phraseFactory.createClause();
- var np = this.phraseFactory.createNounPhrase();
- np.setHead("cat");
- np.setDeterminer("the");
- senSpec.addComplement(np);
- senSpec.addComplement(this.phraseFactory.createStringElement("loves a dog"));
- var completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- Assert.AreEqual("The cat loves a dog.", this.realiser.realise(completeSen).getRealisation());
- }
-
-
- /**
- * Test for a StringElement followed by a NP followed by a StringElement
- * "The world loves NP[ABBA] but not a sore loser."
- */
-
- [Test]
- public void mulitpleStringElementsTest()
- {
- var senSpec = this.phraseFactory.createClause();
- senSpec.addComplement(this.phraseFactory.createStringElement("the world loves"));
- var np = this.phraseFactory.createNounPhrase();
- np.setHead("ABBA");
- senSpec.addComplement(np);
- senSpec.addComplement(this.phraseFactory.createStringElement("but not a sore loser"));
- var completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- Assert.AreEqual("The world loves ABBA but not a sore loser.", this.realiser.realise(completeSen).getRealisation());
- }
-
- /**
- * Test for multiple NP phrases with a single StringElement phrase:
- * "NP[John is] a trier NP[for cheese]."
- */
-
- [Test]
- public void mulitpleNPElementsTest()
- {
- var senSpec = this.phraseFactory.createClause();
- var frontNoun = this.phraseFactory.createNounPhrase();
- frontNoun.setHead("john");
- senSpec.addComplement(frontNoun);
- senSpec.addComplement(this.phraseFactory.createStringElement("is a trier"));
- var backNoun = this.phraseFactory.createNounPhrase();
- backNoun.setDeterminer("for");
- backNoun.setNoun("cheese");
- senSpec.addComplement(backNoun);
- var completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- Assert.AreEqual("John is a trier for cheese.", this.realiser.realise(completeSen).getRealisation());
-
- }
-
-
- /**
- * White space check: Test to see how SNLG deals with additional whitespaces:
- *
- * NP[The Nasdaq] rose steadily during NP[early trading], however it plummeted due to NP[a shock] after NP[IBM] announced poor
- * NP[first quarter results].
- */
-
- [Test]
- public void whiteSpaceNPTest()
- {
- var senSpec = this.phraseFactory.createClause();
- var firstNoun = this.phraseFactory.createNounPhrase();
- firstNoun.setDeterminer("the");
- firstNoun.setNoun("Nasdaq");
- senSpec.addComplement(firstNoun);
- senSpec.addComplement(this.phraseFactory.createStringElement(" rose steadily during "));
- var secondNoun = this.phraseFactory.createNounPhrase();
- secondNoun.setSpecifier("early");
- secondNoun.setNoun("trading");
- senSpec.addComplement(secondNoun);
- senSpec.addComplement(this.phraseFactory.createStringElement(" , however it plummeted due to"));
- var thirdNoun = this.phraseFactory.createNounPhrase();
- thirdNoun.setSpecifier("a");
- thirdNoun.setNoun("shock");
- senSpec.addComplement(thirdNoun);
- senSpec.addComplement(this.phraseFactory.createStringElement(" after "));
- var fourthNoun = this.phraseFactory.createNounPhrase();
- fourthNoun.setNoun("IBM");
- senSpec.addComplement(fourthNoun);
- senSpec.addComplement(this.phraseFactory.createStringElement("announced poor "));
- var fifthNoun = this.phraseFactory.createNounPhrase();
- fifthNoun.setSpecifier("first quarter");
- fifthNoun.setNoun("results");
- fifthNoun.setPlural(true);
- senSpec.addComplement(fifthNoun);
- var completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- Assert.AreEqual(
- "The Nasdaq rose steadily during early trading, however it plummeted due to a shock after IBM announced poor first quarter results.",
- this.realiser.realise(completeSen).getRealisation());
- }
-
- /**
- * Point absorption test: Check to see if SNLG respects abbreviations at the end of a sentence.
- * "NP[Yahya] was sleeping his own and dreaming etc."
- */
-
- public void pointAbsorptionTest()
- {
- var senSpec = this.phraseFactory.createClause();
- var firstNoun = this.phraseFactory.createNounPhrase();
- firstNoun.setNoun("yaha");
- senSpec.addComplement(firstNoun);
- senSpec.addComplement("was sleeping on his own and dreaming etc.");
- var completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- Assert.AreEqual("Yaha was sleeping on his own and dreaming etc.",
- this.realiser.realise(completeSen).getRealisation());
-
-
- }
-
- /**
- * Point absorption test: As above, but with trailing white space.
- * "NP[Yaha] was sleeping his own and dreaming etc. "
- */
-
- public void pointAbsorptionTrailingWhiteSpaceTest()
- {
- var senSpec = this.phraseFactory.createClause();
- var firstNoun = this.phraseFactory.createNounPhrase();
- firstNoun.setNoun("yaha");
- senSpec.addComplement(firstNoun);
- senSpec.addComplement("was sleeping on his own and dreaming etc. ");
- var completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- Assert.AreEqual("Yaha was sleeping on his own and dreaming etc.",
- this.realiser.realise(completeSen).getRealisation());
- }
-
- /**
- * Abbreviation test: Check to see how SNLG deals with abbreviations in the middle of a sentence.
- *
- * "NP[Yahya] and friends etc. went to NP[the park] to play."
- */
-
- [Test]
- public void middleAbbreviationTest()
- {
- var senSpec = this.phraseFactory.createClause();
- var firstNoun = this.phraseFactory.createNounPhrase();
- firstNoun.setNoun("yahya");
- senSpec.addComplement(firstNoun);
- senSpec.addComplement(this.phraseFactory.createStringElement("and friends etc. went to"));
- var secondNoun = this.phraseFactory.createNounPhrase();
- secondNoun.setDeterminer("the");
- secondNoun.setNoun("park");
- senSpec.addComplement(secondNoun);
- senSpec.addComplement("to play");
- var completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- Assert.AreEqual("Yahya and friends etc. went to the park to play.",
- this.realiser.realise(completeSen).getRealisation());
- }
-
-
- /**
- * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
- * "I see an NP[elephant]"
- */
-
- [Test]
- public void stringIndefiniteArticleInflectionVowelTest()
- {
- var senSpec = this.phraseFactory.createClause();
- senSpec.addComplement(this.phraseFactory.createStringElement("I see a"));
- var firstNoun = this.phraseFactory.createNounPhrase("elephant");
- senSpec.addComplement(firstNoun);
- var completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- Assert.AreEqual("I see an elephant.",
- this.realiser.realise(completeSen).getRealisation());
-
- }
-
- /**
- * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
- * "I see NP[a elephant]" -->
- */
-
- [Test]
- public void NPIndefiniteArticleInflectionVowelTest()
- {
- var senSpec = this.phraseFactory.createClause();
- senSpec.addComplement(this.phraseFactory.createStringElement("I see"));
- var firstNoun = this.phraseFactory.createNounPhrase("elephant");
- firstNoun.setDeterminer("a");
- senSpec.addComplement(firstNoun);
- var completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- Assert.AreEqual("I see an elephant.",
- this.realiser.realise(completeSen).getRealisation());
-
- }
-
-
- /**
- * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
- * "I see an NP[cow]"
- */
-
- // Unknown status in Java Library [Test]
- public void stringIndefiniteArticleInflectionConsonantTest()
- {
- var senSpec = this.phraseFactory.createClause();
- senSpec.addComplement(this.phraseFactory.createStringElement("I see an"));
- var firstNoun = this.phraseFactory.createNounPhrase("cow");
- senSpec.addComplement(firstNoun);
- var completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- this.realiser.setDebugMode(true);
- // Do not attempt "an" -> "a"
- Assert.AreNotEqual("I see an cow.",
- this.realiser.realise(completeSen).getRealisation());
- }
-
- /**
- * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
- * "I see NP[an cow]" -->
- */
-
- [Test]
- public void NPIndefiniteArticleInflectionConsonantTest()
- {
- var senSpec = this.phraseFactory.createClause();
- senSpec.addComplement(this.phraseFactory.createStringElement("I see"));
- var firstNoun = this.phraseFactory.createNounPhrase("cow");
- firstNoun.setDeterminer("an");
- senSpec.addComplement(firstNoun);
- var completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- // Do not attempt "an" -> "a"
- Assert.AreEqual("I see an cow.",
- this.realiser.realise(completeSen).getRealisation());
- }
-
-
- /**
- * aggregationStringElementTest: Test to see if we can aggregate two StringElements in a CoordinatedPhraseElement.
- */
-
- [Test]
- public void aggregationStringElementTest()
- {
-
- var coordinate =
- this.phraseFactory.createCoordinatedPhrase(new StringElement("John is going to Tesco"),
- new StringElement("Mary is going to Sainsburys"));
- var sentence = this.phraseFactory.createClause();
- sentence.addComplement(coordinate);
-
- Assert.AreEqual("John is going to Tesco and Mary is going to Sainsburys.",
- this.realiser.realiseSentence(sentence));
- }
-
-
- /**
- * Tests that no empty space is added when a StringElement is instantiated with an empty string
- * or null object.
- */
-
- [Test]
- public void nullAndEmptyStringElementTest()
- {
-
- var nullStringElement = this.phraseFactory.createStringElement(null);
- var emptyStringElement = this.phraseFactory.createStringElement("");
- var beautiful = this.phraseFactory.createStringElement("beautiful");
- var horseLike = this.phraseFactory.createStringElement("horse-like");
- var creature = this.phraseFactory.createStringElement("creature");
-
- // Test1: null or empty at beginning
- var test1 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
- test1.addPostModifier(emptyStringElement);
- test1.addPostModifier(beautiful);
- test1.addPostModifier(horseLike);
- test1.addPostModifier(creature);
- Assert.AreEqual("A unicorn is regarded as a beautiful horse-like creature.",
- this.realiser.realiseSentence(test1));
-
- // Test2: empty or null at end
- var test2 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
- test2.addPostModifier(beautiful);
- test2.addPostModifier(horseLike);
- test2.addPostModifier(creature);
- test2.addPostModifier(nullStringElement);
- Assert.AreEqual("A unicorn is regarded as a beautiful horse-like creature.",
- this.realiser.realiseSentence(test2));
-
- // Test3: empty or null in the middle
- var test3 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
- test3.addPostModifier("beautiful");
- test3.addPostModifier("horse-like");
- test3.addPostModifier("");
- test3.addPostModifier("creature");
- Assert.AreEqual("A unicorn is regarded as a beautiful horse-like creature.",
- this.realiser.realiseSentence(test3));
-
- // Test4: empty or null in the middle with empty or null at beginning
- var test4 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
- test4.addPostModifier("");
- test4.addPostModifier("beautiful");
- test4.addPostModifier("horse-like");
- test4.addPostModifier(nullStringElement);
- test4.addPostModifier("creature");
- Assert.AreEqual("A unicorn is regarded as a beautiful horse-like creature.",
- this.realiser.realiseSentence(test4));
-
- }
-
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/TutorialTest.cs b/SharpSimpleNLGUnitTests/syntax/TutorialTest.cs
deleted file mode 100644
index 4fda0f9..0000000
--- a/SharpSimpleNLGUnitTests/syntax/TutorialTest.cs
+++ /dev/null
@@ -1,465 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using System.Collections.Generic;
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
- /**
- * Tests from SimpleNLG tutorial
- *
- *
- *
- * Copyright (C) 2011, University of Aberdeen
- *
- *
- * @author Ehud Reiter
- *
- */
-
- public class TutorialTest
- {
-
-
-
- [Test]
- public void section3_Test()
- {
- var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
-
- NLGElement s1 = nlgFactory.createSentence("my dog is happy");
-
- var r = new Realiser(lexicon);
-
- var output = r.realiseSentence(s1);
-
- Assert.AreEqual("My dog is happy.", output);
- }
-
- /**
- * test section 5 code
- */
-
- [Test]
- public void section5_Test()
- {
- var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
- var realiser = new Realiser(lexicon);
-
- var p = nlgFactory.createClause();
- p.setSubject("my dog");
- p.setVerb("chase");
- p.setObject("George");
-
- var output = realiser.realiseSentence(p);
- Assert.AreEqual("My dog chases George.", output);
- }
-
- /**
- * test section 6 code
- */
-
- [Test]
- public void section6_Test()
- {
- var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
- var realiser = new Realiser(lexicon);
-
- var p = nlgFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("chase");
- p.setObject("George");
-
- p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- var output = realiser.realiseSentence(p);
- Assert.AreEqual("Mary chased George.", output);
-
- p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- output = realiser.realiseSentence(p);
- Assert.AreEqual("Mary will chase George.", output);
-
- p.setFeature(Feature.NEGATED.ToString(), true);
- output = realiser.realiseSentence(p);
- Assert.AreEqual("Mary will not chase George.", output);
-
- p = nlgFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("chase");
- p.setObject("George");
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(),
- InterrogativeType.YES_NO);
- output = realiser.realiseSentence(p);
- Assert.AreEqual("Does Mary chase George?", output);
-
- p.setSubject("Mary");
- p.setVerb("chase");
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
- output = realiser.realiseSentence(p);
- Assert.AreEqual("Who does Mary chase?", output);
-
- p = nlgFactory.createClause();
- p.setSubject("the dog");
- p.setVerb("wake up");
- output = realiser.realiseSentence(p);
- Assert.AreEqual("The dog wakes up.", output);
-
- }
-
- /**
- * test ability to use variant words
- */
-
- [Test]
- public void variantsTest()
- {
- var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
- var realiser = new Realiser(lexicon);
-
- var p = nlgFactory.createClause();
- p.setSubject("my dog");
- p.setVerb("is"); // variant of be
- p.setObject("George");
-
- var output = realiser.realiseSentence(p);
- Assert.AreEqual("My dog is George.", output);
-
- p = nlgFactory.createClause();
- p.setSubject("my dog");
- p.setVerb("chases"); // variant of chase
- p.setObject("George");
-
- output = realiser.realiseSentence(p);
- Assert.AreEqual("My dog chases George.", output);
-
-
- p = nlgFactory.createClause();
- p.setSubject(nlgFactory.createNounPhrase("the", "dogs")); // variant of "dog"
- p.setVerb("is"); // variant of be
- p.setObject("happy"); // variant of happy
- output = realiser.realiseSentence(p);
- Assert.AreEqual("The dog is happy.", output);
-
- p = nlgFactory.createClause();
- p.setSubject(nlgFactory.createNounPhrase("the", "children")); // variant of "child"
- p.setVerb("is"); // variant of be
- p.setObject("happy"); // variant of happy
- output = realiser.realiseSentence(p);
- Assert.AreEqual("The child is happy.", output);
-
- // following functionality is enabled
- p = nlgFactory.createClause();
- p.setSubject(nlgFactory.createNounPhrase("the", "dogs")); // variant of "dog"
- p.setVerb("is"); // variant of be
- p.setObject("happy"); // variant of happy
- output = realiser.realiseSentence(p);
- Assert.AreEqual("The dog is happy.", output); //corrected automatically
- }
-
- /* Following code tests the section 5 to 15
- * sections 5 & 6 are repeated here in order to match the simplenlg tutorial version 4
- * James Christie
- * June 2011
- */
-
- /**
- * test section 5 to match simplenlg tutorial version 4's code
- */
-
- [Test]
- public void section5A_Test()
- {
- var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
- var realiser = new Realiser(lexicon);
-
- var p = nlgFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("chase");
- p.setObject("the monkey");
-
- var output = realiser.realiseSentence(p);
- Assert.AreEqual("Mary chases the monkey.", output);
- } // testSection5A
-
- /**
- * test section 6 to match simplenlg tutorial version 4' code
- */
-
- [Test]
- public void section6A_Test()
- {
- var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
- var realiser = new Realiser(lexicon);
-
- var p = nlgFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("chase");
- p.setObject("the monkey");
-
- p.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- var output = realiser.realiseSentence(p);
- Assert.AreEqual("Mary chased the monkey.", output);
-
- p.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- output = realiser.realiseSentence(p);
- Assert.AreEqual("Mary will chase the monkey.", output);
-
- p.setFeature(Feature.NEGATED.ToString(), true);
- output = realiser.realiseSentence(p);
- Assert.AreEqual("Mary will not chase the monkey.", output);
-
- p = nlgFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("chase");
- p.setObject("the monkey");
-
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.YES_NO);
- output = realiser.realiseSentence(p);
- Assert.AreEqual("Does Mary chase the monkey?", output);
-
- p.setSubject("Mary");
- p.setVerb("chase");
- p.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), InterrogativeType.WHO_OBJECT);
- output = realiser.realiseSentence(p);
- Assert.AreEqual("Who does Mary chase?", output);
- }
-
- /**
- * test section 7 code
- */
-
- [Test]
- public void section7_Test()
- {
- var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
- var realiser = new Realiser(lexicon);
-
- var p = nlgFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("chase");
- p.setObject("the monkey");
- p.addComplement("very quickly");
- p.addComplement("despite her exhaustion");
-
- var output = realiser.realiseSentence(p);
- Assert.AreEqual("Mary chases the monkey very quickly despite her exhaustion.", output);
- }
-
- /**
- * test section 8 code
- */
-
- [Test]
- public void section8_Test()
- {
- var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
- var realiser = new Realiser(lexicon);
- //realiser.setDebugMode(true);
- var subject = nlgFactory.createNounPhrase("Mary");
- var obj = nlgFactory.createNounPhrase("the monkey");
- var verb = nlgFactory.createVerbPhrase("chase");
- subject.addModifier("fast");
-
- var p = nlgFactory.createClause();
- p.setSubject(subject);
- p.setVerb(verb);
- p.setObject(obj);
-
- var outputA = realiser.realiseSentence(p);
- Assert.AreEqual("Fast Mary chases the monkey.", outputA);
-
- verb.addModifier("quickly");
-
- var outputB = realiser.realiseSentence(p);
- Assert.AreEqual("Fast Mary quickly chases the monkey.", outputB);
- }
-
- // there is no code specified in section 9
-
- /**
- * test section 10 code
- */
-
- [Test]
- public void section10_Test()
- {
- var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
- var realiser = new Realiser(lexicon);
-
- var subject1 = nlgFactory.createNounPhrase("Mary");
- var subject2 = nlgFactory.createNounPhrase("your", "giraffe");
-
- // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API
- var subj = nlgFactory.createCoordinatedPhrase(subject1, subject2);
-
- var verb = nlgFactory.createVerbPhrase("chase");
-
- var p = nlgFactory.createClause();
- p.setSubject(subj);
- p.setVerb(verb);
- p.setObject("the monkey");
-
- var outputA = realiser.realiseSentence(p);
- Assert.AreEqual("Mary and your giraffe chase the monkey.", outputA);
-
- var object1 = nlgFactory.createNounPhrase("the monkey");
- var object2 = nlgFactory.createNounPhrase("George");
-
- // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API
- var obj = nlgFactory.createCoordinatedPhrase(object1, object2);
- obj.addCoordinate("Martha");
- p.setObject(obj);
-
- var outputB = realiser.realiseSentence(p);
- Assert.AreEqual("Mary and your giraffe chase the monkey, George and Martha.", outputB);
-
- obj.setFeature(Feature.CONJUNCTION.ToString(), "or");
-
- var outputC = realiser.realiseSentence(p);
- Assert.AreEqual("Mary and your giraffe chase the monkey, George or Martha.", outputC);
- }
-
- /**
- * test section 11 code
- */
-
- [Test]
- public void section11_Test()
- {
- var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
-
- var realiser = new Realiser(lexicon);
-
- var pA = nlgFactory.createClause("Mary", "chase", "the monkey");
- pA.addComplement("in the park");
-
- var outputA = realiser.realiseSentence(pA);
- Assert.AreEqual("Mary chases the monkey in the park.", outputA);
-
- // alternative build paradigm
- var place = nlgFactory.createNounPhrase("park");
- var pB = nlgFactory.createClause("Mary", "chase", "the monkey");
-
- // next line is depreciated ~ may be corrected in the API
- place.setDeterminer("the");
- var pp = nlgFactory.createPrepositionPhrase();
- pp.addComplement(place);
- pp.setPreposition("in");
-
- pB.addComplement(pp);
-
- var outputB = realiser.realiseSentence(pB);
- Assert.AreEqual("Mary chases the monkey in the park.", outputB);
-
- place.addPreModifier("leafy");
-
- var outputC = realiser.realiseSentence(pB);
- Assert.AreEqual("Mary chases the monkey in the leafy park.", outputC);
- } // testSection11
-
- // section12 only has a code table as illustration
-
- /**
- * test section 13 code
- */
-
- [Test]
- public void section13_Test()
- {
- var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
-
- var realiser = new Realiser(lexicon);
-
- var s1 = nlgFactory.createClause("my cat", "like", "fish");
- var s2 = nlgFactory.createClause("my dog", "like", "big bones");
- var s3 = nlgFactory.createClause("my horse", "like", "grass");
-
- var c = nlgFactory.createCoordinatedPhrase();
- c.addCoordinate(s1);
- c.addCoordinate(s2);
- c.addCoordinate(s3);
-
- var outputA = realiser.realiseSentence(c);
- Assert.AreEqual("My cat likes fish, my dog likes big bones and my horse likes grass.", outputA);
-
- var p = nlgFactory.createClause("I", "be", "happy");
- var q = nlgFactory.createClause("I", "eat", "fish");
- q.setFeature(Feature.COMPLEMENTISER.ToString(), "because");
- q.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- p.addComplement(q);
-
- var outputB = realiser.realiseSentence(p);
- Assert.AreEqual("I am happy because I ate fish.", outputB);
- }
-
- /**
- * test section 14 code
- */
-
- [Test]
- public void section14_Test()
- {
- var lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- var nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
-
- var realiser = new Realiser(lexicon);
-
- var p1 = nlgFactory.createClause("Mary", "chase", "the monkey");
- var p2 = nlgFactory.createClause("The monkey", "fight back");
- var p3 = nlgFactory.createClause("Mary", "be", "nervous");
-
- var s1 = nlgFactory.createSentence(p1);
- var s2 = nlgFactory.createSentence(p2);
- var s3 = nlgFactory.createSentence(p3);
-
- var par1 = nlgFactory.createParagraph(new List { s1, s2, s3});
-
- var output14a = realiser.realise(par1).getRealisation();
- Assert.AreEqual("Mary chases the monkey. The monkey fights back. Mary is nervous.\n\n", output14a);
-
- var section = nlgFactory.createSection("The Trials and Tribulation of Mary and the Monkey");
- section.addComponent(par1);
- var output14b = realiser.realise(section).getRealisation();
- Assert.AreEqual(
- "The Trials and Tribulation of Mary and the Monkey\nMary chases the monkey. The monkey fights back. Mary is nervous.\n\n",
- output14b);
- }
-
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/VerbPhraseTest.cs b/SharpSimpleNLGUnitTests/syntax/VerbPhraseTest.cs
deleted file mode 100644
index c6f5931..0000000
--- a/SharpSimpleNLGUnitTests/syntax/VerbPhraseTest.cs
+++ /dev/null
@@ -1,472 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "SharpSimpleNLG".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood, Nick Hodge
- */
-
-/* Additional Notes:
- * - Original Java source is SimpleNLG from 12-Jun-2016 https://github.com/simplenlg/simplenlg
- * - This is a port of the Java version to C# with no additional features
- * - I have left the "Initial Developer" section to reflect this fact
- * - Any questions, comments, feedback on this port can be sent to Nick Hodge
- */
-
-using NUnit.Framework;
-using SimpleNLG;
-
-namespace SimpleNLGTests.syntax
-{
- /**
- * These are tests for the verb phrase and coordinate VP classes.
- * @author agatt
- */
-
- public class VerbPhraseTest : SimpleNLG4TestBase
- {
-
-
- /**
- * Some tests to check for an early bug which resulted in reduplication of
- * verb particles in the past tense e.g. "fall down down" or "creep up up"
- */
-
- [Test]
- public void testVerbParticle()
- {
- var v = this.phraseFactory.createVerbPhrase("fall down");
-
- Assert.AreEqual(
- "down", v.getFeatureAsString(Feature.PARTICLE.ToString()));
-
- Assert.AreEqual(
- "fall", ((WordElement) v.getVerb()).getBaseForm());
-
- v.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- v.setFeature(Feature.PERSON.ToString(), Person.THIRD);
- v.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
-
- Assert.AreEqual(
- "fell down", this.realiser.realise(v).getRealisation());
-
- v.setFeature(Feature.FORM.ToString(), Form.PAST_PARTICIPLE);
- Assert.AreEqual(
- "fallen down", this.realiser.realise(v).getRealisation());
- }
-
- /**
- * Tests for the tense and aspect.
- */
-
- [Test]
- public void simplePastTest()
- {
- // "fell down"
- this.fallDown.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- Assert.AreEqual(
- "fell down", this.realiser.realise(this.fallDown).getRealisation());
-
- }
-
- /**
- * Test tense aspect.
- */
-
- [Test]
- public void tenseAspectTest()
- {
- // had fallen down
- this.realiser.setLexicon(this.lexicon);
- this.fallDown.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- this.fallDown.setFeature(Feature.PERFECT.ToString(), true);
-
- Assert.AreEqual("had fallen down", this.realiser.realise(
- this.fallDown).getRealisation());
-
- // had been falling down
- this.fallDown.setFeature(Feature.PROGRESSIVE.ToString(), true);
- Assert.AreEqual("had been falling down", this.realiser.realise(
- this.fallDown).getRealisation());
-
- // will have been kicked
- this.kick.setFeature(Feature.PASSIVE.ToString(), true);
- this.kick.setFeature(Feature.PERFECT.ToString(), true);
- this.kick.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- Assert.AreEqual("will have been kicked", this.realiser.realise(
- this.kick).getRealisation());
-
- // will have been being kicked
- this.kick.setFeature(Feature.PROGRESSIVE.ToString(), true);
- Assert.AreEqual("will have been being kicked", this.realiser
- .realise(this.kick).getRealisation());
-
- // will not have been being kicked
- this.kick.setFeature(Feature.NEGATED.ToString(), true);
- Assert.AreEqual("will not have been being kicked", this.realiser
- .realise(this.kick).getRealisation());
-
- // passivisation should suppress the complement
- this.kick.clearComplements();
- this.kick.addComplement(this.man);
- Assert.AreEqual("will not have been being kicked", this.realiser
- .realise(this.kick).getRealisation());
-
- // de-passivisation should now give us "will have been kicking the man"
- this.kick.setFeature(Feature.PASSIVE.ToString(), false);
- Assert.AreEqual("will not have been kicking the man", this.realiser
- .realise(this.kick).getRealisation());
-
- // remove the future tense --
- // this is a test of an earlier bug that would still realise "will"
- this.kick.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);
- Assert.AreEqual("has not been kicking the man", this.realiser
- .realise(this.kick).getRealisation());
- }
-
- /**
- * Test for realisation of VP complements.
- */
-
- [Test]
- public void complementationTest()
- {
-
- // was kissing Mary
- var mary = this.phraseFactory.createNounPhrase("Mary");
- mary.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.OBJECT);
- this.kiss.clearComplements();
- this.kiss.addComplement(mary);
- this.kiss.setFeature(Feature.PROGRESSIVE.ToString(), true);
- this.kiss.setFeature(Feature.TENSE.ToString(), Tense.PAST);
-
- Assert.AreEqual("was kissing Mary", this.realiser
- .realise(this.kiss).getRealisation());
-
- var mary2 = new CoordinatedPhraseElement(mary,
- this.phraseFactory.createNounPhrase("Susan"));
- // add another complement -- should come out as "Mary and Susan"
- this.kiss.clearComplements();
- this.kiss.addComplement(mary2);
- Assert.AreEqual("was kissing Mary and Susan", this.realiser
- .realise(this.kiss).getRealisation());
-
- // passivise -- should make the direct object complement disappear
- // Note: The verb doesn't come out as plural because agreement
- // is determined by the sentential subjects and this VP isn't inside a
- // sentence
- this.kiss.setFeature(Feature.PASSIVE.ToString(), true);
- Assert.AreEqual("was being kissed", this.realiser
- .realise(this.kiss).getRealisation());
-
- // make it plural (this is usually taken care of in SPhraseSpec)
- this.kiss.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
- Assert.AreEqual("were being kissed", this.realiser.realise(
- this.kiss).getRealisation());
-
- // depassivise and add post-mod: yields "was kissing Mary in the room"
- this.kiss.addPostModifier(this.inTheRoom);
- this.kiss.setFeature(Feature.PASSIVE.ToString(), false);
- this.kiss.setFeature(Feature.NUMBER.ToString(), NumberAgreement.SINGULAR);
- Assert.AreEqual("was kissing Mary and Susan in the room",
- this.realiser.realise(this.kiss).getRealisation());
-
- // passivise again: should make direct object disappear, but not postMod
- // ="was being kissed in the room"
- this.kiss.setFeature(Feature.PASSIVE.ToString(), true);
- this.kiss.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL);
- Assert.AreEqual("were being kissed in the room", this.realiser
- .realise(this.kiss).getRealisation());
- }
-
- /**
- * This tests for the default complement ordering, relative to pre and
- * postmodifiers.
- */
-
- [Test]
- public void complementationTest_2()
- {
- // give the woman the dog
- this.woman.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
- DiscourseFunction.INDIRECT_OBJECT);
- this.dog.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
- DiscourseFunction.OBJECT);
- this.give.clearComplements();
- this.give.addComplement(this.dog);
- this.give.addComplement(this.woman);
- Assert.AreEqual("gives the woman the dog", this.realiser.realise(
- this.give).getRealisation());
-
- // add a few premodifiers and postmodifiers
- this.give.addPreModifier("slowly");
- this.give.addPostModifier(this.behindTheCurtain);
- this.give.addPostModifier(this.inTheRoom);
- Assert.AreEqual(
- "slowly gives the woman the dog behind the curtain in the room",
- this.realiser.realise(this.give).getRealisation());
-
- // reset the arguments
- this.give.clearComplements();
- this.give.addComplement(this.dog);
- var womanBoy = new CoordinatedPhraseElement(
- this.woman, this.boy);
- womanBoy.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
- DiscourseFunction.INDIRECT_OBJECT);
- this.give.addComplement(womanBoy);
-
- // if we unset the passive, we should get the indirect objects
- // they won't be coordinated
- this.give.setFeature(Feature.PASSIVE.ToString(), false);
- Assert.AreEqual(
- "slowly gives the woman and the boy the dog behind the curtain in the room",
- this.realiser.realise(this.give).getRealisation());
-
- // set them to a coordinate instead
- // set ONLY the complement INDIRECT_OBJECT, leaves OBJECT intact
- this.give.clearComplements();
- this.give.addComplement(womanBoy);
- this.give.addComplement(this.dog);
- var complements = this.give
- .getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString());
-
- var indirectCount = 0;
- foreach (var eachElement in complements)
- {
- if (DiscourseFunction.INDIRECT_OBJECT.Equals(eachElement
- .getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString())))
- {
- indirectCount++;
- }
- }
- Assert.AreEqual(1, indirectCount); // only one indirect object
- // where
- // there were two before
-
- Assert.AreEqual(
- "slowly gives the woman and the boy the dog behind the curtain in the room",
- this.realiser.realise(this.give).getRealisation());
- }
-
- /**
- * Test for complements raised in the passive case.
- */
-
- [Test]
- public void passiveComplementTest()
- {
- NPPhraseSpec woman2 = this.phraseFactory.createNounPhrase("the", "woman");
- NPPhraseSpec dog2 = this.phraseFactory.createNounPhrase("the", "dog");
- VPPhraseSpec give2 = this.phraseFactory.createVerbPhrase("give");
- PPPhraseSpec behindTheCurtain2 = this.phraseFactory.createPrepositionPhrase("behind");
- NPPhraseSpec np52 = this.phraseFactory.createNounPhrase("the", "curtain");
- behindTheCurtain2.addComplement(np52);
-
- PPPhraseSpec inTheRoom2 = this.phraseFactory.createPrepositionPhrase("in");
- NPPhraseSpec np62 = this.phraseFactory.createNounPhrase("the", "room");
- inTheRoom2.addComplement(np62);
-
-
- // add some arguments
- dog2.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
- DiscourseFunction.OBJECT);
- woman2.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
- DiscourseFunction.INDIRECT_OBJECT);
- give2.addComplement(dog2);
- give2.addComplement(woman2);
- Assert.AreEqual("gives the woman the dog", this.realiser.realise(
- give2).getRealisation());
-
- // add a few premodifiers and postmodifiers
- give2.addPreModifier("slowly");
- give2.addPostModifier(behindTheCurtain2);
- give2.addPostModifier(inTheRoom2);
- Assert.AreEqual(
- "slowly gives the woman the dog behind the curtain in the room",
- this.realiser.realise(give2).getRealisation());
-
- // passivise: This should suppress "the dog"
- give2.clearComplements();
- give2.addComplement(dog2);
- give2.addComplement(woman2);
- give2.setFeature(Feature.PASSIVE.ToString(), true);
-
- Assert.AreEqual(
- "is slowly given the woman behind the curtain in the room",
- this.realiser.realise(give2).getRealisation());
- }
-
- /**
- * Test VP with sentential complements. This tests for structures like "said
- * that John was walking"
- */
-
- [Test]
- public void clausalComplementTest()
- {
- this.phraseFactory.setLexicon(this.lexicon);
- var s = this.phraseFactory.createClause();
-
- s.setSubject(this.phraseFactory
- .createNounPhrase("John"));
-
- // Create a sentence first
- var maryAndSusan = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Mary"),
- this.phraseFactory.createNounPhrase("Susan"));
-
- this.kiss.clearComplements();
- s.setVerbPhrase(this.kiss);
- s.setObject(maryAndSusan);
- s.setFeature(Feature.PROGRESSIVE.ToString(), true);
- s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- s.addPostModifier(this.inTheRoom);
- Assert.AreEqual("John was kissing Mary and Susan in the room",
- this.realiser.realise(s).getRealisation());
-
- // make the main VP past
- this.say.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- Assert.AreEqual("said", this.realiser.realise(this.say)
- .getRealisation());
-
- // now add the sentence as complement of "say". Should make the sentence
- // subordinate
- // note that sentential punctuation is suppressed
- this.say.addComplement(s);
- Assert.AreEqual(
- "said that John was kissing Mary and Susan in the room",
- this.realiser.realise(this.say).getRealisation());
-
- // add a postModifier to the main VP
- // yields [says [that John was kissing Mary and Susan in the room]
- // [behind the curtain]]
- this.say.addPostModifier(this.behindTheCurtain);
- Assert.AreEqual(
- "said that John was kissing Mary and Susan in the room behind the curtain",
- this.realiser.realise(this.say).getRealisation());
-
- // create a new sentential complement
- var s2 = this.phraseFactory.createClause(this.phraseFactory
- .createNounPhrase("all"),
- "be",
- this.phraseFactory.createAdjectivePhrase("fine"));
-
- s2.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- Assert.AreEqual("all will be fine", this.realiser.realise(s2)
- .getRealisation());
-
- // add the new complement to the VP
- // yields [said [that John was kissing Mary and Susan in the room and
- // all will be fine] [behind the curtain]]
- var s3 = new CoordinatedPhraseElement(s, s2);
- this.say.clearComplements();
- this.say.addComplement(s3);
-
- // first with outer complementiser suppressed
- s3.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true);
- Assert.AreEqual(
- "said that John was kissing Mary and Susan in the room "
- + "and all will be fine behind the curtain",
- this.realiser.realise(this.say).getRealisation());
-
- setUp();
-
- s = this.phraseFactory.createClause();
-
- s.setSubject(this.phraseFactory
- .createNounPhrase("John"));
-
- // Create a sentence first
- maryAndSusan = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Mary"),
- this.phraseFactory.createNounPhrase("Susan"));
-
- s.setVerbPhrase(this.kiss);
- s.setObject(maryAndSusan);
- s.setFeature(Feature.PROGRESSIVE.ToString(), true);
- s.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- s.addPostModifier(this.inTheRoom);
- s2 = this.phraseFactory.createClause(this.phraseFactory
- .createNounPhrase("all"),
- "be",
- this.phraseFactory.createAdjectivePhrase("fine"));
-
- s2.setFeature(Feature.TENSE.ToString(), Tense.FUTURE);
- // then with complementiser not suppressed and not aggregated
- s3 = new CoordinatedPhraseElement(s, s2);
- this.say.addComplement(s3);
- this.say.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- this.say.addPostModifier(this.behindTheCurtain);
-
- this.realiser.setDebugMode(true);
- Assert.AreEqual(
- "said that John was kissing Mary and Susan in the room and "
- + "that all will be fine behind the curtain",
- this.realiser.realise(this.say).getRealisation());
-
- }
-
- /**
- * Test VP coordination and aggregation:
- *
- * If the simplenlg.features of a coordinate VP are set, they should be
- * inherited by its daughter VP;
- * 2. We can aggregate the coordinate VP so it's realised with one
- * wide-scope auxiliary
- */
-
- [Test]
- public void coordinationTest()
- {
- // simple case
- VPPhraseSpec kiss2 = this.phraseFactory.createVerbPhrase("kiss");
- kiss2.addComplement(this.dog);
- VPPhraseSpec kick2 = this.phraseFactory.createVerbPhrase("kick");
- kick2.addComplement(this.boy);
-
- var coord1 = new CoordinatedPhraseElement(
- kiss2, kick2);
-
- coord1.setFeature(Feature.PERSON.ToString(), Person.THIRD);
- coord1.setFeature(Feature.TENSE.ToString(), Tense.PAST);
- Assert.AreEqual("kissed the dog and kicked the boy", this.realiser
- .realise(coord1).getRealisation());
-
- // with negation: should be inherited by all components
- coord1.setFeature(Feature.NEGATED.ToString(), true);
- this.realiser.setLexicon(this.lexicon);
- Assert.AreEqual("did not kiss the dog and did not kick the boy",
- this.realiser.realise(coord1).getRealisation());
-
- // set a modal
- coord1.setFeature(Feature.MODAL.ToString(), "could");
- Assert.AreEqual(
- "could not have kissed the dog and could not have kicked the boy",
- this.realiser.realise(coord1).getRealisation());
-
- // set perfect and progressive
- coord1.setFeature(Feature.PERFECT.ToString(), true);
- coord1.setFeature(Feature.PROGRESSIVE.ToString(), true);
- Assert.AreEqual("could not have been kissing the dog and "
- + "could not have been kicking the boy", this.realiser.realise(
- coord1).getRealisation());
-
- // now aggregate
- coord1.setFeature(Feature.AGGREGATE_AUXILIARY.ToString(), true);
- Assert.AreEqual(
- "could not have been kissing the dog and kicking the boy",
- this.realiser.realise(coord1).getRealisation());
- }
- }
-}
\ No newline at end of file
diff --git a/SharpSimpleNLGUnitTests/syntax/english/AdjectivePhraseTest.java b/SharpSimpleNLGUnitTests/syntax/english/AdjectivePhraseTest.java
deleted file mode 100644
index e08e03a..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/AdjectivePhraseTest.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.syntax.english;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.framework.CoordinatedPhraseElement;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.PhraseElement;
-import simplenlg.framework.StringElement;
-
-/**
- * This class incorporates a few tests for adjectival phrases. Also tests for
- * adverbial phrase specs, which are very similar
- *
- * @author agatt
- */
-public class AdjectivePhraseTest extends SimpleNLG4Test {
-
- /**
- * Instantiates a new adj p test.
- *
- * @param name
- * the name
- */
- public AdjectivePhraseTest(String name) {
- super(name);
- }
-
-
- @Override
- @After
- public void tearDown() {
- super.tearDown();
- }
-
-
- /**
- * Test premodification & coordination of Adjective Phrases (Not much else
- * to simplenlg.test)
- */
- @Test
- public void testAdj() {
-
- // form the adjphrase "incredibly salacious"
- this.salacious.addPreModifier(this.phraseFactory
- .createAdverbPhrase("incredibly")); //$NON-NLS-1$
- Assert.assertEquals("incredibly salacious", this.realiser //$NON-NLS-1$
- .realise(this.salacious).getRealisation());
-
- // form the adjphrase "incredibly beautiful"
- this.beautiful.addPreModifier("amazingly"); //$NON-NLS-1$
- Assert.assertEquals("amazingly beautiful", this.realiser //$NON-NLS-1$
- .realise(this.beautiful).getRealisation());
-
- // coordinate the two aps
- CoordinatedPhraseElement coordap = new CoordinatedPhraseElement(
- this.salacious, this.beautiful);
- Assert.assertEquals("incredibly salacious and amazingly beautiful", //$NON-NLS-1$
- this.realiser.realise(coordap).getRealisation());
-
- // changing the inner conjunction
- coordap.setFeature(Feature.CONJUNCTION, "or"); //$NON-NLS-1$
- Assert.assertEquals("incredibly salacious or amazingly beautiful", //$NON-NLS-1$
- this.realiser.realise(coordap).getRealisation());
-
- // coordinate this with a new AdjPhraseSpec
- CoordinatedPhraseElement coord2 = new CoordinatedPhraseElement(coordap,
- this.stunning);
- Assert.assertEquals(
- "incredibly salacious or amazingly beautiful and stunning", //$NON-NLS-1$
- this.realiser.realise(coord2).getRealisation());
-
- // add a premodifier the coordinate phrase, yielding
- // "seriously and undeniably incredibly salacious or amazingly beautiful
- // and stunning"
- CoordinatedPhraseElement preMod = new CoordinatedPhraseElement(
- new StringElement("seriously"), new StringElement("undeniably")); //$NON-NLS-1$//$NON-NLS-2$
-
- coord2.addPreModifier(preMod);
- Assert.assertEquals(
- "seriously and undeniably incredibly salacious or amazingly beautiful and stunning", //$NON-NLS-1$
- this.realiser.realise(coord2).getRealisation());
-
- // adding a coordinate rather than coordinating should give a different
- // result
- coordap.addCoordinate(this.stunning);
- Assert.assertEquals(
- "incredibly salacious, amazingly beautiful or stunning", //$NON-NLS-1$
- this.realiser.realise(coordap).getRealisation());
-
- }
-
- /**
- * Simple test of adverbials
- */
- @Test
- public void testAdv() {
-
- PhraseElement sent = this.phraseFactory.createClause("John", "eat"); //$NON-NLS-1$ //$NON-NLS-2$
-
- PhraseElement adv = this.phraseFactory.createAdverbPhrase("quickly"); //$NON-NLS-1$
-
- sent.addPreModifier(adv);
-
- Assert.assertEquals("John quickly eats", this.realiser.realise(sent) //$NON-NLS-1$
- .getRealisation());
-
- adv.addPreModifier("very"); //$NON-NLS-1$
-
- Assert.assertEquals("John very quickly eats", this.realiser.realise( //$NON-NLS-1$
- sent).getRealisation());
-
- }
-
- /**
- * Test participles as adjectives
- */
- @Test
- public void testParticipleAdj() {
- PhraseElement ap = this.phraseFactory
- .createAdjectivePhrase(this.lexicon.getWord("associated",
- LexicalCategory.ADJECTIVE));
- Assert.assertEquals("associated", this.realiser.realise(ap)
- .getRealisation());
- }
-
- /**
- * Test for multiple adjective modifiers with comma-separation. Example courtesy of William Bradshaw (Data2Text Ltd).
- */
- @Test
- public void testMultipleModifiers() {
- PhraseElement np = this.phraseFactory
- .createNounPhrase(this.lexicon.getWord("message",
- LexicalCategory.NOUN));
- np.addPreModifier(this.lexicon.getWord("active",
- LexicalCategory.ADJECTIVE));
- np.addPreModifier(this.lexicon.getWord("temperature",
- LexicalCategory.ADJECTIVE));
- Assert.assertEquals("active, temperature message", this.realiser.realise(np).getRealisation());
-
- //now we set the realiser not to separate using commas
- this.realiser.setCommaSepPremodifiers(false);
- Assert.assertEquals("active temperature message", this.realiser.realise(np).getRealisation());
-
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/ClauseAggregationTest.java b/SharpSimpleNLGUnitTests/syntax/english/ClauseAggregationTest.java
deleted file mode 100644
index 73d90c9..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/ClauseAggregationTest.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.syntax.english;
-
-import java.util.Arrays;
-import java.util.List;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.aggregation.BackwardConjunctionReductionRule;
-import simplenlg.aggregation.Aggregator;
-import simplenlg.aggregation.ClauseCoordinationRule;
-import simplenlg.aggregation.ForwardConjunctionReductionRule;
-import simplenlg.features.Feature;
-import simplenlg.framework.NLGElement;
-import simplenlg.phrasespec.SPhraseSpec;
-
-/**
- * Some tests for aggregation.
- *
- * @author Albert Gatt, University of Malta & University of Aberdeen
- *
- */
-public class ClauseAggregationTest extends SimpleNLG4Test {
- // set up a few more fixtures
- /** The s4. */
- SPhraseSpec s1, s2, s3, s4, s5, s6;
- Aggregator aggregator;
- ClauseCoordinationRule coord;
- ForwardConjunctionReductionRule fcr;
- BackwardConjunctionReductionRule bcr;
-
- /**
- * Instantiates a new clause aggregation test.
- *
- * @param name
- * the name
- */
- public ClauseAggregationTest(String name) {
- super(name);
- aggregator = new Aggregator();
- aggregator.initialise();
- coord = new ClauseCoordinationRule();
- fcr = new ForwardConjunctionReductionRule();
- bcr = new BackwardConjunctionReductionRule();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see simplenlg.test.SimplenlgTest#setUp()
- */
- @Override
- @Before
- protected void setUp() {
- super.setUp();
-
- // the woman kissed the man behind the curtain
- this.s1 = this.phraseFactory.createClause();
- this.s1.setSubject(this.woman);
- this.s1.setVerbPhrase(this.phraseFactory.createVerbPhrase("kiss"));
- this.s1.setObject(this.man);
- this.s1.addPostModifier(this.phraseFactory
- .createPrepositionPhrase("behind", this.phraseFactory
- .createNounPhrase("the", "curtain")));
-
- // the woman kicked the dog on the rock
- this.s2 = this.phraseFactory.createClause();
- this.s2.setSubject(this.phraseFactory.createNounPhrase("the", "woman")); //$NON-NLS-1$
- this.s2.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick")); //$NON-NLS-1$
- this.s2.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
- this.s2.addPostModifier(this.onTheRock);
-
- // the woman kicked the dog behind the curtain
- this.s3 = this.phraseFactory.createClause();
- this.s3.setSubject(this.phraseFactory.createNounPhrase("the", "woman")); //$NON-NLS-1$
- this.s3.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick")); //$NON-NLS-1$
- this.s3.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
- this.s3.addPostModifier(this.phraseFactory
- .createPrepositionPhrase("behind", this.phraseFactory
- .createNounPhrase("the", "curtain")));
-
- // the man kicked the dog behind the curtain
- this.s4 = this.phraseFactory.createClause();
- this.s4.setSubject(this.man); //$NON-NLS-1$
- this.s4.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick")); //$NON-NLS-1$
- this.s4.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
- this.s4.addPostModifier(this.behindTheCurtain);
-
- // the girl kicked the dog behind the curtain
- this.s5 = this.phraseFactory.createClause();
- this.s5.setSubject(this.phraseFactory.createNounPhrase("the", "girl")); //$NON-NLS-1$
- this.s5.setVerbPhrase(this.phraseFactory.createVerbPhrase("kick")); //$NON-NLS-1$
- this.s5.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
- this.s5.addPostModifier(this.behindTheCurtain);
-
- // the woman kissed the dog behind the curtain
- this.s6 = this.phraseFactory.createClause();
- this.s6.setSubject(this.phraseFactory.createNounPhrase("the", "woman")); //$NON-NLS-1$
- this.s6.setVerbPhrase(this.phraseFactory.createVerbPhrase("kiss")); //$NON-NLS-1$
- this.s6.setObject(this.phraseFactory.createNounPhrase("the", "dog"));
- this.s6.addPostModifier(this.phraseFactory
- .createPrepositionPhrase("behind", this.phraseFactory
- .createNounPhrase("the", "curtain")));
- }
-
- @After
- public void tearDown() {
- super.tearDown();
-
- this.s1 = null; this.s2 = null; this.s3 = null;
- this.s4 = null; this.s5 = null; this.s6 = null;
- this.aggregator = null;
- this.coord = null;
- this.fcr = null;
- this.bcr = null;
- }
-
- /**
- * Test clause coordination with two sentences with same subject but
- * different postmodifiers: fails
- */
- @Test
- public void testCoordinationSameSubjectFail() {
- List elements = Arrays.asList((NLGElement) this.s1,
- (NLGElement) this.s2);
- List result = this.coord.apply(elements);
- Assert.assertEquals(2, result.size());
- }
-
- /**
- * Test clause coordination with two sentences one of which is passive:
- * fails
- */
- @Test
- public void testCoordinationPassiveFail() {
- this.s1.setFeature(Feature.PASSIVE, true);
- List elements = Arrays.asList((NLGElement) this.s1,
- (NLGElement) this.s2);
- List result = this.coord.apply(elements);
- Assert.assertEquals(2, result.size());
- }
-
-// /**
-// * Test clause coordination with 2 sentences with same subject: succeeds
-// */
-// @Test
-// public void testCoordinationSameSubjectSuccess() {
-// List elements = Arrays.asList((NLGElement) this.s1,
-// (NLGElement) this.s3);
-// List result = this.coord.apply(elements);
-// Assert.assertTrue(result.size() == 1); // should only be one sentence
-// NLGElement aggregated = result.get(0);
-// Assert
-// .assertEquals(
-// "the woman kisses the man and kicks the dog behind the curtain", //$NON-NLS-1$
-// this.realiser.realise(aggregated).getRealisation());
-// }
-
- /**
- * Test clause coordination with 2 sentences with same VP: succeeds
- */
- @Test
- public void testCoordinationSameVP() {
- List elements = Arrays.asList((NLGElement) this.s3,
- (NLGElement) this.s4);
- List result = this.coord.apply(elements);
- Assert.assertTrue(result.size() == 1); // should only be one sentence
- NLGElement aggregated = result.get(0);
- Assert.assertEquals(
- "the woman and the man kick the dog behind the curtain", //$NON-NLS-1$
- this.realiser.realise(aggregated).getRealisation());
- }
-
- /**
- * Coordination of sentences with front modifiers: should preserve the mods
- */
- @Test
- public void testCoordinationWithModifiers() {
- // now add a couple of front modifiers
- this.s3.addFrontModifier(this.phraseFactory
- .createAdverbPhrase("however"));
- this.s4.addFrontModifier(this.phraseFactory
- .createAdverbPhrase("however"));
- List elements = Arrays.asList((NLGElement) this.s3,
- (NLGElement) this.s4);
- List result = this.coord.apply(elements);
- Assert.assertTrue(result.size() == 1); // should only be one sentence
- NLGElement aggregated = result.get(0);
- Assert
- .assertEquals(
- "however the woman and the man kick the dog behind the curtain", //$NON-NLS-1$
- this.realiser.realise(aggregated).getRealisation());
- }
-
- /**
- * Test coordination of 3 sentences with the same VP
- */
- public void testCoordinationSameVP2() {
- List elements = Arrays.asList((NLGElement) this.s3,
- (NLGElement) this.s4, (NLGElement) this.s5);
- List result = this.coord.apply(elements);
- Assert.assertTrue(result.size() == 1); // should only be one sentence
- NLGElement aggregated = result.get(0);
- Assert
- .assertEquals(
- "the woman and the man and the girl kick the dog behind the curtain", //$NON-NLS-1$
- this.realiser.realise(aggregated).getRealisation());
- }
-
- /**
- * Forward conjunction reduction test
- */
- @Test
- public void testForwardConjReduction() {
- NLGElement aggregated = this.fcr.apply(this.s2, this.s3);
- Assert
- .assertEquals(
- "the woman kicks the dog on the rock and kicks the dog behind the curtain", //$NON-NLS-1$
- this.realiser.realise(aggregated).getRealisation());
- }
-
- /**
- * Backward conjunction reduction test
- */
- @Test
- public void testBackwardConjunctionReduction() {
- NLGElement aggregated = this.bcr.apply(this.s3, this.s6);
- Assert
- .assertEquals(
- "the woman kicks and the woman kisses the dog behind the curtain",
- this.realiser.realise(aggregated).getRealisation());
- }
-
- /**
- * Test multiple aggregation procedures in a single aggregator.
- */
-// @Test
-// public void testForwardBackwardConjunctionReduction() {
-// this.aggregator.addRule(this.fcr);
-// this.aggregator.addRule(this.bcr);
-// realiser.setDebugMode(true);
-// List result = this.aggregator.realise(Arrays.asList((NLGElement) this.s2, (NLGElement) this.s3));
-// Assert.assertTrue(result.size() == 1); // should only be one sentence
-// NLGElement aggregated = result.get(0);
-// NLGElement aggregated = this.phraseFactory.createdCoordinatedPhrase(this.s2, this.s3);
-// Assert
-// .assertEquals(
-// "the woman kicks the dog on the rock and behind the curtain", //$NON-NLS-1$
-// this.realiser.realise(aggregated).getRealisation());
-// }
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/ClauseTest.java b/SharpSimpleNLGUnitTests/syntax/english/ClauseTest.java
deleted file mode 100644
index 397c8df..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/ClauseTest.java
+++ /dev/null
@@ -1,926 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.features.ClauseStatus;
-import simplenlg.features.DiscourseFunction;
-import simplenlg.features.Feature;
-import simplenlg.features.Form;
-import simplenlg.features.InternalFeature;
-import simplenlg.features.NumberAgreement;
-import simplenlg.features.Tense;
-import simplenlg.framework.CoordinatedPhraseElement;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.NLGElement;
-import simplenlg.framework.PhraseCategory;
-import simplenlg.framework.PhraseElement;
-import simplenlg.phrasespec.AdjPhraseSpec;
-import simplenlg.phrasespec.AdvPhraseSpec;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.PPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.phrasespec.VPPhraseSpec;
-
-// TODO: Auto-generated Javadoc
-/**
- * The Class STest.
- */
-public class ClauseTest extends SimpleNLG4Test {
-
- // set up a few more fixtures
- /** The s4. */
- SPhraseSpec s1, s2, s3, s4;
-
- /**
- * Instantiates a new s test.
- *
- * @param name
- * the name
- */
- public ClauseTest(String name) {
- super(name);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see simplenlg.test.SimplenlgTest#setUp()
- */
- @Override
- @Before
- protected void setUp() {
- super.setUp();
-
- // the woman kisses the man
- this.s1 = this.phraseFactory.createClause();
- this.s1.setSubject(this.woman);
- this.s1.setVerbPhrase(this.kiss);
- this.s1.setObject(this.man);
-
- // there is the dog on the rock
- this.s2 = this.phraseFactory.createClause();
- this.s2.setSubject("there"); //$NON-NLS-1$
- this.s2.setVerb("be"); //$NON-NLS-1$
- this.s2.setObject(this.dog);
- this.s2.addPostModifier(this.onTheRock);
-
- // the man gives the woman John's flower
- this.s3 = this.phraseFactory.createClause();
- this.s3.setSubject(this.man);
- this.s3.setVerbPhrase(this.give);
-
- NPPhraseSpec flower = this.phraseFactory.createNounPhrase("flower"); //$NON-NLS-1$
- NPPhraseSpec john = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
- john.setFeature(Feature.POSSESSIVE, true);
- flower.setFeature(InternalFeature.SPECIFIER, john);
- this.s3.setObject(flower);
- this.s3.setIndirectObject(this.woman);
-
- this.s4 = this.phraseFactory.createClause();
- this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
- this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
-
- CoordinatedPhraseElement subject = this.phraseFactory
- .createCoordinatedPhrase(this.phraseFactory
- .createNounPhrase("Jane"), this.phraseFactory //$NON-NLS-1$
- .createNounPhrase("Andrew")); //$NON-NLS-1$
-
- this.s4.setSubject(subject);
-
- PhraseElement pick = this.phraseFactory.createVerbPhrase("pick up"); //$NON-NLS-1$
- this.s4.setVerbPhrase(pick);
- this.s4.setObject("the balls"); //$NON-NLS-1$
- this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
- this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
- }
-
- @After
- public void tearDown() {
- super.tearDown();
-
- this.s1 = null;
- this.s2 = null;
- this.s3 = null;
- this.s4 = null;
- }
-
-
- /**
- * Initial test for basic sentences.
- */
- @Test
- public void testBasic() {
- Assert.assertEquals("the woman kisses the man", this.realiser //$NON-NLS-1$
- .realise(this.s1).getRealisation());
- Assert.assertEquals("there is the dog on the rock", this.realiser //$NON-NLS-1$
- .realise(this.s2).getRealisation());
-
- setUp();
- Assert.assertEquals("the man gives the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
- Assert
- .assertEquals(
- "however tomorrow Jane and Andrew will pick up the balls in the shop", //$NON-NLS-1$
- this.realiser.realise(this.s4).getRealisation());
- }
-
- /**
- * Test did not
- */
- @Test
- public void testDidNot() {
- PhraseElement s = phraseFactory.createClause("John", "eat");
- s.setFeature(Feature.TENSE, Tense.PAST);
- s.setFeature(Feature.NEGATED, true);
-
- Assert.assertEquals("John did not eat", //$NON-NLS-1$
- this.realiser.realise(s).getRealisation());
-
- }
-
- /**
- * Test did not
- */
- @Test
- public void testVPNegation() {
- // negate the VP
- PhraseElement vp = phraseFactory.createVerbPhrase("lie");
- vp.setFeature(Feature.TENSE, Tense.PAST);
- vp.setFeature(Feature.NEGATED, true);
- PhraseElement compl = phraseFactory.createVerbPhrase("etherize");
- compl.setFeature(Feature.TENSE, Tense.PAST);
- vp.setComplement(compl);
-
- SPhraseSpec s = phraseFactory.createClause(phraseFactory
- .createNounPhrase("the", "patient"), vp);
-
- Assert.assertEquals("the patient did not lie etherized", //$NON-NLS-1$
- this.realiser.realise(s).getRealisation());
-
- }
-
- /**
- * Test that pronominal args are being correctly cast as NPs.
- */
- @Test
- public void testPronounArguments() {
- // the subject of s2 should have been cast into a pronominal NP
- NLGElement subj = this.s2.getFeatureAsElementList(
- InternalFeature.SUBJECTS).get(0);
- Assert.assertTrue(subj.isA(PhraseCategory.NOUN_PHRASE));
- // Assert.assertTrue(LexicalCategory.PRONOUN.equals(((PhraseElement)
- // subj)
- // .getCategory()));
- }
-
- /**
- * Tests for setting tense, aspect and passive from the sentence interface.
- */
- @Test
- public void testTenses() {
- // simple past
- this.s3.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals("the man gave the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
-
- // perfect
- this.s3.setFeature(Feature.PERFECT, true);
- Assert.assertEquals("the man had given the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
-
- // negation
- this.s3.setFeature(Feature.NEGATED, true);
- Assert.assertEquals("the man had not given the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
-
- this.s3.setFeature(Feature.PROGRESSIVE, true);
- Assert.assertEquals(
- "the man had not been giving the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
-
- // passivisation with direct and indirect object
- this.s3.setFeature(Feature.PASSIVE, true);
- // Assert.assertEquals(
- // "John's flower had not been being given the woman by the man", //$NON-NLS-1$
- // this.realiser.realise(this.s3).getRealisation());
- }
-
- /**
- * Test what happens when a sentence is subordinated as complement of a
- * verb.
- */
- @Test
- public void testSubordination() {
-
- // subordinate sentence by setting it as complement of a verb
- this.say.addComplement(this.s3);
-
- // check the getter
- Assert.assertEquals(ClauseStatus.SUBORDINATE, this.s3
- .getFeature(InternalFeature.CLAUSE_STATUS));
-
- // check realisation
- Assert.assertEquals("says that the man gives the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.say).getRealisation());
- }
-
- /**
- * Test the various forms of a sentence, including subordinates.
- */
- /**
- *
- */
- @Test
- public void testForm() {
-
- // check the getter method
- Assert.assertEquals(Form.NORMAL, this.s1.getFeatureAsElement(
- InternalFeature.VERB_PHRASE).getFeature(Feature.FORM));
-
- // infinitive
- this.s1.setFeature(Feature.FORM, Form.INFINITIVE);
- Assert
- .assertEquals(
- "to kiss the man", this.realiser.realise(this.s1).getRealisation()); //$NON-NLS-1$
-
- // gerund with "there"
- this.s2.setFeature(Feature.FORM, Form.GERUND);
- Assert.assertEquals("there being the dog on the rock", this.realiser //$NON-NLS-1$
- .realise(this.s2).getRealisation());
-
- // gerund with possessive
- this.s3.setFeature(Feature.FORM, Form.GERUND);
- Assert.assertEquals("the man's giving the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
-
- // imperative
- this.s3.setFeature(Feature.FORM, Form.IMPERATIVE);
-
- Assert.assertEquals("give the woman John's flower", this.realiser //$NON-NLS-1$
- .realise(this.s3).getRealisation());
-
- // subordinating the imperative to a verb should turn it to infinitive
- this.say.addComplement(this.s3);
-
- Assert.assertEquals("says to give the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.say).getRealisation());
-
- // imperative -- case II
- this.s4.setFeature(Feature.FORM, Form.IMPERATIVE);
- Assert.assertEquals("however tomorrow pick up the balls in the shop", //$NON-NLS-1$
- this.realiser.realise(this.s4).getRealisation());
-
- // infinitive -- case II
- this.s4 = this.phraseFactory.createClause();
- this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
- this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
-
- CoordinatedPhraseElement subject = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"), this.phraseFactory //$NON-NLS-1$
- .createNounPhrase("Andrew")); //$NON-NLS-1$
-
- this.s4.setFeature(InternalFeature.SUBJECTS, subject);
-
- PhraseElement pick = this.phraseFactory.createVerbPhrase("pick up"); //$NON-NLS-1$
- this.s4.setFeature(InternalFeature.VERB_PHRASE, pick);
- this.s4.setObject("the balls"); //$NON-NLS-1$
- this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
- this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
- this.s4.setFeature(Feature.FORM, Form.INFINITIVE);
- Assert.assertEquals(
- "however to pick up the balls in the shop tomorrow", //$NON-NLS-1$
- this.realiser.realise(this.s4).getRealisation());
- }
-
- /**
- * Slightly more complex tests for forms.
- */
- @Test
- public void testForm2() {
- // set s4 as subject of a new sentence
- SPhraseSpec temp = this.phraseFactory.createClause(this.s4, "be", //$NON-NLS-1$
- "recommended"); //$NON-NLS-1$
-
- Assert.assertEquals(
- "however tomorrow Jane and Andrew's picking up the " + //$NON-NLS-1$
- "balls in the shop is recommended", //$NON-NLS-1$
- this.realiser.realise(temp).getRealisation());
-
- // compose this with a new sentence
- // ER - switched direct and indirect object in sentence
- SPhraseSpec temp2 = this.phraseFactory.createClause("I", "tell", temp); //$NON-NLS-1$ //$NON-NLS-2$
- temp2.setFeature(Feature.TENSE, Tense.FUTURE);
-
- PhraseElement indirectObject = this.phraseFactory
- .createNounPhrase("John"); //$NON-NLS-1$
-
- temp2.setIndirectObject(indirectObject);
-
- Assert.assertEquals("I will tell John that however tomorrow Jane and " + //$NON-NLS-1$
- "Andrew's picking up the balls in the shop is " + //$NON-NLS-1$
- "recommended", //$NON-NLS-1$
- this.realiser.realise(temp2).getRealisation());
-
- // turn s4 to imperative and put it in indirect object position
-
- this.s4 = this.phraseFactory.createClause();
- this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
- this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
-
- CoordinatedPhraseElement subject = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"), this.phraseFactory //$NON-NLS-1$
- .createNounPhrase("Andrew")); //$NON-NLS-1$
-
- this.s4.setSubject(subject);
-
- PhraseElement pick = this.phraseFactory.createVerbPhrase("pick up"); //$NON-NLS-1$
- this.s4.setVerbPhrase(pick);
- this.s4.setObject("the balls"); //$NON-NLS-1$
- this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
- this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
- this.s4.setFeature(Feature.FORM, Form.IMPERATIVE);
-
- temp2 = this.phraseFactory.createClause("I", "tell", this.s4); //$NON-NLS-1$ //$NON-NLS-2$
- indirectObject = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
- temp2.setIndirectObject(indirectObject);
- temp2.setFeature(Feature.TENSE, Tense.FUTURE);
-
- Assert.assertEquals("I will tell John however to pick up the balls " //$NON-NLS-1$
- + "in the shop tomorrow", this.realiser.realise(temp2) //$NON-NLS-1$
- .getRealisation());
- }
-
- /**
- * Tests for gerund forms and genitive subjects.
- */
- @Test
- public void testGerundsubject() {
-
- // the man's giving the woman John's flower upset Peter
- SPhraseSpec _s4 = this.phraseFactory.createClause();
- _s4.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset")); //$NON-NLS-1$
- _s4.setFeature(Feature.TENSE, Tense.PAST);
- _s4.setObject(this.phraseFactory.createNounPhrase("Peter")); //$NON-NLS-1$
- this.s3.setFeature(Feature.PERFECT, true);
-
- // set the sentence as subject of another: makes it a gerund
- _s4.setSubject(this.s3);
-
- // suppress the genitive realisation of the NP subject in gerund
- // sentences
- this.s3.setFeature(Feature.SUPPRESS_GENITIVE_IN_GERUND, true);
-
- // check the realisation: subject should not be genitive
- Assert.assertEquals(
- "the man having given the woman John's flower upset Peter", //$NON-NLS-1$
- this.realiser.realise(_s4).getRealisation());
-
- }
-
- /**
- * Some tests for multiple embedded sentences.
- */
- @Test
- public void testComplexSentence1() {
- setUp();
- // the man's giving the woman John's flower upset Peter
- SPhraseSpec complexS = this.phraseFactory.createClause();
- complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset")); //$NON-NLS-1$
- complexS.setFeature(Feature.TENSE, Tense.PAST);
- complexS.setObject(this.phraseFactory.createNounPhrase("Peter")); //$NON-NLS-1$
- this.s3.setFeature(Feature.PERFECT, true);
- complexS.setSubject(this.s3);
-
- // check the realisation: subject should be genitive
- Assert.assertEquals(
- "the man's having given the woman John's flower upset Peter", //$NON-NLS-1$
- this.realiser.realise(complexS).getRealisation());
-
- setUp();
- // coordinate sentences in subject position
- SPhraseSpec s5 = this.phraseFactory.createClause();
- s5.setSubject(this.phraseFactory.createNounPhrase("some", "person")); //$NON-NLS-1$ //$NON-NLS-2$
- s5.setVerbPhrase(this.phraseFactory.createVerbPhrase("stroke")); //$NON-NLS-1$
- s5.setObject(this.phraseFactory.createNounPhrase("the", "cat")); //$NON-NLS-1$ //$NON-NLS-2$
-
- CoordinatedPhraseElement coord = new CoordinatedPhraseElement(this.s3,
- s5);
- complexS = this.phraseFactory.createClause();
- complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset")); //$NON-NLS-1$
- complexS.setFeature(Feature.TENSE, Tense.PAST);
- complexS.setObject(this.phraseFactory.createNounPhrase("Peter")); //$NON-NLS-1$
- complexS.setSubject(coord);
- this.s3.setFeature(Feature.PERFECT, true);
-
- Assert.assertEquals("the man's having given the woman John's flower " //$NON-NLS-1$
- + "and some person's stroking the cat upset Peter", //$NON-NLS-1$
- this.realiser.realise(complexS).getRealisation());
-
- setUp();
- // now subordinate the complex sentence
- // coord.setClauseStatus(SPhraseSpec.ClauseType.MAIN);
- SPhraseSpec s6 = this.phraseFactory.createClause();
- s6.setVerbPhrase(this.phraseFactory.createVerbPhrase("tell")); //$NON-NLS-1$
- s6.setFeature(Feature.TENSE, Tense.PAST);
- s6.setSubject(this.phraseFactory.createNounPhrase("the", "boy")); //$NON-NLS-1$ //$NON-NLS-2$
- // ER - switched indirect and direct object
- PhraseElement indirect = this.phraseFactory.createNounPhrase("every", //$NON-NLS-1$
- "girl"); //$NON-NLS-1$
- s6.setIndirectObject(indirect);
- complexS = this.phraseFactory.createClause();
- complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset")); //$NON-NLS-1$
- complexS.setFeature(Feature.TENSE, Tense.PAST);
- complexS.setObject(this.phraseFactory.createNounPhrase("Peter")); //$NON-NLS-1$
- s6.setObject(complexS);
- coord = new CoordinatedPhraseElement(this.s3, s5);
- complexS.setSubject(coord);
- this.s3.setFeature(Feature.PERFECT, true);
- Assert.assertEquals(
- "the boy told every girl that the man's having given the woman " //$NON-NLS-1$
- + "John's flower and some person's stroking the cat " //$NON-NLS-1$
- + "upset Peter", //$NON-NLS-1$
- this.realiser.realise(s6).getRealisation());
-
- }
-
- /**
- * More coordination tests.
- */
- @Test
- public void testComplexSentence3() {
- setUp();
-
- this.s1 = this.phraseFactory.createClause();
- this.s1.setSubject(this.woman);
- this.s1.setVerb("kiss");
- this.s1.setObject(this.man);
-
- PhraseElement _man = this.phraseFactory.createNounPhrase("the", "man"); //$NON-NLS-1$ //$NON-NLS-2$
- this.s3 = this.phraseFactory.createClause();
- this.s3.setSubject(_man);
- this.s3.setVerb("give");
-
- NPPhraseSpec flower = this.phraseFactory.createNounPhrase("flower"); //$NON-NLS-1$
- NPPhraseSpec john = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
- john.setFeature(Feature.POSSESSIVE, true);
- flower.setSpecifier(john);
- this.s3.setObject(flower);
-
- PhraseElement _woman = this.phraseFactory.createNounPhrase(
- "the", "woman"); //$NON-NLS-1$ //$NON-NLS-2$
- this.s3.setIndirectObject(_woman);
-
- // the coordinate sentence allows us to raise and lower complementiser
- CoordinatedPhraseElement coord2 = new CoordinatedPhraseElement(this.s1,
- this.s3);
- coord2.setFeature(Feature.TENSE, Tense.PAST);
-
- this.realiser.setDebugMode(true);
- Assert
- .assertEquals(
- "the woman kissed the man and the man gave the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(coord2).getRealisation());
- }
-
- // /**
- // * Sentence with clausal subject with verb "be" and a progressive feature
- // */
- // public void testComplexSentence2() {
- // SPhraseSpec subject = this.phraseFactory.createClause(
- // this.phraseFactory.createNounPhrase("the", "child"),
- // this.phraseFactory.createVerbPhrase("be"), this.phraseFactory
- // .createWord("difficult", LexicalCategory.ADJECTIVE));
- // subject.setFeature(Feature.PROGRESSIVE, true);
- // }
-
- /**
- * Tests recogition of strings in API.
- */
- @Test
- public void testStringRecognition() {
-
- // test recognition of forms of "be"
- PhraseElement _s1 = this.phraseFactory.createClause(
- "my cat", "be", "sad"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- Assert.assertEquals(
- "my cat is sad", this.realiser.realise(_s1).getRealisation()); //$NON-NLS-1$
-
- // test recognition of pronoun for afreement
- PhraseElement _s2 = this.phraseFactory
- .createClause("I", "want", "Mary"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- Assert.assertEquals(
- "I want Mary", this.realiser.realise(_s2).getRealisation()); //$NON-NLS-1$
-
- // test recognition of pronoun for correct form
- PhraseElement subject = this.phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$
- subject.setFeature(InternalFeature.SPECIFIER, "a"); //$NON-NLS-1$
- subject.addPostModifier("from next door"); //$NON-NLS-1$
- PhraseElement object = this.phraseFactory.createNounPhrase("I"); //$NON-NLS-1$
- PhraseElement s = this.phraseFactory.createClause(subject,
- "chase", object); //$NON-NLS-1$
- s.setFeature(Feature.PROGRESSIVE, true);
- Assert.assertEquals("a dog from next door is chasing me", //$NON-NLS-1$
- this.realiser.realise(s).getRealisation());
- }
-
- /**
- * Tests complex agreement.
- */
- @Test
- public void testAgreement() {
-
- // basic agreement
- NPPhraseSpec np = this.phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$
- np.setSpecifier("the"); //$NON-NLS-1$
- np.addPreModifier("angry"); //$NON-NLS-1$
- PhraseElement _s1 = this.phraseFactory
- .createClause(np, "chase", "John"); //$NON-NLS-1$ //$NON-NLS-2$
- Assert.assertEquals("the angry dog chases John", this.realiser //$NON-NLS-1$
- .realise(_s1).getRealisation());
-
- // plural
- np = this.phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$
- np.setSpecifier("the"); //$NON-NLS-1$
- np.addPreModifier("angry"); //$NON-NLS-1$
- np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- _s1 = this.phraseFactory.createClause(np, "chase", "John"); //$NON-NLS-1$ //$NON-NLS-2$
- Assert.assertEquals("the angry dogs chase John", this.realiser //$NON-NLS-1$
- .realise(_s1).getRealisation());
-
- // test agreement with "there is"
- np = this.phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$
- np.addPreModifier("angry"); //$NON-NLS-1$
- np.setFeature(Feature.NUMBER, NumberAgreement.SINGULAR);
- np.setSpecifier("a"); //$NON-NLS-1$
- PhraseElement _s2 = this.phraseFactory.createClause("there", "be", np); //$NON-NLS-1$ //$NON-NLS-2$
- Assert.assertEquals("there is an angry dog", this.realiser //$NON-NLS-1$
- .realise(_s2).getRealisation());
-
- // plural with "there"
- np = this.phraseFactory.createNounPhrase("dog"); //$NON-NLS-1$
- np.addPreModifier("angry"); //$NON-NLS-1$
- np.setSpecifier("a"); //$NON-NLS-1$
- np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- _s2 = this.phraseFactory.createClause("there", "be", np); //$NON-NLS-1$ //$NON-NLS-2$
- Assert.assertEquals("there are some angry dogs", this.realiser //$NON-NLS-1$
- .realise(_s2).getRealisation());
- }
-
- /**
- * Tests passive.
- */
- @Test
- public void testPassive() {
- // passive with just complement
- SPhraseSpec _s1 = this.phraseFactory.createClause(null,
- "intubate", this.phraseFactory.createNounPhrase("the", "baby")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- _s1.setFeature(Feature.PASSIVE, true);
-
- Assert.assertEquals("the baby is intubated", this.realiser //$NON-NLS-1$
- .realise(_s1).getRealisation());
-
- // passive with subject and complement
- _s1 = this.phraseFactory.createClause(null,
- "intubate", this.phraseFactory.createNounPhrase("the", "baby")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- _s1.setSubject(this.phraseFactory.createNounPhrase("the nurse")); //$NON-NLS-1$
- _s1.setFeature(Feature.PASSIVE, true);
- Assert.assertEquals("the baby is intubated by the nurse", //$NON-NLS-1$
- this.realiser.realise(_s1).getRealisation());
-
- // passive with subject and indirect object
- SPhraseSpec _s2 = this.phraseFactory.createClause(null, "give", //$NON-NLS-1$
- this.phraseFactory.createNounPhrase("the", "baby")); //$NON-NLS-1$ //$NON-NLS-2$
-
- PhraseElement morphine = this.phraseFactory
- .createNounPhrase("50ug of morphine"); //$NON-NLS-1$
- _s2.setIndirectObject(morphine);
- _s2.setFeature(Feature.PASSIVE, true);
- Assert.assertEquals("the baby is given 50ug of morphine", //$NON-NLS-1$
- this.realiser.realise(_s2).getRealisation());
-
- // passive with subject, complement and indirect object
- _s2 = this.phraseFactory.createClause(this.phraseFactory
- .createNounPhrase("the", "nurse"), "give", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- this.phraseFactory.createNounPhrase("the", "baby")); //$NON-NLS-1$ //$NON-NLS-2$
-
- morphine = this.phraseFactory.createNounPhrase("50ug of morphine"); //$NON-NLS-1$
- _s2.setIndirectObject(morphine);
- _s2.setFeature(Feature.PASSIVE, true);
- Assert.assertEquals("the baby is given 50ug of morphine by the nurse", //$NON-NLS-1$
- this.realiser.realise(_s2).getRealisation());
-
- // test agreement in passive
- PhraseElement _s3 = this.phraseFactory.createClause(
- new CoordinatedPhraseElement("my dog", "your cat"), "chase", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- "George"); //$NON-NLS-1$
- _s3.setFeature(Feature.TENSE, Tense.PAST);
- _s3.addFrontModifier("yesterday"); //$NON-NLS-1$
- Assert.assertEquals("yesterday my dog and your cat chased George", //$NON-NLS-1$
- this.realiser.realise(_s3).getRealisation());
-
- _s3 = this.phraseFactory.createClause(new CoordinatedPhraseElement(
- "my dog", "your cat"), "chase", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- this.phraseFactory.createNounPhrase("George")); //$NON-NLS-1$
- _s3.setFeature(Feature.TENSE, Tense.PAST);
- _s3.addFrontModifier("yesterday"); //$NON-NLS-1$
- _s3.setFeature(Feature.PASSIVE, true);
- Assert.assertEquals(
- "yesterday George was chased by my dog and your cat", //$NON-NLS-1$
- this.realiser.realise(_s3).getRealisation());
-
- // test correct pronoun forms
- PhraseElement _s4 = this.phraseFactory.createClause(this.phraseFactory
- .createNounPhrase("he"), "chase", //$NON-NLS-1$ //$NON-NLS-2$
- this.phraseFactory.createNounPhrase("I")); //$NON-NLS-1$
- Assert.assertEquals("he chases me", this.realiser.realise(_s4) //$NON-NLS-1$
- .getRealisation());
- _s4 = this.phraseFactory
- .createClause(
- this.phraseFactory.createNounPhrase("he"), "chase", this.phraseFactory.createNounPhrase("me")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- _s4.setFeature(Feature.PASSIVE, true);
- Assert
- .assertEquals(
- "I am chased by him", this.realiser.realise(_s4).getRealisation()); //$NON-NLS-1$
-
- // same thing, but giving the S constructor "me". Should recognise
- // correct pro
- // anyway
- PhraseElement _s5 = this.phraseFactory
- .createClause("him", "chase", "I"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- Assert.assertEquals(
- "he chases me", this.realiser.realise(_s5).getRealisation()); //$NON-NLS-1$
-
- _s5 = this.phraseFactory.createClause("him", "chase", "I"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- _s5.setFeature(Feature.PASSIVE, true);
- Assert
- .assertEquals(
- "I am chased by him", this.realiser.realise(_s5).getRealisation()); //$NON-NLS-1$
- }
-
- /**
- * Test that complements set within the VP are raised when sentence is
- * passivised.
- */
- @Test
- public void testPassiveWithInternalVPComplement() {
- PhraseElement vp = this.phraseFactory.createVerbPhrase(phraseFactory
- .createWord("upset", LexicalCategory.VERB));
- vp.addComplement(phraseFactory.createNounPhrase("the", "man"));
- PhraseElement _s6 = this.phraseFactory.createClause(phraseFactory
- .createNounPhrase("the", "child"), vp);
- _s6.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals("the child upset the man", this.realiser.realise(
- _s6).getRealisation());
-
- _s6.setFeature(Feature.PASSIVE, true);
- Assert.assertEquals("the man was upset by the child", this.realiser
- .realise(_s6).getRealisation());
- }
-
- /**
- * Tests tenses with modals.
- */
- @Test
- public void testModal() {
-
- setUp();
- // simple modal in present tense
- this.s3.setFeature(Feature.MODAL, "should"); //$NON-NLS-1$
- Assert.assertEquals("the man should give the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
-
- // modal + future -- uses present
- setUp();
- this.s3.setFeature(Feature.MODAL, "should"); //$NON-NLS-1$
- this.s3.setFeature(Feature.TENSE, Tense.FUTURE);
- Assert.assertEquals("the man should give the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
-
- // modal + present progressive
- setUp();
- this.s3.setFeature(Feature.MODAL, "should"); //$NON-NLS-1$
- this.s3.setFeature(Feature.TENSE, Tense.FUTURE);
- this.s3.setFeature(Feature.PROGRESSIVE, true);
- Assert.assertEquals("the man should be giving the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
-
- // modal + past tense
- setUp();
- this.s3.setFeature(Feature.MODAL, "should"); //$NON-NLS-1$
- this.s3.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals(
- "the man should have given the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
-
- // modal + past progressive
- setUp();
- this.s3.setFeature(Feature.MODAL, "should"); //$NON-NLS-1$
- this.s3.setFeature(Feature.TENSE, Tense.PAST);
- this.s3.setFeature(Feature.PROGRESSIVE, true);
-
- Assert.assertEquals(
- "the man should have been giving the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
-
- }
-
- /**
- * Test for passivisation with mdoals
- */
- @Test
- public void testModalWithPassive() {
- NPPhraseSpec object = this.phraseFactory.createNounPhrase("the",
- "pizza");
- AdjPhraseSpec post = this.phraseFactory.createAdjectivePhrase("good");
- AdvPhraseSpec as = this.phraseFactory.createAdverbPhrase("as");
- as.addComplement(post);
- VPPhraseSpec verb = this.phraseFactory.createVerbPhrase("classify");
- verb.addPostModifier(as);
- verb.addComplement(object);
- SPhraseSpec s = this.phraseFactory.createClause();
- s.setVerbPhrase(verb);
- s.setFeature(Feature.MODAL, "can");
- // s.setFeature(Feature.FORM, Form.INFINITIVE);
- s.setFeature(Feature.PASSIVE, true);
- Assert.assertEquals("the pizza can be classified as good",
- this.realiser.realise(s).getRealisation());
- }
-
- @Test
- public void testPassiveWithPPCompl() {
- // passive with just complement
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("wave");
- subject.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- NPPhraseSpec object = this.phraseFactory.createNounPhrase("surfer");
- object.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
-
- SPhraseSpec _s1 = this.phraseFactory.createClause(subject,
- "carry", object); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- // add a PP complement
- PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("to",
- this.phraseFactory.createNounPhrase("the", "shore"));
- pp.setFeature(InternalFeature.DISCOURSE_FUNCTION,
- DiscourseFunction.INDIRECT_OBJECT);
- _s1.addComplement(pp);
-
- _s1.setFeature(Feature.PASSIVE, true);
-
- Assert.assertEquals(
- "surfers are carried to the shore by waves", this.realiser //$NON-NLS-1$
- .realise(_s1).getRealisation());
- }
-
- @Test
- public void testPassiveWithPPMod() {
- // passive with just complement
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("wave");
- subject.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- NPPhraseSpec object = this.phraseFactory.createNounPhrase("surfer");
- object.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
-
- SPhraseSpec _s1 = this.phraseFactory.createClause(subject,
- "carry", object); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- // add a PP complement
- PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("to",
- this.phraseFactory.createNounPhrase("the", "shore"));
- _s1.addPostModifier(pp);
-
- _s1.setFeature(Feature.PASSIVE, true);
-
- Assert.assertEquals(
- "surfers are carried to the shore by waves", this.realiser //$NON-NLS-1$
- .realise(_s1).getRealisation());
- }
-
- @Test
- public void testCuePhrase() {
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("wave");
- subject.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- NPPhraseSpec object = this.phraseFactory.createNounPhrase("surfer");
- object.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
-
- SPhraseSpec _s1 = this.phraseFactory.createClause(subject,
- "carry", object); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- // add a PP complement
- PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("to",
- this.phraseFactory.createNounPhrase("the", "shore"));
- _s1.addPostModifier(pp);
-
- _s1.setFeature(Feature.PASSIVE, true);
-
- _s1.addFrontModifier("however");
-
-
- //without comma separation of cue phrase
- Assert.assertEquals(
- "however surfers are carried to the shore by waves", this.realiser //$NON-NLS-1$
- .realise(_s1).getRealisation());
-
- //with comma separation
- this.realiser.setCommaSepCuephrase(true);
- Assert.assertEquals(
- "however, surfers are carried to the shore by waves", this.realiser //$NON-NLS-1$
- .realise(_s1).getRealisation());
- }
-
-
- /**
- * Check that setComplement replaces earlier complements
- */
- @Test
- public void setComplementTest() {
- SPhraseSpec s = this.phraseFactory.createClause();
- s.setSubject("I");
- s.setVerb("see");
- s.setObject("a dog");
-
- Assert.assertEquals("I see a dog", this.realiser.realise(s)
- .getRealisation());
-
- s.setObject("a cat");
- Assert.assertEquals("I see a cat", this.realiser.realise(s)
- .getRealisation());
-
- s.setObject("a wolf");
- Assert.assertEquals("I see a wolf", this.realiser.realise(s)
- .getRealisation());
-
- }
-
-
- /**
- * Test for subclauses involving WH-complements Based on a query by Owen
- * Bennett
- */
- @Test
- public void subclausesTest() {
- // Once upon a time, there was an Accountant, called Jeff, who lived in
- // a forest.
-
- // main sentence
- NPPhraseSpec acct = this.phraseFactory.createNounPhrase("a",
- "accountant");
-
- // first postmodifier of "an accountant"
- VPPhraseSpec sub1 = this.phraseFactory.createVerbPhrase("call");
- sub1.addComplement("Jeff");
- sub1.setFeature(Feature.FORM, Form.PAST_PARTICIPLE);
- // this is an appositive modifier, which makes simplenlg put it between
- // commas
- sub1.setFeature(Feature.APPOSITIVE, true);
- acct.addPostModifier(sub1);
-
- // second postmodifier of "an accountant" is "who lived in a forest"
- SPhraseSpec sub2 = this.phraseFactory.createClause();
- VPPhraseSpec subvp = this.phraseFactory.createVerbPhrase("live");
- subvp.setFeature(Feature.TENSE, Tense.PAST);
- subvp.setComplement(this.phraseFactory.createPrepositionPhrase("in",
- this.phraseFactory.createNounPhrase("a", "forest")));
- sub2.setVerbPhrase(subvp);
- // simplenlg can't yet handle wh-clauses in NPs, so we need to hack it
- // by setting the subject to "who"
- sub2.setSubject("who");
- acct.addPostModifier(sub2);
-
- // main sentence
- SPhraseSpec s = this.phraseFactory.createClause("there", "be", acct);
- s.setFeature(Feature.TENSE, Tense.PAST);
-
- // add front modifier "once upon a time"
- s.addFrontModifier("once upon a time");
-
- Assert.assertEquals(
- "once upon a time there was an accountant, called Jeff, who lived in a forest",
- this.realiser.realise(s).getRealisation());
-
- }
-
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/CoordinationTest.java b/SharpSimpleNLGUnitTests/syntax/english/CoordinationTest.java
deleted file mode 100644
index adc3db2..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/CoordinationTest.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.features.Tense;
-import simplenlg.framework.CoordinatedPhraseElement;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.PPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.phrasespec.VPPhraseSpec;
-
-/**
- * Some tests for coordination, especially of coordinated VPs with modifiers.
- *
- * @author Albert Gatt
- *
- */
-public class CoordinationTest extends SimpleNLG4Test {
-
- public CoordinationTest(String name) {
- super(name);
- }
-
- @Override
- @After
- public void tearDown() {
- super.tearDown();
- }
-
-
- /**
- * Check that empty coordinate phrases are not realised as "null"
- */
- @Test
- public void emptyCoordinationTest() {
- // first a simple phrase with no coordinates
- CoordinatedPhraseElement coord = this.phraseFactory
- .createCoordinatedPhrase();
- Assert.assertEquals("", this.realiser.realise(coord).getRealisation());
-
- // now one with a premodifier and nothing else
- coord.addPreModifier(this.phraseFactory.createAdjectivePhrase("nice"));
- Assert.assertEquals("nice", this.realiser.realise(coord)
- .getRealisation());
- }
-
- /**
- * Test pre and post-modification of coordinate VPs inside a sentence.
- */
- @Test
- public void testModifiedCoordVP() {
- CoordinatedPhraseElement coord = this.phraseFactory
- .createCoordinatedPhrase(this.getUp, this.fallDown);
- coord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals("got up and fell down", this.realiser
- .realise(coord).getRealisation());
-
- // add a premodifier
- coord.addPreModifier("slowly");
- Assert.assertEquals("slowly got up and fell down", this.realiser
- .realise(coord).getRealisation());
-
- // adda postmodifier
- coord.addPostModifier(this.behindTheCurtain);
- Assert.assertEquals("slowly got up and fell down behind the curtain",
- this.realiser.realise(coord).getRealisation());
-
- // put within the context of a sentence
- SPhraseSpec s = this.phraseFactory.createClause("Jake", coord);
- s.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals(
- "Jake slowly got up and fell down behind the curtain",
- this.realiser.realise(s).getRealisation());
-
- // add premod to the sentence
- s.addPreModifier(this.lexicon
- .getWord("however", LexicalCategory.ADVERB));
- Assert.assertEquals(
- "Jake however slowly got up and fell down behind the curtain",
- this.realiser.realise(s).getRealisation());
-
- // add postmod to the sentence
- s.addPostModifier(this.inTheRoom);
- Assert.assertEquals(
- "Jake however slowly got up and fell down behind the curtain in the room",
- this.realiser.realise(s).getRealisation());
- }
-
- /**
- * Test due to Chris Howell -- create a complex sentence with front modifier
- * and coordinateVP. This is a version in which we create the coordinate
- * phrase directly.
- */
- @Test
- public void testCoordinateVPComplexSubject() {
- // "As a result of the procedure the patient had an adverse contrast media reaction and went into cardiogenic shock."
- SPhraseSpec s = this.phraseFactory.createClause();
-
- s.setSubject(this.phraseFactory.createNounPhrase("the", "patient"));
-
- // first VP
- VPPhraseSpec vp1 = this.phraseFactory.createVerbPhrase(this.lexicon
- .getWord("have", LexicalCategory.VERB));
- NPPhraseSpec np1 = this.phraseFactory.createNounPhrase("a",
- this.lexicon.getWord("contrast media reaction",
- LexicalCategory.NOUN));
- np1.addPreModifier(this.lexicon.getWord("adverse",
- LexicalCategory.ADJECTIVE));
- vp1.addComplement(np1);
-
- // second VP
- VPPhraseSpec vp2 = this.phraseFactory.createVerbPhrase(this.lexicon
- .getWord("go", LexicalCategory.VERB));
- PPPhraseSpec pp = this.phraseFactory
- .createPrepositionPhrase("into", this.lexicon.getWord(
- "cardiogenic shock", LexicalCategory.NOUN));
- vp2.addComplement(pp);
-
- // coordinate
- CoordinatedPhraseElement coord = this.phraseFactory
- .createCoordinatedPhrase(vp1, vp2);
- coord.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals(
- "had an adverse contrast media reaction and went into cardiogenic shock",
- this.realiser.realise(coord).getRealisation());
-
- // now put this in the sentence
- s.setVerbPhrase(coord);
- s.addFrontModifier("As a result of the procedure");
- Assert.assertEquals(
- "As a result of the procedure the patient had an adverse contrast media reaction and went into cardiogenic shock",
- this.realiser.realise(s).getRealisation());
-
- }
-
- /**
- * Test setting a conjunction to null
- */
- public void testNullConjunction() {
- SPhraseSpec p = this.phraseFactory.createClause("I", "be", "happy");
- SPhraseSpec q = this.phraseFactory.createClause("I", "eat", "fish");
- CoordinatedPhraseElement pq = this.phraseFactory
- .createCoordinatedPhrase();
- pq.addCoordinate(p);
- pq.addCoordinate(q);
- pq.setFeature(Feature.CONJUNCTION, "");
-
- // should come out without conjunction
- Assert.assertEquals("I am happy I eat fish", this.realiser.realise(pq)
- .getRealisation());
-
- // should come out without conjunction
- pq.setFeature(Feature.CONJUNCTION, null);
- Assert.assertEquals("I am happy I eat fish", this.realiser.realise(pq)
- .getRealisation());
-
- }
-
- /**
- * Check that the negation feature on a child of a coordinate phrase remains
- * as set, unless explicitly set otherwise at the parent level.
- */
- @Test
- public void testNegationFeature() {
- SPhraseSpec s1 = this.phraseFactory
- .createClause("he", "have", "asthma");
- SPhraseSpec s2 = this.phraseFactory.createClause("he", "have",
- "diabetes");
- s1.setFeature(Feature.NEGATED, true);
- CoordinatedPhraseElement coord = this.phraseFactory
- .createCoordinatedPhrase(s1, s2);
- String realisation = this.realiser.realise(coord).getRealisation();
- System.out.println(realisation);
- Assert.assertEquals("he does not have asthma and he has diabetes",
- realisation);
- }
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/DeterminerTest.java b/SharpSimpleNLGUnitTests/syntax/english/DeterminerTest.java
deleted file mode 100644
index 670154b..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/DeterminerTest.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import junit.framework.Assert;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import simplenlg.framework.NLGFactory;
-import simplenlg.lexicon.Lexicon;
-import simplenlg.lexicon.NIHDBLexicon;
-import simplenlg.lexicon.XMLLexicon;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * Some determiner tests -- in particular for indefinite articles like "a" or "an".
- *
- * @author Saad Mahamood, Data2Text Limited.
- *
- */
-public class DeterminerTest {
-
- /** The realiser. */
- private Realiser realiser;
-
- private NLGFactory phraseFactory;
-
- private Lexicon lexicon;
-
- private final String DB_FILENAME = "src/test/resources/NIHLexicon/lexAccess2011.data";
-
- /**
- * Set up the variables we'll need for this simplenlg.test to run (Called
- * automatically by JUnit)
- */
- @Before
- public void setUp() {
- this.lexicon = new XMLLexicon(); // built in lexicon
-
- this.phraseFactory = new NLGFactory(this.lexicon);
- this.realiser = new Realiser(this.lexicon);
- }
-
- @After
- public void tearDown() {
- this.realiser = null;
-
- this.phraseFactory = null;
-
- if(null != lexicon) {
- lexicon = null;
- }
- }
-
- /**
- * testLowercaseConstant - Test for when there is a lower case constant
- */
- @Test
- public void testLowercaseConstant() {
-
- SPhraseSpec sentence = this.phraseFactory.createClause();
-
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "dog");
- sentence.setSubject(subject);
-
- String output = this.realiser.realiseSentence(sentence);
-
- Assert.assertEquals("A dog.", output);
- }
-
- /**
- * testLowercaseVowel - Test for "an" as a specifier.
- */
- @Test
- public void testLowercaseVowel() {
- SPhraseSpec sentence = this.phraseFactory.createClause();
-
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "owl");
- sentence.setSubject(subject);
-
- String output = this.realiser.realiseSentence(sentence);
-
- Assert.assertEquals("An owl.", output);
- }
-
- /**
- * testUppercaseConstant - Test for when there is a upper case constant
- */
- @Test
- public void testUppercaseConstant() {
-
- SPhraseSpec sentence = this.phraseFactory.createClause();
-
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "Cat");
- sentence.setSubject(subject);
-
- String output = this.realiser.realiseSentence(sentence);
-
- Assert.assertEquals("A Cat.", output);
- }
-
- /**
- * testUppercaseVowel - Test for "an" as a specifier for upper subjects.
- */
- @Test
- public void testUppercaseVowel() {
- SPhraseSpec sentence = this.phraseFactory.createClause();
-
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "Emu");
- sentence.setSubject(subject);
-
- String output = this.realiser.realiseSentence(sentence);
-
- Assert.assertEquals("An Emu.", output);
- }
-
- /**
- * testNumericA - Test for "a" specifier with a numeric subject
- */
- @Test
- public void testNumericA() {
- SPhraseSpec sentence = this.phraseFactory.createClause();
-
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "7");
- sentence.setSubject(subject);
-
- String output = this.realiser.realiseSentence(sentence);
-
- Assert.assertEquals("A 7.", output);
- }
-
- /**
- * testNumericAn - Test for "an" specifier with a numeric subject
- */
- @Test
- public void testNumericAn() {
- SPhraseSpec sentence = this.phraseFactory.createClause();
-
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "11");
- sentence.setSubject(subject);
-
- String output = this.realiser.realiseSentence(sentence);
-
- Assert.assertEquals("An 11.", output);
- }
-
- /**
- * testIrregularSubjects - Test irregular subjects that don't conform to the
- * vowel vs. constant divide.
- */
- @Test
- public void testIrregularSubjects() {
- SPhraseSpec sentence = this.phraseFactory.createClause();
-
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("a", "one");
- sentence.setSubject(subject);
-
- String output = this.realiser.realiseSentence(sentence);
-
- Assert.assertEquals("A one.", output);
- }
-
- /**
- * testSingluarThisDeterminerNPObject - Test for "this" when used in the singular form as a determiner in a NP Object
- */
- @Test
- public void testSingluarThisDeterminerNPObject() {
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("this", "monkey");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.assertEquals("This monkey.", this.realiser.realiseSentence(sentence_1));
- }
-
- /**
- * testPluralThisDeterminerNPObject - Test for "this" when used in the plural form as a determiner in a NP Object
- */
- @Test
- public void testPluralThisDeterminerNPObject() {
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(true);
- nounPhrase_1.setDeterminer("this");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.assertEquals("These monkeys.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testSingluarThatDeterminerNPObject - Test for "that" when used in the singular form as a determiner in a NP Object
- */
- @Test
- public void testSingluarThatDeterminerNPObject() {
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("that", "monkey");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.assertEquals("That monkey.", this.realiser.realiseSentence(sentence_1));
- }
-
- /**
- * testPluralThatDeterminerNPObject - Test for "that" when used in the plural form as a determiner in a NP Object
- */
- @Test
- public void testPluralThatDeterminerNPObject() {
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(true);
- nounPhrase_1.setDeterminer("that");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.assertEquals("Those monkeys.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testSingularThoseDeterminerNPObject - Test for "those" when used in the singular form as a determiner in a NP Object
- */
- @Test
- public void testSingularThoseDeterminerNPObject() {
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(false);
- nounPhrase_1.setDeterminer("those");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.assertEquals("That monkey.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testSingularTheseDeterminerNPObject - Test for "these" when used in the singular form as a determiner in a NP Object
- */
- @Test
- public void testSingularTheseDeterminerNPObject() {
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(false);
- nounPhrase_1.setDeterminer("these");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.assertEquals("This monkey.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testPluralThoseDeterminerNPObject - Test for "those" when used in the plural form as a determiner in a NP Object
- */
- @Test
- public void testPluralThoseDeterminerNPObject() {
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(true);
- nounPhrase_1.setDeterminer("those");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.assertEquals("Those monkeys.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testPluralTheseDeterminerNPObject - Test for "these" when used in the plural form as a determiner in a NP Object
- */
- @Test
- public void testPluralTheseDeterminerNPObject() {
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(true);
- nounPhrase_1.setDeterminer("these");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.assertEquals("These monkeys.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testSingularTheseDeterminerNPObject - Test for "these" when used in the singular form as a determiner in a NP Object
- * using the NIHDB Lexicon.
- */
- @Test
- public void testSingularTheseDeterminerNPObject_NIHDBLexicon() {
- this.lexicon = new NIHDBLexicon(DB_FILENAME);
- this.phraseFactory = new NLGFactory(this.lexicon);
- this.realiser = new Realiser(this.lexicon);
-
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(false);
- nounPhrase_1.setDeterminer("these");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.assertEquals("This monkey.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testSingularThoseDeterminerNPObject - Test for "those" when used in the singular form as a determiner in a NP Object
- * using the NIHDB Lexicon
- */
- @Test
- public void testSingularThoseDeterminerNPObject_NIHDBLexicon() {
- this.lexicon = new NIHDBLexicon(DB_FILENAME);
- this.phraseFactory = new NLGFactory(this.lexicon);
- this.realiser = new Realiser(this.lexicon);
-
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(false);
- nounPhrase_1.setDeterminer("those");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.assertEquals("That monkey.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testPluralThatDeterminerNPObject - Test for "that" when used in the plural form as a determiner in a NP Object
- * using the NIHDB Lexicon.
- */
- @Test
- public void testPluralThatDeterminerNPObject_NIHDBLexicon() {
- this.lexicon = new NIHDBLexicon(DB_FILENAME);
- this.phraseFactory = new NLGFactory(this.lexicon);
- this.realiser = new Realiser(this.lexicon);
-
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(true);
- nounPhrase_1.setDeterminer("that");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.assertEquals("Those monkeys.", this.realiser.realiseSentence(sentence_1));
-
- }
-
- /**
- * testPluralThisDeterminerNPObject - Test for "this" when used in the plural form as a determiner in a NP Object
- * using the NIHDBLexicon.
- */
- @Test
- public void testPluralThisDeterminerNPObject_NIHDBLexicon() {
- this.lexicon = new NIHDBLexicon(DB_FILENAME);
- this.phraseFactory = new NLGFactory(this.lexicon);
- this.realiser = new Realiser(this.lexicon);
-
- SPhraseSpec sentence_1 = this.phraseFactory.createClause();
-
- NPPhraseSpec nounPhrase_1 = this.phraseFactory.createNounPhrase("monkey");
- nounPhrase_1.setPlural(true);
- nounPhrase_1.setDeterminer("this");
- sentence_1.setObject(nounPhrase_1);
-
- Assert.assertEquals("These monkeys.", this.realiser.realiseSentence(sentence_1));
-
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/DocumentElementTest.java b/SharpSimpleNLGUnitTests/syntax/english/DocumentElementTest.java
deleted file mode 100644
index 9416f4a..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/DocumentElementTest.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import java.util.Arrays;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.framework.DocumentElement;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-
-/**
- * Tests for the DocumentElement class.
- *
- * @author ereiter
- */
-public class DocumentElementTest extends SimpleNLG4Test {
-
- private SPhraseSpec p1, p2, p3;
-
- /**
- * Instantiates a new document element test.
- *
- * @param name
- * the name
- */
- public DocumentElementTest(String name) {
- super(name);
- }
-
- @Before
- public void setUp() {
- super.setUp();
- p1 = this.phraseFactory.createClause("you", "be", "happy");
- p2 = this.phraseFactory.createClause("I", "be", "sad");
- p3 = this.phraseFactory.createClause("they", "be", "nervous");
- }
-
- @Override
- @After
- public void tearDown() {
- super.tearDown();
- this.p1 = null;
- this.p2 = null;
- this.p3 = null;
- }
-
- /**
- * Basic tests.
- */
- @Test
- public void testBasics() {
- DocumentElement s1 = this.phraseFactory.createSentence(p1);
- DocumentElement s2 = this.phraseFactory.createSentence(p2);
- DocumentElement s3 = this.phraseFactory.createSentence(p3);
-
- DocumentElement par1 = this.phraseFactory.createParagraph(Arrays
- .asList(s1, s2, s3));
-
- Assert.assertEquals("You are happy. I am sad. They are nervous.\n\n",
- this.realiser.realise(par1).getRealisation());
-
- }
-
- /**
- * Ensure that no extra whitespace is inserted into a realisation if a
- * constituent is empty. (This is to check for a bug fix for addition of
- * spurious whitespace).
- */
- public void testExtraWhitespace() {
- NPPhraseSpec np1 = this.phraseFactory.createNounPhrase("a", "vessel");
-
- // empty coordinate as premod
- np1.setPreModifier(this.phraseFactory.createCoordinatedPhrase());
- Assert.assertEquals("a vessel", this.realiser.realise(np1)
- .getRealisation());
-
- // empty adjP as premod
- np1.setPreModifier(this.phraseFactory.createAdjectivePhrase());
- Assert.assertEquals("a vessel", this.realiser.realise(np1)
- .getRealisation());
-
- // empty string
- np1.setPreModifier("");
- Assert.assertEquals("a vessel", this.realiser.realise(np1)
- .getRealisation());
-
- }
-
- /**
- * test whether sents can be embedded in a section without intervening paras
- */
- @Test
- public void testEmbedding() {
- DocumentElement sent = phraseFactory.createSentence("This is a test");
- DocumentElement sent2 = phraseFactory.createSentence(phraseFactory
- .createClause("John", "be", "missing"));
- DocumentElement section = phraseFactory.createSection("SECTION TITLE");
- section.addComponent(sent);
- section.addComponent(sent2);
-
- Assert.assertEquals(
- "SECTION TITLE\nThis is a test.\n\nJohn is missing.\n\n",
- this.realiser.realise(section).getRealisation());
- }
-
- @Test
- public void testSections() {
- // doc which contains a section, and two paras
- DocumentElement doc = this.phraseFactory
- .createDocument("Test Document");
-
- DocumentElement section = this.phraseFactory
- .createSection("Test Section");
- doc.addComponent(section);
-
- DocumentElement para1 = this.phraseFactory.createParagraph();
- DocumentElement sent1 = this.phraseFactory
- .createSentence("This is the first test paragraph");
- para1.addComponent(sent1);
- section.addComponent(para1);
-
- DocumentElement para2 = this.phraseFactory.createParagraph();
- DocumentElement sent2 = this.phraseFactory
- .createSentence("This is the second test paragraph");
- para2.addComponent(sent2);
- section.addComponent(para2);
-
- Assert
- .assertEquals(
- "Test Document\n\nTest Section\nThis is the first test paragraph.\n\nThis is the second test paragraph.\n\n",
- this.realiser.realise(doc).getRealisation());
- //
- // Realiser htmlRealiser = new Realiser();
- // htmlRealiser.setHTML(true);
- // Assert
- // .assertEquals(
- // "Test Document \r\nTest Section \r\nTest Subsection \r\nThis is the first test paragraph. \r\nThis is the second test paragraph. \r\n \r\n\r\n",
- // htmlRealiser.realise(doc));
- //
- // // now lets try a doc with a header, header-less section and
- // subsection,
- // // and 2 paras (no list)
- // doc = new TextSpec();
- // doc.setDocument();
- // doc.setHeading("Test Document2");
- //
- // section = new TextSpec();
- // section.setDocStructure(DocStructure.SECTION);
- // ;
- // doc.addSpec(section);
- //
- // subsection = new TextSpec();
- // subsection.setDocStructure(DocStructure.SUBSECTION);
- // section.addSpec(subsection);
- //
- // // use list from above, with indent
- // subsection.addChild(list);
- // list.setIndentedList(false);
- //
- // Assert
- // .assertEquals(
- // "Test Document2\r\n\r\nThis is the first test paragraph.\r\n\r\nThis is the second test paragraph.\r\n",
- // this.realiser.realise(doc));
- //
- // Assert
- // .assertEquals(
- // "Test Document2 \r\nThis is the first test paragraph.
\r\nThis is the second test paragraph.
\r\n\r\n",
- // htmlRealiser.realise(doc));
-
- }
-
- /**
- * Tests for lists and embedded lists
- */
- public void testListItems() {
- DocumentElement list = this.phraseFactory.createList();
- list.addComponent(this.phraseFactory.createListItem(p1));
- list.addComponent(this.phraseFactory.createListItem(p2));
- list.addComponent(this.phraseFactory.createListItem(this.phraseFactory
- .createCoordinatedPhrase(p1, p2)));
- String realisation = this.realiser.realise(list).getRealisation();
- Assert.assertEquals(
- "* you are happy\n* I am sad\n* you are happy and I am sad\n",
- realisation);
- }
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/ElisionTest.java b/SharpSimpleNLGUnitTests/syntax/english/ElisionTest.java
deleted file mode 100644
index f3e761c..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/ElisionTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import org.junit.After;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import junit.framework.Assert;
-import simplenlg.features.Feature;
-import simplenlg.phrasespec.SPhraseSpec;
-
-/**
- * Tests for elision of phrases and words
- */
-@Ignore
-public class ElisionTest extends SimpleNLG4Test {
-
- public ElisionTest(String name) {
- super(name);
- }
-
- /**
- * Test elision of phrases in various places in the sentence
- */
-// public void testPhraseElision() {
-// SPhraseSpec s1 = this.phraseFactory.createClause();
-// s1.setSubject(this.np4); //the rock
-// this.kiss.setComplement(this.np5);//kiss the curtain
-// s1.setVerbPhrase(this.kiss);
-//
-// Assert.assertEquals("the rock kisses the curtain", this.realiser.realise(s1).getRealisation());
-//
-// //elide subject np
-// this.np4.setFeature(Feature.ELIDED, true);
-// Assert.assertEquals("kisses the curtain", this.realiser.realise(s1).getRealisation());
-//
-// //elide vp
-// this.np4.setFeature(Feature.ELIDED, false);
-// this.kiss.setFeature(Feature.ELIDED, true);
-// Assert.assertEquals("the rock", this.realiser.realise(s1).getRealisation());
-//
-// //elide complement only
-// this.kiss.setFeature(Feature.ELIDED, false);
-// this.np5.setFeature(Feature.ELIDED, true);
-// Assert.assertEquals("the rock kisses", this.realiser.realise(s1).getRealisation());
-// }
-
- @Override
- @After
- public void tearDown() {
- super.tearDown();
- }
-
-
- /**
- * Test for elision of specific words rather than phrases
- */
- @Test
- public void wordElisionTest() {
- this.realiser.setDebugMode(true);
- SPhraseSpec s1 = this.phraseFactory.createClause();
- s1.setSubject(this.np4); //the rock
- this.kiss.setComplement(this.np5);//kiss the curtain
- s1.setVerbPhrase(this.kiss);
-
- this.np5.setFeature(Feature.ELIDED, true);
- Assert.assertEquals("the rock kisses", this.realiser.realise(s1).getRealisation());
- }
-
-
-
- /**
- * Test for elision of specific words rather than phrases
- *
- @Test
- public void testWordElision() {
- this.realiser.setDebugMode(true);
- SPhraseSpec s1 = this.phraseFactory.createClause();
- s1.setSubject(this.np4); //the rock
- this.kiss.setComplement(this.np5);//kiss the curtain
- s1.setVerbPhrase(this.kiss);
-
- this.kiss.getHead().setFeature(Feature.ELIDED, true);
- Assert.assertEquals("the rock kisses the curtain", this.realiser.realise(s1).getRealisation());
- } */
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/FeatureTest.java b/SharpSimpleNLGUnitTests/syntax/english/FeatureTest.java
deleted file mode 100644
index 7e10938..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/FeatureTest.java
+++ /dev/null
@@ -1,368 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.syntax.english;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.features.Tense;
-import simplenlg.framework.CoordinatedPhraseElement;
-import simplenlg.framework.DocumentElement;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.NLGElement;
-import simplenlg.framework.NLGFactory;
-import simplenlg.framework.PhraseElement;
-import simplenlg.phrasespec.AdvPhraseSpec;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.phrasespec.VPPhraseSpec;
-
-/**
- * Tests that check that realization of different Features against NLGElements.
- *
- * @author François Portet
- */
-
-public class FeatureTest extends SimpleNLG4Test {
-
-
- NLGFactory docFactory = new NLGFactory(this.lexicon);
-
- /**
- * Instantiates a new text spec test.
- *
- * @param name
- * the name
- */
- public FeatureTest(String name) {
- super(name);
- }
-
- @Override
- @After
- public void tearDown() {
- super.tearDown();
- this.docFactory = null;
- }
-
- /**
- * Tests use of the Possessive Feature.
- */
- @Test
- public void testPossessiveFeature_PastTense() {
- this.phraseFactory.setLexicon(this.lexicon);
- this.realiser.setLexicon(this.lexicon);
-
- // Create the pronoun 'she'
- NLGElement she = phraseFactory.createWord("she",LexicalCategory.PRONOUN);
-
- // Set possessive on the pronoun to make it 'her'
- she.setFeature(Feature.POSSESSIVE, true);
-
- // Create a noun phrase with the subject lover and the determiner
- // as she
- PhraseElement herLover = phraseFactory.createNounPhrase(she,"lover");
-
- // Create a clause to say 'he be her lover'
- PhraseElement clause = phraseFactory.createClause("he", "be", herLover);
-
- // Add the cue phrase need the comma as orthography
- // currently doesn't handle this.
- // This could be expanded to be a noun phrase with determiner
- // 'two' and noun 'week', set to plural and with a premodifier of
- // 'after'
- clause.setFeature(Feature.CUE_PHRASE, "after two weeks,");
-
- // Add the 'for a fortnight' as a post modifier. Alternatively
- // this could be added as a prepositional phrase 'for' with a
- // complement of a noun phrase ('a' 'fortnight')
- clause.addPostModifier("for a fortnight");
-
- // Set 'be' to 'was' as past tense
- clause.setFeature(Feature.TENSE,Tense.PAST);
-
- // Add the clause to a sentence.
- DocumentElement sentence1 = docFactory.createSentence(clause);
-
- // Realise the sentence
- NLGElement realised = this.realiser.realise(sentence1);
-
- Assert.assertEquals("After two weeks, he was her lover for a fortnight.",
- realised.getRealisation());
- }
-
- /**
- * Basic tests.
- */
- @Test
- public void testTwoPossessiveFeature_PastTense() {
- this.phraseFactory.setLexicon(this.lexicon);
-
- // Create the pronoun 'she'
- NLGElement she = phraseFactory.createWord("she",LexicalCategory.PRONOUN);
-
- // Set possessive on the pronoun to make it 'her'
- she.setFeature(Feature.POSSESSIVE, true);
-
- // Create a noun phrase with the subject lover and the determiner
- // as she
- PhraseElement herLover = phraseFactory.createNounPhrase(she,"lover");
- herLover.setPlural(true);
-
- // Create the pronoun 'he'
- NLGElement he = phraseFactory.createNounPhrase(LexicalCategory.PRONOUN,"he");
- he.setPlural(true);
-
- // Create a clause to say 'they be her lovers'
- PhraseElement clause = phraseFactory.createClause(he, "be", herLover);
- clause.setFeature(Feature.POSSESSIVE, true);
-
- // Add the cue phrase need the comma as orthography
- // currently doesn't handle this.
- // This could be expanded to be a noun phrase with determiner
- // 'two' and noun 'week', set to plural and with a premodifier of
- // 'after'
- clause.setFeature(Feature.CUE_PHRASE, "after two weeks,");
-
- // Add the 'for a fortnight' as a post modifier. Alternatively
- // this could be added as a prepositional phrase 'for' with a
- // complement of a noun phrase ('a' 'fortnight')
- clause.addPostModifier("for a fortnight");
-
- // Set 'be' to 'was' as past tense
- clause.setFeature(Feature.TENSE,Tense.PAST);
-
- // Add the clause to a sentence.
- DocumentElement sentence1 = docFactory.createSentence(clause);
-
- // Realise the sentence
- NLGElement realised = this.realiser.realise(sentence1);
-
- Assert.assertEquals("After two weeks, they were her lovers for a fortnight.", //$NON-NLS-1$
- realised.getRealisation());
- }
-
- /**
- * Test use of the Complementiser feature by combining two S's using cue phrase and gerund.
- */
- @Test
- public void testComplementiserFeature_PastTense() {
- this.phraseFactory.setLexicon(this.lexicon);
-
- PhraseElement born = phraseFactory.createClause("Dave Bus", "be", "born");
- born.setFeature(Feature.TENSE,Tense.PAST);
- born.addPostModifier("in");
- born.setFeature(Feature.COMPLEMENTISER, "which");
-
- PhraseElement theHouse = phraseFactory.createNounPhrase("the", "house");
- theHouse.addComplement(born);
-
- PhraseElement clause = phraseFactory.createClause(theHouse, "be", phraseFactory.createPrepositionPhrase("in", "Edinburgh"));
- DocumentElement sentence = docFactory.createSentence(clause);
- NLGElement realised = realiser.realise(sentence);
-
- // Retrieve the realisation and dump it to the console
- Assert.assertEquals("The house which Dave Bus was born in is in Edinburgh.",
- realised.getRealisation());
- }
-
- /**
- * Test use of the Complementiser feature in a {@link CoordinatedPhraseElement} by combine two S's using cue phrase and gerund.
- */
- @Test
- public void testComplementiserFeatureInACoordinatePhrase_PastTense() {
- this.phraseFactory.setLexicon(this.lexicon);
-
- NLGElement dave = phraseFactory.createWord("Dave Bus", LexicalCategory.NOUN);
- NLGElement albert = phraseFactory.createWord("Albert", LexicalCategory.NOUN);
-
- CoordinatedPhraseElement coord1 = new CoordinatedPhraseElement(
- dave, albert);
-
- PhraseElement born = phraseFactory.createClause(coord1, "be", "born");
- born.setFeature(Feature.TENSE,Tense.PAST);
- born.addPostModifier("in");
- born.setFeature(Feature.COMPLEMENTISER, "which");
-
- PhraseElement theHouse = phraseFactory.createNounPhrase("the", "house");
- theHouse.addComplement(born);
-
- PhraseElement clause = phraseFactory.createClause(theHouse, "be", phraseFactory.createPrepositionPhrase("in", "Edinburgh"));
- DocumentElement sentence = docFactory.createSentence(clause);
-
- NLGElement realised = realiser.realise(sentence);
-
- // Retrieve the realisation and dump it to the console
- Assert.assertEquals("The house which Dave Bus and Albert were born in is in Edinburgh.",
- realised.getRealisation());
- }
-
- /**
- * Test the use of the Progressive and Complementiser Features in future tense.
- */
- @Test
- public void testProgressiveAndComplementiserFeatures_FutureTense() {
- this.phraseFactory.setLexicon(this.lexicon);
-
- // Inner clause is 'I' 'make' 'sentence' 'for'.
- PhraseElement inner = phraseFactory.createClause("I","make", "sentence for");
- // Inner clause set to progressive.
- inner.setFeature(Feature.PROGRESSIVE,true);
-
- //Complementiser on inner clause is 'whom'
- inner.setFeature(Feature.COMPLEMENTISER, "whom");
-
- // create the engineer and add the inner clause as post modifier
- PhraseElement engineer = phraseFactory.createNounPhrase("the engineer");
- engineer.addComplement(inner);
-
- // Outer clause is: 'the engineer' 'go' (preposition 'to' 'holidays')
- PhraseElement outer = phraseFactory.createClause(engineer,"go",phraseFactory.createPrepositionPhrase("to","holidays"));
-
- // Outer clause tense is Future.
- outer.setFeature(Feature.TENSE, Tense.FUTURE);
-
- // Possibly progressive as well not sure.
- outer.setFeature(Feature.PROGRESSIVE,true);
-
- //Outer clause postmodifier would be 'tomorrow'
- outer.addPostModifier("tomorrow");
- DocumentElement sentence = docFactory.createSentence(outer);
- NLGElement realised = realiser.realise(sentence);
-
- // Retrieve the realisation and dump it to the console
- Assert.assertEquals("The engineer whom I am making sentence for will be going to holidays tomorrow.",
- realised.getRealisation());
- }
-
-
- /**
- * Tests the use of the Complementiser, Passive, Perfect features in past tense.
- */
- @Test
- public void testComplementiserPassivePerfectFeatures_PastTense() {
- setUp();
- this.realiser.setLexicon(this.lexicon);
-
- PhraseElement inner = phraseFactory.createClause("I", "play", "poker");
- inner.setFeature(Feature.TENSE,Tense.PAST);
- inner.setFeature(Feature.COMPLEMENTISER, "where");
-
- PhraseElement house = phraseFactory.createNounPhrase("the", "house");
- house.addComplement(inner);
-
- SPhraseSpec outer = phraseFactory.createClause(null, "abandon", house);
-
- outer.addPostModifier("since 1986");
-
- outer.setFeature(Feature.PASSIVE, true);
- outer.setFeature(Feature.PERFECT, true);
-
- DocumentElement sentence = docFactory.createSentence(outer);
- NLGElement realised = realiser.realise(sentence);
-
- // Retrieve the realisation and dump it to the console
- Assert.assertEquals("The house where I played poker has been abandoned since 1986.",
- realised.getRealisation());
- }
-
- /**
- * Tests the user of the progressive and complementiser featuers in past tense.
- */
- @Test
- public void testProgressiveComplementiserFeatures_PastTense() {
- this.phraseFactory.setLexicon(this.lexicon);
-
- NLGElement sandwich = phraseFactory.createNounPhrase(LexicalCategory.NOUN, "sandwich");
- sandwich.setPlural(true);
- //
- PhraseElement first = phraseFactory.createClause("I", "make", sandwich);
- first.setFeature(Feature.TENSE,Tense.PAST);
- first.setFeature(Feature.PROGRESSIVE,true);
- first.setPlural(false);
-
- PhraseElement second = phraseFactory.createClause("the mayonnaise", "run out");
- second.setFeature(Feature.TENSE,Tense.PAST);
- //
- second.setFeature(Feature.COMPLEMENTISER, "when");
-
- first.addComplement(second);
-
- DocumentElement sentence = docFactory.createSentence(first);
- NLGElement realised = realiser.realise(sentence);
-
- // Retrieve the realisation and dump it to the console
- Assert.assertEquals("I was making sandwiches when the mayonnaise ran out.",
- realised.getRealisation());
- }
-
- /**
- * Test the use of Passive in creating a Passive sentence structure: + [be] + + [by] + [Subject].
- */
- @Test
- public void testPassiveFeature() {
- this.realiser.setLexicon(this.lexicon);
-
- PhraseElement phrase = phraseFactory.createClause("recession", "affect", "value");
- phrase.setFeature(Feature.PASSIVE, true);
- DocumentElement sentence = docFactory.createSentence(phrase);
- NLGElement realised = realiser.realise(sentence);
-
- Assert.assertEquals("Value is affected by recession.", realised.getRealisation());
- }
-
-
- /**
- * Test for repetition of the future auxiliary "will", courtesy of Luxor
- * Vlonjati
- */
- @Test
- public void testFutureTense() {
- SPhraseSpec test = this.phraseFactory.createClause();
-
- NPPhraseSpec subj = this.phraseFactory.createNounPhrase("I");
-
- VPPhraseSpec verb = this.phraseFactory.createVerbPhrase("go");
-
- AdvPhraseSpec adverb = this.phraseFactory
- .createAdverbPhrase("tomorrow");
-
- test.setSubject(subj);
- test.setVerbPhrase(verb);
- test.setFeature(Feature.TENSE, Tense.FUTURE);
- test.addPostModifier(adverb);
- String sentence = realiser.realiseSentence(test);
- Assert.assertEquals("I will go tomorrow.", sentence);
-
- SPhraseSpec test2 = this.phraseFactory.createClause();
- NLGElement vb = this.phraseFactory.createWord("go", LexicalCategory.VERB);
- test2.setSubject(subj);
- test2.setVerb(vb);
- test2.setFeature(Feature.TENSE, Tense.FUTURE);
- test2.addPostModifier(adverb);
- String sentence2 = realiser.realiseSentence(test);
- Assert.assertEquals("I will go tomorrow.", sentence2);
-
- }
-
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/HTMLFormatterTest.java b/SharpSimpleNLGUnitTests/syntax/english/HTMLFormatterTest.java
deleted file mode 100644
index 5f5c0aa..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/HTMLFormatterTest.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.After;
-import org.junit.Test;
-
-import simplenlg.format.english.HTMLFormatter;
-import simplenlg.framework.DocumentElement;
-import simplenlg.framework.NLGElement;
-import simplenlg.phrasespec.SPhraseSpec;
-
-// HTMLFormatter and HTMLFormatterTest ~ author James Christie, but taken from TextFormatter and TextFormatterTest
-
-public class HTMLFormatterTest extends SimpleNLG4Test {
-
- /**
- * Instantiates a new document element test.
- *
- * @param name
- * the name
- */
- public HTMLFormatterTest(String name) {
- super(name);
- }
-
- @Override
- @After
- public void tearDown() {
- super.tearDown();
- }
-
-
- /**
- * Check the correct [part] web page contents are being generated
- */
- @Test
- public final void testWebPageContent( ) {
- // now build a document ...
- DocumentElement document = phraseFactory.createDocument( "This is a title" ) ;
-
- DocumentElement section = phraseFactory.createSection( "This is a section" ) ;
-
- DocumentElement paragraph1 = phraseFactory.createParagraph( ) ;
- DocumentElement sentence11 = phraseFactory.createSentence( "This is the first sentence of paragraph 1" ) ;
- paragraph1.addComponent( sentence11 ) ;
- DocumentElement sentence12 = phraseFactory.createSentence( "This is the second sentence of paragraph 1" ) ;
- paragraph1.addComponent( sentence12 ) ;
- section.addComponent( paragraph1 ) ;
- document.addComponent( section ) ;
-
- DocumentElement paragraph2 = phraseFactory.createParagraph( ) ;
- DocumentElement sentence2 = phraseFactory.createSentence( "This is the first sentence of paragraph 2" ) ;
- paragraph2.addComponent( sentence2 ) ;
- document.addComponent( paragraph2 ) ;
-
- DocumentElement paragraph3 = phraseFactory.createParagraph( ) ;
- DocumentElement sentence3 = phraseFactory.createSentence( "This is the first sentence of paragraph 3" ) ;
- paragraph3.addComponent( sentence3 ) ;
- document.addComponent( paragraph3 ) ;
-
- // now for a second section with three sentences in one paragraph using arrays.asList function
- SPhraseSpec p1 = phraseFactory.createClause( "Mary", "chase", "the monkey" ) ;
- SPhraseSpec p2 = phraseFactory.createClause( "the monkey", "fight back" ) ;
- SPhraseSpec p3 = phraseFactory.createClause( "Mary", "be", "nervous" ) ;
-
- DocumentElement s1 = phraseFactory.createSentence( p1 ) ;
- DocumentElement s2 = phraseFactory.createSentence( p2 ) ;
- DocumentElement s3 = phraseFactory.createSentence( p3 ) ;
-
- DocumentElement para1x3 = phraseFactory.createParagraph( Arrays.asList( s1, s2, s3 ) ) ;
-
- DocumentElement sectionList = phraseFactory.createSection( "This section contains lists" ) ;
- sectionList.addComponent( para1x3 ) ;
- document.addComponent( sectionList ) ;
-
- // from David Westwater 4-10-11
- DocumentElement element = phraseFactory.createList( ) ;
- List < NLGElement > list = new ArrayList < NLGElement > ( ) ;
- list.add( phraseFactory.createListItem( phraseFactory.createStringElement( "Item 1" ) ) ) ;
- list.add( phraseFactory.createListItem( phraseFactory.createStringElement( "Item 2" ) ) ) ;
- list.add( phraseFactory.createListItem( phraseFactory.createStringElement( "Item 3" ) ) ) ;
-
- element.addComponents( list ) ;
- document.addComponent( element ) ;
-
- // ... finally produce some output with HMTL tags ...
- System.out.println( "HTML realisation ~ \n=============================\n" ) ;
-
- String output = "" ;
-
- // this.realiser.setFormatter( new TextFormatter( ) ) ;
- this.realiser.setFormatter( new HTMLFormatter( ) ) ;
- // realiser.setDebugMode( true ) ; // hide after testing
- output += realiser.realise( document ).getRealisation( ) ;
-
- System.out.println( output ) ; // just to visually check what is being produced
-
- String expectedResults =
- "This is a title " +
- "This is a section " +
- "This is the first sentence of paragraph 1. This is the second sentence of paragraph 1.
" +
- "This is the first sentence of paragraph 2.
" +
- "This is the first sentence of paragraph 3.
" +
- "This section contains lists " +
- "Mary chases the monkey. The monkey fights back. Mary is nervous.
" +
- "" +
- "Item 1 " +
- "Item 2 " +
- "Item 3 " +
- " " ;
-
- assertEquals( expectedResults, output ) ; // when realisation is working then complete this test
- } // testWebPageContents
-} // class
-
-
diff --git a/SharpSimpleNLGUnitTests/syntax/english/InterrogativeTest.java b/SharpSimpleNLGUnitTests/syntax/english/InterrogativeTest.java
deleted file mode 100644
index 230964a..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/InterrogativeTest.java
+++ /dev/null
@@ -1,836 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import junit.framework.Assert;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.features.InterrogativeType;
-import simplenlg.features.Person;
-import simplenlg.features.Tense;
-import simplenlg.framework.CoordinatedPhraseElement;
-import simplenlg.framework.DocumentElement;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.NLGElement;
-import simplenlg.framework.NLGFactory;
-import simplenlg.framework.PhraseElement;
-import simplenlg.lexicon.Lexicon;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.PPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * JUnit test case for interrogatives.
- *
- * @author agatt
- */
-public class InterrogativeTest extends SimpleNLG4Test {
-
- // set up a few more fixtures
- /** The s5. */
- SPhraseSpec s1, s2, s3, s4, s5;
-
- /**
- * Instantiates a new interrogative test.
- *
- * @param name
- * the name
- */
- public InterrogativeTest(String name) {
- super(name);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see simplenlg.test.SimplenlgTest#setUp()
- */
- @Override
- @Before
- protected void setUp() {
- super.setUp();
-
- // // the man gives the woman John's flower
- PhraseElement john = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
- john.setFeature(Feature.POSSESSIVE, true);
- PhraseElement flower = this.phraseFactory.createNounPhrase(john,
- "flower"); //$NON-NLS-1$
- PhraseElement _woman = this.phraseFactory.createNounPhrase(
- "the", "woman"); //$NON-NLS-1$ //$NON-NLS-2$
- this.s3 = this.phraseFactory.createClause(this.man, this.give, flower);
- this.s3.setIndirectObject(_woman);
-
- CoordinatedPhraseElement subjects = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"), //$NON-NLS-1$
- this.phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$
- this.s4 = this.phraseFactory.createClause(subjects, "pick up", //$NON-NLS-1$
- "the balls"); //$NON-NLS-1$
- this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
- this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
- this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
- this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
- // this.s5 = new SPhraseSpec();
- // this.s5.setSubject(new NPPhraseSpec("the", "dog"));
- // this.s5.setHead("be");
- // this.s5.setComplement(new NPPhraseSpec("the", "rock"),
- // DiscourseFunction.OBJECT);
-
- }
-
- /**
- * Tests a couple of fairly simple questions.
- */
- @Test
- public void testSimpleQuestions() {
- setUp();
- this.phraseFactory.setLexicon(this.lexicon);
- this.realiser.setLexicon(this.lexicon);
-
- // simple present
- this.s1 = this.phraseFactory.createClause(this.woman, this.kiss,
- this.man);
- this.s1.setFeature(Feature.TENSE, Tense.PRESENT);
- this.s1.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
-
- NLGFactory docFactory = new NLGFactory(this.lexicon);
- DocumentElement sent = docFactory.createSentence(this.s1);
- Assert.assertEquals("Does the woman kiss the man?", this.realiser //$NON-NLS-1$
- .realise(sent).getRealisation());
-
- // simple past
- // sentence: "the woman kissed the man"
- this.s1 = this.phraseFactory.createClause(this.woman, this.kiss,
- this.man);
- this.s1.setFeature(Feature.TENSE, Tense.PAST);
- this.s1.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- Assert.assertEquals("did the woman kiss the man", this.realiser //$NON-NLS-1$
- .realise(this.s1).getRealisation());
-
- // copular/existential: be-fronting
- // sentence = "there is the dog on the rock"
- this.s2 = this.phraseFactory.createClause("there", "be", this.dog); //$NON-NLS-1$ //$NON-NLS-2$
- this.s2.addPostModifier(this.onTheRock);
- this.s2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- Assert.assertEquals("is there the dog on the rock", this.realiser //$NON-NLS-1$
- .realise(this.s2).getRealisation());
-
- // perfective
- // sentence -- "there has been the dog on the rock"
- this.s2 = this.phraseFactory.createClause("there", "be", this.dog); //$NON-NLS-1$ //$NON-NLS-2$
- this.s2.addPostModifier(this.onTheRock);
- this.s2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- this.s2.setFeature(Feature.PERFECT, true);
- Assert.assertEquals("has there been the dog on the rock", //$NON-NLS-1$
- this.realiser.realise(this.s2).getRealisation());
-
- // progressive
- // sentence: "the man was giving the woman John's flower"
- PhraseElement john = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
- john.setFeature(Feature.POSSESSIVE, true);
- PhraseElement flower = this.phraseFactory.createNounPhrase(john,
- "flower"); //$NON-NLS-1$
- PhraseElement _woman = this.phraseFactory.createNounPhrase(
- "the", "woman"); //$NON-NLS-1$ //$NON-NLS-2$
- this.s3 = this.phraseFactory.createClause(this.man, this.give, flower);
- this.s3.setIndirectObject(_woman);
- this.s3.setFeature(Feature.TENSE, Tense.PAST);
- this.s3.setFeature(Feature.PROGRESSIVE, true);
- this.s3.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- NLGElement realised = this.realiser.realise(this.s3);
- Assert.assertEquals("was the man giving the woman John's flower", //$NON-NLS-1$
- realised.getRealisation());
-
- // modal
- // sentence: "the man should be giving the woman John's flower"
- setUp();
- john = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
- john.setFeature(Feature.POSSESSIVE, true);
- flower = this.phraseFactory.createNounPhrase(john, "flower"); //$NON-NLS-1$
- _woman = this.phraseFactory.createNounPhrase("the", "woman"); //$NON-NLS-1$ //$NON-NLS-2$
- this.s3 = this.phraseFactory.createClause(this.man, this.give, flower);
- this.s3.setIndirectObject(_woman);
- this.s3.setFeature(Feature.TENSE, Tense.PAST);
- this.s3.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- this.s3.setFeature(Feature.MODAL, "should"); //$NON-NLS-1$
- Assert.assertEquals(
- "should the man have given the woman John's flower", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
-
- // complex case with cue phrases
- // sentence: "however, tomorrow, Jane and Andrew will pick up the balls
- // in the shop"
- // this gets the front modifier "tomorrow" shifted to the end
- setUp();
- CoordinatedPhraseElement subjects = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"), //$NON-NLS-1$
- this.phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$
- this.s4 = this.phraseFactory.createClause(subjects, "pick up", //$NON-NLS-1$
- "the balls"); //$NON-NLS-1$
- this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
- this.s4.setFeature(Feature.CUE_PHRASE, "however,"); //$NON-NLS-1$
- this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
- this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
- this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- Assert.assertEquals(
- "however, will Jane and Andrew pick up the balls in the shop tomorrow", //$NON-NLS-1$
- this.realiser.realise(this.s4).getRealisation());
- }
-
- /**
- * Test for sentences with negation.
- */
- @Test
- public void testNegatedQuestions() {
- setUp();
- this.phraseFactory.setLexicon(this.lexicon);
- this.realiser.setLexicon(this.lexicon);
-
- // sentence: "the woman did not kiss the man"
- this.s1 = this.phraseFactory.createClause(this.woman, "kiss", this.man);
- this.s1.setFeature(Feature.TENSE, Tense.PAST);
- this.s1.setFeature(Feature.NEGATED, true);
- this.s1.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- Assert.assertEquals("did the woman not kiss the man", this.realiser //$NON-NLS-1$
- .realise(this.s1).getRealisation());
-
- // sentence: however, tomorrow, Jane and Andrew will not pick up the
- // balls in the shop
- CoordinatedPhraseElement subjects = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"), //$NON-NLS-1$
- this.phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$
- this.s4 = this.phraseFactory.createClause(subjects, "pick up", //$NON-NLS-1$
- "the balls"); //$NON-NLS-1$
- this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
- this.s4.setFeature(Feature.CUE_PHRASE, "however,"); //$NON-NLS-1$
- this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
- this.s4.setFeature(Feature.NEGATED, true);
- this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
- this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- Assert.assertEquals(
- "however, will Jane and Andrew not pick up the balls in the shop tomorrow", //$NON-NLS-1$
- this.realiser.realise(this.s4).getRealisation());
- }
-
- /**
- * Tests for coordinate VPs in question form.
- */
- @Test
- public void testCoordinateVPQuestions() {
-
- // create a complex vp: "kiss the dog and walk in the room"
- setUp();
- CoordinatedPhraseElement complex = new CoordinatedPhraseElement(
- this.kiss, this.walk);
- this.kiss.addComplement(this.dog);
- this.walk.addComplement(this.inTheRoom);
-
- // sentence: "However, tomorrow, Jane and Andrew will kiss the dog and
- // will walk in the room"
- CoordinatedPhraseElement subjects = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"), //$NON-NLS-1$
- this.phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$
- this.s4 = this.phraseFactory.createClause(subjects, complex);
- this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
- this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
- this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
-
- Assert.assertEquals(
- "however tomorrow Jane and Andrew will kiss the dog and will walk in the room", //$NON-NLS-1$
- this.realiser.realise(this.s4).getRealisation());
-
- // setting to interrogative should automatically give us a single,
- // wide-scope aux
- setUp();
- subjects = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"), //$NON-NLS-1$
- this.phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$
- this.kiss.addComplement(this.dog);
- this.walk.addComplement(this.inTheRoom);
- complex = new CoordinatedPhraseElement(this.kiss, this.walk);
- this.s4 = this.phraseFactory.createClause(subjects, complex);
- this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
- this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
- this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
- this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
-
- Assert.assertEquals(
- "however will Jane and Andrew kiss the dog and walk in the room tomorrow", //$NON-NLS-1$
- this.realiser.realise(this.s4).getRealisation());
-
- // slightly more complex -- perfective
- setUp();
- this.realiser.setLexicon(this.lexicon);
- subjects = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Jane"), //$NON-NLS-1$
- this.phraseFactory.createNounPhrase("Andrew")); //$NON-NLS-1$
- complex = new CoordinatedPhraseElement(this.kiss, this.walk);
- this.kiss.addComplement(this.dog);
- this.walk.addComplement(this.inTheRoom);
- this.s4 = this.phraseFactory.createClause(subjects, complex);
- this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
- this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$
- this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
- this.s4.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- this.s4.setFeature(Feature.PERFECT, true);
-
- Assert.assertEquals(
- "however will Jane and Andrew have kissed the dog and walked in the room tomorrow", //$NON-NLS-1$
- this.realiser.realise(this.s4).getRealisation());
- }
-
- /**
- * Test for simple WH questions in present tense.
- */
- @Test
- public void testSimpleQuestions2() {
- setUp();
- this.realiser.setLexicon(this.lexicon);
- PhraseElement s = this.phraseFactory.createClause("the woman", "kiss", //$NON-NLS-1$ //$NON-NLS-2$
- "the man"); //$NON-NLS-1$
-
- // try with the simple yes/no type first
- s.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- Assert.assertEquals("does the woman kiss the man", this.realiser //$NON-NLS-1$
- .realise(s).getRealisation());
-
- // now in the passive
- s = this.phraseFactory.createClause("the woman", "kiss", //$NON-NLS-1$ //$NON-NLS-2$
- "the man"); //$NON-NLS-1$
- s.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- s.setFeature(Feature.PASSIVE, true);
- Assert.assertEquals("is the man kissed by the woman", this.realiser //$NON-NLS-1$
- .realise(s).getRealisation());
-
- // // subject interrogative with simple present
- // // sentence: "the woman kisses the man"
- s = this.phraseFactory.createClause("the woman", "kiss", //$NON-NLS-1$ //$NON-NLS-2$
- "the man"); //$NON-NLS-1$
- s.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
-
- Assert.assertEquals("who kisses the man", this.realiser.realise(s) //$NON-NLS-1$
- .getRealisation());
-
- // object interrogative with simple present
- s = this.phraseFactory.createClause("the woman", "kiss", //$NON-NLS-1$ //$NON-NLS-2$
- "the man"); //$NON-NLS-1$
- s.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
- Assert.assertEquals("who does the woman kiss", this.realiser //$NON-NLS-1$
- .realise(s).getRealisation());
-
- // subject interrogative with passive
- s = this.phraseFactory.createClause("the woman", "kiss", //$NON-NLS-1$ //$NON-NLS-2$
- "the man"); //$NON-NLS-1$
- s.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
- s.setFeature(Feature.PASSIVE, true);
- Assert.assertEquals("who is the man kissed by", this.realiser //$NON-NLS-1$
- .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(
- "however who will pick up the balls in the shop tomorrow", //$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(
- "however who will the balls be picked up in the shop by tomorrow", //$NON-NLS-1$
- this.realiser.realise(this.s4).getRealisation());
-
- // object interrogative
- setUp();
- this.s4.setFeature(Feature.INTERROGATIVE_TYPE,
- InterrogativeType.WHAT_OBJECT);
- Assert.assertEquals(
- "however what will Jane and Andrew pick up in the shop tomorrow", //$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(
- "however what will be picked up in the shop by Jane and Andrew tomorrow", //$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(
- "however how will the balls be picked up in the shop by Jane and Andrew tomorrow", //$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(
- "however why will the balls be picked up in the shop by Jane and Andrew tomorrow", //$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, "should"); //$NON-NLS-1$
- Assert.assertEquals(
- "however how should the balls be picked up in the shop by Jane and Andrew tomorrow", //$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("who does the man give John's flower to", //$NON-NLS-1$
- this.realiser.realise(this.s3).getRealisation());
- }
-
- /**
- * WH movement in the progressive
- */
- @Test
- public void testProgrssiveWHSubjectQuestions() {
- SPhraseSpec p = this.phraseFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("eat");
- p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
- p.setFeature(Feature.PROGRESSIVE, true);
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
- Assert.assertEquals("who is eating the pie", //$NON-NLS-1$
- this.realiser.realise(p).getRealisation());
- }
-
- /**
- * WH movement in the progressive
- */
- @Test
- public void testProgrssiveWHObjectQuestions() {
- SPhraseSpec p = this.phraseFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("eat");
- p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
- p.setFeature(Feature.PROGRESSIVE, true);
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
- Assert.assertEquals("what is Mary eating", //$NON-NLS-1$
- this.realiser.realise(p).getRealisation());
-
- // AG -- need to check this; it doesn't work
- // p.setFeature(Feature.NEGATED, true);
- // Assert.assertEquals("what is Mary not eating", //$NON-NLS-1$
- // this.realiser.realise(p).getRealisation());
-
- }
-
- /**
- * Negation with WH movement for subject
- */
- @Test
- public void testNegatedWHSubjQuestions() {
- SPhraseSpec p = this.phraseFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("eat");
- p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
- p.setFeature(Feature.NEGATED, true);
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
- Assert.assertEquals("who does not eat the pie", //$NON-NLS-1$
- this.realiser.realise(p).getRealisation());
- }
-
- /**
- * Negation with WH movement for object
- */
- @Test
- public void testNegatedWHObjQuestions() {
- SPhraseSpec p = this.phraseFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("eat");
- p.setObject(this.phraseFactory.createNounPhrase("the", "pie"));
- p.setFeature(Feature.NEGATED, true);
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
- NLGElement realisation = this.realiser.realise(p);
- Assert.assertEquals("what does Mary not eat", //$NON-NLS-1$
- realisation.getRealisation());
- }
-
- /**
- * Test questyions in the tutorial.
- */
- @Test
- public void testTutorialQuestions() {
- setUp();
- this.realiser.setLexicon(this.lexicon);
-
- PhraseElement p = this.phraseFactory.createClause("Mary", "chase", //$NON-NLS-1$ //$NON-NLS-2$
- "George"); //$NON-NLS-1$
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- Assert.assertEquals("does Mary chase George", this.realiser.realise(p) //$NON-NLS-1$
- .getRealisation());
-
- p = this.phraseFactory.createClause("Mary", "chase", //$NON-NLS-1$ //$NON-NLS-2$
- "George"); //$NON-NLS-1$
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
- Assert.assertEquals("who does Mary chase", this.realiser.realise(p) //$NON-NLS-1$
- .getRealisation());
-
- }
-
- /**
- * Subject WH Questions with modals
- */
- @Test
- public void testModalWHSubjectQuestion() {
- SPhraseSpec p = this.phraseFactory.createClause(this.dog, "upset",
- this.man);
- p.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals("the dog upset the man", this.realiser.realise(p)
- .getRealisation());
-
- // first without modal
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
- Assert.assertEquals("who upset the man", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
- Assert.assertEquals("what upset the man", this.realiser.realise(p)
- .getRealisation());
-
- // now with modal auxiliary
- p.setFeature(Feature.MODAL, "may");
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
- Assert.assertEquals("who may have upset the man", this.realiser
- .realise(p).getRealisation());
-
- p.setFeature(Feature.TENSE, Tense.FUTURE);
- Assert.assertEquals("who may upset the man", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.TENSE, Tense.PAST);
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
- Assert.assertEquals("what may have upset the man", this.realiser
- .realise(p).getRealisation());
-
- p.setFeature(Feature.TENSE, Tense.FUTURE);
- Assert.assertEquals("what may upset the man", this.realiser.realise(p)
- .getRealisation());
- }
-
- /**
- * Subject WH Questions with modals
- */
- @Test
- public void testModalWHObjectQuestion() {
- SPhraseSpec p = this.phraseFactory.createClause(this.dog, "upset",
- this.man);
- p.setFeature(Feature.TENSE, Tense.PAST);
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
-
- Assert.assertEquals("who did the dog upset", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.MODAL, "may");
- Assert.assertEquals("who may the dog have upset", this.realiser
- .realise(p).getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
- Assert.assertEquals("what may the dog have upset", this.realiser
- .realise(p).getRealisation());
-
- p.setFeature(Feature.TENSE, Tense.FUTURE);
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
- Assert.assertEquals("who may the dog upset", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
- Assert.assertEquals("what may the dog upset", this.realiser.realise(p)
- .getRealisation());
- }
-
- /**
- * Questions with tenses requiring auxiliaries + subject WH
- */
- @Test
- public void testAuxWHSubjectQuestion() {
- SPhraseSpec p = this.phraseFactory.createClause(this.dog, "upset",
- this.man);
- p.setFeature(Feature.TENSE, Tense.PRESENT);
- p.setFeature(Feature.PERFECT, true);
- Assert.assertEquals("the dog has upset the man",
- this.realiser.realise(p).getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
- Assert.assertEquals("who has upset the man", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
- Assert.assertEquals("what has upset the man", this.realiser.realise(p)
- .getRealisation());
- }
-
- /**
- * Questions with tenses requiring auxiliaries + subject WH
- */
- @Test
- public void testAuxWHObjectQuestion() {
- SPhraseSpec p = this.phraseFactory.createClause(this.dog, "upset",
- this.man);
-
- // first without any aux
- p.setFeature(Feature.TENSE, Tense.PAST);
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
- Assert.assertEquals("what did the dog upset", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
- Assert.assertEquals("who did the dog upset", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.TENSE, Tense.PRESENT);
- p.setFeature(Feature.PERFECT, true);
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
- Assert.assertEquals("who has the dog upset", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
- Assert.assertEquals("what has the dog upset", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.TENSE, Tense.FUTURE);
- p.setFeature(Feature.PERFECT, true);
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
- Assert.assertEquals("who will the dog have upset", this.realiser
- .realise(p).getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
- Assert.assertEquals("what will the dog have upset", this.realiser
- .realise(p).getRealisation());
-
- }
-
- /**
- * Test for questions with "be"
- */
- @Test
- public void testBeQuestions() {
- SPhraseSpec p = this.phraseFactory.createClause(
- this.phraseFactory.createNounPhrase("a", "ball"),
- this.phraseFactory.createWord("be", LexicalCategory.VERB),
- this.phraseFactory.createNounPhrase("a", "toy"));
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
- Assert.assertEquals("what is a ball", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- Assert.assertEquals("is a ball a toy", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
- Assert.assertEquals("what is a toy", this.realiser.realise(p)
- .getRealisation());
-
- SPhraseSpec p2 = this.phraseFactory.createClause("Mary", "be",
- "beautiful");
- p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
- Assert.assertEquals("why is Mary beautiful", this.realiser.realise(p2)
- .getRealisation());
-
- p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHERE);
- Assert.assertEquals("where is Mary beautiful", this.realiser.realise(p2)
- .getRealisation());
-
- p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
- Assert.assertEquals("who is beautiful", this.realiser.realise(p2)
- .getRealisation());
- }
-
- /**
- * Test for questions with "be" in future tense
- */
- @Test
- public void testBeQuestionsFuture() {
- SPhraseSpec p = this.phraseFactory.createClause(
- this.phraseFactory.createNounPhrase("a", "ball"),
- this.phraseFactory.createWord("be", LexicalCategory.VERB),
- this.phraseFactory.createNounPhrase("a", "toy"));
- p.setFeature(Feature.TENSE, Tense.FUTURE);
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
- Assert.assertEquals("what will a ball be", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- Assert.assertEquals("will a ball be a toy", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
- Assert.assertEquals("what will be a toy", this.realiser.realise(p)
- .getRealisation());
-
- SPhraseSpec p2 = this.phraseFactory.createClause("Mary", "be",
- "beautiful");
- p2.setFeature(Feature.TENSE, Tense.FUTURE);
- p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
- Assert.assertEquals("why will Mary be beautiful", this.realiser
- .realise(p2).getRealisation());
-
- p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHERE);
- Assert.assertEquals("where will Mary be beautiful", this.realiser
- .realise(p2).getRealisation());
-
- p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
- Assert.assertEquals("who will be beautiful", this.realiser.realise(p2)
- .getRealisation());
- }
-
- /**
- * Tests for WH questions with be in past tense
- */
- @Test
- public void testBeQuestionsPast() {
- SPhraseSpec p = this.phraseFactory.createClause(
- this.phraseFactory.createNounPhrase("a", "ball"),
- this.phraseFactory.createWord("be", LexicalCategory.VERB),
- this.phraseFactory.createNounPhrase("a", "toy"));
- p.setFeature(Feature.TENSE, Tense.PAST);
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
- Assert.assertEquals("what was a ball", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
- Assert.assertEquals("was a ball a toy", this.realiser.realise(p)
- .getRealisation());
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
- Assert.assertEquals("what was a toy", this.realiser.realise(p)
- .getRealisation());
-
- SPhraseSpec p2 = this.phraseFactory.createClause("Mary", "be",
- "beautiful");
- p2.setFeature(Feature.TENSE, Tense.PAST);
- p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
- Assert.assertEquals("why was Mary beautiful", this.realiser.realise(p2)
- .getRealisation());
-
- p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHERE);
- Assert.assertEquals("where was Mary beautiful", this.realiser.realise(p2)
- .getRealisation());
-
- p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
- Assert.assertEquals("who was beautiful", this.realiser.realise(p2)
- .getRealisation());
- }
-
-
- /**
- * Test WHERE, HOW and WHY questions, with copular predicate "be"
- */
- public void testSimpleBeWHQuestions() {
- SPhraseSpec p = this.phraseFactory.createClause("I", "be");
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHERE);
- Assert.assertEquals("Where am I?", realiser.realiseSentence(p));
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
- Assert.assertEquals("Why am I?", realiser.realiseSentence(p));
-
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.HOW);
- Assert.assertEquals("How am I?", realiser.realiseSentence(p));
-
- }
-
- /**
- * Test a simple "how" question, based on query from Albi Oxa
- */
- @Test
- public void testHowPredicateQuestion() {
- SPhraseSpec test = this.phraseFactory.createClause();
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("You");
-
- subject.setFeature(Feature.PRONOMINAL, true);
- subject.setFeature(Feature.PERSON, Person.SECOND);
- test.setSubject(subject);
- test.setVerb("be");
-
- test.setFeature(Feature.INTERROGATIVE_TYPE,
- InterrogativeType.HOW_PREDICATE);
- test.setFeature(Feature.TENSE, Tense.PRESENT);
-
- String result = realiser.realiseSentence(test);
- Assert.assertEquals("How are you?", result);
-
- }
-
- /**
- * Case 1 checks that "What do you think about John?" can be generated.
- *
- * Case 2 checks that the same clause is generated, even when an object is
- * declared.
- */
- @Test
- public void testWhatObjectInterrogative() {
- Lexicon lexicon = Lexicon.getDefaultLexicon();
- NLGFactory nlg = new NLGFactory(lexicon);
- Realiser realiser = new Realiser(lexicon);
-
- // Case 1, no object is explicitly given:
- SPhraseSpec clause = nlg.createClause("you", "think");
- PPPhraseSpec aboutJohn = nlg.createPrepositionPhrase("about", "John");
- clause.addPostModifier(aboutJohn);
- clause.setFeature(Feature.INTERROGATIVE_TYPE,
- InterrogativeType.WHAT_OBJECT);
- String realisation = realiser.realiseSentence(clause);
- System.out.println(realisation);
- Assert.assertEquals("What do you think about John?", realisation);
-
- // Case 2:
- // Add "bad things" as the object so the object doesn't remain null:
- clause.setObject("bad things");
- realisation = realiser.realiseSentence(clause);
- System.out.println(realiser.realiseSentence(clause));
- Assert.assertEquals("What do you think about John?", realisation);
- }
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/NounPhraseTest.java b/SharpSimpleNLGUnitTests/syntax/english/NounPhraseTest.java
deleted file mode 100644
index 0b2dc2d..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/NounPhraseTest.java
+++ /dev/null
@@ -1,617 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell.
- */
-
-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.framework.CoordinatedPhraseElement;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.NLGElement;
-import simplenlg.framework.PhraseElement;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-
-/**
- * Tests for the NPPhraseSpec and CoordinateNPPhraseSpec classes.
- *
- * @author agatt
- */
-public class NounPhraseTest extends SimpleNLG4Test {
-
- /**
- * Instantiates a new nP test.
- *
- * @param name
- * the name
- */
- public NounPhraseTest(String name) {
- super(name);
- }
-
- @Override
- @After
- public void tearDown() {
- super.tearDown();
- }
-
-
- /**
- * Test the setPlural() method in noun phrases.
- */
- @Test
- public void testPlural() {
- this.np4.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- Assert.assertEquals(
- "the rocks", this.realiser.realise(this.np4).getRealisation()); //$NON-NLS-1$
-
- this.np5.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- Assert
- .assertEquals(
- "the curtains", this.realiser.realise(this.np5).getRealisation()); //$NON-NLS-1$
-
- this.np5.setFeature(Feature.NUMBER, NumberAgreement.SINGULAR);
- Assert.assertEquals(NumberAgreement.SINGULAR, this.np5
- .getFeature(Feature.NUMBER));
- Assert
- .assertEquals(
- "the curtain", this.realiser.realise(this.np5).getRealisation()); //$NON-NLS-1$
-
- this.np5.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- Assert
- .assertEquals(
- "the curtains", this.realiser.realise(this.np5).getRealisation()); //$NON-NLS-1$
- }
-
- /**
- * Test the pronominalisation method for full NPs.
- */
- @Test
- public void testPronominalisation() {
- // sing
- this.proTest1.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
- this.proTest1.setFeature(Feature.PRONOMINAL, true);
- Assert.assertEquals(
- "she", this.realiser.realise(this.proTest1).getRealisation()); //$NON-NLS-1$
-
- // sing, possessive
- this.proTest1.setFeature(Feature.POSSESSIVE, true);
- Assert.assertEquals(
- "her", this.realiser.realise(this.proTest1).getRealisation()); //$NON-NLS-1$
-
- // plural pronoun
- this.proTest2.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- this.proTest2.setFeature(Feature.PRONOMINAL, true);
- Assert.assertEquals(
- "they", this.realiser.realise(this.proTest2).getRealisation()); //$NON-NLS-1$
-
- // accusative: "them"
- this.proTest2.setFeature(InternalFeature.DISCOURSE_FUNCTION,
- DiscourseFunction.OBJECT);
- Assert.assertEquals(
- "them", this.realiser.realise(this.proTest2).getRealisation()); //$NON-NLS-1$
- }
-
- /**
- * Test the pronominalisation method for full NPs (more thorough than above)
- */
- @Test
- public void testPronominalisation2() {
- // Ehud - added extra pronominalisation tests
- NPPhraseSpec pro = phraseFactory.createNounPhrase("Mary");
- pro.setFeature(Feature.PRONOMINAL, true);
- pro.setFeature(Feature.PERSON, Person.FIRST);
- SPhraseSpec sent = phraseFactory.createClause(pro, "like", "John");
- Assert
- .assertEquals("I like John.", this.realiser
- .realiseSentence(sent));
-
- pro = phraseFactory.createNounPhrase("Mary");
- pro.setFeature(Feature.PRONOMINAL, true);
- pro.setFeature(Feature.PERSON, Person.SECOND);
- sent = phraseFactory.createClause(pro, "like", "John");
- Assert.assertEquals("You like John.", this.realiser
- .realiseSentence(sent));
-
- pro = phraseFactory.createNounPhrase("Mary");
- pro.setFeature(Feature.PRONOMINAL, true);
- pro.setFeature(Feature.PERSON, Person.THIRD);
- pro.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
- sent = phraseFactory.createClause(pro, "like", "John");
- Assert.assertEquals("She likes John.", this.realiser
- .realiseSentence(sent));
-
- pro = phraseFactory.createNounPhrase("Mary");
- pro.setFeature(Feature.PRONOMINAL, true);
- pro.setFeature(Feature.PERSON, Person.FIRST);
- pro.setPlural(true);
- sent = phraseFactory.createClause(pro, "like", "John");
- Assert.assertEquals("We like John.", this.realiser
- .realiseSentence(sent));
-
- pro = phraseFactory.createNounPhrase("Mary");
- pro.setFeature(Feature.PRONOMINAL, true);
- pro.setFeature(Feature.PERSON, Person.SECOND);
- pro.setPlural(true);
- sent = phraseFactory.createClause(pro, "like", "John");
- Assert.assertEquals("You like John.", this.realiser
- .realiseSentence(sent));
-
- pro = phraseFactory.createNounPhrase("Mary");
- pro.setFeature(Feature.PRONOMINAL, true);
- pro.setFeature(Feature.PERSON, Person.THIRD);
- pro.setPlural(true);
- pro.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
- sent = phraseFactory.createClause(pro, "like", "John");
- Assert.assertEquals("They like John.", this.realiser
- .realiseSentence(sent));
-
- pro = phraseFactory.createNounPhrase("John");
- pro.setFeature(Feature.PRONOMINAL, true);
- pro.setFeature(Feature.PERSON, Person.FIRST);
- sent = phraseFactory.createClause("Mary", "like", pro);
- Assert.assertEquals("Mary likes me.", this.realiser
- .realiseSentence(sent));
-
- pro = phraseFactory.createNounPhrase("John");
- pro.setFeature(Feature.PRONOMINAL, true);
- pro.setFeature(Feature.PERSON, Person.SECOND);
- sent = phraseFactory.createClause("Mary", "like", pro);
- Assert.assertEquals("Mary likes you.", this.realiser
- .realiseSentence(sent));
-
- pro = phraseFactory.createNounPhrase("John");
- pro.setFeature(Feature.PRONOMINAL, true);
- pro.setFeature(Feature.PERSON, Person.THIRD);
- pro.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
- sent = phraseFactory.createClause("Mary", "like", pro);
- Assert.assertEquals("Mary likes him.", this.realiser
- .realiseSentence(sent));
-
- pro = phraseFactory.createNounPhrase("John");
- pro.setFeature(Feature.PRONOMINAL, true);
- pro.setFeature(Feature.PERSON, Person.FIRST);
- pro.setPlural(true);
- sent = phraseFactory.createClause("Mary", "like", pro);
- Assert.assertEquals("Mary likes us.", this.realiser
- .realiseSentence(sent));
-
- pro = phraseFactory.createNounPhrase("John");
- pro.setFeature(Feature.PRONOMINAL, true);
- pro.setFeature(Feature.PERSON, Person.SECOND);
- pro.setPlural(true);
- sent = phraseFactory.createClause("Mary", "like", pro);
- Assert.assertEquals("Mary likes you.", this.realiser
- .realiseSentence(sent));
-
- pro = phraseFactory.createNounPhrase("John");
- pro.setFeature(Feature.PRONOMINAL, true);
- pro.setFeature(Feature.PERSON, Person.THIRD);
- pro.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
- pro.setPlural(true);
- sent = phraseFactory.createClause("Mary", "like", pro);
- Assert.assertEquals("Mary likes them.", this.realiser
- .realiseSentence(sent));
- }
-
- /**
- * Test premodification in NPS.
- */
- @Test
- public void testPremodification() {
- this.man.addPreModifier(this.salacious);
- Assert.assertEquals("the salacious man", this.realiser //$NON-NLS-1$
- .realise(this.man).getRealisation());
-
- this.woman.addPreModifier(this.beautiful);
- Assert.assertEquals("the beautiful woman", this.realiser.realise( //$NON-NLS-1$
- this.woman).getRealisation());
-
- this.dog.addPreModifier(this.stunning);
- Assert.assertEquals("the stunning dog", this.realiser.realise(this.dog) //$NON-NLS-1$
- .getRealisation());
-
- // premodification with a WordElement
- this.man.setPreModifier(this.phraseFactory.createWord("idiotic",
- LexicalCategory.ADJECTIVE));
- Assert.assertEquals("the idiotic man", this.realiser //$NON-NLS-1$
- .realise(this.man).getRealisation());
-
- }
-
- /**
- * Test prepositional postmodification.
- */
- @Test
- public void testPostmodification() {
- this.man.addPostModifier(this.onTheRock);
- Assert.assertEquals("the man on the rock", this.realiser.realise( //$NON-NLS-1$
- this.man).getRealisation());
-
- this.woman.addPostModifier(this.behindTheCurtain);
- Assert.assertEquals("the woman behind the curtain", this.realiser //$NON-NLS-1$
- .realise(this.woman).getRealisation());
-
- // postmodification with a WordElement
- this.man.setPostModifier(this.phraseFactory.createWord("jack",
- LexicalCategory.NOUN));
- Assert.assertEquals("the man jack", this.realiser.realise( //$NON-NLS-1$
- this.man).getRealisation());
- }
-
- /**
- * Test nominal complementation
- */
- @Test
- public void testComplementation() {
- // complementation with a WordElement
- this.man.setComplement(this.phraseFactory.createWord("jack",
- LexicalCategory.NOUN));
- Assert.assertEquals("the man jack", this.realiser.realise( //$NON-NLS-1$
- this.man).getRealisation());
-
- this.woman.addComplement(this.behindTheCurtain);
- Assert.assertEquals("the woman behind the curtain", this.realiser //$NON-NLS-1$
- .realise(this.woman).getRealisation());
- }
-
- /**
- * Test possessive constructions.
- */
- @Test
- public void testPossessive() {
-
- // simple possessive 's: 'a man's'
- PhraseElement possNP = this.phraseFactory.createNounPhrase("a", "man"); //$NON-NLS-1$ //$NON-NLS-2$
- possNP.setFeature(Feature.POSSESSIVE, true);
- Assert.assertEquals("a man's", this.realiser.realise(possNP) //$NON-NLS-1$
- .getRealisation());
-
- // now set this possessive as specifier of the NP 'the dog'
- this.dog.setFeature(InternalFeature.SPECIFIER, possNP);
- Assert.assertEquals("a man's dog", this.realiser.realise(this.dog) //$NON-NLS-1$
- .getRealisation());
-
- // convert possNP to pronoun and turn "a dog" into "his dog"
- // need to specify gender, as default is NEUTER
- possNP.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
- possNP.setFeature(Feature.PRONOMINAL, true);
- Assert.assertEquals("his dog", this.realiser.realise(this.dog) //$NON-NLS-1$
- .getRealisation());
-
- // make it slightly more complicated: "his dog's rock"
- this.dog.setFeature(Feature.POSSESSIVE, true); // his dog's
-
- // his dog's rock (substituting "the"
- // for the
- // entire phrase)
- this.np4.setFeature(InternalFeature.SPECIFIER, this.dog);
- Assert.assertEquals("his dog's rock", this.realiser.realise(this.np4) //$NON-NLS-1$
- .getRealisation());
- }
-
- /**
- * Test NP coordination.
- */
- @Test
- public void testCoordination() {
-
- CoordinatedPhraseElement cnp1 = new CoordinatedPhraseElement(this.dog,
- this.woman);
- // simple coordination
- Assert.assertEquals("the dog and the woman", this.realiser //$NON-NLS-1$
- .realise(cnp1).getRealisation());
-
- // simple coordination with complementation of entire coordinate NP
- cnp1.addComplement(this.behindTheCurtain);
- Assert.assertEquals("the dog and the woman behind the curtain", //$NON-NLS-1$
- this.realiser.realise(cnp1).getRealisation());
-
- // raise the specifier in this cnp
- // Assert.assertEquals(true, cnp1.raiseSpecifier()); // should return
- // true as all
- // sub-nps have same spec
- // assertEquals("the dog and woman behind the curtain",
- // realiser.realise(cnp1));
- }
-
- /**
- * Another battery of tests for NP coordination.
- */
- @Test
- public void testCoordination2() {
-
- // simple coordination of complementised nps
- this.dog.clearComplements();
- this.woman.clearComplements();
-
- CoordinatedPhraseElement cnp1 = new CoordinatedPhraseElement(this.dog,
- this.woman);
- cnp1.setFeature(Feature.RAISE_SPECIFIER, true);
- NLGElement realised = this.realiser.realise(cnp1);
- Assert.assertEquals("the dog and woman", realised.getRealisation());
-
- this.dog.addComplement(this.onTheRock);
- this.woman.addComplement(this.behindTheCurtain);
-
- CoordinatedPhraseElement cnp2 = new CoordinatedPhraseElement(this.dog,
- this.woman);
-
- this.woman.setFeature(InternalFeature.RAISED, false);
- Assert.assertEquals(
- "the dog on the rock and the woman behind the curtain", //$NON-NLS-1$
- this.realiser.realise(cnp2).getRealisation());
-
- // complementised coordinates + outer pp modifier
- cnp2.addPostModifier(this.inTheRoom);
- Assert
- .assertEquals(
- "the dog on the rock and the woman behind the curtain in the room", //$NON-NLS-1$
- this.realiser.realise(cnp2).getRealisation());
-
- // set the specifier for this cnp; should unset specifiers for all inner
- // coordinates
- NLGElement every = this.phraseFactory.createWord(
- "every", LexicalCategory.DETERMINER); //$NON-NLS-1$
-
- cnp2.setFeature(InternalFeature.SPECIFIER, every);
-
- Assert
- .assertEquals(
- "every dog on the rock and every woman behind the curtain in the room", //$NON-NLS-1$
- this.realiser.realise(cnp2).getRealisation());
-
- // pronominalise one of the constituents
- this.dog.setFeature(Feature.PRONOMINAL, true); // ="it"
- this.dog.setFeature(InternalFeature.SPECIFIER, this.phraseFactory
- .createWord("the", LexicalCategory.DETERMINER));
- // raising spec still returns true as spec has been set
- cnp2.setFeature(Feature.RAISE_SPECIFIER, true);
-
- // CNP should be realised with pronominal internal const
- Assert.assertEquals(
- "it and every woman behind the curtain in the room", //$NON-NLS-1$
- this.realiser.realise(cnp2).getRealisation());
- }
-
- /**
- * Test possessives in coordinate NPs.
- */
- @Test
- public void testPossessiveCoordinate() {
- // simple coordination
- CoordinatedPhraseElement cnp2 = new CoordinatedPhraseElement(this.dog,
- this.woman);
- Assert.assertEquals("the dog and the woman", this.realiser //$NON-NLS-1$
- .realise(cnp2).getRealisation());
-
- // set possessive -- wide-scope by default
- cnp2.setFeature(Feature.POSSESSIVE, true);
- Assert.assertEquals("the dog and the woman's", this.realiser.realise( //$NON-NLS-1$
- cnp2).getRealisation());
-
- // set possessive with pronoun
- this.dog.setFeature(Feature.PRONOMINAL, true);
- this.dog.setFeature(Feature.POSSESSIVE, true);
- cnp2.setFeature(Feature.POSSESSIVE, true);
- Assert.assertEquals("its and the woman's", this.realiser.realise(cnp2) //$NON-NLS-1$
- .getRealisation());
-
- }
-
- /**
- * Test A vs An.
- */
- @Test
- public void testAAn() {
- PhraseElement _dog = this.phraseFactory.createNounPhrase("a", "dog"); //$NON-NLS-1$ //$NON-NLS-2$
- Assert.assertEquals("a dog", this.realiser.realise(_dog) //$NON-NLS-1$
- .getRealisation());
-
- _dog.addPreModifier("enormous"); //$NON-NLS-1$
-
- Assert.assertEquals("an enormous dog", this.realiser.realise(_dog) //$NON-NLS-1$
- .getRealisation());
-
- PhraseElement elephant = this.phraseFactory.createNounPhrase(
- "a", "elephant"); //$NON-NLS-1$ //$NON-NLS-2$
- Assert.assertEquals("an elephant", this.realiser.realise(elephant) //$NON-NLS-1$
- .getRealisation());
-
- elephant.addPreModifier("big"); //$NON-NLS-1$
- Assert.assertEquals("a big elephant", this.realiser.realise(elephant) //$NON-NLS-1$
- .getRealisation());
-
- // test treating of plural specifiers
- _dog.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
-
- Assert.assertEquals("some enormous dogs", this.realiser.realise(_dog) //$NON-NLS-1$
- .getRealisation());
- }
-
- /**
- * Further tests for a/an agreement with coordinated premodifiers
- */
- public void testAAnCoord() {
- NPPhraseSpec _dog = this.phraseFactory.createNounPhrase("a", "dog");
- _dog.addPreModifier(this.phraseFactory.createCoordinatedPhrase(
- "enormous", "black"));
- String realisation = this.realiser.realise(_dog).getRealisation();
- Assert.assertEquals("an enormous and black dog", realisation);
- }
-
- /**
- * Test for a/an agreement with numbers
- */
- public void testAAnWithNumbers() {
- NPPhraseSpec num = this.phraseFactory.createNounPhrase("a", "change");
- String realisation;
-
- // no an with "one"
- num.setPreModifier("one percent");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("a one percent change", realisation);
-
- // an with "eighty"
- num.setPreModifier("eighty percent");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("an eighty percent change", realisation);
-
- // an with 80
- num.setPreModifier("80%");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("an 80% change", realisation);
-
- // an with 80000
- num.setPreModifier("80000");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("an 80000 change", realisation);
-
- // an with 11,000
- num.setPreModifier("11,000");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("an 11,000 change", realisation);
-
- // an with 18
- num.setPreModifier("18%");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("an 18% change", realisation);
-
- // a with 180
- num.setPreModifier("180");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("a 180 change", realisation);
-
- // a with 1100
- num.setPreModifier("1100");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("a 1100 change", realisation);
-
- // a with 180,000
- num.setPreModifier("180,000");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("a 180,000 change", realisation);
-
- // an with 11000
- num.setPreModifier("11000");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("an 11000 change", realisation);
-
- // an with 18000
- num.setPreModifier("18000");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("an 18000 change", realisation);
-
- // an with 18.1
- num.setPreModifier("18.1%");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("an 18.1% change", realisation);
-
- // an with 11.1
- num.setPreModifier("11.1%");
- realisation = this.realiser.realise(num).getRealisation();
- Assert.assertEquals("an 11.1% change", realisation);
-
- }
-
- /**
- * Test Modifier "guess" placement.
- */
- @Test
- public void testModifier() {
- PhraseElement _dog = this.phraseFactory.createNounPhrase("a", "dog"); //$NON-NLS-1$ //$NON-NLS-2$
- _dog.addPreModifier("angry"); //$NON-NLS-1$
-
- Assert.assertEquals("an angry dog", this.realiser.realise(_dog) //$NON-NLS-1$
- .getRealisation());
-
- _dog.addPostModifier("in the park"); //$NON-NLS-1$
- Assert.assertEquals("an angry dog in the park", this.realiser.realise( //$NON-NLS-1$
- _dog).getRealisation());
-
- PhraseElement cat = this.phraseFactory.createNounPhrase("a", "cat"); //$NON-NLS-1$ //$NON-NLS-2$
- cat.addPreModifier(this.phraseFactory.createAdjectivePhrase("angry")); //$NON-NLS-1$
- Assert.assertEquals("an angry cat", this.realiser.realise(cat) //$NON-NLS-1$
- .getRealisation());
-
- cat.addPostModifier(this.phraseFactory.createPrepositionPhrase(
- "in", "the park")); //$NON-NLS-1$ //$NON-NLS-2$
- Assert.assertEquals("an angry cat in the park", this.realiser.realise( //$NON-NLS-1$
- cat).getRealisation());
-
- }
- @Test
- public void testPluralNounsBelongingToASingular() {
-
- SPhraseSpec sent = this.phraseFactory.createClause("I", "count up");
- sent.setFeature(Feature.TENSE, Tense.PAST);
- NPPhraseSpec obj = this.phraseFactory.createNounPhrase("digit");
- obj.setPlural(true);
- NPPhraseSpec possessor = this.phraseFactory.createNounPhrase("the", "box");
- possessor.setPlural(false);
- possessor.setFeature(Feature.POSSESSIVE, true);
- obj.setSpecifier(possessor);
- sent.setObject(obj);
-
- Assert.assertEquals("I counted up the box's digits", this.realiser.realise(sent) //$NON-NLS-1$
- .getRealisation());
- }
-
-
- @Test
- public void testSingularNounsBelongingToAPlural() {
-
- SPhraseSpec sent = this.phraseFactory.createClause("I", "clean");
- sent.setFeature(Feature.TENSE, Tense.PAST);
- NPPhraseSpec obj = this.phraseFactory.createNounPhrase("car");
- obj.setPlural(false);
- NPPhraseSpec possessor = this.phraseFactory.createNounPhrase("the", "parent");
- possessor.setPlural(true);
- possessor.setFeature(Feature.POSSESSIVE, true);
- obj.setSpecifier(possessor);
- sent.setObject(obj);
-
- Assert.assertEquals("I cleaned the parents' car", this.realiser.realise(sent) //$NON-NLS-1$
- .getRealisation());
- }
-
- /**
- * Test for appositive postmodifiers
- */
- @Test
- public void testAppositivePostmodifier() {
- PhraseElement _dog = this.phraseFactory.createNounPhrase("the", "dog");
- PhraseElement _rott = this.phraseFactory.createNounPhrase("a", "rottweiler");
- _rott.setFeature(Feature.APPOSITIVE, true);
- _dog.addPostModifier(_rott);
- SPhraseSpec _sent = this.phraseFactory.createClause(_dog, "ran");
- Assert.assertEquals("The dog, a rottweiler runs.", this.realiser.realiseSentence(_sent));
- }
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/OrthographyFormatTest.java b/SharpSimpleNLGUnitTests/syntax/english/OrthographyFormatTest.java
deleted file mode 100644
index 3fcd900..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/OrthographyFormatTest.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import java.util.Arrays;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.format.english.TextFormatter;
-import simplenlg.framework.DocumentElement;
-import simplenlg.framework.NLGElement;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.PPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.features.Feature;
-
-public class OrthographyFormatTest extends SimpleNLG4Test {
-
- private DocumentElement list1, list2;
- private DocumentElement listItem1, listItem2, listItem3;
- private String list1Realisation = new StringBuffer("* in the room")
- .append("\n* behind the curtain").append("\n").toString();
- private String list2Realisation = new StringBuffer("* on the rock")
- .append("\n* ").append(list1Realisation).append("\n").toString();
-
- public OrthographyFormatTest(String name) {
- super(name);
- }
-
- @Before
- public void setUp() {
- super.setUp();
-
- // need to set formatter for realiser (set to null in the test
- // superclass)
- this.realiser.setFormatter(new TextFormatter());
-
- // a couple phrases as list items
- this.listItem1 = this.phraseFactory.createListItem(this.inTheRoom);
- this.listItem2 = this.phraseFactory
- .createListItem(this.behindTheCurtain);
- this.listItem3 = this.phraseFactory.createListItem(this.onTheRock);
-
- // a simple depth-1 list of phrases
- this.list1 = this.phraseFactory
- .createList(Arrays.asList(new DocumentElement[] {
- this.listItem1, this.listItem2 }));
-
- // a list consisting of one phrase (depth-1) + a list )(depth-2)
- this.list2 = this.phraseFactory.createList(Arrays
- .asList(new DocumentElement[] { this.listItem3,
- this.phraseFactory.createListItem(this.list1) }));
- }
-
- @Override
- @After
- public void tearDown() {
- super.tearDown();
- this.list1 = null; this.list2 = null;
- this.listItem1 = null; this.listItem2 = null; this.listItem3 = null;
- this.list1Realisation = null;
- list2Realisation = null;
- }
-
- /**
- * Test the realisation of a simple list
- */
- @Test
- public void testSimpleListOrthography() {
- NLGElement realised = this.realiser.realise(this.list1);
- Assert.assertEquals(this.list1Realisation, realised.getRealisation());
- }
-
- /**
- * Test the realisation of a list with an embedded list
- */
- @Test
- public void testEmbeddedListOrthography() {
- NLGElement realised = this.realiser.realise(this.list2);
- Assert.assertEquals(this.list2Realisation, realised.getRealisation());
- }
-
- /**
- * Test the realisation of appositive pre-modifiers with commas around them.
- */
- @Test
- public void testAppositivePreModifiers() {
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("I");
- NPPhraseSpec object = this.phraseFactory.createNounPhrase("a bag");
-
- SPhraseSpec _s1 = this.phraseFactory.createClause(subject,
- "carry", object);
-
- // add a PP complement
- PPPhraseSpec pp = this.phraseFactory.createPrepositionPhrase("on",
- this.phraseFactory.createNounPhrase("most", "Tuesdays"));
- _s1.addPreModifier(pp);
-
- //without appositive feature on pp
- Assert.assertEquals(
- "I on most Tuesdays carry a bag", this.realiser
- .realise(_s1).getRealisation());
-
- //with appositive feature
- pp.setFeature(Feature.APPOSITIVE, true);
- Assert.assertEquals(
- "I, on most Tuesdays, carry a bag", this.realiser
- .realise(_s1).getRealisation());
- }
-
-
- /**
- * Test the realisation of appositive pre-modifiers with commas around them.
- */
- @Test
- public void testCommaSeparatedFrontModifiers() {
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("I");
- NPPhraseSpec object = this.phraseFactory.createNounPhrase("a bag");
-
- SPhraseSpec _s1 = this.phraseFactory.createClause(subject,
- "carry", object);
-
- // add a PP complement
- PPPhraseSpec pp1 = this.phraseFactory.createPrepositionPhrase("on",
- this.phraseFactory.createNounPhrase("most", "Tuesdays"));
- _s1.addFrontModifier(pp1);
-
- PPPhraseSpec pp2 = this.phraseFactory.createPrepositionPhrase("since",
- this.phraseFactory.createNounPhrase("1991"));
- _s1.addFrontModifier(pp2);
- pp1.setFeature(Feature.APPOSITIVE, true);
- pp2.setFeature(Feature.APPOSITIVE, true);
-
- //without setCommaSepCuephrase
- Assert.assertEquals(
- "on most Tuesdays since 1991 I carry a bag", this.realiser
- .realise(_s1).getRealisation());
-
- //with setCommaSepCuephrase
- this.realiser.setCommaSepCuephrase(true);
- Assert.assertEquals(
- "on most Tuesdays, since 1991, I carry a bag", this.realiser
- .realise(_s1).getRealisation());
- }
-
- /**
- * Ensure we don't end up with doubled commas.
- */
- @Test
- public void testNoDoubledCommas() {
- NPPhraseSpec subject = this.phraseFactory.createNounPhrase("I");
- NPPhraseSpec object = this.phraseFactory.createNounPhrase("a bag");
-
- SPhraseSpec _s1 = this.phraseFactory.createClause(subject,
- "carry", object);
-
- PPPhraseSpec pp1 = this.phraseFactory.createPrepositionPhrase("on",
- this.phraseFactory.createNounPhrase("most", "Tuesdays"));
- _s1.addFrontModifier(pp1);
-
- PPPhraseSpec pp2 = this.phraseFactory.createPrepositionPhrase("since",
- this.phraseFactory.createNounPhrase("1991"));
- PPPhraseSpec pp3 = this.phraseFactory.createPrepositionPhrase("except",
- this.phraseFactory.createNounPhrase("yesterday"));
-
- pp2.setFeature(Feature.APPOSITIVE, true);
- pp3.setFeature(Feature.APPOSITIVE, true);
-
- pp1.addPostModifier(pp2);
- pp1.addPostModifier(pp3);
-
- this.realiser.setCommaSepCuephrase(true);
-
- Assert.assertEquals(
- "on most Tuesdays, since 1991, except yesterday, I carry a bag", this.realiser
- .realise(_s1).getRealisation());
- // without my fix (that we're testing here), you'd end up with
- // "on most Tuesdays, since 1991,, except yesterday, I carry a bag"
- }
-
-// <[on most Tuesdays, since 1991, except yesterday, ]I carry a bag> but was:<[]I carry a bag>
-
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/PhraseSpecTest.java b/SharpSimpleNLGUnitTests/syntax/english/PhraseSpecTest.java
deleted file mode 100644
index 1838704..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/PhraseSpecTest.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.syntax.english;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.features.Tense;
-import simplenlg.framework.InflectedWordElement;
-import simplenlg.framework.NLGElement;
-import simplenlg.framework.PhraseElement;
-import simplenlg.framework.StringElement;
-import simplenlg.framework.WordElement;
-import simplenlg.phrasespec.SPhraseSpec;
-
-/**
- * test suite for simple XXXPhraseSpec classes
- * @author ereiter
- *
- */
-
-public class PhraseSpecTest extends SimpleNLG4Test {
-
- public PhraseSpecTest(String name) {
- super(name);
- }
-
-
- @Override
- @After
- public void tearDown() {
- super.tearDown();
- }
-
- /**
- * Check that empty phrases are not realised as "null"
- */
- @Test
- public void emptyPhraseRealisationTest() {
- SPhraseSpec emptyClause = this.phraseFactory.createClause();
- Assert.assertEquals("", this.realiser.realise(emptyClause)
- .getRealisation());
- }
-
-
- /**
- * Test SPhraseSpec
- */
- @Test
- public void testSPhraseSpec() {
-
- // simple test of methods
- SPhraseSpec c1 = (SPhraseSpec) phraseFactory.createClause();
- c1.setVerb("give");
- c1.setSubject("John");
- c1.setObject("an apple");
- c1.setIndirectObject("Mary");
- c1.setFeature(Feature.TENSE, Tense.PAST);
- c1.setFeature(Feature.NEGATED, true);
-
- // check getXXX methods
- Assert.assertEquals("give", getBaseForm(c1.getVerb()));
- Assert.assertEquals("John", getBaseForm(c1.getSubject()));
- Assert.assertEquals("an apple", getBaseForm(c1.getObject()));
- Assert.assertEquals("Mary", getBaseForm(c1.getIndirectObject()));
-
- Assert.assertEquals("John did not give Mary an apple", this.realiser //$NON-NLS-1$
- .realise(c1).getRealisation());
-
-
-
- // test modifier placement
- SPhraseSpec c2 = (SPhraseSpec) phraseFactory.createClause();
- c2.setVerb("see");
- c2.setSubject("the man");
- c2.setObject("me");
- c2.addModifier("fortunately");
- c2.addModifier("quickly");
- c2.addModifier("in the park");
- // try setting tense directly as a feature
- c2.setFeature(Feature.TENSE, Tense.PAST);
- Assert.assertEquals("fortunately the man quickly saw me in the park", this.realiser //$NON-NLS-1$
- .realise(c2).getRealisation());
- }
-
- // get string for head of constituent
- private String getBaseForm(NLGElement constituent) {
- if (constituent == null)
- return null;
- else if (constituent instanceof StringElement)
- return constituent.getRealisation();
- else if (constituent instanceof WordElement)
- return ((WordElement)constituent).getBaseForm();
- else if (constituent instanceof InflectedWordElement)
- return getBaseForm(((InflectedWordElement)constituent).getBaseWord());
- else if (constituent instanceof PhraseElement)
- return getBaseForm(((PhraseElement)constituent).getHead());
- else
- return null;
- }
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/PremodifierTest.java b/SharpSimpleNLGUnitTests/syntax/english/PremodifierTest.java
deleted file mode 100644
index e5feff2..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/PremodifierTest.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, and Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import junit.framework.Assert;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.features.Tense;
-import simplenlg.framework.NLGFactory;
-import simplenlg.lexicon.Lexicon;
-import simplenlg.phrasespec.AdvPhraseSpec;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.phrasespec.VPPhraseSpec;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * {@link PremodifierTest} contains a series of JUnit test cases for Premodifiers.
- *
- * @author Saad Mahamood
- */
-public class PremodifierTest {
-
- private Lexicon lexicon = null;
- private NLGFactory phraseFactory = null;
- private Realiser realiser = null;
-
- @Before
- public void setup() {
- lexicon = Lexicon.getDefaultLexicon();
- phraseFactory = new NLGFactory(lexicon);
- realiser = new Realiser(lexicon);
- }
-
-
-
- /**
- * Test change from "a" to "an" in the presence of a premodifier with a
- * vowel
- */
- @Test
- public void indefiniteWithPremodifierTest() {
- SPhraseSpec s = this.phraseFactory.createClause("there", "be");
- s.setFeature(Feature.TENSE, Tense.PRESENT);
- NPPhraseSpec np = this.phraseFactory.createNounPhrase("a", "stenosis");
- s.setObject(np);
-
- // check without modifiers -- article should be "a"
- Assert.assertEquals("there is a stenosis", this.realiser.realise(s)
- .getRealisation());
-
- // add a single modifier -- should turn article to "an"
- np.addPreModifier(this.phraseFactory.createAdjectivePhrase("eccentric"));
- Assert.assertEquals("there is an eccentric stenosis", this.realiser
- .realise(s).getRealisation());
- }
-
- /**
- * Test for comma separation between premodifers
- */
- @Test
- public void multipleAdjPremodifiersTest() {
- NPPhraseSpec np = this.phraseFactory.createNounPhrase("a", "stenosis");
- np.addPreModifier(this.phraseFactory.createAdjectivePhrase("eccentric"));
- np.addPreModifier(this.phraseFactory.createAdjectivePhrase("discrete"));
- Assert.assertEquals("an eccentric, discrete stenosis", this.realiser
- .realise(np).getRealisation());
- }
-
- /**
- * Test for comma separation between verb premodifiers
- */
- @Test
- public void multipleAdvPremodifiersTest() {
- AdvPhraseSpec adv1 = this.phraseFactory.createAdverbPhrase("slowly");
- AdvPhraseSpec adv2 = this.phraseFactory
- .createAdverbPhrase("discretely");
-
- // case 1: concatenated premods: should have comma
- VPPhraseSpec vp = this.phraseFactory.createVerbPhrase("run");
- vp.addPreModifier(adv1);
- vp.addPreModifier(adv2);
- Assert.assertEquals("slowly, discretely runs", this.realiser
- .realise(vp).getRealisation());
-
- // case 2: coordinated premods: no comma
- VPPhraseSpec vp2 = this.phraseFactory.createVerbPhrase("eat");
- vp2.addPreModifier(this.phraseFactory.createCoordinatedPhrase(adv1,
- adv2));
- Assert.assertEquals("slowly and discretely eats", this.realiser
- .realise(vp2).getRealisation());
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/PrepositionalPhraseTest.java b/SharpSimpleNLGUnitTests/syntax/english/PrepositionalPhraseTest.java
deleted file mode 100644
index 647998d..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/PrepositionalPhraseTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.framework.CoordinatedPhraseElement;
-
-// TODO: Auto-generated Javadoc
-/**
- * This class groups together some tests for prepositional phrases and
- * coordinate prepositional phrases.
- * @author agatt
- */
-public class PrepositionalPhraseTest extends SimpleNLG4Test {
-
- /**
- * Instantiates a new pP test.
- *
- * @param name
- * the name
- */
- public PrepositionalPhraseTest(String name) {
- super(name);
- }
-
- @Override
- @After
- public void tearDown() {
- super.tearDown();
- }
-
- /**
- * Basic test for the pre-set PP fixtures.
- */
- @Test
- public void testBasic() {
- Assert.assertEquals("in the room", this.realiser //$NON-NLS-1$
- .realise(this.inTheRoom).getRealisation());
- Assert.assertEquals("behind the curtain", this.realiser //$NON-NLS-1$
- .realise(this.behindTheCurtain).getRealisation());
- Assert.assertEquals("on the rock", this.realiser //$NON-NLS-1$
- .realise(this.onTheRock).getRealisation());
- }
-
- /**
- * Test for coordinate NP complements of PPs.
- */
- @Test
- public void testComplementation() {
- this.inTheRoom.clearComplements();
- this.inTheRoom.addComplement(new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("the", "room"), //$NON-NLS-1$ //$NON-NLS-2$
- this.phraseFactory.createNounPhrase("a", "car"))); //$NON-NLS-1$//$NON-NLS-2$
- Assert.assertEquals("in the room and a car", this.realiser //$NON-NLS-1$
- .realise(this.inTheRoom).getRealisation());
- }
-
- /**
- * Test for PP coordination.
- */
- public void testCoordination() {
- // simple coordination
-
- CoordinatedPhraseElement coord1 = new CoordinatedPhraseElement(
- this.inTheRoom, this.behindTheCurtain);
- Assert.assertEquals("in the room and behind the curtain", this.realiser //$NON-NLS-1$
- .realise(coord1).getRealisation());
-
- // change the conjunction
- coord1.setFeature(Feature.CONJUNCTION, "or"); //$NON-NLS-1$
- Assert.assertEquals("in the room or behind the curtain", this.realiser //$NON-NLS-1$
- .realise(coord1).getRealisation());
-
- // new coordinate
- CoordinatedPhraseElement coord2 = new CoordinatedPhraseElement(
- this.onTheRock, this.underTheTable);
- coord2.setFeature(Feature.CONJUNCTION, "or"); //$NON-NLS-1$
- Assert.assertEquals("on the rock or under the table", this.realiser //$NON-NLS-1$
- .realise(coord2).getRealisation());
-
- // coordinate two coordinates
- CoordinatedPhraseElement coord3 = new CoordinatedPhraseElement(coord1,
- coord2);
-
- String text = this.realiser.realise(coord3).getRealisation();
- Assert
- .assertEquals(
- "in the room or behind the curtain and on the rock or under the table", //$NON-NLS-1$
- text);
- }
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/SimpleNLG4Test.java b/SharpSimpleNLGUnitTests/syntax/english/SimpleNLG4Test.java
deleted file mode 100644
index d8b3cd8..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/SimpleNLG4Test.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.syntax.english;
-
-import junit.framework.TestCase;
-
-import org.junit.After;
-import org.junit.Before;
-
-
-import simplenlg.framework.NLGFactory;
-import simplenlg.framework.PhraseElement;
-import simplenlg.lexicon.XMLLexicon;
-import simplenlg.lexicon.Lexicon;
-import simplenlg.phrasespec.VPPhraseSpec;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * This class is the base class for all JUnit simplenlg.test cases for
- * simplenlg. It sets up a a JUnit fixture, i.e. the basic objects (basic
- * constituents) that all other tests can use.
- * @author agatt
- */
-public abstract class SimpleNLG4Test extends TestCase {
-
- /** The realiser. */
- protected Realiser realiser;
-
- protected NLGFactory phraseFactory;
-
- protected Lexicon lexicon;
-
- /** The pro test2. */
- protected PhraseElement man, woman, dog, boy, np4, np5, np6, proTest1, proTest2;
-
- /** The salacious. */
- protected PhraseElement beautiful, stunning, salacious;
-
- /** The under the table. */
- protected PhraseElement onTheRock, behindTheCurtain, inTheRoom, underTheTable;
-
- /** The say. */
- protected VPPhraseSpec kick, kiss, walk, talk, getUp, fallDown, give, say;
-
- /**
- * Instantiates a new simplenlg test.
- *
- * @param name
- * the name
- */
- public SimpleNLG4Test(String name) {
- super(name);
- }
-
- /**
- * Set up the variables we'll need for this simplenlg.test to run (Called
- * automatically by JUnit)
- */
- @Override
- @Before
- protected void setUp() {
- lexicon = new XMLLexicon(); // built in lexicon
-
- this.phraseFactory = new NLGFactory(this.lexicon);
- this.realiser = new Realiser(this.lexicon);
-
- this.man = this.phraseFactory.createNounPhrase("the", "man"); //$NON-NLS-1$ //$NON-NLS-2$
- this.woman = this.phraseFactory.createNounPhrase("the", "woman"); //$NON-NLS-1$//$NON-NLS-2$
- this.dog = this.phraseFactory.createNounPhrase("the", "dog"); //$NON-NLS-1$ //$NON-NLS-2$
- this.boy = this.phraseFactory.createNounPhrase("the", "boy"); //$NON-NLS-1$ //$NON-NLS-2$
-
- this.beautiful = this.phraseFactory.createAdjectivePhrase("beautiful"); //$NON-NLS-1$
- this.stunning = this.phraseFactory.createAdjectivePhrase("stunning"); //$NON-NLS-1$
- this.salacious = this.phraseFactory.createAdjectivePhrase("salacious"); //$NON-NLS-1$
-
- this.onTheRock = this.phraseFactory.createPrepositionPhrase("on"); //$NON-NLS-1$
- this.np4 = this.phraseFactory.createNounPhrase("the", "rock"); //$NON-NLS-1$ //$NON-NLS-2$
- this.onTheRock.addComplement(this.np4);
-
- this.behindTheCurtain = this.phraseFactory.createPrepositionPhrase("behind"); //$NON-NLS-1$
- this.np5 = this.phraseFactory.createNounPhrase("the", "curtain"); //$NON-NLS-1$ //$NON-NLS-2$
- this.behindTheCurtain.addComplement(this.np5);
-
- this.inTheRoom = this.phraseFactory.createPrepositionPhrase("in"); //$NON-NLS-1$
- this.np6 = this.phraseFactory.createNounPhrase("the", "room"); //$NON-NLS-1$ //$NON-NLS-2$
- this.inTheRoom.addComplement(this.np6);
-
- this.underTheTable = this.phraseFactory.createPrepositionPhrase("under"); //$NON-NLS-1$
- this.underTheTable.addComplement(this.phraseFactory.createNounPhrase("the", "table")); //$NON-NLS-1$ //$NON-NLS-2$
-
- this.proTest1 = this.phraseFactory.createNounPhrase("the", "singer"); //$NON-NLS-1$ //$NON-NLS-2$
- this.proTest2 = this.phraseFactory.createNounPhrase("some", "person"); //$NON-NLS-1$ //$NON-NLS-2$
-
- this.kick = this.phraseFactory.createVerbPhrase("kick"); //$NON-NLS-1$
- this.kiss = this.phraseFactory.createVerbPhrase("kiss"); //$NON-NLS-1$
- this.walk = this.phraseFactory.createVerbPhrase("walk"); //$NON-NLS-1$
- this.talk = this.phraseFactory.createVerbPhrase("talk"); //$NON-NLS-1$
- this.getUp = this.phraseFactory.createVerbPhrase("get up"); //$NON-NLS-1$
- this.fallDown = this.phraseFactory.createVerbPhrase("fall down"); //$NON-NLS-1$
- this.give = this.phraseFactory.createVerbPhrase("give"); //$NON-NLS-1$
- this.say = this.phraseFactory.createVerbPhrase("say"); //$NON-NLS-1$
- }
-
- @Override
- @After
- public void tearDown() {
- this.realiser = null;
-
- this.phraseFactory = null;
-
- if(null != lexicon) {
- lexicon = null;
- }
-
- this.man = null; this.woman = null; this.dog = null; this.boy = null;
- this.np4 = null; this.np5 = null; this.np6 = null; this.proTest1 = null;
- this.proTest2 = null;
-
- this.beautiful = null; this.stunning = null; this.salacious = null;
-
- this.onTheRock = null; this.behindTheCurtain= null;
- this.inTheRoom = null; this.underTheTable = null;
-
- this.kick = null; this.kiss = null; this.walk = null; this.talk = null;
- this.getUp = null; this.fallDown = null; this.give = null; this.say = null;
- }
-
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/StandAloneExample.java b/SharpSimpleNLGUnitTests/syntax/english/StandAloneExample.java
deleted file mode 100644
index 14e01d1..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/StandAloneExample.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-package simplenlg.syntax.english;
-
-import org.junit.Ignore;
-
-import simplenlg.features.Feature;
-import simplenlg.features.Tense;
-import simplenlg.framework.DocumentElement;
-import simplenlg.framework.InflectedWordElement;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.NLGElement;
-import simplenlg.framework.NLGFactory;
-import simplenlg.framework.StringElement;
-import simplenlg.framework.WordElement;
-import simplenlg.lexicon.Lexicon;
-import simplenlg.lexicon.XMLLexicon;
-import simplenlg.phrasespec.AdjPhraseSpec;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.PPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * @author Dave Westwater, Data2Text Ltd
- *
- */
-@Ignore
-public class StandAloneExample {
-
- /**
- * @param args
- */
- public static void main(String[] args) {
-
- // below is a simple complete example of using simplenlg V4
- // afterwards is an example of using simplenlg just for morphology
-
- // set up
- Lexicon lexicon = new XMLLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
-
- // create sentences
- // "John did not go to the bigger park. He played football there."
- NPPhraseSpec thePark = nlgFactory.createNounPhrase("the", "park"); // create an NP
- AdjPhraseSpec bigp = nlgFactory.createAdjectivePhrase("big"); // create AdjP
- bigp.setFeature(Feature.IS_COMPARATIVE, true); // use comparative form ("bigger")
- thePark.addModifier(bigp); // add adj as modifier in NP
- // above relies on default placement rules. You can force placement as a premodifier
- // (before head) by using addPreModifier
- PPPhraseSpec toThePark = nlgFactory.createPrepositionPhrase("to"); // create a PP
- toThePark.setObject(thePark); // set PP object
- // could also just say nlgFactory.createPrepositionPhrase("to", the Park);
-
- SPhraseSpec johnGoToThePark = nlgFactory.createClause("John", // create sentence
- "go", toThePark);
-
- johnGoToThePark.setFeature(Feature.TENSE,Tense.PAST); // set tense
- johnGoToThePark.setFeature(Feature.NEGATED, true); // set negated
-
- // note that constituents (such as subject and object) are set with setXXX methods
- // while features are set with setFeature
-
- DocumentElement sentence = nlgFactory // create a sentence DocumentElement from SPhraseSpec
- .createSentence(johnGoToThePark);
-
- // below creates a sentence DocumentElement by concatenating strings
- StringElement hePlayed = new StringElement("he played");
- StringElement there = new StringElement("there");
- WordElement football = new WordElement("football");
-
- DocumentElement sentence2 = nlgFactory.createSentence();
- sentence2.addComponent(hePlayed);
- sentence2.addComponent(football);
- sentence2.addComponent(there);
-
- // now create a paragraph which contains these sentences
- DocumentElement paragraph = nlgFactory.createParagraph();
- paragraph.addComponent(sentence);
- paragraph.addComponent(sentence2);
-
- // create a realiser. Note that a lexicon is specified, this should be
- // the same one used by the NLGFactory
- Realiser realiser = new Realiser(lexicon);
- //realiser.setDebugMode(true); // uncomment this to print out debug info during realisation
- NLGElement realised = realiser.realise(paragraph);
-
- System.out.println(realised.getRealisation());
-
- // end of main example
-
- // second example - using simplenlg just for morphology
- // below is clumsy as direct access to morphology isn't properly supported in V4.2
- // hopefully will be better supported in later versions
-
- // get word element for "child"
- WordElement word = (WordElement) nlgFactory.createWord("child", LexicalCategory.NOUN);
- // create InflectedWordElement from word element
- InflectedWordElement inflectedWord = new InflectedWordElement(word);
- // set the inflected word to plural
- inflectedWord.setPlural(true);
- // realise the inflected word
- String result = realiser.realise(inflectedWord).getRealisation();
-
- System.out.println(result);
- }
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/StringElementTest.java b/SharpSimpleNLGUnitTests/syntax/english/StringElementTest.java
deleted file mode 100644
index 07c40f7..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/StringElementTest.java
+++ /dev/null
@@ -1,407 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import static org.junit.Assert.*;
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import simplenlg.framework.CoordinatedPhraseElement;
-import simplenlg.framework.DocumentElement;
-import simplenlg.framework.LexicalCategory;
-import simplenlg.framework.NLGElement;
-import simplenlg.framework.NLGFactory;
-import simplenlg.framework.StringElement;
-import simplenlg.lexicon.Lexicon;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * Tests for string elements as parts of larger phrases
- *
- * @author bertugatt
- *
- */
-public class StringElementTest {
-
- private Lexicon lexicon = null;
- private NLGFactory phraseFactory = null;
- private Realiser realiser = null;
-
- @Before
- public void setup() {
- lexicon = Lexicon.getDefaultLexicon();
- phraseFactory = new NLGFactory(lexicon);
- realiser = new Realiser(lexicon);
- }
-
- @After
- public void tearDown() {
- lexicon = null;
- phraseFactory = null;
- realiser = null;
- }
-
- /**
- * Test that string elements can be used as heads of NP
- */
- @Test
- public void stringElementAsHeadTest() {
- NPPhraseSpec np = this.phraseFactory.createNounPhrase();
- np.setHead(phraseFactory.createStringElement("dogs and cats"));
- np.setSpecifier(phraseFactory.createWord("the",
- LexicalCategory.DETERMINER));
- assertEquals("the dogs and cats", this.realiser.realise(np)
- .getRealisation());
- }
-
- /**
- * Sentences whose VP is a canned string
- */
- @Test
- public void stringElementAsVPTest() {
- SPhraseSpec s = this.phraseFactory.createClause();
- s.setVerbPhrase(this.phraseFactory.createStringElement("eats and drinks"));
- s.setSubject(this.phraseFactory.createStringElement("the big fat man"));
- assertEquals("the big fat man eats and drinks", this.realiser
- .realise(s).getRealisation());
- }
-
- /**
- * Test for when the SPhraseSpec has a NPSpec added directly after it:
- * "Mary loves NP[the cow]."
- */
- @Test
- public void tailNPStringElementTest() {
- SPhraseSpec senSpec = this.phraseFactory.createClause();
- senSpec.addComplement((this.phraseFactory.createStringElement("mary loves")));
- NPPhraseSpec np = this.phraseFactory.createNounPhrase();
- np.setHead("cow");
- np.setDeterminer("the");
- senSpec.addComplement(np);
- DocumentElement completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- assertEquals("Mary loves the cow.", this.realiser.realise(completeSen).getRealisation());
- }
-
- /**
- * Test for a NP followed by a canned text: "NP[A cat] loves a dog".
- */
- @Test
- public void frontNPStringElementTest() {
- SPhraseSpec senSpec = this.phraseFactory.createClause();
- NPPhraseSpec np = this.phraseFactory.createNounPhrase();
- np.setHead("cat");
- np.setDeterminer("the");
- senSpec.addComplement(np);
- senSpec.addComplement(this.phraseFactory.createStringElement("loves a dog"));
- DocumentElement completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- assertEquals("The cat loves a dog.", this.realiser.realise(completeSen).getRealisation());
- }
-
-
- /**
- * Test for a StringElement followed by a NP followed by a StringElement
- * "The world loves NP[ABBA] but not a sore loser."
- */
- @Test
- public void mulitpleStringElementsTest() {
- SPhraseSpec senSpec = this.phraseFactory.createClause();
- senSpec.addComplement(this.phraseFactory.createStringElement("the world loves"));
- NPPhraseSpec np = this.phraseFactory.createNounPhrase();
- np.setHead("ABBA");
- senSpec.addComplement(np);
- senSpec.addComplement(this.phraseFactory.createStringElement("but not a sore loser"));
- DocumentElement completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- assertEquals("The world loves ABBA but not a sore loser.", this.realiser.realise(completeSen).getRealisation());
- }
-
- /**
- * Test for multiple NP phrases with a single StringElement phrase:
- * "NP[John is] a trier NP[for cheese]."
- */
- @Test
- public void mulitpleNPElementsTest() {
- SPhraseSpec senSpec = this.phraseFactory.createClause();
- NPPhraseSpec frontNoun = this.phraseFactory.createNounPhrase();
- frontNoun.setHead("john");
- senSpec.addComplement(frontNoun);
- senSpec.addComplement(this.phraseFactory.createStringElement("is a trier"));
- NPPhraseSpec backNoun = this.phraseFactory.createNounPhrase();
- backNoun.setDeterminer("for");
- backNoun.setNoun("cheese");
- senSpec.addComplement(backNoun);
- DocumentElement completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- assertEquals("John is a trier for cheese.", this.realiser.realise(completeSen).getRealisation());
-
- }
-
-
- /**
- * White space check: Test to see how SNLG deals with additional whitespaces:
- *
- * NP[The Nasdaq] rose steadily during NP[early trading], however it plummeted due to NP[a shock] after NP[IBM] announced poor
- * NP[first quarter results].
- */
- @Test
- public void whiteSpaceNPTest() {
- SPhraseSpec senSpec = this.phraseFactory.createClause();
- NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase();
- firstNoun.setDeterminer("the");
- firstNoun.setNoun("Nasdaq");
- senSpec.addComplement(firstNoun);
- senSpec.addComplement(this.phraseFactory.createStringElement(" rose steadily during "));
- NPPhraseSpec secondNoun = this.phraseFactory.createNounPhrase();
- secondNoun.setSpecifier("early");
- secondNoun.setNoun("trading");
- senSpec.addComplement(secondNoun);
- senSpec.addComplement(this.phraseFactory.createStringElement(" , however it plummeted due to"));
- NPPhraseSpec thirdNoun = this.phraseFactory.createNounPhrase();
- thirdNoun.setSpecifier("a");
- thirdNoun.setNoun("shock");
- senSpec.addComplement(thirdNoun);
- senSpec.addComplement(this.phraseFactory.createStringElement(" after "));
- NPPhraseSpec fourthNoun = this.phraseFactory.createNounPhrase();
- fourthNoun.setNoun("IBM");
- senSpec.addComplement(fourthNoun);
- senSpec.addComplement(this.phraseFactory.createStringElement("announced poor "));
- NPPhraseSpec fifthNoun = this.phraseFactory.createNounPhrase();
- fifthNoun.setSpecifier("first quarter");
- fifthNoun.setNoun("results");
- fifthNoun.setPlural(true);
- senSpec.addComplement(fifthNoun);
- DocumentElement completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- assertEquals("The Nasdaq rose steadily during early trading, however it plummeted due to a shock after IBM announced poor first quarter results.",
- this.realiser.realise(completeSen).getRealisation());
- }
-
- /**
- * Point absorption test: Check to see if SNLG respects abbreviations at the end of a sentence.
- * "NP[Yahya] was sleeping his own and dreaming etc."
- */
-
- public void pointAbsorptionTest() {
- SPhraseSpec senSpec = this.phraseFactory.createClause();
- NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase();
- firstNoun.setNoun("yaha");
- senSpec.addComplement(firstNoun);
- senSpec.addComplement("was sleeping on his own and dreaming etc.");
- DocumentElement completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- assertEquals("Yaha was sleeping on his own and dreaming etc.",
- this.realiser.realise(completeSen).getRealisation());
-
-
- }
-
- /**
- * Point absorption test: As above, but with trailing white space.
- * "NP[Yaha] was sleeping his own and dreaming etc. "
- */
- public void pointAbsorptionTrailingWhiteSpaceTest() {
- SPhraseSpec senSpec = this.phraseFactory.createClause();
- NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase();
- firstNoun.setNoun("yaha");
- senSpec.addComplement(firstNoun);
- senSpec.addComplement("was sleeping on his own and dreaming etc. ");
- DocumentElement completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- assertEquals("Yaha was sleeping on his own and dreaming etc.",
- this.realiser.realise(completeSen).getRealisation());
- }
-
- /**
- * Abbreviation test: Check to see how SNLG deals with abbreviations in the middle of a sentence.
- *
- * "NP[Yahya] and friends etc. went to NP[the park] to play."
- */
- @Test
- public void middleAbbreviationTest() {
- SPhraseSpec senSpec = this.phraseFactory.createClause();
- NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase();
- firstNoun.setNoun("yahya");
- senSpec.addComplement(firstNoun);
- senSpec.addComplement(this.phraseFactory.createStringElement("and friends etc. went to"));
- NPPhraseSpec secondNoun = this.phraseFactory.createNounPhrase();
- secondNoun.setDeterminer("the");
- secondNoun.setNoun("park");
- senSpec.addComplement(secondNoun);
- senSpec.addComplement("to play");
- DocumentElement completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- assertEquals("Yahya and friends etc. went to the park to play.",
- this.realiser.realise(completeSen).getRealisation());
- }
-
-
- /**
- * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
- * "I see an NP[elephant]"
- */
- @Test
- public void stringIndefiniteArticleInflectionVowelTest() {
- SPhraseSpec senSpec = this.phraseFactory.createClause();
- senSpec.addComplement(this.phraseFactory.createStringElement("I see a"));
- NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase("elephant");
- senSpec.addComplement(firstNoun);
- DocumentElement completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- assertEquals("I see an elephant.",
- this.realiser.realise(completeSen).getRealisation());
-
- }
-
- /**
- * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
- * "I see NP[a elephant]" -->
- */
- @Test
- public void NPIndefiniteArticleInflectionVowelTest() {
- SPhraseSpec senSpec = this.phraseFactory.createClause();
- senSpec.addComplement(this.phraseFactory.createStringElement("I see"));
- NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase("elephant");
- firstNoun.setDeterminer("a");
- senSpec.addComplement(firstNoun);
- DocumentElement completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- assertEquals("I see an elephant.",
- this.realiser.realise(completeSen).getRealisation());
-
- }
-
-
- /**
- * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
- * "I see an NP[cow]"
- */
- @Test
- public void stringIndefiniteArticleInflectionConsonantTest() {
- SPhraseSpec senSpec = this.phraseFactory.createClause();
- senSpec.addComplement(this.phraseFactory.createStringElement("I see an"));
- NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase("cow");
- senSpec.addComplement(firstNoun);
- DocumentElement completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- // Do not attempt "an" -> "a"
- assertNotSame("I see an cow.",
- this.realiser.realise(completeSen).getRealisation());
- }
-
- /**
- * Indefinite Article Inflection: StringElement to test how SNLG handles a/an situations.
- * "I see NP[an cow]" -->
- */
- @Test
- public void NPIndefiniteArticleInflectionConsonantTest() {
- SPhraseSpec senSpec = this.phraseFactory.createClause();
- senSpec.addComplement(this.phraseFactory.createStringElement("I see"));
- NPPhraseSpec firstNoun = this.phraseFactory.createNounPhrase("cow");
- firstNoun.setDeterminer("an");
- senSpec.addComplement(firstNoun);
- DocumentElement completeSen = this.phraseFactory.createSentence();
- completeSen.addComponent(senSpec);
- // Do not attempt "an" -> "a"
- assertEquals("I see an cow.",
- this.realiser.realise(completeSen).getRealisation());
- }
-
-
- /**
- * aggregationStringElementTest: Test to see if we can aggregate two StringElements in a CoordinatedPhraseElement.
- */
- @Test
- public void aggregationStringElementTest() {
-
- CoordinatedPhraseElement coordinate =
- phraseFactory.createCoordinatedPhrase(new StringElement("John is going to Tesco"),
- new StringElement("Mary is going to Sainsburys"));
- SPhraseSpec sentence = phraseFactory.createClause();
- sentence.addComplement(coordinate);
-
- assertEquals("John is going to Tesco and Mary is going to Sainsburys.",
- realiser.realiseSentence(sentence));
- }
-
-
- /**
- * Tests that no empty space is added when a StringElement is instantiated with an empty string
- * or null object.
- */
- @Test
- public void nullAndEmptyStringElementTest() {
-
- NLGElement nullStringElement = this.phraseFactory.createStringElement(null);
- NLGElement emptyStringElement = this.phraseFactory.createStringElement("");
- NLGElement beautiful = this.phraseFactory.createStringElement("beautiful");
- NLGElement horseLike = this.phraseFactory.createStringElement("horse-like");
- NLGElement creature = this.phraseFactory.createStringElement("creature");
-
- // Test1: null or empty at beginning
- SPhraseSpec test1 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
- test1.addPostModifier(emptyStringElement);
- test1.addPostModifier(beautiful);
- test1.addPostModifier(horseLike);
- test1.addPostModifier(creature);
- System.out.println(realiser.realiseSentence(test1));
- Assert.assertEquals("A unicorn is regarded as a beautiful horse-like creature.",
- realiser.realiseSentence(test1));
-
- // Test2: empty or null at end
- SPhraseSpec test2 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
- test2.addPostModifier(beautiful);
- test2.addPostModifier(horseLike);
- test2.addPostModifier(creature);
- test2.addPostModifier(nullStringElement);
- System.out.println(realiser.realiseSentence(test2));
- Assert.assertEquals("A unicorn is regarded as a beautiful horse-like creature.",
- realiser.realiseSentence(test2));
-
- // Test3: empty or null in the middle
- SPhraseSpec test3 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
- test3.addPostModifier("beautiful");
- test3.addPostModifier("horse-like");
- test3.addPostModifier("");
- test3.addPostModifier("creature");
- System.out.println(realiser.realiseSentence(test3));
- Assert.assertEquals("A unicorn is regarded as a beautiful horse-like creature.",
- realiser.realiseSentence(test3));
-
- // Test4: empty or null in the middle with empty or null at beginning
- SPhraseSpec test4 = this.phraseFactory.createClause("a unicorn", "be", "regarded as a");
- test4.addPostModifier("");
- test4.addPostModifier("beautiful");
- test4.addPostModifier("horse-like");
- test4.addPostModifier(nullStringElement);
- test4.addPostModifier("creature");
- System.out.println(realiser.realiseSentence(test4));
- Assert.assertEquals("A unicorn is regarded as a beautiful horse-like creature.",
- realiser.realiseSentence(test4));
-
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/TutorialTest.java b/SharpSimpleNLGUnitTests/syntax/english/TutorialTest.java
deleted file mode 100644
index 153bd8c..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/TutorialTest.java
+++ /dev/null
@@ -1,450 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import static org.junit.Assert.*;
-
-import java.util.Arrays;
-
-import org.junit.Test;
-
-import simplenlg.features.Feature;
-import simplenlg.features.InterrogativeType;
-import simplenlg.features.Tense;
-import simplenlg.framework.CoordinatedPhraseElement;
-import simplenlg.framework.DocumentElement;
-import simplenlg.framework.NLGElement;
-import simplenlg.framework.NLGFactory;
-import simplenlg.lexicon.Lexicon;
-import simplenlg.phrasespec.NPPhraseSpec;
-import simplenlg.phrasespec.PPPhraseSpec;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.phrasespec.VPPhraseSpec;
-import simplenlg.realiser.english.Realiser;
-
-/**
- * Tests from SimpleNLG tutorial
- *
- *
- *
- * Copyright (C) 2011, University of Aberdeen
- *
- *
- * @author Ehud Reiter
- *
- */
-public class TutorialTest {
-
-
- // no code in sections 1 and 2
-
- /**
- * test section 3 code
- */
- @Test
- public void section3_Test() {
- Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
-
- NLGElement s1 = nlgFactory.createSentence("my dog is happy");
-
- Realiser r = new Realiser(lexicon);
-
- String output = r.realiseSentence(s1);
-
- assertEquals("My dog is happy.", output);
- }
-
- /**
- * test section 5 code
- */
- @Test
- public void section5_Test() {
- Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
- Realiser realiser = new Realiser(lexicon);
-
- SPhraseSpec p = nlgFactory.createClause();
- p.setSubject("my dog");
- p.setVerb("chase");
- p.setObject("George");
-
- String output = realiser.realiseSentence(p);
- assertEquals("My dog chases George.", output);
- }
-
- /**
- * test section 6 code
- */
- @Test
- public void section6_Test() {
- Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
- Realiser realiser = new Realiser(lexicon);
-
- SPhraseSpec p = nlgFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("chase");
- p.setObject("George");
-
- p.setFeature(Feature.TENSE, Tense.PAST);
- String output = realiser.realiseSentence(p);
- assertEquals("Mary chased George.", output);
-
- p.setFeature(Feature.TENSE, Tense.FUTURE);
- output = realiser.realiseSentence(p);
- assertEquals("Mary will chase George.", output);
-
- p.setFeature(Feature.NEGATED, true);
- output = realiser.realiseSentence(p);
- assertEquals("Mary will not chase George.", output);
-
- p = nlgFactory.createClause();
- p.setSubject("Mary");
- p.setVerb("chase");
- p.setObject("George");
-
- p.setFeature(Feature.INTERROGATIVE_TYPE,
- InterrogativeType.YES_NO);
- output = realiser.realiseSentence(p);
- assertEquals("Does Mary chase George?", output);
-
- p.setSubject("Mary");
- p.setVerb("chase");
- p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
- output = realiser.realiseSentence(p);
- assertEquals("Who does Mary chase?", output);
-
- p = nlgFactory.createClause();
- p.setSubject("the dog");
- p.setVerb("wake up");
- output = realiser.realiseSentence(p);
- assertEquals("The dog wakes up.", output);
-
- }
-
- /**
- * test ability to use variant words
- */
- @Test
- public void variantsTest() {
- Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon
- Realiser realiser = new Realiser(lexicon);
-
- SPhraseSpec p = nlgFactory.createClause();
- p.setSubject("my dog");
- p.setVerb("is"); // variant of be
- p.setObject("George");
-
- String output = realiser.realiseSentence(p);
- assertEquals("My dog is George.", output);
-
- p = nlgFactory.createClause();
- p.setSubject("my dog");
- p.setVerb("chases"); // variant of chase
- p.setObject("George");
-
- output = realiser.realiseSentence(p);
- assertEquals("My dog chases George.", output);
-
-
- p = nlgFactory.createClause();
- p.setSubject(nlgFactory.createNounPhrase("the", "dogs")); // variant of "dog"
- p.setVerb("is"); // variant of be
- p.setObject("happy"); // variant of happy
- output = realiser.realiseSentence(p);
- assertEquals("The dog is happy.", output);
-
- p = nlgFactory.createClause();
- p.setSubject(nlgFactory.createNounPhrase("the", "children")); // variant of "child"
- p.setVerb("is"); // variant of be
- p.setObject("happy"); // variant of happy
- output = realiser.realiseSentence(p);
- assertEquals("The child is happy.", output);
-
- // following functionality is enabled
- p = nlgFactory.createClause();
- p.setSubject(nlgFactory.createNounPhrase("the", "dogs")); // variant of "dog"
- p.setVerb("is"); // variant of be
- p.setObject("happy"); // variant of happy
- output = realiser.realiseSentence(p);
- assertEquals("The dog is happy.", output); //corrected automatically
- }
-
- /* Following code tests the section 5 to 15
- * sections 5 & 6 are repeated here in order to match the simplenlg tutorial version 4
- * James Christie
- * June 2011
- */
-
- /**
- * test section 5 to match simplenlg tutorial version 4's code
- */
- @Test
- public void section5A_Test() {
- Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
- Realiser realiser = new Realiser( lexicon );
-
- SPhraseSpec p = nlgFactory.createClause();
- p.setSubject( "Mary" );
- p.setVerb( "chase" );
- p.setObject( "the monkey" );
-
- String output = realiser.realiseSentence( p );
- assertEquals( "Mary chases the monkey.", output );
- } // testSection5A
-
- /**
- * test section 6 to match simplenlg tutorial version 4' code
- */
- @Test
- public void section6A_Test() {
- Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
- Realiser realiser = new Realiser( lexicon );
-
- SPhraseSpec p = nlgFactory.createClause();
- p.setSubject( "Mary" );
- p.setVerb( "chase" );
- p.setObject( "the monkey" );
-
- p.setFeature( Feature.TENSE, Tense.PAST );
- String output = realiser.realiseSentence( p );
- assertEquals( "Mary chased the monkey.", output );
-
- p.setFeature( Feature.TENSE, Tense.FUTURE );
- output = realiser.realiseSentence( p );
- assertEquals( "Mary will chase the monkey.", output );
-
- p.setFeature( Feature.NEGATED, true );
- output = realiser.realiseSentence( p );
- assertEquals( "Mary will not chase the monkey.", output );
-
- p = nlgFactory.createClause();
- p.setSubject( "Mary" );
- p.setVerb( "chase" );
- p.setObject( "the monkey" );
-
- p.setFeature( Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO );
- output = realiser.realiseSentence( p );
- assertEquals( "Does Mary chase the monkey?", output );
-
- p.setSubject( "Mary" );
- p.setVerb( "chase" );
- p.setFeature( Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT );
- output = realiser.realiseSentence( p );
- assertEquals( "Who does Mary chase?", output );
- }
-
- /**
- * test section 7 code
- */
- @Test
- public void section7_Test() {
- Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
- Realiser realiser = new Realiser( lexicon );
-
- SPhraseSpec p = nlgFactory.createClause();
- p.setSubject( "Mary" );
- p.setVerb( "chase" );
- p.setObject( "the monkey" );
- p.addComplement( "very quickly" );
- p.addComplement( "despite her exhaustion" );
-
- String output = realiser.realiseSentence( p );
- assertEquals( "Mary chases the monkey very quickly despite her exhaustion.", output );
- }
-
- /**
- * test section 8 code
- */
- @Test
- public void section8_Test() {
- Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
- Realiser realiser = new Realiser( lexicon );
-
- NPPhraseSpec subject = nlgFactory.createNounPhrase( "Mary" );
- NPPhraseSpec object = nlgFactory.createNounPhrase( "the monkey" );
- VPPhraseSpec verb = nlgFactory.createVerbPhrase( "chase" );;
- subject.addModifier( "fast" );
-
- SPhraseSpec p = nlgFactory.createClause();
- p.setSubject( subject );
- p.setVerb( verb );
- p.setObject( object );
-
- String outputA = realiser.realiseSentence( p );
- assertEquals( "Fast Mary chases the monkey.", outputA );
-
- verb.addModifier( "quickly" );
-
- String outputB = realiser.realiseSentence( p );
- assertEquals( "Fast Mary quickly chases the monkey.", outputB );
- }
-
- // there is no code specified in section 9
-
- /**
- * test section 10 code
- */
- @Test
- public void section10_Test() {
- Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
- Realiser realiser = new Realiser( lexicon );
-
- NPPhraseSpec subject1 = nlgFactory.createNounPhrase( "Mary" );
- NPPhraseSpec subject2 = nlgFactory.createNounPhrase( "your", "giraffe" );
-
- // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API
- CoordinatedPhraseElement subj = nlgFactory.createCoordinatedPhrase( subject1, subject2 );
-
- VPPhraseSpec verb = nlgFactory.createVerbPhrase( "chase" );;
-
- SPhraseSpec p = nlgFactory.createClause();
- p.setSubject( subj );
- p.setVerb( verb );
- p.setObject( "the monkey" );
-
- String outputA = realiser.realiseSentence( p );
- assertEquals( "Mary and your giraffe chase the monkey.", outputA );
-
- NPPhraseSpec object1 = nlgFactory.createNounPhrase( "the monkey" );
- NPPhraseSpec object2 = nlgFactory.createNounPhrase( "George" );
-
- // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API
- CoordinatedPhraseElement obj = nlgFactory.createCoordinatedPhrase( object1, object2 );
- obj.addCoordinate( "Martha" );
- p.setObject( obj );
-
- String outputB = realiser.realiseSentence( p );
- assertEquals( "Mary and your giraffe chase the monkey, George and Martha.", outputB );
-
- obj.setFeature( Feature.CONJUNCTION, "or" );
-
- String outputC = realiser.realiseSentence( p );
- assertEquals( "Mary and your giraffe chase the monkey, George or Martha.", outputC );
- }
-
- /**
- * test section 11 code
- */
- @Test
- public void section11_Test() {
- Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
-
- Realiser realiser = new Realiser( lexicon );
-
- SPhraseSpec pA = nlgFactory.createClause( "Mary", "chase", "the monkey" );
- pA.addComplement( "in the park" );
-
- String outputA = realiser.realiseSentence( pA );
- assertEquals( "Mary chases the monkey in the park.", outputA );
-
- // alternative build paradigm
- NPPhraseSpec place = nlgFactory.createNounPhrase( "park" );
- SPhraseSpec pB = nlgFactory.createClause( "Mary", "chase", "the monkey" );
-
- // next line is depreciated ~ may be corrected in the API
- place.setDeterminer( "the" );
- PPPhraseSpec pp = nlgFactory.createPrepositionPhrase();
- pp.addComplement( place );
- pp.setPreposition( "in" );
-
- pB.addComplement( pp );
-
- String outputB = realiser.realiseSentence( pB );
- assertEquals( "Mary chases the monkey in the park.", outputB );
-
- place.addPreModifier( "leafy" );
-
- String outputC = realiser.realiseSentence( pB );
- assertEquals( "Mary chases the monkey in the leafy park.", outputC );
- } // testSection11
-
- // section12 only has a code table as illustration
-
- /**
- * test section 13 code
- */
- @Test
- public void section13_Test() {
- Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
-
- Realiser realiser = new Realiser( lexicon );
-
- SPhraseSpec s1 = nlgFactory.createClause( "my cat", "like", "fish" );
- SPhraseSpec s2 = nlgFactory.createClause( "my dog", "like", "big bones" );
- SPhraseSpec s3 = nlgFactory.createClause( "my horse", "like", "grass" );
-
- CoordinatedPhraseElement c = nlgFactory.createCoordinatedPhrase();
- c.addCoordinate( s1 );
- c.addCoordinate( s2 );
- c.addCoordinate( s3 );
-
- String outputA = realiser.realiseSentence( c );
- assertEquals( "My cat likes fish, my dog likes big bones and my horse likes grass.", outputA );
-
- SPhraseSpec p = nlgFactory.createClause( "I", "be", "happy" );
- SPhraseSpec q = nlgFactory.createClause( "I", "eat", "fish" );
- q.setFeature( Feature.COMPLEMENTISER, "because" );
- q.setFeature( Feature.TENSE, Tense.PAST );
- p.addComplement( q );
-
- String outputB = realiser.realiseSentence( p );
- assertEquals( "I am happy because I ate fish.", outputB );
- }
-
- /**
- * test section 14 code
- */
- @Test
- public void section14_Test() {
- Lexicon lexicon = Lexicon.getDefaultLexicon(); // default simplenlg lexicon
- NLGFactory nlgFactory = new NLGFactory( lexicon ); // factory based on lexicon
-
- Realiser realiser = new Realiser( lexicon );
-
- SPhraseSpec p1 = nlgFactory.createClause( "Mary", "chase", "the monkey" );
- SPhraseSpec p2 = nlgFactory.createClause( "The monkey", "fight back" );
- SPhraseSpec p3 = nlgFactory.createClause( "Mary", "be", "nervous" );
-
- DocumentElement s1 = nlgFactory.createSentence( p1 );
- DocumentElement s2 = nlgFactory.createSentence( p2 );
- DocumentElement s3 = nlgFactory.createSentence( p3 );
-
- DocumentElement par1 = nlgFactory.createParagraph( Arrays.asList( s1, s2, s3 ) );
-
- String output14a = realiser.realise( par1 ).getRealisation();
- assertEquals( "Mary chases the monkey. The monkey fights back. Mary is nervous.\n\n", output14a );
-
- DocumentElement section = nlgFactory.createSection( "The Trials and Tribulation of Mary and the Monkey" );
- section.addComponent( par1 );
- String output14b = realiser.realise( section ).getRealisation();
- assertEquals( "The Trials and Tribulation of Mary and the Monkey\nMary chases the monkey. The monkey fights back. Mary is nervous.\n\n", output14b );
- }
-
-}
diff --git a/SharpSimpleNLGUnitTests/syntax/english/VerbPhraseTest.java b/SharpSimpleNLGUnitTests/syntax/english/VerbPhraseTest.java
deleted file mode 100644
index f5029a5..0000000
--- a/SharpSimpleNLGUnitTests/syntax/english/VerbPhraseTest.java
+++ /dev/null
@@ -1,461 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is "Simplenlg".
- *
- * The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
- * Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
- *
- * Contributor(s): Ehud Reiter, Albert Gatt, Dave Wewstwater, Roman Kutlak, Margaret Mitchell, Saad Mahamood.
- */
-
-package simplenlg.syntax.english;
-
-import java.util.List;
-
-import org.junit.After;
-import org.junit.Test;
-
-import simplenlg.features.DiscourseFunction;
-import simplenlg.features.Feature;
-import simplenlg.features.Form;
-import simplenlg.features.InternalFeature;
-import simplenlg.features.NumberAgreement;
-import simplenlg.features.Person;
-import simplenlg.features.Tense;
-import simplenlg.framework.CoordinatedPhraseElement;
-import simplenlg.framework.NLGElement;
-import simplenlg.framework.PhraseElement;
-import simplenlg.framework.WordElement;
-import simplenlg.phrasespec.SPhraseSpec;
-import simplenlg.phrasespec.VPPhraseSpec;
-
-/**
- * These are tests for the verb phrase and coordinate VP classes.
- * @author agatt
- */
-public class VerbPhraseTest extends SimpleNLG4Test {
-
- /**
- * Instantiates a new vP test.
- *
- * @param name
- * the name
- */
- public VerbPhraseTest(String name) {
- super(name);
- }
-
-
- @Override
- @After
- public void tearDown() {
- super.tearDown();
- }
-
-
- /**
- * Some tests to check for an early bug which resulted in reduplication of
- * verb particles in the past tense e.g. "fall down down" or "creep up up"
- */
- @Test
- public void testVerbParticle() {
- VPPhraseSpec v = this.phraseFactory.createVerbPhrase("fall down"); //$NON-NLS-1$
-
- assertEquals(
- "down", v.getFeatureAsString(Feature.PARTICLE)); //$NON-NLS-1$
-
- assertEquals(
- "fall", ((WordElement) v.getVerb()).getBaseForm()); //$NON-NLS-1$
-
- v.setFeature(Feature.TENSE,Tense.PAST);
- v.setFeature(Feature.PERSON, Person.THIRD);
- v.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
-
- assertEquals(
- "fell down", this.realiser.realise(v).getRealisation()); //$NON-NLS-1$
-
- v.setFeature(Feature.FORM, Form.PAST_PARTICIPLE);
- assertEquals(
- "fallen down", this.realiser.realise(v).getRealisation()); //$NON-NLS-1$
- }
-
- /**
- * Tests for the tense and aspect.
- */
- @Test
- public void simplePastTest() {
- // "fell down"
- this.fallDown.setFeature(Feature.TENSE,Tense.PAST);
- assertEquals(
- "fell down", this.realiser.realise(this.fallDown).getRealisation()); //$NON-NLS-1$
-
- }
-
- /**
- * Test tense aspect.
- */
- @Test
- public void tenseAspectTest() {
- // had fallen down
- this.realiser.setLexicon(this.lexicon);
- this.fallDown.setFeature(Feature.TENSE,Tense.PAST);
- this.fallDown.setFeature(Feature.PERFECT, true);
-
- assertEquals("had fallen down", this.realiser.realise( //$NON-NLS-1$
- this.fallDown).getRealisation());
-
- // had been falling down
- this.fallDown.setFeature(Feature.PROGRESSIVE, true);
- assertEquals("had been falling down", this.realiser.realise( //$NON-NLS-1$
- this.fallDown).getRealisation());
-
- // will have been kicked
- this.kick.setFeature(Feature.PASSIVE, true);
- this.kick.setFeature(Feature.PERFECT, true);
- this.kick.setFeature(Feature.TENSE,Tense.FUTURE);
- assertEquals("will have been kicked", this.realiser.realise( //$NON-NLS-1$
- this.kick).getRealisation());
-
- // will have been being kicked
- this.kick.setFeature(Feature.PROGRESSIVE, true);
- assertEquals("will have been being kicked", this.realiser //$NON-NLS-1$
- .realise(this.kick).getRealisation());
-
- // will not have been being kicked
- this.kick.setFeature(Feature.NEGATED, true);
- assertEquals("will not have been being kicked", this.realiser //$NON-NLS-1$
- .realise(this.kick).getRealisation());
-
- // passivisation should suppress the complement
- this.kick.clearComplements();
- this.kick.addComplement(this.man);
- assertEquals("will not have been being kicked", this.realiser //$NON-NLS-1$
- .realise(this.kick).getRealisation());
-
- // de-passivisation should now give us "will have been kicking the man"
- this.kick.setFeature(Feature.PASSIVE, false);
- assertEquals("will not have been kicking the man", this.realiser //$NON-NLS-1$
- .realise(this.kick).getRealisation());
-
- // remove the future tense --
- // this is a test of an earlier bug that would still realise "will"
- this.kick.setFeature(Feature.TENSE,Tense.PRESENT);
- assertEquals("has not been kicking the man", this.realiser //$NON-NLS-1$
- .realise(this.kick).getRealisation());
- }
-
- /**
- * Test for realisation of VP complements.
- */
- @Test
- public void complementationTest() {
-
- // was kissing Mary
- PhraseElement mary = this.phraseFactory.createNounPhrase("Mary"); //$NON-NLS-1$
- mary.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.OBJECT);
- this.kiss.clearComplements();
- this.kiss.addComplement(mary);
- this.kiss.setFeature(Feature.PROGRESSIVE, true);
- this.kiss.setFeature(Feature.TENSE,Tense.PAST);
-
- assertEquals("was kissing Mary", this.realiser //$NON-NLS-1$
- .realise(this.kiss).getRealisation());
-
- CoordinatedPhraseElement mary2 = new CoordinatedPhraseElement(mary,
- this.phraseFactory.createNounPhrase("Susan")); //$NON-NLS-1$
- // add another complement -- should come out as "Mary and Susan"
- this.kiss.clearComplements();
- this.kiss.addComplement(mary2);
- assertEquals("was kissing Mary and Susan", this.realiser //$NON-NLS-1$
- .realise(this.kiss).getRealisation());
-
- // passivise -- should make the direct object complement disappear
- // Note: The verb doesn't come out as plural because agreement
- // is determined by the sentential subjects and this VP isn't inside a
- // sentence
- this.kiss.setFeature(Feature.PASSIVE, true);
- assertEquals("was being kissed", this.realiser //$NON-NLS-1$
- .realise(this.kiss).getRealisation());
-
- // make it plural (this is usually taken care of in SPhraseSpec)
- this.kiss.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- assertEquals("were being kissed", this.realiser.realise( //$NON-NLS-1$
- this.kiss).getRealisation());
-
- // depassivise and add post-mod: yields "was kissing Mary in the room"
- this.kiss.addPostModifier(this.inTheRoom);
- this.kiss.setFeature(Feature.PASSIVE, false);
- this.kiss.setFeature(Feature.NUMBER, NumberAgreement.SINGULAR);
- assertEquals("was kissing Mary and Susan in the room", //$NON-NLS-1$
- this.realiser.realise(this.kiss).getRealisation());
-
- // passivise again: should make direct object disappear, but not postMod
- // ="was being kissed in the room"
- this.kiss.setFeature(Feature.PASSIVE, true);
- this.kiss.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
- assertEquals("were being kissed in the room", this.realiser //$NON-NLS-1$
- .realise(this.kiss).getRealisation());
- }
-
- /**
- * This tests for the default complement ordering, relative to pre and
- * postmodifiers.
- */
- @Test
- public void complementationTest_2() {
- // give the woman the dog
- this.woman.setFeature(InternalFeature.DISCOURSE_FUNCTION,
- DiscourseFunction.INDIRECT_OBJECT);
- this.dog.setFeature(InternalFeature.DISCOURSE_FUNCTION,
- DiscourseFunction.OBJECT);
- this.give.clearComplements();
- this.give.addComplement(this.dog);
- this.give.addComplement(this.woman);
- assertEquals("gives the woman the dog", this.realiser.realise( //$NON-NLS-1$
- this.give).getRealisation());
-
- // add a few premodifiers and postmodifiers
- this.give.addPreModifier("slowly"); //$NON-NLS-1$
- this.give.addPostModifier(this.behindTheCurtain);
- this.give.addPostModifier(this.inTheRoom);
- assertEquals(
- "slowly gives the woman the dog behind the curtain in the room", //$NON-NLS-1$
- this.realiser.realise(this.give).getRealisation());
-
- // reset the arguments
- this.give.clearComplements();
- this.give.addComplement(this.dog);
- CoordinatedPhraseElement womanBoy = new CoordinatedPhraseElement(
- this.woman, this.boy);
- womanBoy.setFeature(InternalFeature.DISCOURSE_FUNCTION,
- DiscourseFunction.INDIRECT_OBJECT);
- this.give.addComplement(womanBoy);
-
- // if we unset the passive, we should get the indirect objects
- // they won't be coordinated
- this.give.setFeature(Feature.PASSIVE, false);
- assertEquals(
- "slowly gives the woman and the boy the dog behind the curtain in the room", //$NON-NLS-1$
- this.realiser.realise(this.give).getRealisation());
-
- // set them to a coordinate instead
- // set ONLY the complement INDIRECT_OBJECT, leaves OBJECT intact
- this.give.clearComplements();
- this.give.addComplement(womanBoy);
- this.give.addComplement(this.dog);
- List complements = this.give
- .getFeatureAsElementList(InternalFeature.COMPLEMENTS);
-
- int indirectCount = 0;
- for (NLGElement eachElement : complements) {
- if (DiscourseFunction.INDIRECT_OBJECT.equals(eachElement
- .getFeature(InternalFeature.DISCOURSE_FUNCTION))) {
- indirectCount++;
- }
- }
- assertEquals(1, indirectCount); // only one indirect object
- // where
- // there were two before
-
- assertEquals(
- "slowly gives the woman and the boy the dog behind the curtain in the room", //$NON-NLS-1$
- this.realiser.realise(this.give).getRealisation());
- }
-
- /**
- * Test for complements raised in the passive case.
- */
- @Test
- public void passiveComplementTest() {
- // add some arguments
- this.dog.setFeature(InternalFeature.DISCOURSE_FUNCTION,
- DiscourseFunction.OBJECT);
- this.woman.setFeature(InternalFeature.DISCOURSE_FUNCTION,
- DiscourseFunction.INDIRECT_OBJECT);
- this.give.addComplement(this.dog);
- this.give.addComplement(this.woman);
- assertEquals("gives the woman the dog", this.realiser.realise( //$NON-NLS-1$
- this.give).getRealisation());
-
- // add a few premodifiers and postmodifiers
- this.give.addPreModifier("slowly"); //$NON-NLS-1$
- this.give.addPostModifier(this.behindTheCurtain);
- this.give.addPostModifier(this.inTheRoom);
- assertEquals(
- "slowly gives the woman the dog behind the curtain in the room", //$NON-NLS-1$
- this.realiser.realise(this.give).getRealisation());
-
- // passivise: This should suppress "the dog"
- this.give.clearComplements();
- this.give.addComplement(this.dog);
- this.give.addComplement(this.woman);
- this.give.setFeature(Feature.PASSIVE, true);
-
- assertEquals(
- "is slowly given the woman behind the curtain in the room", //$NON-NLS-1$
- this.realiser.realise(this.give).getRealisation());
- }
-
- /**
- * Test VP with sentential complements. This tests for structures like "said
- * that John was walking"
- */
- @Test
- public void clausalComplementTest() {
- this.phraseFactory.setLexicon(this.lexicon);
- SPhraseSpec s = this.phraseFactory.createClause();
-
- s.setSubject(this.phraseFactory
- .createNounPhrase("John")); //$NON-NLS-1$
-
- // Create a sentence first
- CoordinatedPhraseElement maryAndSusan = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Mary"), //$NON-NLS-1$
- this.phraseFactory.createNounPhrase("Susan")); //$NON-NLS-1$
-
- this.kiss.clearComplements();
- s.setVerbPhrase(this.kiss);
- s.setObject(maryAndSusan);
- s.setFeature(Feature.PROGRESSIVE, true);
- s.setFeature(Feature.TENSE,Tense.PAST);
- s.addPostModifier(this.inTheRoom);
- assertEquals("John was kissing Mary and Susan in the room", //$NON-NLS-1$
- this.realiser.realise(s).getRealisation());
-
- // make the main VP past
- this.say.setFeature(Feature.TENSE,Tense.PAST);
- assertEquals("said", this.realiser.realise(this.say) //$NON-NLS-1$
- .getRealisation());
-
- // now add the sentence as complement of "say". Should make the sentence
- // subordinate
- // note that sentential punctuation is suppressed
- this.say.addComplement(s);
- assertEquals(
- "said that John was kissing Mary and Susan in the room", //$NON-NLS-1$
- this.realiser.realise(this.say).getRealisation());
-
- // add a postModifier to the main VP
- // yields [says [that John was kissing Mary and Susan in the room]
- // [behind the curtain]]
- this.say.addPostModifier(this.behindTheCurtain);
- assertEquals(
- "said that John was kissing Mary and Susan in the room behind the curtain", //$NON-NLS-1$
- this.realiser.realise(this.say).getRealisation());
-
- // create a new sentential complement
- PhraseElement s2 = this.phraseFactory.createClause(this.phraseFactory
- .createNounPhrase("all"), //$NON-NLS-1$
- "be", //$NON-NLS-1$
- this.phraseFactory.createAdjectivePhrase("fine")); //$NON-NLS-1$
-
- s2.setFeature(Feature.TENSE,Tense.FUTURE);
- assertEquals("all will be fine", this.realiser.realise(s2) //$NON-NLS-1$
- .getRealisation());
-
- // add the new complement to the VP
- // yields [said [that John was kissing Mary and Susan in the room and
- // all will be fine] [behind the curtain]]
- CoordinatedPhraseElement s3 = new CoordinatedPhraseElement(s, s2);
- this.say.clearComplements();
- this.say.addComplement(s3);
-
- // first with outer complementiser suppressed
- s3.setFeature(Feature.SUPRESSED_COMPLEMENTISER, true);
- assertEquals(
- "said that John was kissing Mary and Susan in the room " //$NON-NLS-1$
- + "and all will be fine behind the curtain", //$NON-NLS-1$
- this.realiser.realise(this.say).getRealisation());
-
- setUp();
- s = this.phraseFactory.createClause();
-
- s.setSubject(this.phraseFactory
- .createNounPhrase("John")); //$NON-NLS-1$
-
- // Create a sentence first
- maryAndSusan = new CoordinatedPhraseElement(
- this.phraseFactory.createNounPhrase("Mary"), //$NON-NLS-1$
- this.phraseFactory.createNounPhrase("Susan")); //$NON-NLS-1$
-
- s.setVerbPhrase(this.kiss);
- s.setObject(maryAndSusan);
- s.setFeature(Feature.PROGRESSIVE, true);
- s.setFeature(Feature.TENSE,Tense.PAST);
- s.addPostModifier(this.inTheRoom);
- s2 = this.phraseFactory.createClause(this.phraseFactory
- .createNounPhrase("all"), //$NON-NLS-1$
- "be", //$NON-NLS-1$
- this.phraseFactory.createAdjectivePhrase("fine")); //$NON-NLS-1$
-
- s2.setFeature(Feature.TENSE,Tense.FUTURE);
- // then with complementiser not suppressed and not aggregated
- s3 = new CoordinatedPhraseElement(s, s2);
- this.say.addComplement(s3);
- this.say.setFeature(Feature.TENSE,Tense.PAST);
- this.say.addPostModifier(this.behindTheCurtain);
-
- assertEquals(
- "said that John was kissing Mary and Susan in the room and " //$NON-NLS-1$
- + "that all will be fine behind the curtain", //$NON-NLS-1$
- this.realiser.realise(this.say).getRealisation());
-
- }
-
- /**
- * Test VP coordination and aggregation:
- *
- * If the simplenlg.features of a coordinate VP are set, they should be
- * inherited by its daughter VP;
- * 2. We can aggregate the coordinate VP so it's realised with one
- * wide-scope auxiliary
- */
- @Test
- public void coordinationTest() {
- // simple case
- this.kiss.addComplement(this.dog);
- this.kick.addComplement(this.boy);
-
- CoordinatedPhraseElement coord1 = new CoordinatedPhraseElement(
- this.kiss, this.kick);
-
- coord1.setFeature(Feature.PERSON, Person.THIRD);
- coord1.setFeature(Feature.TENSE,Tense.PAST);
- assertEquals("kissed the dog and kicked the boy", this.realiser //$NON-NLS-1$
- .realise(coord1).getRealisation());
-
- // with negation: should be inherited by all components
- coord1.setFeature(Feature.NEGATED, true);
- this.realiser.setLexicon(this.lexicon);
- assertEquals("did not kiss the dog and did not kick the boy", //$NON-NLS-1$
- this.realiser.realise(coord1).getRealisation());
-
- // set a modal
- coord1.setFeature(Feature.MODAL, "could"); //$NON-NLS-1$
- assertEquals(
- "could not have kissed the dog and could not have kicked the boy", //$NON-NLS-1$
- this.realiser.realise(coord1).getRealisation());
-
- // set perfect and progressive
- coord1.setFeature(Feature.PERFECT, true);
- coord1.setFeature(Feature.PROGRESSIVE, true);
- assertEquals("could not have been kissing the dog and " //$NON-NLS-1$
- + "could not have been kicking the boy", this.realiser.realise( //$NON-NLS-1$
- coord1).getRealisation());
-
- // now aggregate
- coord1.setFeature(Feature.AGGREGATE_AUXILIARY, true);
- assertEquals(
- "could not have been kissing the dog and kicking the boy", //$NON-NLS-1$
- this.realiser.realise(coord1).getRealisation());
- }
-}
From 96bd407e5e40b97698dc48d4833fed8dd85cc1f5 Mon Sep 17 00:00:00 2001
From: Arash Sabet
Date: Sat, 8 Jul 2017 06:41:36 -0400
Subject: [PATCH 09/10] Updated solution committed
---
SharpSimpleNLG.sln | 6 ------
1 file changed, 6 deletions(-)
diff --git a/SharpSimpleNLG.sln b/SharpSimpleNLG.sln
index 4c75c7a..13ab00e 100644
--- a/SharpSimpleNLG.sln
+++ b/SharpSimpleNLG.sln
@@ -20,8 +20,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpSimpleNLG", "SharpSimp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpSimpleNLGConsoleNetCore", "SharpSimpleNLGConsoleNetCore\SharpSimpleNLGConsoleNetCore.csproj", "{3E619416-20EC-429F-A467-9F7BFE8BACB1}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpSimpleNLGUnitTests", "SharpSimpleNLGUnitTests\SharpSimpleNLGUnitTests.csproj", "{F4C4C12D-F50D-46F4-9F53-F7C997AD97B8}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -48,10 +46,6 @@ Global
{3E619416-20EC-429F-A467-9F7BFE8BACB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E619416-20EC-429F-A467-9F7BFE8BACB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E619416-20EC-429F-A467-9F7BFE8BACB1}.Release|Any CPU.Build.0 = Release|Any CPU
- {F4C4C12D-F50D-46F4-9F53-F7C997AD97B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {F4C4C12D-F50D-46F4-9F53-F7C997AD97B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {F4C4C12D-F50D-46F4-9F53-F7C997AD97B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {F4C4C12D-F50D-46F4-9F53-F7C997AD97B8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
From 77e5f63d83b71816bc2594648a663651b6c91999 Mon Sep 17 00:00:00 2001
From: Arash Sabet
Date: Sat, 8 Jul 2017 06:45:03 -0400
Subject: [PATCH 10/10] Library's package info updated.
---
SharpSimpleNLG/Properties/AssemblyInfo.cs | 2 +-
SharpSimpleNLG/SharpSimpleNLG.csproj | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/SharpSimpleNLG/Properties/AssemblyInfo.cs b/SharpSimpleNLG/Properties/AssemblyInfo.cs
index 4fbd895..7884eb6 100644
--- a/SharpSimpleNLG/Properties/AssemblyInfo.cs
+++ b/SharpSimpleNLG/Properties/AssemblyInfo.cs
@@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SharpSimpleNLG")]
-[assembly: AssemblyCopyright("Copyright © 2016 Various Parties")]
+[assembly: AssemblyCopyright("Copyright © 2017 Various Parties")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
diff --git a/SharpSimpleNLG/SharpSimpleNLG.csproj b/SharpSimpleNLG/SharpSimpleNLG.csproj
index 4cf49e9..d287997 100644
--- a/SharpSimpleNLG/SharpSimpleNLG.csproj
+++ b/SharpSimpleNLG/SharpSimpleNLG.csproj
@@ -13,6 +13,11 @@
false
false
false
+ 1.2.0
+ https://github.com/nickhodge/SharpSimpleNLG/blob/master/LICENSE.md
+
+ https://github.com/nickhodge/SharpSimpleNLG
+ git
bin\$(Configuration)\$(Framework)