Added support for gaphrase format.
--- a/Makefile Fri May 08 22:13:02 2020 +0300
+++ b/Makefile Fri May 08 23:19:32 2020 +0300
@@ -147,8 +147,14 @@
DICTDZ_FILES := $(C5_FILES:.c5=.dict.dz)
INDEX_FILES := $(C5_FILES:.c5=.index)
+GAPHRASE_FILES := $(wildcard *.gaphrase)
+GADIALOG_FILES := $(wildcard *.gadialog)
+
SRS_TAB_FILES := $(patsubst %.gadict,dist/srs/%.tab.txt,$(GADICT_FILES))
-SRS_ANKI_FILES := $(patsubst %.gadict,dist/anki/%.apkg,$(GADICT_FILES)) dist/anki/gadialog.apkg
+SRS_ANKI_FILES := \
+ $(patsubst %.gadict,dist/anki/%.apkg,$(GADICT_FILES)) \
+ $(patsubst %.gaphrase,dist/anki/%.apkg,$(GAPHRASE_FILES)) \
+ $(patsubst %.gadialog,dist/anki/%.apkg,$(GADIALOG_FILES))
DICT_HTML_FILES := $(patsubst %.gadict,dist/html/%.html,$(GADICT_FILES))
@@ -670,6 +676,9 @@
dist/anki/%.apkg: %.gadialog py/gadialog_srs_anki.py $(MAKEFILE_LIST) | dist/anki/
PYTHONPATH=$(ANKI_PY_DIR): LC_ALL=en_US.utf8 python3 -B py/gadialog_srs_anki.py -name="$*" $< $@
+dist/anki/%.apkg: %.gaphrase py/gaphrase_srs_anki.py $(MAKEFILE_LIST) | dist/anki/
+ PYTHONPATH=$(ANKI_PY_DIR): LC_ALL=en_US.utf8 python3 -B py/gaphrase_srs_anki.py -name="$*" $< $@
+
# General rules.
dist/anki/%.apkg: %.gadict %.del py/gadict.py py/gadict_srs_anki.py $(FREQLIST_DEP) $(MAKEFILE_LIST) | dist/anki/
PYTHONPATH=$(ANKI_PY_DIR): LC_ALL=en_US.utf8 python3 -B py/gadict_srs_anki.py -name=$* -rich -delfile=$*.del $(FREQLIST_OPT) $< $@
--- a/contrib/gaphrase.el Fri May 08 22:13:02 2020 +0300
+++ b/contrib/gaphrase.el Fri May 08 23:19:32 2020 +0300
@@ -24,8 +24,7 @@
(defvar gaphrase-font-lock-keywords
'(("^# [1-9][0-9]*" . font-lock-type-face)
- ("^## [1-9][0-9]*" . font-lock-warning-face)
- ("^- " . font-lock-keyword-face)))
+ ("^## [1-9][0-9]*" . font-lock-warning-face)))
(defvar gaphrase-syntax-table
(let ((table (make-syntax-table text-mode-syntax-table)))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gacollocation.gaphrase Fri May 08 23:19:32 2020 +0300
@@ -0,0 +1,68 @@
+## 33
+
+# 1
+on a regular basis
+# 2
+fast food
+# 3
+fast car
+# 4
+quick glance
+# 5
+quick meal
+# 6
+take a photo
+# 7
+stick to the rules
+# 8
+make an effort
+# 9
+powerful engine
+# 10
+ancient monument
+# 11
+make a mistake
+# 12
+strictly forbidden
+# 13
+bitterly cold
+# 14
+pinch dark
+# 15
+substantial meal
+# 16
+live music
+# 17
+key ring
+# 18
+heavy snow
+# 19
+bitterly disappointed
+# 20
+desperately jealous
+# 21
+sharp pain
+# 22
+ease the pain
+# 23
+sharp contrast
+# 24
+sharp difference
+# 25
+sharp distinction
+# 26
+sharp drop
+# 27
+sharp increase
+# 28
+sharp rise
+# 29
+piece of advice
+# 30
+have access to
+# 31
+find a way
+# 32
+learn the hard way
+# 33
+get in sb way
--- a/py/gaphrase_srs_anki.py Fri May 08 22:13:02 2020 +0300
+++ b/py/gaphrase_srs_anki.py Fri May 08 23:19:32 2020 +0300
@@ -65,7 +65,6 @@
COMMENT_RE = re.compile("^; ")
NUM_RE = re.compile(u"^# ([1-9][0-9]*)$")
- PHRASE_START_RE = re.compile(u"^- (.*)")
def __init__(self):
pass
@@ -86,7 +85,7 @@
def parse(self, stream):
self.lineno = 0
self.stream = stream
- self.dom = dict()
+ self.dom = dict() # num => phrase
self.eof = False
try:
self.parse_prelude()
@@ -113,31 +112,20 @@
"""Assume we are at ``# NUM`` line."""
num = self.num
phrase_buf = []
- phrases = []
while True:
self.readline()
if self.eof:
- if len(phrase_buf) > 0:
- phrases.append(" ".join(phrase_buf))
break
m = self.NUM_RE.match(self.line)
if m:
- if len(phrase_buf) > 0:
- phrases.append(" ".join(phrase_buf))
self.num = m.group(1)
break
- m = self.PHRASE_START_RE.match(self.line)
- if m:
- if len(phrase_buf) > 0:
- phrases.append(" ".join(phrase_buf))
- phrase_buf = [m.group(1)]
- else:
- phrase_buf.append(self.line)
- if len(phrases) == 0:
+ phrase_buf.append(self.line)
+ if len(phrase_buf) == 0:
raise ParseException("""There are no any phrases...""")
if num in self.dom:
raise ParseException("""Conflicting key: {}...""".format(num))
- self.dom[num] = phrases
+ self.dom[num] = " ".join(phrase_buf)
FIN = io.open(FINAME, mode='r', buffering=1, encoding="utf-8")
@@ -160,12 +148,6 @@
.line {
margin-bottom: 0.5em;
}
-.odd {
- color: #004000;
-}
-.even {
- color: #000080;
-}
"""
class AnkiDbBuilder:
@@ -216,18 +198,6 @@
def close(self):
self.collection.close()
-def write_lines(buf, lines):
- odd = True
- for line in lines:
- if odd:
- buf.append("<div class='line odd'>")
- else:
- buf.append("<div class='line even'>")
- buf.append("- ")
- buf.append(line)
- buf.append("</div>")
- odd = not odd
-
# Looks like anki libs change working directory to media directory of current deck
# Therefore absolute path should be stored before creating temporary deck
FONAME = os.path.abspath(FONAME)
@@ -236,9 +206,11 @@
try:
BUILDER = AnkiDbBuilder(TMPDIR, NAME)
- for num, lines in DOM.items():
+ for num, phrase in DOM.items():
buf = []
- write_lines(buf, lines)
+ buf.append("<div class='line'>")
+ buf.append(phrase)
+ buf.append("</div>")
front = "".join(buf)
BUILDER.add_note(num, front)
BUILDER.export(FONAME)