aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2004-06-19 17:16:12 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2004-06-19 17:16:12 +0000
commit0e8ee6746d944ca4e963c3db7d9fcc151817dd04 (patch)
tree30bc9062b9ca2fdfbd0e2ef170a15652f9678814
parent8584636b72b0151c01b03bf9ef66dcc15682cc4e (diff)
downloadellinika-0e8ee6746d944ca4e963c3db7d9fcc151817dd04.tar.gz
ellinika-0e8ee6746d944ca4e963c3db7d9fcc151817dd04.tar.bz2
Reflect changes to the database structure.
git-svn-id: file:///home/puszcza/svnroot/ellinika/trunk@145 941c8c0f-9102-463b-b60b-cd22ce0e6858
-rw-r--r--cgi-bin/dict.cgi.in60
-rw-r--r--src/gram.y31
-rw-r--r--src/main.c11
-rw-r--r--src/trans.h2
4 files changed, 73 insertions, 31 deletions
diff --git a/cgi-bin/dict.cgi.in b/cgi-bin/dict.cgi.in
index ca5984c..a327be7 100644
--- a/cgi-bin/dict.cgi.in
+++ b/cgi-bin/dict.cgi.in
@@ -108,22 +108,39 @@
(cons "?" arglist))))))
;; Τα μέρη του λογου
-(define part-of-speech
- (list (cons "κανένα μέρος του λόγου" #f)
- (cons "ρήμα" "(dict.pos=\"μετ.\" OR dict.pos=\"αμετ.\" OR dict.pos=\"μετ.,αμετ.\" OR dict.pos=\"απρόσ.\")")
- (cons "μεταβατικό" "dict.pos=\"μετ.\"")
- (cons "αμετάβατο" "dict.pos=\"αμετ.\"")
- (cons "άρθρο" "dict.pos=\"άρθρο\"")
- (cons "αριθμός" "dict.pos=\"αριθ.\"")
- (cons "επίθετο" "dict.pos=\"επίθ.\"")
- (cons "επίρρημα" "dict.pos=\"επίρρ.\"")
- (cons "επιφώνημα" "dict.pos=\"επιφ.\"")
- (cons "μετοχή" "dict.pos=\"μετοχή\"")
- (cons "μόριο" "dict.pos=\"μόριο\"")
- (cons "πρόθεση" "dict.pos=\"πρόθ.\"")
- (cons "σύνδεσμος" "dict.pos=\"σύνδ.\"")
- (cons "ουσιαστικό" "(dict.pos=\"ο\" OR dict.pos=\"η\" OR dict.pos=\"το\")")))
+(define part-of-speech '())
+(define (hbase num)
+ (do ((i 0 (1+ i))
+ (n num (ash n -1)))
+ ((= n 0) (ash 1 (- i 1)))))
+
+(define (load-pos)
+ (let ((conn (sql-connect
+ sql-iface sql-host sql-port sql-database
+ sql-username sql-password)))
+ (cond
+ (conn
+ (let ((plist (sql-query
+ conn
+ "SELECT name,id FROM pos WHERE canonical='Y' order by id")))
+ (set! part-of-speech
+ (cons
+ (cons "κανένα μέρος του λόγου" #f)
+ (map
+ (lambda (x)
+ (let* ((value (string->number (car (cdr x))))
+ (mask (hbase value)))
+ (cons (car x)
+ (number->string
+ (if (= value mask)
+ value
+ (logand
+ value
+ (lognot mask)))))))
+ plist)))
+ (sql-connect-close conn))))))
+
;; Protect occurences of " in a string.
;; Usual backslash escapes do not work in INPUT widgets, so I
;; change all quotation marks to &#34;
@@ -151,6 +168,7 @@
(define (main-form)
+ (load-pos)
(display "<FORM ACTION=\"")
(display (make-cgi-name))
(display "\" METHOD=POST>
@@ -673,7 +691,7 @@
(cond
((> (string->number theme) 0)
(string-append
- "SELECT dict.word FROM dict,topic_tab WHERE "
+ "SELECT DISTINCT dict.word FROM dict,topic_tab WHERE "
(cond
((not (string-null? key))
(string-append "dict.sound LIKE \""
@@ -687,19 +705,19 @@
(if (> (string->number pos) 0)
(let ((pos-entry
(list-ref part-of-speech (string->number pos))))
- (string-append "AND "
+ (string-append "AND dict.pos & "
(cdr pos-entry)))
"")
" order by word"))
(else
(string-append
- "SELECT word FROM dict WHERE sound like \""
+ "SELECT DISTINCT word FROM dict WHERE sound like \""
(greek-to-transcription key)
"%\" "
(if (> (string->number pos) 0)
(let ((pos-entry (list-ref part-of-speech
(string->number pos))))
- (string-append "AND "
+ (string-append "AND dict.pos &"
(cdr pos-entry)))
"")
" ORDER BY WORD"))))))
@@ -746,9 +764,9 @@
(result (sql-query
conn
(string-append
- "SELECT dict.word,dict.ident,dict.pos,dict.forms,articles.subindex,articles.meaning from dict,articles where dict.word=\""
+ "SELECT dict.word,dict.ident,pos.abbr,dict.forms,articles.subindex,articles.meaning FROM dict,articles,pos WHERE dict.word=\""
key
- "\" and dict.ident=articles.ident order by dict.ident, articles.subindex"))))
+ "\" and dict.ident=articles.ident and dict.pos=pos.id and pos.canonical='Y' order by dict.ident, articles.subindex"))))
(cond
((null? result)
diff --git a/src/gram.y b/src/gram.y
index 597d566..c8ee0d7 100644
--- a/src/gram.y
+++ b/src/gram.y
@@ -9,19 +9,22 @@ struct obstack stk;
struct descr *make_descr(enum descr_type type, u_char *value);
static int _register_topic(void *item, void *data);
+static int convert_pos(char *text, int *pos);
%}
%token NODE POS END MEANING ALIAS ANT TOPIC FORMS XREF
%token <string> STRING
-%type <string> string pos forms
+%type <num> pos
+%type <string> string forms
%type <header> nodehdr alias
%type <descr> descr
%type <list> list aliases descrlist header
%type <item> item
%union {
+ int num;
u_char *string;
struct header *header;
struct descr *descr;
@@ -106,11 +109,12 @@ nodehdr : NODE string pos forms
pos : /* empty */
{
- $$ = NULL;
+ $$ = -1;
}
| POS string
{
- $$ = $2;
+ if (convert_pos($2, &$$))
+ YYERROR;
}
;
@@ -226,3 +230,24 @@ _register_topic(void *item, void *data)
list_append(node->descr, data);
return 0;
}
+
+
+static int
+convert_pos(char *text, int *pos)
+{
+ unsigned long n;
+ if (sql_query_n(&n,
+ "SELECT id FROM pos WHERE abbr=\"%s\"",
+ text)
+ && sql_query_n(&n,
+ "SELECT id FROM pos WHERE abbr_lat=\"%s\"",
+ text)
+ && sql_query_n(&n,
+ "SELECT id FROM pos WHERE name=\"%s\"",
+ text)) {
+ yyerror("unknown or misspelled part of speech");
+ return 1;
+ }
+ *pos = n;
+ return 0;
+}
diff --git a/src/main.c b/src/main.c
index 4eedbbb..bd2f6f5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -41,7 +41,7 @@ create_node(RAD_LIST *hdr, RAD_LIST *descr)
for (i = list_count(hdr)-1; i >= 0; i--) {
struct header *dp = list_item(hdr, i);
- if (!dp->pos) {
+ if (dp->pos < 0) {
if (prev)
dp->pos = prev->pos;
else {
@@ -53,7 +53,7 @@ create_node(RAD_LIST *hdr, RAD_LIST *descr)
error_count++;
}
}
- if (dp->pos)
+ if (dp->pos >= 0)
prev = dp;
}
node->header = hdr;
@@ -79,10 +79,10 @@ _emit_headers(void *item, void *data)
fprintf(stderr, "Emitting %s\n", hp->key);
sound = greek_to_transcription(hp->key);
if (hp->forms)
- sql_query("INSERT INTO dict VALUES(%lu,\"%s\",\"%s\",\"%s\",\"%s\")",
+ sql_query("INSERT INTO dict VALUES(%lu,\"%s\",\"%s\",%d,\"%s\")",
dict_index, hp->key, sound, hp->pos, hp->forms);
else
- sql_query("INSERT INTO dict (ident,word,sound,pos) VALUES(%lu,\"%s\",\"%s\",\"%s\")",
+ sql_query("INSERT INTO dict (ident,word,sound,pos) VALUES(%lu,\"%s\",\"%s\",%d)",
dict_index, hp->key, sound, hp->pos);
efree(sound);
return 0;
@@ -273,6 +273,7 @@ main(int argc, char **argv)
make_m4_args (m4_bin, include_list);
node_list = list_create();
+ sql_connect();
argc -= optind;
argv += optind;
@@ -282,8 +283,6 @@ main(int argc, char **argv)
if (compile_only)
return 0;
- sql_connect();
-
antonym_list = list_create();
xref_list = list_create();
diff --git a/src/trans.h b/src/trans.h
index 1244cab..e342a5d 100644
--- a/src/trans.h
+++ b/src/trans.h
@@ -23,7 +23,7 @@ struct gram_item {
struct header {
u_char *key;
- char *pos;
+ int pos;
u_char *forms;
};

Return to:

Send suggestions and report system problems to the System administrator.