Add syntax to add related words. Add separators between ant/syn/rel in
generated output.
--- a/contrib/gadict.el Sat Sep 17 10:18:12 2016 +0300
+++ b/contrib/gadict.el Wed Sep 21 22:09:37 2016 +0300
@@ -22,16 +22,22 @@
;;; Code:
+(defconst gadict--art-lang-regex (regexp-opt '("en" "ru" "uk" "la")))
+(defconst gadict--art-rel-regex (regexp-opt '("ant" "syn" "rel" "topic")))
+(defconst gadict--art-var-regex (regexp-opt '("v1" "v2" "v3" "s" "pl" "male" "female" "abbr" "comp" "super" "Am" "Br" "Au")))
+(defconst gadict--art-pos-regex (regexp-opt '("n" "v" "adj" "adv" "pron" "prep" "num" "conj" "int" "phr" "phr\\.v" "contr" "abbr" "prefix")))
+
(defvar gadict-font-lock-keywords
- '( ("^\\(__\\)\n\n\\(\\w.*\\)$" (1 font-lock-function-name-face) (2 font-lock-keyword-face))
+ `( ("^\\(__\\)\n\n\\(\\w.*\\)$" (1 font-lock-function-name-face) (2 font-lock-keyword-face))
("^ .*\n\\(\\w.*\\)" (1 font-lock-keyword-face))
("^#.*" . font-lock-comment-face)
("^ +\\[[^]\n]+]" . font-lock-type-face)
- ("^\\(?:en\\|ru\\|uk\\|la\\): " . font-lock-type-face)
- ("^\\(?:en\\|ru\\|uk\\|la\\)> " . font-lock-doc-face)
- ("^\\(?:topic\\|ant\\|syn\\): " . font-lock-doc-face)
- ("^ +\\(?:v1\\|v2\\|v3\\|s\\|pl\\|male\\|female\\|abbr\\|comp\\|super\\|Am\\|Br\\|Au\\)$" . font-lock-doc-face)
- ("^\\(?:n\\|v\\|adj\\|adv\\|pron\\|prep\\|num\\|conj\\|int\\|phr\\|phr\\.v\\|contr\\|abbr\\|prefix\\)$" . font-lock-type-face) ))
+ (,(format "^%s: " gadict--art-lang-regex) . font-lock-type-face)
+ (,(format "^%s> " gadict--art-lang-regex) . font-lock-doc-face)
+ (,(format "^%s= " gadict--art-lang-regex) . font-lock-constant-face)
+ (,(format "^%s: " gadict--art-rel-regex) . font-lock-doc-face)
+ (,(format "^ +%s$" gadict--art-var-regex) . font-lock-doc-face)
+ (,(format "^%s$" gadict--art-pos-regex) . font-lock-warning-face) ))
(defun gadict-setup-fontlock ()
"Setup gadict fontlock."
--- a/py/gadict.py Sat Sep 17 10:18:12 2016 +0300
+++ b/py/gadict.py Wed Sep 21 22:09:37 2016 +0300
@@ -45,7 +45,7 @@
class Sense:
- def __init__(self, pos, tr_list = None, ex_list = None, syn_list = None, ant_list = None, topic_list = None):
+ def __init__(self, pos, tr_list = None, ex_list = None, ant_list = None, syn_list = None, rel_list = None, topic_list = None):
if not pos:
raise ParseException("Part of speech expected...\n")
self.pos = pos
@@ -53,36 +53,43 @@
if not tr_list:
self.tr_list = []
self.ex_list = ex_list
+ self.ant_list = ant_list
self.syn_list = syn_list
- self.ant_list = ant_list
+ self.rel_list = rel_list
self.topic_list = topic_list
def add_tr(self, tr):
self.tr_list.append(tr)
def add_ex(self, ex):
- if not self.ex_list:
+ if self.ex_list:
+ self.ex_list.append(ex)
+ else:
self.ex_list = [ex]
+
+ def add_ant(self, ant):
+ if self.ant_list:
+ self.ant_list.append(ant)
else:
- self.ex_list.append(ex)
+ self.ant_list = [ant]
def add_syn(self, syn):
- if not self.syn_list:
+ if self.syn_list:
+ self.syn_list.append(syn)
+ else:
self.syn_list = [syn]
- else:
- self.syn_list.append(syn)
- def add_ant(self, ant):
- if not self.ant_list:
- self.ant_list = [ant]
+ def add_rel(self, rel):
+ if self.rel_list:
+ self.rel_list.append(rel)
else:
- self.ant_list.append(ant)
+ self.rel_list = [rel]
def add_topic(self, topic):
- if not self.topic_list:
+ if self.topic_list:
+ self.topic_list.append(topic)
+ else:
self.topic_list = [topic]
- else:
- self.topic_list.append(topic)
def __str__(self):
if tr_list:
@@ -107,6 +114,7 @@
TOPIC_RE = regex.compile(u"^topic: (\\p{L}.*)$")
SYN_RE = regex.compile(u"^syn: (\\p{L}.*)$")
ANT_RE = regex.compile(u"^ant: (\\p{L}.*)$")
+ REL_RE = regex.compile(u"^rel: (\\p{L}.*)$")
CONT_RE = regex.compile(u"^ +(.*)")
@@ -314,6 +322,15 @@
raise ParseException("""Empty antonym...""")
sense.add_ant(ant)
continue
+ m = self.REL_RE.match(self.line)
+ if m is not None:
+ rels = m.group(1).split(";")
+ for rel in rels:
+ rel = rel.strip()
+ if len(rel) == 0:
+ raise ParseException("""Empty relation...""")
+ sense.add_rel(rel)
+ continue
m = self.TRANSL_RE.match(self.line)
if m is not None:
sense.add_tr((m.group(1), m.group(2) + self.parse_translation_continuation()))
--- a/py/gadict_c5.py Sat Sep 17 10:18:12 2016 +0300
+++ b/py/gadict_c5.py Wed Sep 21 22:09:37 2016 +0300
@@ -92,12 +92,22 @@
FOUT.write("«")
FOUT.write(sense.pos)
FOUT.write("» ")
+ need_sep = False
if sense.ant_list and len(sense.ant_list) > 0:
FOUT.write(" ant: ")
FOUT.write("; ".join(["{"+s+"}" for s in sense.ant_list]))
+ need_sep = True
if sense.syn_list and len(sense.syn_list) > 0:
+ if need_sep:
+ FOUT.write(" |")
FOUT.write(" syn: ")
FOUT.write("; ".join(["{"+s+"}" for s in sense.syn_list]))
+ need_sep = True
+ if sense.rel_list and len(sense.rel_list) > 0:
+ if need_sep:
+ FOUT.write(" |")
+ FOUT.write(" see: ")
+ FOUT.write("; ".join(["{"+s+"}" for s in sense.rel_list]))
if not LANGS or len(LANGS) != 1:
FOUT.write("\n")
for (lang, tr) in sense.tr_list:
--- a/py/gadict_srs_anki.py Sat Sep 17 10:18:12 2016 +0300
+++ b/py/gadict_srs_anki.py Wed Sep 21 22:09:37 2016 +0300
@@ -98,10 +98,13 @@
font-style: italic;
}
.ant {
- color: red;
+ color: #404080;
}
.syn {
- color: blue;
+ color: #804040;
+}
+.rel {
+ color: #804080;
}
.attrs {
color: blue;
@@ -230,14 +233,25 @@
buf.append("<span class='pos'>")
buf.append(sense.pos)
buf.append("</span>")
+ need_sep = False
if sense.ant_list and len(sense.ant_list) > 0:
buf.append(" <span class='ant'>ant: ")
buf.append("; ".join(sense.ant_list))
buf.append("</span>")
+ need_sep = True
if sense.syn_list and len(sense.syn_list) > 0:
+ if need_sep:
+ buf.append(" |")
buf.append(" <span class='syn'>syn: ")
buf.append("; ".join(sense.syn_list))
buf.append("</span>")
+ need_sep = True
+ if sense.rel_list and len(sense.rel_list) > 0:
+ if need_sep:
+ buf.append(" |")
+ buf.append(" <span class='rel'>rel: ")
+ buf.append("; ".join(sense.rel_list))
+ buf.append("</span>")
for (lang, tr) in sense.tr_list:
if len(sense.tr_list) > 1:
buf.append("<div class='sense'>")
--- a/www/HACKING.rst Sat Sep 17 10:18:12 2016 +0300
+++ b/www/HACKING.rst Wed Sep 21 22:09:37 2016 +0300
@@ -88,8 +88,8 @@
* *singularity* or *number*: ``s`` - single, ``pl`` - plural.
* *verb voice* or *verb tense*: ``v1`` - infinitive, ``v2`` - past tense,
``v3`` past participle tense.
-* *gender*: ``male`` or ``female``
-* *comparison*: ``comp`` - comparative or ``super`` - superlative
+* *gender*: ``male`` or ``female``.
+* *comparison*: ``comp`` - comparative or ``super`` - superlative.
*Parts of speech* are:
@@ -102,9 +102,6 @@
* ``conj`` - conjunction
* ``num`` - numeral
* ``int`` - interjection
-
-Special markers with roles same as for parts of speech:
-
* ``abbr`` - abbreviation
* ``phr`` - phrase
* ``phr.v`` - phrasal verb
@@ -122,7 +119,8 @@
* ``meal``, ``office``, etc
* ``size``, ``shape``, ``age``, ``color``
-Synonyms marked by ``syn:``, antonyms marked by ``ant:``.
+Synonyms marked by ``syn:``, antonyms marked by ``ant:``, related (see also)
+terms marked by ``rel:``, topics/tags marked by ``topic:``.
Translation marked by lowercase ISO 639-1 code, like: