Gather data
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package puzzle;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
import puzzle.ExportFormat.Bit;
|
||||
@@ -227,17 +228,17 @@ public record SwedishGenerator(int[] buff) {
|
||||
}
|
||||
}
|
||||
|
||||
static record Lemma(int index, byte[] word, int simpel, ArrayList<String> clue) {
|
||||
static record Lemma(int index, byte[] word, int simpel, String[] clue) {
|
||||
|
||||
static int LEMMA_COUNTER = 0;
|
||||
public Lemma(int index, String word, int simpel, String clu) {
|
||||
this(index, word.getBytes(StandardCharsets.US_ASCII), simpel, new ArrayList<String>(10));
|
||||
clue.add(clu);
|
||||
public Lemma(int index, String word, int simpel, String[] clu) {
|
||||
this(index, word.getBytes(StandardCharsets.US_ASCII), simpel, clu);
|
||||
}
|
||||
public Lemma(String word, int simpel, String clue) { this(LEMMA_COUNTER++, word, simpel, clue); }
|
||||
byte byteAt(int idx) { return word[idx]; }
|
||||
@Override public int hashCode() { return index; }
|
||||
@Override public boolean equals(Object o) { return (o == this) || (o instanceof Lemma l && l.index == index); }
|
||||
public Lemma(String word, int simpel, String clue) { this(LEMMA_COUNTER++, word, simpel, new String[]{ clue }); }
|
||||
public Lemma(String word, int simpel, String[] clue) { this(LEMMA_COUNTER++, word, simpel, clue); }
|
||||
byte byteAt(int idx) { return word[idx]; }
|
||||
@Override public int hashCode() { return index; }
|
||||
@Override public boolean equals(Object o) { return (o == this) || (o instanceof Lemma l && l.index == index); }
|
||||
}
|
||||
|
||||
public static record Dict(Lemma[] wordz,
|
||||
@@ -245,14 +246,11 @@ public record SwedishGenerator(int[] buff) {
|
||||
int[] lenCounts) {
|
||||
|
||||
public Dict(Lemma[] wordz) {
|
||||
var lemmas = wordz.clone();
|
||||
Arrays.sort(lemmas, Comparator.comparingInt(wd -> wd.simpel));
|
||||
|
||||
var lenCounts = new int[MAX_WORD_LENGTH + 1];
|
||||
var index = new DictEntry[MAX_WORD_LENGTH + 1];
|
||||
Arrays.setAll(index, i -> new DictEntry(i));
|
||||
int maxLength = -1;
|
||||
for (var lemma : lemmas) {
|
||||
for (var lemma : wordz) {
|
||||
var L = lemma.word.length;
|
||||
if (L > maxLength) maxLength = L;
|
||||
lenCounts[L]++;
|
||||
@@ -270,6 +268,8 @@ public record SwedishGenerator(int[] buff) {
|
||||
this(wordz, index, lenCounts);
|
||||
}
|
||||
}
|
||||
|
||||
static final Gson GSON = new Gson();
|
||||
static Dict loadWords(String wordsPath) {
|
||||
String raw;
|
||||
try {
|
||||
@@ -279,7 +279,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
raw = "WOORD,level_1_to_10,hint\nEU,2,hint\nUUR,2,hint\nAUTO,2,hint\nBOOM,2,hint\nHUIS,2,hint\nKAT,2,hint\nZEE,2,hint\nRODE,2,hint\nDRAAD,2,hint\nKENNIS,2,hint\nNETWERK,2,hint\nPAKTE,2,hint\n";
|
||||
}
|
||||
|
||||
var map = new HashMap<String, Lemma>();
|
||||
var map = new ArrayList<Lemma>();
|
||||
var first = true;
|
||||
for (var line : raw.split("\\R")) {
|
||||
if (line.isBlank()) {
|
||||
@@ -304,18 +304,14 @@ public record SwedishGenerator(int[] buff) {
|
||||
rawClue = rawClue.substring(1, rawClue.length() - 1).replace("\"\"", "\"");
|
||||
}
|
||||
if (score >= 1) {
|
||||
if (map.containsKey(s)) {
|
||||
map.get(s).clue.add(rawClue);
|
||||
} else {
|
||||
map.put(s, new Lemma(s, simpel, rawClue));
|
||||
}
|
||||
map.add(new Lemma(s, simpel, GSON.fromJson(rawClue, String[].class)));
|
||||
}
|
||||
} else {
|
||||
System.err.println("Invalid word: " + line);
|
||||
}
|
||||
}
|
||||
|
||||
return new Dict(map.values().toArray(Lemma[]::new));
|
||||
return new Dict(map .toArray(Lemma[]::new));
|
||||
}
|
||||
static int[] intersectSorted(int[] buff, int[] a, int aLen, int[] b, int bLen) {
|
||||
//var out = new int[Math.min(aLen, bLen)];
|
||||
|
||||
Reference in New Issue
Block a user