Skip to content

Commit

Permalink
Yomi chan dict works
Browse files Browse the repository at this point in the history
  • Loading branch information
QuillDev committed Feb 20, 2021
1 parent c91483e commit 0723cd4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
9 changes: 6 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- [ ] Add toggles for Text Color / Orientation

##TODO Optimizations
- [ ] Speed Up YomiChan style dictionary searching (it's really slow w/ more than 1);
16 changes: 13 additions & 3 deletions src/main/java/GUI/App.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package GUI;

import Scanner.KanjiScanner;
import Scanner.Translator;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
Expand All @@ -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 {
Expand All @@ -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();

Expand All @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/Scanner/KanjiScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/Scanner/Translator.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ public String searchFor(String query){
continue;
}

return JsonPath.read(document, String.format("$[%s][5][0]", index)).toString();
ArrayList<String> 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();
}
}
}
Expand Down

0 comments on commit 0723cd4

Please sign in to comment.