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 #30 from eb4j/topic-dsl-image
Browse files Browse the repository at this point in the history
Support dsl image
  • Loading branch information
miurahr authored Sep 27, 2021
2 parents f90278a + 3f38fe6 commit dc96d76
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void closeDict(final IDictionary dict) {
}

public List<String> getDictionaryNames() {
return Collections.unmodifiableList(dictionaries.stream().map(IDictionary::getDictionaryName).collect(Collectors.toList()));
return dictionaries.stream().map(IDictionary::getDictionaryName).collect(Collectors.toUnmodifiableList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class LingvoDSLDictionary implements IDictionary {

protected final DictionaryData<String> data;

private final String dictionaryDir;
private final String bookName;


Expand All @@ -47,6 +47,7 @@ public LingvoDSLDictionary(final File file) throws Exception {
bookName = fileName.substring(0, fileName.length() - 4);
}
readDslFile(file);
dictionaryDir = file.getParentFile().getAbsolutePath();
}

@SuppressWarnings("avoidinlineconditionals")
Expand Down Expand Up @@ -95,13 +96,13 @@ public String getDictionaryName() {

@Override
public List<DictionaryEntry> readArticles(final String word) {
return data.lookUp(word).stream().map(e -> new DictionaryEntry(e.getKey(), e.getValue(), bookName))
return data.lookUp(word).stream().map(e -> new DictionaryEntry(e.getKey(), e.getValue().replaceAll("@dir@", dictionaryDir), bookName))
.collect(Collectors.toList());
}

@Override
public List<DictionaryEntry> readArticlesPredictive(final String word) {
return data.lookUpPredictive(word).stream().map(e -> new DictionaryEntry(e.getKey(), e.getValue(), bookName))
return data.lookUpPredictive(word).stream().map(e -> new DictionaryEntry(e.getKey(), e.getValue().replaceAll("@dir@", dictionaryDir), bookName))
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -175,8 +176,14 @@ static String replaceTag(final String line) {
reList.add(new RE("\\[/preview\\]", ""));
reList.add(new RE("\\[ref\\]", ""));
reList.add(new RE("\\[/ref\\]", ""));
reList.add(new RE("\\[s\\]", ""));
reList.add(new RE("\\[/s\\]", ""));
reList.add(new RE("\\[s\\](.+?\\.wav)\\[/s\\]", "<a href=\"file://@dir@/$1\"/>SOUND: $1</a>"));
reList.add(new RE("\\[s\\](.+?\\.jpg)\\[/s\\]", "<img src=\"file://@dir@/$1\"/>"));
reList.add(new RE("\\[s\\](.+?\\.bmp)\\[/s\\]", "<img src=\"file://@dir@/$1\"/>"));
reList.add(new RE("\\[s\\](.+?\\.tif)\\[/s\\]", "<img src=\"file://@dir@/$1\"/>"));
reList.add(new RE("\\[s\\](.+?\\.tiff)\\[/s\\]", "<img src=\"file://@dir@/$1\"/>"));
reList.add(new RE("\\[s\\](.+?\\.png)\\[/s\\]", "<img src=\"file://@dir@/$1\"/>"));
reList.add(new RE("\\[video\\](.+?)\\[/video\\]", "<a href=\"file://@dir@/$1\">VIDEO: $1</a>"));
reList.add(new RE("\\[s\\](.+?)\\[/s\\]", "UNSUPPORTED MEDIA: $1"));
reList.add(new RE("\\[sub\\](.+?)\\[/sub\\]", "<sub>$1</sub>"));
reList.add(new RE("\\[sup\\](.+?)\\[/sup\\]", "<sup>$1</sup>"));
reList.add(new RE("\\[trn1\\]", ""));
Expand All @@ -189,8 +196,6 @@ static String replaceTag(final String line) {
reList.add(new RE("\\[u\\](.+?)\\[/u\\]",
"<span style='text-decoration:underline'>$1</span>"));
reList.add(new RE("\\[url\\](.+?)\\[/url\\]", "<a href='$1'>$1</a>"));
reList.add(new RE("\\[video\\]", ""));
reList.add(new RE("\\[/video\\]", ""));
// The following line tries to replace a letter surrounded by ['][/'] tags (indicating stress)
// with a red letter (the default behavior in Lingvo).
reList.add(new RE("\\['\\].\\[/'\\]", "<span style='color:red'>$1</span>"));
Expand Down

0 comments on commit dc96d76

Please sign in to comment.