diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java index a60fe15..cc18a8a 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java @@ -40,6 +40,7 @@ import org.x4o.fc18.cake2.pie9d.FCDotPIE9DDash09; import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6; import org.x4o.fc18.octal8.PrimordialOctal; import org.x4o.fc18.zion7.FourCornerZion7Candlelier; +import org.x4o.fc18.zion7.FourCornerZion7NumberGram; import org.x4o.fc18.zion7.FourCornerZion7SalahSequence; import org.x4o.fc18.zion7.FourCornerZionStenoLexer; import org.x4o.fc18.zion7.FourCornerZionStenoLexerSmoke; @@ -135,7 +136,7 @@ public class FourCornerUnicodeDisplay { lexer.withSmokeSignals(printer).read(chars); } - private final class StenoUnicodePrinter implements FourCornerZion7Candlelier.Adapter, FourCornerZionStenoLexerSmoke.AdapterMonoPipe { + private final class StenoUnicodePrinter implements FourCornerZion7Candlelier, FourCornerZionStenoLexerSmoke.AdapterMonoPipe { private final StringBuilder output; private boolean wasExternalWord = false; @@ -170,13 +171,21 @@ public class FourCornerUnicodeDisplay { return false; } + @Override + public void strobeDocumentAlpha() { + } + + @Override + public void strobeDocumentOmega() { + } + @Override public void strobeWords(List cakePoints) { for (int i = 0; i < cakePoints.size(); i++) { strobeWord(cakePoints.get(i)); } } - + @Override public void strobeWord(int cakePoint) { @@ -236,6 +245,16 @@ public class FourCornerUnicodeDisplay { output.append("#"); } + @Override + public void strobeNumberGrams(FourCornerZion7NumberGram gram, List values) { + // todo use external words + List math = new ArrayList<>(); + for (Integer num : values) { + FourCornerRecipe.toDecimalsX18(math, num); + } + renderFromInt18(math, output); + } + @Override public void strobeNCR1632(BigInteger numerator, BigInteger denominator) { List math = new ArrayList<>(); diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/cake2/FourCornerDotCake.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/cake2/FourCornerDotCake.java index 57216c0..808b8c1 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/cake2/FourCornerDotCake.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/cake2/FourCornerDotCake.java @@ -310,8 +310,11 @@ public enum FourCornerDotCake { // =========== Define document structures and sandworms + FC_DOZEGER_192(0x026800, 512, "Dozeger 192 bit integer"), + FC_DOZIMAL_192(0x026A00, 512, "Dozimal 192 bit decimal"), + /// Reserved Flag4 Structures - __RESERVED_F4(0x026800, 0x026DBE - 0x026800, "Reserved for F4 structures"), + __RESERVED_F4(0x026C00, 0x026DBE - 0x026C00, "Reserved for F4 structures"), /// Tele Type Ytructure00 zero one Nether Line FC_F4TTY0001_NL(0x026DBE, 1, FCDotF4TTY0001DashNL.values(), "Flag4 TTY00 zero one Nether Line"), diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7Candlelier.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7Candlelier.java index f462624..02c4663 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7Candlelier.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7Candlelier.java @@ -39,9 +39,10 @@ public interface FourCornerZion7Candlelier extends FourCornerZion7AlphaOmega { /// Block of word cake points. void strobeWords(List cakePoints); - //void strobeWordGrams(int gramBase, List values); - //void strobeWordDozimal(BigDecimal value); - //void strobeWordDozeger(BigInteger value); // up to 192 bit integer + /// Block of one of more number grams of given base. + void strobeNumberGrams(FourCornerZion7NumberGram gram, List values); + //void strobeNumberDozimal(BigDecimal value); + //void strobeNumberDozeger(BigInteger value); // up to 192 bit integer /// 1152 bit fractions of two 576 bit numbers. void strobeNCR1632(BigInteger numerator, BigInteger denominator); @@ -65,6 +66,10 @@ public interface FourCornerZion7Candlelier extends FourCornerZion7AlphaOmega { default void strobeWords(List cakePoints) { } + @Override + default void strobeNumberGrams(FourCornerZion7NumberGram gram, List values) { + } + @Override default void strobeNCR1632(BigInteger numerator, BigInteger denominator) { } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7NumberGram.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7NumberGram.java new file mode 100644 index 0000000..ca0ec43 --- /dev/null +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7NumberGram.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2004-2014, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.x4o.fc18.zion7; + +import org.x4o.fc18.cake2.FourCornerDotCake; + +/// The supported number grams. +/// +/// @author Willem Cazander +/// @version 1.0 Aug 25, 2025 +public enum FourCornerZion7NumberGram { + + CUT_2(FourCornerDotCake.FC_BMW0102_S2), + CUT_10(FourCornerDotCake.FC_AMD0110_SA), + CUT_256(FourCornerDotCake.FC_IBM1616_H8), + CUT_27(FourCornerDotCake.FC_NES0127_9C), + CUT_9(FourCornerDotCake.FC_WDC0109_S9), + CUT_6(FourCornerDotCake.FC_SCO0106_S6), + CUT_3(FourCornerDotCake.FC_NXP0103_S3), + CUT_5(FourCornerDotCake.FC_NEC0105_S5), + CUT_7(FourCornerDotCake.FC_W3C0107_S7), + CUT_1(FourCornerDotCake.FC_UWU0101_S1), + CUT_4(FourCornerDotCake.FC_DNA0104_S4), + CUT_26(FourCornerDotCake.FC_ICL0126_9B), + CUT_60(FourCornerDotCake.FC_PDS6001_BC), + CUT_12(FourCornerDotCake.FC_SDS1201_AM), + CUT_24(FourCornerDotCake.FC_RCA2401_PM), + CUT_8(FourCornerDotCake.FC_OCE0801_H3), + CUT_64(FourCornerDotCake.FC_OCE0808_H6), + CUT_512(FourCornerDotCake.FC_OCE0864_H9), + CUT_2048(FourCornerDotCake.FC_BIP0039_2K), + ; + private static final FourCornerZion7NumberGram[] VALUES = values(); + private final int cutCount; + private final int cutZeroCakePoint; + + private FourCornerZion7NumberGram(FourCornerDotCake slice) { + cutCount = slice.getStop() - slice.getStart(); + cutZeroCakePoint = slice.getStart(); + } + + public int cutCount() { + return cutCount; + } + + public int cutZeroCakePoint() { + return cutZeroCakePoint; + } + + static public int valuesLength() { + return VALUES.length; + } + + static public FourCornerZion7NumberGram valueOf(int idx) { + return VALUES[idx]; + } + + static public FourCornerZion7NumberGram valueByCutCount(int cutCount) { + final int valuesLength = valuesLength(); + for (int i = 0; i < valuesLength; i++) { + FourCornerZion7NumberGram gram = valueOf(i); + if (gram.cutCount() == cutCount) { + return gram; + } + } + return null; + } +} diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoGrapher.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoGrapher.java index d21d9b5..82aa94c 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoGrapher.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoGrapher.java @@ -111,12 +111,12 @@ public class FourCornerZionStenoGrapher { @Override public void strobeDocumentAlpha() { } - + @Override public void strobeDocumentOmega() { outFlush(); } - + @Override public void strobeWord(int cakePoint) { if (isSixBit && cakePoint > 63) { @@ -127,7 +127,7 @@ public class FourCornerZionStenoGrapher { } outAdd(cakePoint); } - + @Override public void strobeWords(List cakePoints) { Objects.requireNonNull(cakePoints); @@ -137,7 +137,28 @@ public class FourCornerZionStenoGrapher { } outFlush(); } - + + @Override + public void strobeNumberGrams(FourCornerZion7NumberGram gram, List values) { + Objects.requireNonNull(gram); + Objects.requireNonNull(values); + if (isSixBit) { + // todo + } + int gramCount = values.size(); + for (int i = 0; i < gramCount; i++) { + int gramValue = values.get(i); + if (gramValue < 0) { + throw new IllegalArgumentException("Gram value is smaller than zero"); + } + if (gramValue > gram.cutCount()) { + throw new IllegalArgumentException("Gram value is greater than cut count: " + gram.cutCount()); + } + strobeWord(gram.cutZeroCakePoint() + gramValue); + } + outFlush(); + } + @Override public void strobeNCR1632(BigInteger numerator, BigInteger denominator) { Objects.requireNonNull(numerator); @@ -237,7 +258,7 @@ public class FourCornerZionStenoGrapher { } outFlush(); } - + @Override public void strobeSandWalker(List rhythm) { Objects.requireNonNull(rhythm); @@ -259,7 +280,7 @@ public class FourCornerZionStenoGrapher { //} // todo bring back native 18 bit sand walking if space allow (for adult rule) } - + @Override public void strobeSandWorm(List spice) { Objects.requireNonNull(spice); @@ -289,7 +310,7 @@ public class FourCornerZionStenoGrapher { } outFlush(); } - + @Override public void strobeSalahSequence(FourCornerZion7SalahSequence type, List> arguments) { Objects.requireNonNull(type); diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java index 02fbac5..92397d2 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java @@ -30,6 +30,7 @@ import java.util.Objects; import java.util.Optional; import org.x4o.fc18.cake2.FourCornerDotCake; +import org.x4o.fc18.cake2.FourCornerDotCakeTower; import org.x4o.fc18.cake2.flag4.FCDotF4TTY0001DashNL; import org.x4o.fc18.cake2.flag4.FCDotF4TXT0001DashSP; import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6; @@ -92,6 +93,10 @@ public class FourCornerZionStenoLexer { if (FourCornerDotCake.FC_NCR1632_NUM.equals(cakeSlice)) { continue; // parse block manually } + if (FourCornerDotCakeTower.TXT_GRAMS.equals(cakeSlice.tower())) { + CAKE_SLICE_EATERS.add(new StenoScannerNumberGramSlice(cakeSlice)); + continue; + } CAKE_SLICE_EATERS.add(new StenoScannerWordCakeSlice(cakeSlice)); } CAKE_SLICE_EATERS.add(new StenoScannerCDCDEC()); @@ -281,6 +286,25 @@ public class FourCornerZionStenoLexer { } } + static class StenoScannerNumberGramSlice extends StenoScanner { + + private final FourCornerZion7NumberGram numberGram; + + public StenoScannerNumberGramSlice(FourCornerDotCake cakeSlice) { + super(cakeSlice); + this.numberGram = FourCornerZion7NumberGram.valueByCutCount(cakeSlice.getStop() - cakeSlice.getStart()); + } + + @Override + public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) { + List offsets = new ArrayList<>(); + for (int i = idxFirst; i <= idxLast; i++) { + offsets.add(lexer.input.get(i) - blockStart); + } + lexer.handler.strobeNumberGrams(numberGram, offsets); + } + } + static class StenoScannerSandWorm extends StenoScanner { public StenoScannerSandWorm() { diff --git a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/gram5/FCNumberGramTest.java b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/gram5/FCNumberGramTest.java new file mode 100644 index 0000000..a4e383a --- /dev/null +++ b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/gram5/FCNumberGramTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2004-2014, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.x4o.fc18.cake2.gram5; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.x4o.fc18.FourCornerUnicodeDisplay; +import org.x4o.fc18.zion7.FourCornerZion7Candlelier; +import org.x4o.fc18.zion7.FourCornerZion7NumberGram; +import org.x4o.fc18.zion7.FourCornerZionStenoGrapher; + +/** + * Tests txt grams encoding. + * + * @author Willem Cazander + * @version 1.0 Aug 25, 2025 + */ +public class FCNumberGramTest { + + @Test + public void testCut10Simple() throws Exception { + List out = new ArrayList<>(); + FourCornerZion7Candlelier writer = FourCornerZionStenoGrapher.writerX18(out); + writer.strobeNumberGrams(FourCornerZion7NumberGram.CUT_10, List.of(0,1,2,3,4,5,6,7,8,9)); + String res = FourCornerUnicodeDisplay.text().renderFromInt18(out); + Assertions.assertEquals("0123456789", res); + } + + @Test + public void testCutArguFail() throws Exception { + List out = new ArrayList<>(); + FourCornerZion7Candlelier writer = FourCornerZionStenoGrapher.writerX18(out); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + writer.strobeNumberGrams(FourCornerZion7NumberGram.CUT_10, List.of(11)); + }); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + writer.strobeNumberGrams(FourCornerZion7NumberGram.CUT_10, List.of(-1)); + }); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + writer.strobeNumberGrams(FourCornerZion7NumberGram.CUT_1, List.of(1)); + }); + } +}