FC18: Renamed mapper to recipe with fc18 generators static methods only

This commit is contained in:
Willem Cazander 2025-08-07 17:01:45 +02:00
parent 6b8d281e40
commit c6144b8956
10 changed files with 72 additions and 92 deletions

View file

@ -35,7 +35,7 @@ import java.util.stream.Collectors;
import org.x4o.fc18.FourCornerUnicodeDisplay;
import org.x4o.fc18.FourCornerUnicodeImport;
import org.x4o.fc18.FourCornerUnicodeMapper;
import org.x4o.fc18.FourCornerRecipe;
import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6;
import org.x4o.fc18.cake2.zero33.dec1.FCDotCMD5401Dash2D;
import org.x4o.fc18.octal8.PrimordialOctalOrangeString;
@ -81,7 +81,7 @@ public class KanjiDictTest {
String valueUnicode = new StringBuilder().appendCodePoint(lit.getCodePoint()).toString();
kuTen2UNI2K.addAll(FourCornerUnicodeImport.strict().convertToInt18(key));
kuTen2UNI2K.add(FCDotCDC1604DashP6.NY09_EQUALS.cakePointDotIndex());
kuTen2UNI2K.addAll(FourCornerUnicodeMapper.DICTIONARY.embedUNI2K(valueUnicode));
kuTen2UNI2K.addAll(FourCornerRecipe.embedUNI2K(valueUnicode));
kuTen2UNI2K.addAll(FCDotCMD5401Dash2D.CMD_F4TTY0001_NL.cakePointSequence());
}
for (String key : dict.mapKuTen213().keySet()) {
@ -89,7 +89,7 @@ public class KanjiDictTest {
String valueUnicode = new StringBuilder().appendCodePoint(lit.getCodePoint()).toString();
kuTen2UNI2K.addAll(FourCornerUnicodeImport.strict().convertToInt18(key));
kuTen2UNI2K.add(FCDotCDC1604DashP6.NY09_EQUALS.cakePointDotIndex());
kuTen2UNI2K.addAll(FourCornerUnicodeMapper.DICTIONARY.embedUNI2K(valueUnicode));
kuTen2UNI2K.addAll(FourCornerRecipe.embedUNI2K(valueUnicode));
kuTen2UNI2K.addAll(FCDotCMD5401Dash2D.CMD_F4TTY0001_NL.cakePointSequence());
}
// size 316575 (baklave TTY)

View file

@ -24,12 +24,8 @@ package org.x4o.fc18;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.PrimitiveIterator;
import org.x4o.fc18.cake2.FourCornerDotCake;
@ -43,63 +39,16 @@ import org.x4o.fc18.cake2.pie9c.FCDotPIE9CDash20;
import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6;
import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0;
/// Holds conversion maps between four corner int18 and unicode int21 points.
/// Holds different lookup and conversion maps towards four corner int18 cake points.
///
/// @author Willem Cazander
/// @version 1.0 Jan 09, 2025
public enum FourCornerUnicodeMapper {
DICTIONARY,
;
final public class FourCornerRecipe {
private final Map<Integer, List<Integer>> int18To21 = new HashMap<>();
private final Map<Integer, FourCornerX00PetitVide> int21ToVide = new HashMap<>();
private FourCornerUnicodeMapper() {
for (FourCornerDotCake slice : FourCornerDotCake.values()) {
FourCornerX00PetitVide[] videPoints = slice.getVidePoints();
if (videPoints.length == 0) {
continue;
}
mapPointsX18(videPoints);
mapPointsX21(videPoints);
}
int18To21.forEach((k,v) -> int18To21.put(k, Collections.unmodifiableList(v)));
private FourCornerRecipe() {
}
private void mapPointsX18(FourCornerX00PetitVide[] petitVides) {
for (FourCornerX00PetitVide petitVide : petitVides) {
Optional<FourCornerX18CakePointDotIndex> x18CakeDotIndex = petitVide.kaasX18CakeDotIndex();
if (x18CakeDotIndex.isEmpty()) {
continue;
}
int char18 = x18CakeDotIndex.get().cakePointDotIndex();
petitVide.kaasX21CodeSequence().ifPresent(v -> {
int18To21.put(char18, v.codePointSequence());
});
}
}
private void mapPointsX21(FourCornerX00PetitVide[] petitVides) {
for (FourCornerX00PetitVide petitVide : petitVides) {
petitVide.kaasX21CodeDotIndex().ifPresent(v -> {
int codePoint = v.codePointDotIndex();
if (codePoint >= 0) {
int21ToVide.put(codePoint, v);
}
});
}
}
public List<Integer> findByX18(Integer letter) {
return int18To21.get(letter);
}
public FourCornerX00PetitVide findByX21(Integer letter) {
return int21ToVide.get(letter);
}
// TODO: move this not really unicode related, AND add the muffin version too... move into StenoGrapher later?
public List<Integer> embedFC18(List<Integer> cakePoints) {
static public List<Integer> embedFC18(List<Integer> cakePoints) {
if (cakePoints.isEmpty()) {
return cakePoints;
}
@ -144,7 +93,7 @@ public enum FourCornerUnicodeMapper {
}
@Deprecated // TODO: move to sand worm
public List<Integer> embedUNI2K(String value) {
static public List<Integer> embedUNI2K(String value) {
List<Integer> result = new ArrayList<>(value.length());
PrimitiveIterator.OfInt i = value.codePoints().iterator();
int bankSelect = 0;
@ -168,21 +117,21 @@ public enum FourCornerUnicodeMapper {
return result;
}
// todo move...
public List<Integer> embedNCR1632Denominator(BigInteger value) {
static public List<Integer> embedNCR1632Denominator(BigInteger value) {
return embedNCR1632Value(value, FourCornerDotCake.FC_NCR1632_XD.getStart());
}
// todo move...
public List<Integer> embedNCR1632Numerator(BigInteger value) {
static public List<Integer> embedNCR1632Numerator(BigInteger value) {
return embedNCR1632Value(value, FourCornerDotCake.FC_NCR1632_XN.getStart());
}
// todo move...
private List<Integer> embedNCR1632Value(BigInteger value, int bankStart) {
static private List<Integer> embedNCR1632Value(BigInteger value, int bankStart) {
if (value.equals(BigInteger.ZERO)) {
throw new IllegalArgumentException("The value ZERO is not allowed.");
}
//if (value.signum() == -1) {
// // TODO: check if we need one octal for pos/neg/qNaN/sNaN/pos_inf/neg_inf/free/free options
//}
List<Integer> result = new ArrayList<>();
BigInteger valueZero = value.subtract(BigInteger.ONE);
if (valueZero.equals(BigInteger.ZERO)) {
@ -202,28 +151,28 @@ public enum FourCornerUnicodeMapper {
reminder = reminder.subtract(BigInteger.valueOf(bankValue).shiftLeft(i * 9));
}
if (!reminder.equals(BigInteger.ZERO)) {
throw new IllegalArgumentException("value is larger than 576 bit allowed: " + reminder + " of " + value);
throw new IllegalArgumentException("Value is larger than 576 bit: " + reminder + " of " + value);
}
return result;
}
public List<FourCornerX18CakePointDotIndex> toScriptSuper(int value) {
static public List<FourCornerX18CakePointDotIndex> toScriptSuper(int value) {
return toScript(Integer.toString(value), 0);
}
public List<FourCornerX18CakePointDotIndex> toScriptSub(int value) {
static public List<FourCornerX18CakePointDotIndex> toScriptSub(int value) {
return toScript(Integer.toString(value), 10);
}
public List<FourCornerX18CakePointDotIndex> toScriptSuper(BigInteger value) {
static public List<FourCornerX18CakePointDotIndex> toScriptSuper(BigInteger value) {
return toScript(value.toString(10), 0);
}
public List<FourCornerX18CakePointDotIndex> toScriptSub(BigInteger value) {
static public List<FourCornerX18CakePointDotIndex> toScriptSub(BigInteger value) {
return toScript(value.toString(10), 10);
}
private List<FourCornerX18CakePointDotIndex> toScript(String value, int off) {
static private List<FourCornerX18CakePointDotIndex> toScript(String value, int off) {
List<FourCornerX18CakePointDotIndex> result = new ArrayList<>();
PrimitiveIterator.OfInt i = value.codePoints().iterator();
while (i.hasNext()) {
@ -237,21 +186,21 @@ public enum FourCornerUnicodeMapper {
continue;
}
int num = chr - '0';
result.add(FCDotPIE9CDash20.values()[num + off]);
result.add(FCDotPIE9CDash20.valueOf(num + off));
}
return result;
}
public List<FourCornerX06BaklavaPointSequence> toDecimalsX06(int value) {
static public List<FourCornerX06BaklavaPointSequence> toDecimalsX06(int value) {
return toDecimalsX00(value);
}
public List<FourCornerX18CakePointSequence> toDecimalsX18(int value) {
static public List<FourCornerX18CakePointSequence> toDecimalsX18(int value) {
return toDecimalsX00(value);
}
@SuppressWarnings("unchecked")
private <T extends FourCornerX00PetitVide> List<T> toDecimalsX00(int value) {
static private <T extends FourCornerX00PetitVide> List<T> toDecimalsX00(int value) {
List<T> result = new ArrayList<>();
String valueStr = Integer.toString(value);
PrimitiveIterator.OfInt i = valueStr.codePoints().iterator();

View file

@ -226,9 +226,9 @@ public class FourCornerUnicodeDisplay {
@Override
public void strobeNCR1632(BigInteger denominator, BigInteger numerator) {
List<Integer> math = new ArrayList<>();
FourCornerUnicodeMapper.DICTIONARY.toScriptSuper(numerator).forEach(v -> math.add(v.cakePointDotIndex()));
FourCornerRecipe.toScriptSuper(numerator).forEach(v -> math.add(v.cakePointDotIndex()));
math.add(FCDotCDC1604DashP6.NY02_BAR_V_RIGHT.ordinal());
FourCornerUnicodeMapper.DICTIONARY.toScriptSub(denominator).forEach(v -> math.add(v.cakePointDotIndex()));
FourCornerRecipe.toScriptSub(denominator).forEach(v -> math.add(v.cakePointDotIndex()));
renderFromInt18(math, output);
}

View file

@ -23,12 +23,15 @@
package org.x4o.fc18;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.PrimitiveIterator;
import java.util.Set;
import java.util.stream.Collectors;
import org.x4o.fc18.cake2.FourCornerDotCake;
import org.x4o.fc18.cake2.FourCornerX00PetitVide;
import org.x4o.fc18.cake2.FourCornerX06BaklavaPointSequence;
import org.x4o.fc18.cake2.FourCornerX08MuffinPointSequence;
@ -48,6 +51,7 @@ public class FourCornerUnicodeImport {
private boolean convertWhitespaces = false;
private boolean failOnMissing = false;
private List<FCDotCDC1604DashP6> missingCharIndicator = null;
private final Map<Integer, FourCornerX00PetitVide> int21ToVide = new HashMap<>();
private static final Set<Integer> WHITE_SPACES = Set.of(
'\u3000','\u205F','\u202F','\u200A','\u2009','\u2008','\u2007','\u2006',
'\u2005','\u2004','\u2003','\u2002','\u2001','\u2000','\u00A0','\u0020')
@ -58,6 +62,24 @@ public class FourCornerUnicodeImport {
this.convertDiacritics = convertDiacritics;
this.failOnMissing = failOnMissing;
this.missingCharIndicator = missingCharIndicator;
for (FourCornerDotCake slice : FourCornerDotCake.values()) {
FourCornerX00PetitVide[] videPoints = slice.getVidePoints();
if (videPoints.length == 0) {
continue;
}
mapPointsX21(videPoints);
}
}
private void mapPointsX21(FourCornerX00PetitVide[] petitVides) {
for (FourCornerX00PetitVide petitVide : petitVides) {
petitVide.kaasX21CodeDotIndex().ifPresent(v -> {
int codePoint = v.codePointDotIndex();
if (codePoint >= 0) {
int21ToVide.put(codePoint, v);
}
});
}
}
static public FourCornerUnicodeImport strict() {
@ -231,7 +253,7 @@ public class FourCornerUnicodeImport {
}
private boolean handleDictionary(ImportState ctx) {
FourCornerX00PetitVide chs = FourCornerUnicodeMapper.DICTIONARY.findByX21(ctx.codePoint);
FourCornerX00PetitVide chs = int21ToVide.get(ctx.codePoint);
if (chs == null) {
return false;
}

View file

@ -58,6 +58,7 @@ public enum FCDotPIE9CDash20 implements FourCornerDotCollePie9 {
SUB_8('₈'),
SUB_9('₉'),
;
static final private FCDotPIE9CDash20[] VALUES = values(); // values() is slow method
private final List<Integer> codePointDisplay;
private FCDotPIE9CDash20(int...codePoints) {
@ -78,4 +79,12 @@ public enum FCDotPIE9CDash20 implements FourCornerDotCollePie9 {
public List<Integer> codePointSequence() {
return codePointDisplay;
}
static public int valuesLength() {
return VALUES.length;
}
static public FCDotPIE9CDash20 valueOf(int idx) {
return VALUES[idx];
}
}

View file

@ -26,7 +26,7 @@ import java.math.BigInteger;
import java.util.List;
import java.util.Objects;
import org.x4o.fc18.FourCornerUnicodeMapper;
import org.x4o.fc18.FourCornerRecipe;
import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0;
import org.x4o.fc18.octal8.PrimordialOctal;
@ -64,8 +64,8 @@ public class FourCornerZionStenoGrapher {
@Override
public void strobeNCR1632(BigInteger denominator, BigInteger numerator) {
out.addAll(FourCornerUnicodeMapper.DICTIONARY.embedNCR1632Denominator(denominator));
out.addAll(FourCornerUnicodeMapper.DICTIONARY.embedNCR1632Numerator(numerator));
out.addAll(FourCornerRecipe.embedNCR1632Denominator(denominator));
out.addAll(FourCornerRecipe.embedNCR1632Numerator(numerator));
}
@Override

View file

@ -59,7 +59,7 @@ public class FourCornerZionStenoLexer {
private final FourCornerZion7WaterCodex handlerCodex;
private final FourCornerZion7SalahSequence handlerSalahSequence;
private final FourCornerZion7TempleScrolls handlerTempleScrolls;
private final int denominatorBank[] = new int[64]; // <== is the terminator select per 9 bit group of 9 bit values
private final int denominatorBank[] = new int[64]; // <== is the terminator select are 6 bit of banks with 9 bit of values.
private final int numeratorBank[] = new int[denominatorBank.length];
private List<Integer> input;
private int inputIndex = 0;

View file

@ -101,9 +101,9 @@ public class FourCornerUnicodeDisplayTest {
List<Integer> cdc = new ArrayList<>();
cdc.add(FCDotCDC1604DashP6.NX23_W.ordinal());
cdc.add(FCDotCDC1604DashP6.NY09_EQUALS.ordinal());
cdc.addAll(FourCornerUnicodeMapper.DICTIONARY.embedUNI2K("©Δ∞ 仙上主天"));
cdc.addAll(FourCornerRecipe.embedUNI2K("©Δ∞ 仙上主天"));
cdc.add(FCDotCDC1604DashP6.NY20_PLUS.ordinal());
cdc.addAll(FourCornerUnicodeMapper.DICTIONARY.embedUNI2K("𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡 𑀪𑀸𑀕"));
cdc.addAll(FourCornerRecipe.embedUNI2K("𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡 𑀪𑀸𑀕"));
cdc.add(FCDotCDC1604DashP6.NY14_SEMICOLON.ordinal());
//cdc.add(FCDotCDC1604DashP6._NEWLINE.ordinal());
@ -114,7 +114,7 @@ public class FourCornerUnicodeDisplayTest {
int bitsFC18 = cdc.size()*18;
Assertions.assertTrue(bitsFC18 < bitsUTF8, "FC18 is not smaller");
List<Integer> cdc6 = FourCornerUnicodeMapper.DICTIONARY.embedFC18(cdc);
List<Integer> cdc6 = FourCornerRecipe.embedFC18(cdc);
Assertions.assertEquals(outputExpected, FourCornerUnicodeDisplay.text().renderFromInt18(cdc6));
Assertions.assertTrue(cdc6.size() > cdc.size(), "FCx6 is not bigger");

View file

@ -28,7 +28,7 @@ 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.FourCornerUnicodeMapper;
import org.x4o.fc18.FourCornerRecipe;
import org.x4o.fc18.cake2.FourCornerX06BaklavaPointSequence;
import org.x4o.fc18.cake2.zero33.vt06.VTDash06DotZeroACursor;
import org.x4o.fc18.cake2.zero33.vt06.VTDash06DotZeroCClear;
@ -45,9 +45,9 @@ public class FCDotVT06Test {
public void testCusorGoto() throws Exception {
List<FourCornerX06BaklavaPointSequence> cdc = new ArrayList<>();
cdc.add(VTDash06DotZeroACursor.VT_CURSOR_GOTO);
cdc.addAll(FourCornerUnicodeMapper.DICTIONARY.toDecimalsX06(123)); // TODO: fix these are the wrong, we need to use the txt grams version
cdc.addAll(FourCornerRecipe.toDecimalsX06(123)); // TODO: fix these are the wrong, we need to use the txt grams version
cdc.add(FCDotCDC1604DashP6._RAKA_QUESTION);
cdc.addAll(FourCornerUnicodeMapper.DICTIONARY.toDecimalsX06(456));
cdc.addAll(FourCornerRecipe.toDecimalsX06(456));
cdc.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION);
Assertions.assertEquals("␘␘␇AG␇␇␇^BCD?␇␇␇^EFG!", FourCornerUnicodeDisplay.raw().renderFromX06(cdc));
@ -59,7 +59,7 @@ public class FCDotVT06Test {
public void testClearTop5Lines() throws Exception {
List<FourCornerX06BaklavaPointSequence> cdc = new ArrayList<>();
cdc.add(VTDash06DotZeroCClear.VT_CLEAR_TOP);
cdc.addAll(FourCornerUnicodeMapper.DICTIONARY.toDecimalsX06(5));
cdc.addAll(FourCornerRecipe.toDecimalsX06(5));
cdc.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION);
Assertions.assertEquals("␘␘␇CA␇␇␇^F!", FourCornerUnicodeDisplay.raw().renderFromX06(cdc));

View file

@ -29,7 +29,7 @@ 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.FourCornerUnicodeMapper;
import org.x4o.fc18.FourCornerRecipe;
import org.x4o.fc18.cake2.FourCornerDotCake;
import org.x4o.fc18.cake2.FourCornerX06BaklavaPointSequence;
import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6;
@ -139,10 +139,10 @@ public class LexerNCRTest {
List<Integer> cdc = new ArrayList<>();
for (int x = 1; x <= 1024; x++) {
BigInteger v = BigInteger.valueOf(x);
cdc.addAll(FourCornerUnicodeMapper.DICTIONARY.embedNCR1632Denominator(v));
cdc.addAll(FourCornerRecipe.embedNCR1632Denominator(v));
//cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart()); // NXX_1
List<Integer> nomList = FourCornerUnicodeMapper.DICTIONARY.embedNCR1632Numerator(BigInteger.ONE);
List<Integer> nomList = FourCornerRecipe.embedNCR1632Numerator(BigInteger.ONE);
Assertions.assertEquals(1, nomList.size());
cdc.addAll(nomList); // NXX_1
}