Revision: 12654
http://sourceforge.net/p/foray/code/12654
Author: victormote
Date: 2022-06-14 22:02:44 +0000 (Tue, 14 Jun 2022)
Log Message:
-----------
Rough-in implementation of CompoundBreak.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
Added Paths:
-----------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/CompoundBreak4a.java
Added: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/CompoundBreak4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/CompoundBreak4a.java (rev 0)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/CompoundBreak4a.java 2022-06-14 22:02:44 UTC (rev 12654)
@@ -0,0 +1,225 @@
+/*
+ * Copyright 2022 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.orthography;
+
+import org.foray.common.kp.KpLeaf4a;
+import org.foray.common.kp.KpLeafIterator4a;
+import org.foray.common.primitive.StringUtils;
+
+import org.axsl.kp.KpBox;
+import org.axsl.kp.KpBranch;
+import org.axsl.kp.KpContext;
+import org.axsl.kp.KpLeaf;
+import org.axsl.kp.KpLeafIterator;
+import org.axsl.kp.KpNode;
+import org.axsl.kp.KpPenalty;
+import org.axsl.kp.KpUserAgent;
+import org.axsl.orthography.CompoundBreak;
+
+/**
+ * FOray implementation of {@link CompoundBreak}.
+ * Instances of this class are immutable.
+ */
+public final class CompoundBreak4a implements CompoundBreak, KpBranch {
+
+ /** Pre-built singleton instance. */
+ public static final CompoundBreak4a INSTANCE = new CompoundBreak4a();
+
+ /** The box portion of this compound break. */
+ private CompoundBreak4a.Box box;
+
+ /** The penalty portion of this compound break. */
+ private CompoundBreak4a.Penalty penalty;
+
+ /**
+ * Private constructor. This class is a singleton, and should be instantiated only within itself.
+ * Use {@link #getInstance()} to obtain the singleton instance of this class.
+ */
+ private CompoundBreak4a() {
+ this.box = new Box();
+ this.penalty = new Penalty();
+ }
+
+ /**
+ * Returns the singleton instance of this class.
+ * @return singleton instance of this class.
+ */
+ public static CompoundBreak4a getInstance() {
+ return CompoundBreak4a.INSTANCE;
+ }
+
+ @Override
+ public String toString() {
+ return "-";
+ }
+
+ @Override
+ public org.axsl.kp.KpNode.Type getKpNodeType() {
+ return KpNode.Type.BRANCH;
+ }
+
+ @Override
+ public int qtyKpNodes() {
+ return 2;
+ }
+
+ @Override
+ public int qtyKpLeaves() {
+ return 2;
+ }
+
+ @Override
+ public int qtyKpLeavesStrict() {
+ return 2;
+ }
+
+ @Override
+ public CharSequence getText() {
+ return "-";
+ }
+
+ @Override
+ public KpNode kpNodeAt(final int nodeIndex) {
+ switch (nodeIndex) {
+ case 0: return this.box;
+ case 1: return this.penalty;
+ default: throw new ArrayIndexOutOfBoundsException();
+ }
+ }
+
+ @Override
+ public KpLeaf kpLeafAt(final int leafIndex) {
+ switch (leafIndex) {
+ case 0: return this.box;
+ case 1: return this.penalty;
+ default: throw new ArrayIndexOutOfBoundsException();
+ }
+ }
+
+ @Override
+ public KpLeafIterator leafIterator() {
+ return new KpLeafIterator4a(this);
+ }
+
+ @Override
+ public KpContext getKpContext() {
+ return null;
+ }
+
+ /**
+ * The Box portion of the compound break.
+ */
+ public class Box extends KpLeaf4a implements KpBox {
+
+ @Override
+ public Type getKpLeafType() {
+ return KpLeaf.Type.BOX;
+ }
+
+ @Override
+ public int getIdealWidth(final KpContext config) {
+ return config.getHyphenCharacterWidth();
+ }
+
+ @Override
+ public int qtyKpLeavesStrict() {
+ return 1;
+ }
+
+ @Override
+ public CharSequence getText() {
+ return "-";
+ }
+
+ @Override
+ public int getStretchability(final KpContext config) {
+ return 0;
+ }
+
+ @Override
+ public int getShrinkability(final KpContext config) {
+ return 0;
+ }
+
+ }
+
+ /**
+ * The Penalty portion of the compound break.
+ */
+ public class Penalty extends KpLeaf4a implements KpPenalty {
+
+ @Override
+ public Type getKpLeafType() {
+ return KpLeaf.Type.PENALTY;
+ }
+
+ @Override
+ public int qtyKpLeavesStrict() {
+ return 1;
+ }
+
+ @Override
+ public CharSequence getText() {
+ return StringUtils.EMPTY_STRING;
+ }
+
+ @Override
+ public int getIdealWidth(final KpContext config) {
+ return 0;
+ }
+
+ @Override
+ public int getStretchability(final KpContext config) {
+ return 0;
+ }
+
+ @Override
+ public int getShrinkability(final KpContext config) {
+ return 0;
+ }
+
+ @Override
+ public int getPenaltyWidth(final KpContext config) {
+ return 0;
+ }
+
+ @Override
+ public int getCost(final KpUserAgent control) {
+ /* TODO: This is almost certainly wrong. This should probably be a separate cost entry in the context. */
+ return control.getCost(KpPenalty.Quality.ACCEPTABLE);
+ }
+
+ @Override
+ public boolean isFlagged() {
+ return false;
+ }
+
+ }
+
+}
Property changes on: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/CompoundBreak4a.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2022-06-14 20:43:31 UTC (rev 12653)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2022-06-14 22:02:44 UTC (rev 12654)
@@ -360,22 +360,25 @@
this.lastWord = actualContentLowercase;
}
- /* Look in the ambiguous words first. */
+ /* Is it an existing ambiguous word? */
if (this.ambiguousWordMap.containsKey(actualContent)) {
final List<StringWord> list = this.ambiguousWordMap.get(actualContent);
list.add(word);
- } else {
- /* See if this is a new ambiguous word. */
- if (wordMap.containsKey(actualContent)) {
- final StringWord existingMapEntry = wordMap.remove(actualContent);
- final List<StringWord> list = new ArrayList<StringWord>();
- list.add(existingMapEntry);
- list.add(word);
- this.ambiguousWordMap.put(actualContent, list);
- } else {
- wordMap.put(actualContent, word);
- }
+ break;
}
+
+ /* Is it a new ambiguous word? */
+ if (wordMap.containsKey(actualContent)) {
+ final StringWord existingMapEntry = wordMap.remove(actualContent);
+ final List<StringWord> list = new ArrayList<StringWord>();
+ list.add(existingMapEntry);
+ list.add(word);
+ this.ambiguousWordMap.put(actualContent, list);
+ break;
+ }
+
+ /* Add it to normal words. */
+ wordMap.put(actualContent, word);
break;
}
case "t": {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|