scuffed-code/tools/unicodetools/com/ibm/text/UCD/TestData.java

483 lines
19 KiB
Java
Raw Normal View History

2001-08-31 00:30:17 +00:00
/**
*******************************************************************************
* Copyright (C) 1996-2001, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/text/UCD/TestData.java,v $
* $Date: 2002/07/30 09:56:40 $
* $Revision: 1.9 $
2001-08-31 00:30:17 +00:00
*
*******************************************************************************
*/
2001-08-30 20:50:18 +00:00
package com.ibm.text.UCD;
import java.util.*;
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import com.ibm.text.utility.*;
public class TestData implements UCD_Types {
/*
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
public static void main (String[] args) throws IOException {
System.out.println("START");
ucd = UCD.make();
System.out.println("Loaded UCD " + ucd.getVersion() + " " + (new Date(ucd.getDate())));
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
checkHoffman("\u05B8\u05B9\u05B1\u0591\u05C3\u05B0\u05AC\u059F");
checkHoffman("\u0592\u05B7\u05BC\u05A5\u05B0\u05C0\u05C4\u05AD");
2001-08-31 00:30:17 +00:00
long mask = 0;
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
if (false) {
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
generateVerticalSlice(BIDI_CLASS, BIDI_CLASS+NEXT_ENUM, KEEP_SPECIAL, HEADER_DERIVED,
"DerivedBidiClass-3.1.1d1.txt");
2001-08-31 00:30:17 +00:00
mask = Utility.setBits(0, DerivedProperty.FC_NFKC_Closure, DerivedProperty.ExpandsOnNFKC);
mask = Utility.clearBit(mask, DerivedProperty.FullCompInclusion);
2001-08-30 20:50:18 +00:00
generateDerived(mask, HEADER_DERIVED, "DerivedNormalizationProperties-3.1.0d1.txt");
generateVerticalSlice(EAST_ASIAN_WIDTH, EAST_ASIAN_WIDTH+NEXT_ENUM, KEEP_SPECIAL, HEADER_DERIVED,
"DerivedEastAsianWidth-3.1.0d1.txt");
2001-08-31 00:30:17 +00:00
generateVerticalSlice(CATEGORY, CATEGORY+NEXT_ENUM, KEEP_SPECIAL, HEADER_DERIVED,
2001-08-30 20:50:18 +00:00
"DerivedGeneralCategory-3.1.0d1.txt");
generateVerticalSlice(COMBINING_CLASS, COMBINING_CLASS+NEXT_ENUM, KEEP_SPECIAL, HEADER_DERIVED,
"DerivedCombiningClass-3.1.0d1.txt");
generateVerticalSlice(DECOMPOSITION_TYPE, DECOMPOSITION_TYPE+NEXT_ENUM, KEEP_SPECIAL, HEADER_DERIVED,
"DerivedDecompositionType-3.1.0d1.txt");
generateVerticalSlice(NUMERIC_TYPE, NUMERIC_TYPE+NEXT_ENUM, KEEP_SPECIAL, HEADER_DERIVED,
"DerivedNumericType-3.1.0d1.txt");
generateVerticalSlice(EAST_ASIAN_WIDTH, EAST_ASIAN_WIDTH+NEXT_ENUM, KEEP_SPECIAL, HEADER_DERIVED,
"DerivedEastAsianWidth-3.1.0d1.txt");
generateVerticalSlice(JOINING_TYPE, JOINING_TYPE+NEXT_ENUM, KEEP_SPECIAL, HEADER_DERIVED,
"DerivedJoiningType-3.1.0d1.txt");
generateVerticalSlice(JOINING_GROUP, JOINING_GROUP+NEXT_ENUM, KEEP_SPECIAL, HEADER_DERIVED,
"DerivedJoiningGroup-3.1.0d1.txt");
generateVerticalSlice(BINARY_PROPERTIES, BINARY_PROPERTIES+1, KEEP_SPECIAL, HEADER_DERIVED,
"DerivedBinaryProperties-3.1.0d1.txt");
generateVerticalSlice(LIMIT_ENUM, LIMIT_ENUM, KEEP_SPECIAL, HEADER_DERIVED,
"DerivedNumericValues-3.1.0d1.txt");
mask = Utility.setBits(0, DerivedProperty.PropMath, DerivedProperty.Mod_ID_Continue_NO_Cf);
2001-08-30 20:50:18 +00:00
generateDerived(mask, HEADER_DERIVED, "DerivedCoreProperties-3.1.0d1.txt");
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
generateVerticalSlice(LINE_BREAK, LINE_BREAK+NEXT_ENUM, KEEP_SPECIAL, HEADER_DERIVED,
"DerivedLineBreak-3.1.0d1.txt");
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
generateVerticalSlice(SCRIPT+1, SCRIPT + NEXT_ENUM, KEEP_SPECIAL, HEADER_SCRIPTS, "Scripts-3.1.0d4.txt");
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
generateVerticalSlice(BINARY_PROPERTIES + White_space, BINARY_PROPERTIES + Noncharacter_Code_Point + 1,
KEEP_SPECIAL, HEADER_EXTEND, "PropList-3.1.0d5.txt");
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
writeNormalizerTestSuite("NormalizationTest-3.1.0d1.txt");
}
2001-08-31 00:30:17 +00:00
//generateDerived(Utility.setBits(0, DerivedProperty.PropMath, DerivedProperty.Mod_ID_Continue_NO_Cf),
2001-08-30 20:50:18 +00:00
// HEADER_DERIVED, "DerivedPropData2-3.1.0d1.txt");
//generateVerticalSlice(SCRIPT, SCRIPT+1, KEEP_SPECIAL, "ScriptCommon-3.1.0d1.txt");
//listStrings("LowerCase-3.1.0d1.txt", 0,0);
//generateVerticalSlice(0, LIMIT_ENUM, SKIP_SPECIAL, PROPLIST1, "DerivedPropData1-3.1.0d1.txt");
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
// AGE stuff
//UCD ucd = UCD.make();
//System.out.println(ucd.getAgeID(0x61));
//System.out.println(ucd.getAgeID(0x2FA1D));
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
//generateCompExclusions();
System.out.println("END");
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
static Normalizer nfkc = new Normalizer(Normalizer.NFKC);
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
public static void checkHoffman(String test) {
String result = nfkc.normalize(test);
System.out.println(Utility.hex(test) + " => " + Utility.hex(result));
System.out.println();
show(test, 0);
System.out.println();
show(result, 0);
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
public static void show(String s, int indent) {
int cp;
for (int i = 0; i < s.length(); i += UTF32.count16(cp)) {
cp = UTF32.char32At(s, i);
String cc = " " + ucd.getCombiningClass(cp);
cc = Utility.repeat(" ", 4 - cc.length()) + cc;
System.out.println(Utility.repeat(" ", indent) + ucd.getCode(cp) + cc + " " + ucd.getName(cp));
String decomp = nfkc.normalize(cp);
if (!decomp.equals(UTF32.valueOf32(cp))) {
show(decomp, indent + 4);
}
}
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
//Remove "d1" from DerivedJoiningGroup-3.1.0d1.txt type names
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
public static String fixFile(String s) {
int len = s.length();
if (!s.endsWith(".txt")) return s;
if (s.charAt(len-6) != 'd') return s;
char c = s.charAt(len-5);
if (c < '0' || '9' < c) return s;
System.out.println("Fixing File Name");
return s.substring(0,len-6) + s.substring(len-4);
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
static final int HEADER_EXTEND = 0, HEADER_DERIVED = 1, HEADER_SCRIPTS = 2;
2001-08-31 00:30:17 +00:00
2001-09-19 23:33:52 +00:00
public static void doHeader(String fileName, PrintWriter output, int headerChoice) {
2001-08-30 20:50:18 +00:00
output.println("# " + fixFile(fileName));
output.println("#");
if (headerChoice == HEADER_SCRIPTS) {
output.println("# For documentation, see UTR #24: Script Names");
output.println("# http://www.unicode.org/unicode/reports/tr24/");
} else if (headerChoice == HEADER_EXTEND) {
output.println("# Unicode Character Database: Extended Properties");
output.println("# For documentation, see PropList.html");
} else {
output.println("# Unicode Character Database: Derived Property Data");
output.println("# Generated algorithmically from the Unicode Character Database");
output.println("# For documentation, see DerivedProperties.html");
}
output.println("# Date: " + myDateFormat.format(new Date()) + " [MD]");
output.println("# Note: Unassigned and Noncharacter codepoints are omitted,");
output.println("# except when listing Noncharacter or Cn.");
output.println("# ================================================");
output.println();
}
2001-08-31 00:30:17 +00:00
public static void generateDerived (long bitMask, int headerChoice, String fileName) throws IOException {
2001-09-19 23:33:52 +00:00
ucd = UCD.make("3.1.0");
PrintWriter output = Utility.openPrintWriter(fileName);
2001-08-30 20:50:18 +00:00
doHeader(fileName, output, headerChoice);
for (int i = 0; i < 32; ++i) {
if ((bitMask & (1<<i)) == 0) continue;
2001-12-05 02:41:23 +00:00
if (i >= DERIVED_PROPERTY_LIMIT) break;
2001-08-30 20:50:18 +00:00
System.out.print('.');
output.println("# ================================================");
output.println();
new DerivedPropertyLister(ucd, i, output).print();
}
output.close();
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
/*
public static void listStrings(String file, int type, int subtype) throws IOException {
2001-09-19 23:33:52 +00:00
ucd = UCD.make("3.1.0");
UCD ucd30 = UCD.make("3.0.0");
PrintWriter output = new PrintStream(new FileOutputStream(GEN_DIR + file));
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
for (int i = 0; i < 0x10FFFF; ++i) {
if ((i & 0xFFF) == 0) System.out.println("# " + i);
if (!ucd.isRepresented(i)) continue;
if (ucd30.isRepresented(i)) continue;
String string = "";
switch(type) {
case 0: string = ucd.getSimpleLowercase(i);
}
if (UTF32.length32(string) == 1 && UTF32.char32At(string,0) == i) continue;
output.println(Utility.hex(i) + "; C; " + Utility.hex(string) + "; # " + ucd.getName(i));
}
output.close();
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
public static void generateCompExclusions() throws IOException {
2001-09-19 23:33:52 +00:00
PrintWriter output = Utility.openPrintWriter("CompositionExclusionsDelta.txt");
2001-08-30 20:50:18 +00:00
new CompLister(output).print();
output.close();
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
static class CompLister extends PropertyLister {
UCD oldUCD;
int oldLength = 0;
2001-08-31 00:30:17 +00:00
2001-09-19 23:33:52 +00:00
public CompLister(PrintWriter output) {
2001-08-30 20:50:18 +00:00
this.output = output;
2001-09-19 23:33:52 +00:00
ucdData = UCD.make("3.1.0");
oldUCD = UCD.make("3.0.0");
2001-08-30 20:50:18 +00:00
showOnConsole = true;
}
2001-12-06 00:05:53 +00:00
public String valueName(int cp) {
2001-08-30 20:50:18 +00:00
return UTF32.length32(ucdData.getDecompositionMapping(cp)) + "";
}
public byte status(int cp) {
2001-08-31 00:30:17 +00:00
if (ucdData.getDecompositionType(cp) == CANONICAL
2001-08-30 20:50:18 +00:00
&& oldUCD.getDecompositionType(cp) != CANONICAL) {
int temp = oldLength;
oldLength = UTF32.length32(ucdData.getDecompositionMapping(cp));
if (temp != oldLength) return BREAK;
return INCLUDE;
}
return EXCLUDE;
}
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
static final byte KEEP_SPECIAL = 0, SKIP_SPECIAL = 1;
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
public static void generateVerticalSlice(int startEnum, int endEnum, byte skipSpecial, int headerChoice, String file) throws IOException {
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
//System.out.println(ucd.toString(0x1E0A));
/*
System.out.println(ucd.getData(0xFFFF));
System.out.println(ucd.getData(0x100000));
System.out.println(ucd.getData(0x100000-1));
System.out.println(ucd.getData(0x100000-2));
System.out.println(ucd.getData(0x100000-3));
if (true) return;
String test2 = ucd.getName(0x2A6D6);
//* /
2001-08-31 00:30:17 +00:00
2001-09-19 23:33:52 +00:00
PrintWriter output = Utility.openPrintWriter(file);
2001-08-30 20:50:18 +00:00
doHeader(file, output, headerChoice);
2001-08-30 20:50:18 +00:00
int last = -1;
for (int i = startEnum; i < endEnum; ++i) {
2001-12-05 02:41:23 +00:00
UnicodeProperty up = UnifiedBinaryProperty.make(i, ucd);
if (up == null) continue;
2001-08-31 00:30:17 +00:00
if (i == DECOMPOSITION_TYPE || i == NUMERIC_TYPE
2001-08-30 20:50:18 +00:00
|| i == (CATEGORY | UNUSED_CATEGORY)
|| i == (BINARY_PROPERTIES | Non_break)
|| i == (JOINING_TYPE | JT_U)
|| i == (SCRIPT | UNUSED_SCRIPT)
|| i == (JOINING_GROUP | NO_SHAPING)
) continue; // skip zero case
if (skipSpecial == SKIP_SPECIAL
&& i >= (BINARY_PROPERTIES | CompositionExclusion)
&& i < (AGE + NEXT_ENUM)) continue;
if ((last & 0xFF00) != (i & 0xFF00) && (i <= BINARY_PROPERTIES || i >= SCRIPT)) {
output.println();
output.println("# ================================================");
output.println("# " + UCD_Names.UNIFIED_PROPERTIES[i>>8]);
output.println("# ================================================");
output.println();
System.out.println();
System.out.println(UCD_Names.UNIFIED_PROPERTIES[i>>8]);
last = i;
} else {
output.println("# ================================================");
output.println();
}
System.out.print(".");
2001-08-31 00:30:17 +00:00
new MyPropertyLister(ucd, i, output).print();
2001-08-30 20:50:18 +00:00
}
if (endEnum == LIMIT_ENUM) {
output.println();
output.println("# ================================================");
output.println("# Numeric Values (from UnicodeData.txt, field 6/7/8)");
output.println("# ================================================");
output.println();
System.out.println();
System.out.println("@NUMERIC VALUES");
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
Set floatSet = new TreeSet();
for (int i = 0; i < 0x10FFFF; ++i) {
float nv = ucd.getNumericValue(i);
if (Float.isNaN(nv)) continue;
floatSet.add(new Float(nv));
}
Iterator it = floatSet.iterator();
while(it.hasNext()) {
new MyFloatLister(ucd, ((Float)it.next()).floatValue(), output).print();
output.println();
System.out.print(".");
}
}
output.close();
System.out.println();
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
static UCD ucd;
static public Normalizer formC, formD, formKC, formKD;
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
static public void writeNormalizerTestSuite(String fileName) throws IOException {
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
PrintWriter log = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(GEN_DIR + fileName),
"UTF8"),
32*1024));
formC = new Normalizer(Normalizer.NFC);
formD = new Normalizer(Normalizer.NFD);
formKC = new Normalizer(Normalizer.NFKC);
formKD = new Normalizer(Normalizer.NFKD);
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
log.println("# " + fixFile(fileName));
log.println("#");
log.println("# Normalization Test Suite");
log.println("# Date: " + myDateFormat.format(new Date()) + " [MD]");
log.println("# Format:");
log.println("#");
log.println("# Columns (c1, c2,...) are separated by semicolons");
log.println("# Comments are indicated with hash marks");
log.println("#");
log.println("# CONFORMANCE:");
log.println("# 1. The following invariants must be true for all conformant implementations");
log.println("#");
log.println("# NFC");
log.println("# c2 == NFC(c1) == NFC(c2) == NFC(c3)");
log.println("# c4 == NFC(c4) == NFC(c5)");
log.println("#");
log.println("# NFD");
log.println("# c3 == NFD(c1) == NFD(c2) == NFD(c3)");
log.println("# c5 == NFD(c4) == NFD(c5");
log.println("#");
log.println("# NFKC");
log.println("# c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5)");
log.println("#");
log.println("# NFKD");
log.println("# c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5)");
log.println("#");
log.println("# 2. For every assigned Unicode 3.1.0 code point X that is not specifically");
log.println("# listed in Part 1, the following invariants must be true for all conformant");
log.println("# implementations:");
log.println("#");
log.println("# X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X)");
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
System.out.println("Writing Part 1");
log.println("#");
log.println("@Part0 # Specific cases");
log.println("#");
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
for (int j = 0; j < testSuiteCases.length; ++j) {
writeLine(testSuiteCases[j], log, false);
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
System.out.println("Writing Part 2");
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
log.println("#");
log.println("@Part1 # Character by character test");
log.println("# All characters not explicitly occurring in c1 of Part 1 have identical NFC, D, KC, KD forms.");
log.println("#");
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
for (int ch = 0; ch < 0x10FFFF; ++ch) {
Utility.dot(ch);
if (!ucd.isAssigned(ch)) continue;
if (ucd.isPUA(ch)) continue;
String cc = UTF32.valueOf32(ch);
writeLine(cc,log, true);
}
Utility.fixDot();
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
System.out.println("Finding Examples");
String[] example = new String[256];
for (int ch = 0; ch < 0x10FFFF; ++ch) {
Utility.dot(ch);
if (!ucd.isAssigned(ch)) continue;
if (ucd.isPUA(ch)) continue;
int cc = ucd.getCombiningClass(ch);
if (example[cc] == null) example[cc] = UTF32.valueOf32(ch);
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
Utility.fixDot();
System.out.println("Writing Part 3");
log.println("#");
log.println("@Part2 # Canonical Order Test");
log.println("#");
for (int ch = 0; ch < 0x10FFFF; ++ch) {
Utility.dot(ch);
if (!ucd.isAssigned(ch)) continue;
if (ucd.isPUA(ch)) continue;
short c = ucd.getCombiningClass(ch);
if (c == 0) continue;
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
// add character with higher class, same class, lower class
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
String sample = "";
for (int i = c+1; i < example.length; ++i) {
if (example[i] == null) continue;
sample += example[i];
break;
}
sample += example[c];
for (int i = c-1; i > 0; --i) {
if (example[i] == null) continue;
sample += example[i];
break;
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
writeLine("a" + sample + UTF32.valueOf32(ch) + "b", log, false);
writeLine("a" + UTF32.valueOf32(ch) + sample + "b", log, false);
}
Utility.fixDot();
log.println("#");
log.println("# END OF FILE");
log.close();
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
static void writeLine(String cc, PrintWriter log, boolean check) {
String c = formC.normalize(cc);
String d = formD.normalize(cc);
String kc = formKC.normalize(cc);
String kd = formKD.normalize(cc);
if (check & cc.equals(c) && cc.equals(d) && cc.equals(kc) && cc.equals(kd)) return;
log.println(
Utility.hex(cc," ") + ";" + Utility.hex(c," ") + ";" + Utility.hex(d," ") + ";"
+ Utility.hex(kc," ") + ";" + Utility.hex(kd," ")
2001-08-31 00:30:17 +00:00
+ "; # ("
2001-08-30 20:50:18 +00:00
+ comma(cc) + "; " + comma(c) + "; " + comma(d) + "; " + comma(kc) + "; " + comma(kd) + "; "
+ ") " + ucd.getName(cc));
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
static StringBuffer commaResult = new StringBuffer();
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
// not recursive!!!
static final String comma(String s) {
commaResult.setLength(0);
int cp;
for (int i = 0; i < s.length(); i += UTF32.count16(i)) {
cp = UTF32.char32At(s, i);
if (ucd.getCategory(cp) == Mn) commaResult.append('\u25CC');
UTF32.append32(commaResult, cp);
}
return commaResult.toString();
}
2001-08-31 00:30:17 +00:00
2001-08-30 20:50:18 +00:00
static final String[] testSuiteCases = {
"\u1E0A",
"\u1E0C",
"\u1E0A\u0323",
"\u1E0C\u0307",
"D\u0307\u0323",
"D\u0323\u0307",
"\u1E0A\u031B",
"\u1E0C\u031B",
"\u1E0A\u031B\u0323",
"\u1E0C\u031B\u0307",
"D\u031B\u0307\u0323",
"D\u031B\u0323\u0307",
"\u00C8",
"\u0112",
"E\u0300",
"E\u0304",
"\u1E14",
"\u0112\u0300",
"\u1E14\u0304",
"E\u0304\u0300",
"E\u0300\u0304",
};
//*/
2001-08-30 20:50:18 +00:00
}