Skip to content

Commit 0723cd4

Browse files
committed
Yomi chan dict works
1 parent c91483e commit 0723cd4

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

readme.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ QuillKanji is a Java based OCR app using [KanjiTomo's API]() with the goal of
33
making deciphering kanji easy. QuillKanji is currently in very early development
44
but it is "functional".
55

6-
## TODO
6+
## TODO Features
77
- [x] Can Scan Kanji On Hover.
88
- [x] Report Best Results to the console.
99
- [x] Java FX GUI.
1010
- [x] Have kanji Meanings
11-
- [ ] Support YomiChan dictionaries.
11+
- [x] Support YomiChan dictionaries.
1212
- [ ] Open YomiChan Dicts in Zip Format
13-
- [ ] Add toggles for Text Color / Orientation
13+
- [ ] Add toggles for Text Color / Orientation
14+
15+
##TODO Optimizations
16+
- [ ] Speed Up YomiChan style dictionary searching (it's really slow w/ more than 1);

src/main/java/GUI/App.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package GUI;
22

33
import Scanner.KanjiScanner;
4+
import Scanner.Translator;
45
import javafx.application.Application;
56
import javafx.application.Platform;
67
import javafx.geometry.Insets;
@@ -18,6 +19,9 @@ public class App extends Application {
1819
private KanjiScanner scanner;
1920
private final Label kanjiLabel = new Label("Kanji");
2021
private final Label meaningLabel = new Label("Meaning");
22+
private final Label yomiDict = new Label("Yomi Meaning");
23+
private final static Translator translator = new Translator();
24+
2125

2226
public App() {
2327
try {
@@ -37,12 +41,14 @@ public void start(Stage stage) {
3741
grid.setVgap(10);
3842
grid.setPadding(new Insets(25, 25, 25, 25));
3943
grid.add(kanjiLabel, 0, 0);
40-
grid.add(meaningLabel, 0, 1);
44+
grid.add(yomiDict, 0, 1);
45+
grid.add(meaningLabel, 0, 2);
4146
Scene scene = new Scene(grid, 640, 480);
4247

43-
var font = new Font("Segoe UI", 24);
48+
var font = new Font("Segoe UI", 18);
4449
kanjiLabel.setFont(font);
4550
meaningLabel.setFont(font);
51+
yomiDict.setFont(font);
4652
stage.setScene(scene);
4753
stage.show();
4854

@@ -64,10 +70,14 @@ public void start(Stage stage) {
6470
if(result.bestMatchingCharacters.equals(lastResult)){
6571
continue;
6672
}
73+
74+
75+
var yomiMeaning = translator.searchFor(result.words.get(0).kanji);
6776
//Change the kanji labels text
6877
Platform.runLater( () -> {
6978
this.kanjiLabel.setText(result.words.get(0).kanji);
70-
this.meaningLabel.setText(result.words.get(0).description);
79+
this.yomiDict.setText("YomiDict:\n"+ yomiMeaning);
80+
this.meaningLabel.setText("InternalDict: \n" + result.words.get(0).description);
7181
});
7282

7383
lastResult = result.bestMatchingCharacters;

src/main/java/Scanner/KanjiScanner.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ public KanjiScanner() throws AWTException {
1717
this.kanjiTomo.setOrientation(Orientation.VERTICAL);
1818
this.kanjiTomo.setCharacterColor(CharacterColor.BLACK_ON_WHITE);
1919
this.kanjiTomo.setDictionary(DictionaryType.JAPANESE_DEFAULT, DictionaryType.JAPANESE_NAMES);
20-
21-
//new Translator();
2220
}
2321

2422
/**

src/main/java/Scanner/Translator.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ public String searchFor(String query){
3030
continue;
3131
}
3232

33-
return JsonPath.read(document, String.format("$[%s][5][0]", index)).toString();
33+
ArrayList<String> meanings = JsonPath.read(document, String.format("$[%s][5]", index));
34+
StringBuilder results = new StringBuilder();
35+
for(int meaningIndex = 0; meaningIndex < Math.min(meanings.size(), 3); meaningIndex++){
36+
var meaning = JsonPath.read(document, String.format("$[%s][5][%s]", index, meaningIndex)).toString();
37+
results.append(String.format("%s) %s", meaningIndex+1, meaning)).append("\n");
38+
}
39+
return results.toString();
3440
}
3541
}
3642
}

0 commit comments

Comments
 (0)