Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ gradlew.bat run
## Formats
- Kindle (sqlite) Default file located /Volumes/Kindle/system/vocabulary/vocab.db
- Text. All words should be in one column.
- Text with translations. (CSV separation with ";" sign)

## Text example:
### Text witout translations
apple
orange
watermelon
### Text with translations
adversarial;состязательный
cinnamon;корица
draw up;составлять (документы)
vigorously;энергично, решительно
19 changes: 17 additions & 2 deletions src/main/java/com/lingualeo/Importer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javax.naming.AuthenticationException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
Expand All @@ -15,6 +16,7 @@
public class Importer {
private final List<Word> words;
private final ApiClient client;
private HashMap<String, String> translations;
private static final Logger logger = Logger.getLogger(Importer.class.getName());
private ProgressBar progressBar;

Expand All @@ -30,6 +32,10 @@ public Importer(List<Word> words, ApiClient client) {
this.client = client;
}

public void setTranslations(HashMap<String, String> translations) {
this.translations = translations;
}

public void startImport() {
if (words.isEmpty()) {
logger.warning("You don't have words in the file");
Expand All @@ -50,8 +56,16 @@ public void startImport() {

for (Word word : words) {
try {
Iterator<TranslateDto> it = client.getTranslates(word.getName()).iterator();
processWord(word, it);
if (translations == null
|| translations.isEmpty()
|| !translations.containsKey(word.getName())) {

Iterator<TranslateDto> it = client.getTranslates(word.getName()).iterator();
processWord(word, it);
} else {
client.addWord(word.getName(), translations.get(word.getName()), word.getContext());
logger.finest("Word added: " + word.getName());
}

float percent = i / count;
updateProgress(percent);
Expand All @@ -61,6 +75,7 @@ public void startImport() {
logger.log(Level.SEVERE, e.getMessage(), e);
}
}

updateProgress(1);
logger.finest("End import to Lingualeo...");
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/lingualeo/controller/FormController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javafx.stage.FileChooser;

import java.io.File;
import java.util.HashMap;
import java.util.List;

public class FormController {
Expand All @@ -18,14 +19,17 @@ public class FormController {
public Button startButton;
public TextArea textField;
public ProgressBar progressBar;
public CheckBox translationsCheckBox;
private List<Word> words;
private HashMap<String, String> translations;

@FXML
protected void handleSubmitButtonAction() {
Thread t = new Thread(
() -> {
String password = passwordField.getText();
Importer importer = new Importer(words, new ApiClient(emailField.getText(), password), progressBar);
importer.setTranslations(translations);
startButton.setDisable(true);
importer.startImport();
}
Expand All @@ -44,6 +48,7 @@ protected void handleFileChooserAction() {
if (file != null) {
BaseReader reader = ReaderFactory.create(file);
words = reader.read();
translations = reader.getTranslations();
this.startButton.setDisable(false);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/lingualeo/reader/BaseReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public abstract class BaseReader {
File file;
List<Word> words = new ArrayList<>();
HashMap<String, String> translations = new HashMap<>();

BaseReader(File file) {
this.file = file;
Expand All @@ -15,6 +17,7 @@ public abstract class BaseReader {
List<Word> getWords() {
return words;
}
public HashMap<String, String> getTranslations() { return translations; }

public abstract List<Word> read();
}
10 changes: 8 additions & 2 deletions src/main/java/com/lingualeo/reader/TextReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ public List<Word> read() {
BufferedReader br = new BufferedReader(fileReader);
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
this.words.add(new Word(line.toLowerCase()));
String[] split_str = line.split(";", 2);
if (split_str.length == 1) {
line = line.trim();
this.words.add(new Word(line.toLowerCase()));
} else {
this.words.add(new Word(split_str[0].trim()));
this.translations.put(split_str[0].trim(), split_str[1].trim());
}
}
fileReader.close();
} catch (IOException e) {
Expand Down