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

Commit

Permalink
DSL: support image tag
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed Sep 27, 2021
1 parent f90278a commit a609934
Show file tree
Hide file tree
Showing 2 changed files with 10 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,11 @@ 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("\\[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 +193,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 a609934

Please sign in to comment.