Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #69 from eb4j/topic-use-dsl4j-library
Browse files Browse the repository at this point in the history
use dsl4j library
  • Loading branch information
miurahr authored Dec 1, 2021
2 parents 5eaa2e1 + f81bd63 commit fd0cd09
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 200 deletions.
6 changes: 6 additions & 0 deletions .idea/copyright/GPL3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ dependencies {
implementation("io.github.dictzip:dictzip:0.9.5")
implementation("com.github.takawitter:trie4j:0.9.8")

// for lingvodsl
implementation("io.github.eb4j:dsl4j:0.3.0")

// for mdict
implementation("io.github.eb4j:mdict4j:0.2.0")
implementation("org.jsoup:jsoup:1.14.3")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* EBViewer, a dictionary viewer application.
* Copyright (C) 2021 Hiroshi Miura.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package io.github.eb4j.ebview.dictionary;

import io.github.eb4j.ebview.data.DictionaryEntry;
Expand Down
85 changes: 79 additions & 6 deletions src/main/java/io/github/eb4j/ebview/dictionary/LingvoDSL.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
/*
* EBViewer, a dictionary viewer application.
* Copyright (C) 2021 Hiroshi Miura.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package io.github.eb4j.ebview.dictionary;

import io.github.eb4j.dsl.DslDictionary;
import io.github.eb4j.dsl.DslResult;
import io.github.eb4j.dsl.visitor.HtmlDslVisitor;
import io.github.eb4j.ebview.data.DictionaryEntry;
import io.github.eb4j.ebview.data.IDictionary;
import io.github.eb4j.ebview.dictionary.lingvo.LingvoDSLDictionary;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Dictionary driver for Lingvo DSL format.
*
* Lingvo DSL format described in Lingvo help. See also
* http://www.dsleditor.narod.ru/art_03.htm(russian).
*
* @author Alex Buloichik
* @author Aaron Madlon-Kay
* @author Hiroshi Miura
*/
public class LingvoDSL implements IDictionaryFactory {
Expand All @@ -31,4 +50,58 @@ public Set<IDictionary> loadDict(final File file) throws Exception {
return result;
}

/**
* Dictionary implementation for Lingvo DSL format.
*
* @author Hiroshi Miura
*/
public static class LingvoDSLDictionary implements IDictionary {

protected final DslDictionary dictionary;
private final HtmlDslVisitor htmlVisitor;

public LingvoDSLDictionary(final File file) throws Exception {
dictionary = DslDictionary.loadDictionary(file);
htmlVisitor = new HtmlDslVisitor(file.getParent());
}

@Override
public String getDictionaryName() {
return dictionary.getDictionaryName();
}

/**
* read article with exact match.
* @param word
* The word to look up in the dictionary
*
* @return list of results.
*/
@Override
public List<DictionaryEntry> readArticles(final String word) {
return readEntries(dictionary.lookup(word));
}

/**
* read article with predictive match.
* @param word
* The word to look up in the dictionary
*
* @return list of results.
*/
@Override
public List<DictionaryEntry> readArticlesPredictive(final String word) {
return readEntries(dictionary.lookupPredictive(word));
}

private List<DictionaryEntry> readEntries(final DslResult dslResult) {
List<DictionaryEntry> list = new ArrayList<>();
for (Map.Entry<String, String> e : dslResult.getEntries(htmlVisitor)) {
DictionaryEntry dictionaryEntry = new DictionaryEntry(e.getKey(), e.getValue(),
dictionary.getDictionaryName());
list.add(dictionaryEntry);
}
return list;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* EBViewer, a dictionary viewer application.
* Copyright (C) 2021 Hiroshi Miura.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package io.github.eb4j.ebview.dictionary.mdict;

import io.github.eb4j.ebview.data.DictionaryEntry;
Expand Down

0 comments on commit fd0cd09

Please sign in to comment.