Revision: 14935
http://sourceforge.net/p/foray/code/14935
Author: victormote
Date: 2026-07-28 12:37:32 +0000 (Tue, 28 Jul 2026)
Log Message:
-----------
Unify wordSegmentAt() method for all InflectedWord subclasses.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/FinalSegmentAddedWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/FinalSegmentModifiedWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/InflectedWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_2c_ed.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_apos_s.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ed.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ed2.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_er2.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_est2.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ies.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ing2.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_s.java
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Word4a.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -213,6 +213,15 @@
@Override
public abstract WordSegment4a wordSegmentAt(int segmentIndex);
+ /**
+ * Convenience method that returns the last segment of this word.
+ * @return The last segment of this word.
+ */
+ public WordSegment4a getLastWordSegment() {
+ final int lastSegmentIndex = qtyWordSegments() - 1;
+ return wordSegmentAt(lastSegmentIndex);
+ }
+
@Override
public Type getKpNodeType() {
return KpNode.Type.BRANCH;
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/FinalSegmentAddedWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/FinalSegmentAddedWord.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/FinalSegmentAddedWord.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -29,7 +29,6 @@
package org.foray.orthography.inflection;
import org.foray.orthography.Word4a;
-import org.foray.orthography.WordSegment4a;
/**
* Wraps a word to add a final segment.
@@ -47,15 +46,4 @@
super(wrappedWord);
}
- @Override
- public WordSegment4a wordSegmentAt(final int segmentIndex) {
- if (segmentIndex < getWrappedWord().qtyWordSegments()) {
- return getWrappedWord().wordSegmentAt(segmentIndex);
- }
- if (segmentIndex < qtyWordSegments()) {
- return getAppendedSegment();
- }
- throw new IndexOutOfBoundsException(Integer.toString(segmentIndex));
- }
-
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/FinalSegmentModifiedWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/FinalSegmentModifiedWord.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/FinalSegmentModifiedWord.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -29,10 +29,7 @@
package org.foray.orthography.inflection;
import org.foray.orthography.Word4a;
-import org.foray.orthography.WordSegment4a;
-import org.axsl.orthography.WordSegment;
-
/**
* Abstract superclass for word wrappers that modify the final segment of the word.
*/
@@ -41,9 +38,6 @@
/** Constant needed for serialization. */
private static final long serialVersionUID = 8075477767144178967L;
- /** The word segment that replaces the last word segment in the wrapped word. */
- private WordSegment4a lastSegment;
-
/**
* Constructor.
* @param wrappedWord The wrapped word.
@@ -50,24 +44,6 @@
*/
protected FinalSegmentModifiedWord(final Word4a wrappedWord) {
super(wrappedWord);
- final int lastSegmentIndex = wrappedWord.qtyWordSegments() - 1;
- final WordSegment unmodifiedSegment = wrappedWord.wordSegmentAt(lastSegmentIndex);
- this.lastSegment = createModifiedSegment(unmodifiedSegment);
}
- @Override
- public WordSegment4a wordSegmentAt(final int segmentIndex) {
- if (segmentIndex == qtyWordSegments() - 1) {
- return this.lastSegment;
- }
- return getWrappedWord().wordSegmentAt(segmentIndex);
- }
-
- /**
- * Returns the segment wrapper that should be treated as the final segment of this word.
- * @param unmodifiedSegment The segment that should be wrapped to create the substitute.
- * @return The segment that replaces the final segment.
- */
- protected abstract WordSegment4a createModifiedSegment(WordSegment unmodifiedSegment);
-
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/InflectedWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/InflectedWord.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/InflectedWord.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -28,6 +28,7 @@
package org.foray.orthography.inflection;
+import org.foray.common.MarkedIndexOutOfBoundsException;
import org.foray.orthography.Word4a;
import org.foray.orthography.WordSegment4a;
import org.foray.orthography.WordWrapper;
@@ -54,6 +55,32 @@
return getWrappedWord().qtyWordSegments() + addedSegments;
}
+ @Override
+ public WordSegment4a wordSegmentAt(final int segmentIndex) {
+ if (segmentIndex >= qtyWordSegments()) {
+ throw new MarkedIndexOutOfBoundsException(segmentIndex, qtyWordSegments());
+ }
+
+ if (getAppendedSegment() == null) {
+ if (segmentIndex == qtyWordSegments() - 1) {
+ if (getModifiedSegment() != null) {
+ return getModifiedSegment();
+ }
+ }
+ } else {
+ if (segmentIndex == qtyWordSegments() - 1) {
+ return getAppendedSegment();
+ }
+ if (segmentIndex == qtyWordSegments() - 2) {
+ if (getModifiedSegment() != null) {
+ return getModifiedSegment();
+ }
+ }
+ }
+
+ return getWrappedWord().wordSegmentAt(segmentIndex);
+ }
+
/**
* Returns the word segment to be appended, if any.
* @return The segment to be appended, or null if none should be appended.
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_2c_ed.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_2c_ed.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_2c_ed.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -33,8 +33,6 @@
import org.foray.orthography.inflection.FinalSegmentModifiedWord;
import org.foray.orthography.inflection.mods.Add_2c_ed;
-import org.axsl.orthography.WordSegment;
-
import java.util.regex.Pattern;
/**
@@ -50,6 +48,9 @@
/** Constant needed for serialization. */
private static final long serialVersionUID = 8394051902368166495L;
+ /** The word segment that replaces the last word segment in the wrapped word. */
+ private WordSegment4a modifiedSegment;
+
/**
* Constructor.
* @param wrappedWord The wrapped word.
@@ -56,6 +57,7 @@
*/
public EngLatnSuffix_2c_ed(final Word4a wrappedWord) {
super(wrappedWord);
+ this.modifiedSegment = new Add_2c_ed(wrappedWord.getLastWordSegment());
}
@Override
@@ -65,12 +67,7 @@
@Override
public WordSegment4a getModifiedSegment() {
- return null;
+ return this.modifiedSegment;
}
- @Override
- protected WordSegment4a createModifiedSegment(final WordSegment unmodifiedSegment) {
- return new Add_2c_ed(unmodifiedSegment);
- }
-
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_apos_s.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_apos_s.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_apos_s.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -33,8 +33,6 @@
import org.foray.orthography.inflection.FinalSegmentModifiedWord;
import org.foray.orthography.inflection.mods.Add_apos_s;
-import org.axsl.orthography.WordSegment;
-
import java.util.regex.Pattern;
/**
@@ -48,6 +46,9 @@
/** Constant needed for serialization. */
private static final long serialVersionUID = 3005622022724534906L;
+ /** The word segment that replaces the last word segment in the wrapped word. */
+ private WordSegment4a modifiedSegment;
+
/**
* Constructor.
* @param wrappedWord The wrapped word.
@@ -54,6 +55,7 @@
*/
public EngLatnSuffix_apos_s(final Word4a wrappedWord) {
super(wrappedWord);
+ this.modifiedSegment = new Add_apos_s(wrappedWord.getLastWordSegment());
}
@Override
@@ -63,12 +65,7 @@
@Override
public WordSegment4a getModifiedSegment() {
- return null;
+ return this.modifiedSegment;
}
- @Override
- protected WordSegment4a createModifiedSegment(final WordSegment unmodifiedSegment) {
- return new Add_apos_s(unmodifiedSegment);
- }
-
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ed.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ed.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ed.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -33,8 +33,6 @@
import org.foray.orthography.inflection.FinalSegmentModifiedWord;
import org.foray.orthography.inflection.mods.Add_ed;
-import org.axsl.orthography.WordSegment;
-
import java.util.regex.Pattern;
/**
@@ -49,6 +47,9 @@
/** Constant needed for serialization. */
private static final long serialVersionUID = -6300334484689323279L;
+ /** The word segment that replaces the last word segment in the wrapped word. */
+ private WordSegment4a modifiedSegment;
+
/**
* Constructor.
* @param wrappedWord The wrapped word.
@@ -55,6 +56,7 @@
*/
public EngLatnSuffix_ed(final Word4a wrappedWord) {
super(wrappedWord);
+ this.modifiedSegment = new Add_ed(wrappedWord.getLastWordSegment());
}
@Override
@@ -64,12 +66,7 @@
@Override
public WordSegment4a getModifiedSegment() {
- return null;
+ return this.modifiedSegment;
}
- @Override
- protected WordSegment4a createModifiedSegment(final WordSegment unmodifiedSegment) {
- return new Add_ed(unmodifiedSegment);
- }
-
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ed2.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ed2.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ed2.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -33,8 +33,6 @@
import org.foray.orthography.inflection.FinalSegmentModifiedWord;
import org.foray.orthography.inflection.mods.Add_d;
-import org.axsl.orthography.WordSegment;
-
import java.util.regex.Pattern;
/**
@@ -49,6 +47,9 @@
/** Constant needed for serialization. */
private static final long serialVersionUID = -8582365946868677749L;
+ /** The word segment that replaces the last word segment in the wrapped word. */
+ private WordSegment4a modifiedSegment;
+
/**
* Constructor.
* @param wrappedWord The wrapped word.
@@ -55,6 +56,7 @@
*/
public EngLatnSuffix_ed2(final Word4a wrappedWord) {
super(wrappedWord);
+ this.modifiedSegment = new Add_d(wrappedWord.getLastWordSegment());
}
@Override
@@ -64,12 +66,7 @@
@Override
public WordSegment4a getModifiedSegment() {
- return null;
+ return this.modifiedSegment;
}
- @Override
- protected WordSegment4a createModifiedSegment(final WordSegment unmodifiedSegment) {
- return new Add_d(unmodifiedSegment);
- }
-
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_er2.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_er2.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_er2.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -48,6 +48,9 @@
/** Constant needed for serialization. */
private static final long serialVersionUID = 844895335860248111L;
+ /** The word segment that replaces the last word segment in the wrapped word. */
+ private WordSegment4a modifiedSegment;
+
/**
* Constructor.
* @param wrappedWord The wrapped word.
@@ -54,6 +57,7 @@
*/
public EngLatnSuffix_er2(final Word4a wrappedWord) {
super(wrappedWord);
+ this.modifiedSegment = new Delete_e(wrappedWord.getLastWordSegment());
}
@Override
@@ -63,23 +67,7 @@
@Override
public WordSegment4a getModifiedSegment() {
- return null;
+ return this.modifiedSegment;
}
- @Override
- public WordSegment4a wordSegmentAt(final int segmentIndex) {
- if (segmentIndex >= qtyWordSegments()) {
- throw new IndexOutOfBoundsException(Integer.toString(segmentIndex));
- }
- if (segmentIndex == qtyWordSegments() - 1) {
- return getAppendedSegment();
- }
- if (segmentIndex == qtyWordSegments() - 2) {
- final WordSegment4a segment = getWrappedWord().wordSegmentAt(segmentIndex);
- final Delete_e replacement = new Delete_e(segment);
- return replacement;
- }
- return getWrappedWord().wordSegmentAt(segmentIndex);
- }
-
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_est2.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_est2.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_est2.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -48,6 +48,9 @@
/** Constant needed for serialization. */
private static final long serialVersionUID = 844895335860248111L;
+ /** The word segment that replaces the last word segment in the wrapped word. */
+ private WordSegment4a modifiedSegment;
+
/**
* Constructor.
* @param wrappedWord The wrapped word.
@@ -54,6 +57,7 @@
*/
public EngLatnSuffix_est2(final Word4a wrappedWord) {
super(wrappedWord);
+ this.modifiedSegment = new Delete_e(wrappedWord.getLastWordSegment());
}
@Override
@@ -63,23 +67,7 @@
@Override
public WordSegment4a getModifiedSegment() {
- return null;
+ return this.modifiedSegment;
}
- @Override
- public WordSegment4a wordSegmentAt(final int segmentIndex) {
- if (segmentIndex >= qtyWordSegments()) {
- throw new IndexOutOfBoundsException(Integer.toString(segmentIndex));
- }
- if (segmentIndex == qtyWordSegments() - 1) {
- return getAppendedSegment();
- }
- if (segmentIndex == qtyWordSegments() - 2) {
- final WordSegment4a segment = getWrappedWord().wordSegmentAt(segmentIndex);
- final Delete_e replacement = new Delete_e(segment);
- return replacement;
- }
- return getWrappedWord().wordSegmentAt(segmentIndex);
- }
-
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ies.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ies.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ies.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -33,8 +33,6 @@
import org.foray.orthography.inflection.FinalSegmentModifiedWord;
import org.foray.orthography.inflection.mods.Replace_y_by_ies;
-import org.axsl.orthography.WordSegment;
-
import java.util.regex.Pattern;
/**
@@ -52,6 +50,9 @@
/** Constant needed for serialization. */
private static final long serialVersionUID = -7424864981681700754L;
+ /** The word segment that replaces the last word segment in the wrapped word. */
+ private WordSegment4a modifiedSegment;
+
/**
* Constructor.
* @param wrappedWord The wrapped word.
@@ -58,6 +59,7 @@
*/
public EngLatnSuffix_ies(final Word4a wrappedWord) {
super(wrappedWord);
+ this.modifiedSegment = new Replace_y_by_ies(wrappedWord.getLastWordSegment());
}
@Override
@@ -67,12 +69,7 @@
@Override
public WordSegment4a getModifiedSegment() {
- return null;
+ return this.modifiedSegment;
}
- @Override
- protected WordSegment4a createModifiedSegment(final WordSegment unmodifiedSegment) {
- return new Replace_y_by_ies(unmodifiedSegment);
- }
-
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ing2.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ing2.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_ing2.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -48,6 +48,9 @@
/** Constant needed for serialization. */
private static final long serialVersionUID = -7846984985428239100L;
+ /** The word segment that replaces the last word segment in the wrapped word. */
+ private WordSegment4a modifiedSegment;
+
/**
* Constructor.
* @param wrappedWord The wrapped word.
@@ -54,6 +57,7 @@
*/
public EngLatnSuffix_ing2(final Word4a wrappedWord) {
super(wrappedWord);
+ this.modifiedSegment = new Delete_e(wrappedWord.getLastWordSegment());
}
@Override
@@ -63,23 +67,7 @@
@Override
public WordSegment4a getModifiedSegment() {
- return null;
+ return this.modifiedSegment;
}
- @Override
- public WordSegment4a wordSegmentAt(final int segmentIndex) {
- if (segmentIndex >= qtyWordSegments()) {
- throw new IndexOutOfBoundsException(Integer.toString(segmentIndex));
- }
- if (segmentIndex == qtyWordSegments() - 1) {
- return getAppendedSegment();
- }
- if (segmentIndex == qtyWordSegments() - 2) {
- final WordSegment4a segment = getWrappedWord().wordSegmentAt(segmentIndex);
- final Delete_e replacement = new Delete_e(segment);
- return replacement;
- }
- return getWrappedWord().wordSegmentAt(segmentIndex);
- }
-
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_s.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_s.java 2026-07-28 11:36:01 UTC (rev 14934)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/inflection/eng/EngLatnSuffix_s.java 2026-07-28 12:37:32 UTC (rev 14935)
@@ -33,8 +33,6 @@
import org.foray.orthography.inflection.FinalSegmentModifiedWord;
import org.foray.orthography.inflection.mods.Add_s;
-import org.axsl.orthography.WordSegment;
-
import java.util.regex.Pattern;
/**
@@ -48,6 +46,9 @@
/** Constant needed for serialization. */
private static final long serialVersionUID = -7424864981681700754L;
+ /** The word segment that replaces the last word segment in the wrapped word. */
+ private WordSegment4a modifiedSegment;
+
/**
* Constructor.
* @param wrappedWord The wrapped word.
@@ -54,6 +55,7 @@
*/
public EngLatnSuffix_s(final Word4a wrappedWord) {
super(wrappedWord);
+ this.modifiedSegment = new Add_s(wrappedWord.getLastWordSegment());
}
@Override
@@ -63,12 +65,7 @@
@Override
public WordSegment4a getModifiedSegment() {
- return null;
+ return this.modifiedSegment;
}
- @Override
- protected WordSegment4a createModifiedSegment(final WordSegment unmodifiedSegment) {
- return new Add_s(unmodifiedSegment);
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|