diff --git a/readme.md b/readme.md index 8bae6c3..989dd4b 100644 --- a/readme.md +++ b/readme.md @@ -3,11 +3,14 @@ QuillKanji is a Java based OCR app using [KanjiTomo's API]() with the goal of making deciphering kanji easy. QuillKanji is currently in very early development but it is "functional". -## TODO +## TODO Features - [x] Can Scan Kanji On Hover. - [x] Report Best Results to the console. - [x] Java FX GUI. - [x] Have kanji Meanings -- [ ] Support YomiChan dictionaries. +- [x] Support YomiChan dictionaries. - [ ] Open YomiChan Dicts in Zip Format -- [ ] Add toggles for Text Color / Orientation \ No newline at end of file +- [ ] Add toggles for Text Color / Orientation + +##TODO Optimizations +- [ ] Speed Up YomiChan style dictionary searching (it's really slow w/ more than 1); \ No newline at end of file diff --git a/src/main/java/GUI/App.java b/src/main/java/GUI/App.java index 0f9f37c..fa37c53 100644 --- a/src/main/java/GUI/App.java +++ b/src/main/java/GUI/App.java @@ -1,6 +1,7 @@ package GUI; import Scanner.KanjiScanner; +import Scanner.Translator; import javafx.application.Application; import javafx.application.Platform; import javafx.geometry.Insets; @@ -18,6 +19,9 @@ public class App extends Application { private KanjiScanner scanner; private final Label kanjiLabel = new Label("Kanji"); private final Label meaningLabel = new Label("Meaning"); + private final Label yomiDict = new Label("Yomi Meaning"); + private final static Translator translator = new Translator(); + public App() { try { @@ -37,12 +41,14 @@ public void start(Stage stage) { grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); grid.add(kanjiLabel, 0, 0); - grid.add(meaningLabel, 0, 1); + grid.add(yomiDict, 0, 1); + grid.add(meaningLabel, 0, 2); Scene scene = new Scene(grid, 640, 480); - var font = new Font("Segoe UI", 24); + var font = new Font("Segoe UI", 18); kanjiLabel.setFont(font); meaningLabel.setFont(font); + yomiDict.setFont(font); stage.setScene(scene); stage.show(); @@ -64,10 +70,14 @@ public void start(Stage stage) { if(result.bestMatchingCharacters.equals(lastResult)){ continue; } + + + var yomiMeaning = translator.searchFor(result.words.get(0).kanji); //Change the kanji labels text Platform.runLater( () -> { this.kanjiLabel.setText(result.words.get(0).kanji); - this.meaningLabel.setText(result.words.get(0).description); + this.yomiDict.setText("YomiDict:\n"+ yomiMeaning); + this.meaningLabel.setText("InternalDict: \n" + result.words.get(0).description); }); lastResult = result.bestMatchingCharacters; diff --git a/src/main/java/Scanner/KanjiScanner.java b/src/main/java/Scanner/KanjiScanner.java index 04df749..a0ebd92 100644 --- a/src/main/java/Scanner/KanjiScanner.java +++ b/src/main/java/Scanner/KanjiScanner.java @@ -17,8 +17,6 @@ public KanjiScanner() throws AWTException { this.kanjiTomo.setOrientation(Orientation.VERTICAL); this.kanjiTomo.setCharacterColor(CharacterColor.BLACK_ON_WHITE); this.kanjiTomo.setDictionary(DictionaryType.JAPANESE_DEFAULT, DictionaryType.JAPANESE_NAMES); - - //new Translator(); } /** diff --git a/src/main/java/Scanner/Translator.java b/src/main/java/Scanner/Translator.java index e2854fe..626e77f 100644 --- a/src/main/java/Scanner/Translator.java +++ b/src/main/java/Scanner/Translator.java @@ -30,7 +30,13 @@ public String searchFor(String query){ continue; } - return JsonPath.read(document, String.format("$[%s][5][0]", index)).toString(); + ArrayList meanings = JsonPath.read(document, String.format("$[%s][5]", index)); + StringBuilder results = new StringBuilder(); + for(int meaningIndex = 0; meaningIndex < Math.min(meanings.size(), 3); meaningIndex++){ + var meaning = JsonPath.read(document, String.format("$[%s][5][%s]", index, meaningIndex)).toString(); + results.append(String.format("%s) %s", meaningIndex+1, meaning)).append("\n"); + } + return results.toString(); } } }