This repository has been archived by the owner on Jul 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
- Loading branch information
Showing
9 changed files
with
98 additions
and
1,243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/io/github/eb4j/ebview/dictionary/pdic/PdicDict.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package io.github.eb4j.ebview.dictionary.pdic; | ||
|
||
import io.github.eb4j.ebview.data.DictionaryEntry; | ||
import io.github.eb4j.ebview.data.IDictionary; | ||
import io.github.eb4j.pdic.PdicDictionary; | ||
import io.github.eb4j.pdic.PdicElement; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
/** | ||
* @author wak (Apache-2.0) | ||
* @author Hiroshi Miura | ||
*/ | ||
public class PdicDict implements IDictionary { | ||
|
||
private final PdicDictionary dict; | ||
private final Locale sourceLocale; | ||
private final String dictionaryName; | ||
|
||
/** | ||
* Construct with .dic file. | ||
* It create index cache file with name .dic.idx. | ||
* | ||
* @param file PDIC .dic file. | ||
* @throws IOException when access error occurred. | ||
*/ | ||
public PdicDict(final File file) throws IOException { | ||
File cache = new File(file.getPath() + ".idx"); | ||
sourceLocale = Locale.ROOT; | ||
this.dict = PdicDictionary.loadDictionary(file, cache); | ||
dictionaryName = file.getName(); | ||
} | ||
|
||
@Override | ||
public String getDictionaryName() { | ||
return dictionaryName; | ||
} | ||
|
||
/** | ||
* Read article's text. | ||
* | ||
* @param word The word to look up in the dictionary | ||
* @return List of entries. May be empty, but cannot be null. | ||
*/ | ||
@Override | ||
public List<DictionaryEntry> readArticles(final String word) throws IOException { | ||
return makeDictionaryEntries(dict.getEntries(word.toLowerCase(sourceLocale))); | ||
} | ||
|
||
/** | ||
* Read article's text. Matching is predictive, so e.g. supplying "term" | ||
* will return articles for "term", "terminology", "termite", etc. | ||
* | ||
* @param word The word to look up in the dictionary | ||
* @return List of entries. May be empty, but cannot be null. | ||
*/ | ||
@Override | ||
public List<DictionaryEntry> readArticlesPredictive(final String word) throws IOException { | ||
return makeDictionaryEntries(dict.getEntriesPredictive(word.toLowerCase(sourceLocale))); | ||
} | ||
|
||
/** | ||
* Dispose IDictionary. Default is no action. | ||
*/ | ||
@Override | ||
public void close() { | ||
} | ||
|
||
private List<DictionaryEntry> makeDictionaryEntries(final List<PdicElement> results) { | ||
List<DictionaryEntry> lists = new ArrayList<>(); | ||
for (PdicElement result : results) { | ||
String word = result.getHeadWord(); | ||
if (word.equals("")) { | ||
word = result.getIndexWord(); | ||
} | ||
StringBuilder articleBuilder = new StringBuilder(); | ||
String pronunciation = result.getPronunciation(); | ||
if (pronunciation != null) { | ||
articleBuilder.append(pronunciation).append(" / "); | ||
} | ||
articleBuilder.append(result.getTranslation()).append("<br/>"); | ||
String example = result.getExample(); | ||
if (example != null) { | ||
articleBuilder.append(example); | ||
} | ||
lists.add(new DictionaryEntry(word, articleBuilder.toString(), dictionaryName)); | ||
} | ||
return lists; | ||
} | ||
|
||
} |
115 changes: 0 additions & 115 deletions
115
src/main/java/io/github/eb4j/ebview/dictionary/pdic/PdicDictionary.java
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
src/main/java/io/github/eb4j/ebview/dictionary/pdic/PdicElement.java
This file was deleted.
Oops, something went wrong.
111 changes: 0 additions & 111 deletions
111
src/main/java/io/github/eb4j/ebview/dictionary/pdic/PdicHeader.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.