unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH -v2] services: dict.scm: Support more dicod configuration
@ 2017-03-30 11:13 Huang Ying
  2017-03-31 22:48 ` bug#26308: " Ludovic Courtès
  0 siblings, 1 reply; 5+ messages in thread
From: Huang Ying @ 2017-03-30 11:13 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel, guix-patches

* gnu/services/dict.scm (<dicod-configuration>): Add handlers to configure
  handlers (module instances).
  (<dicod-handler>): Add new record type to describe handler (module instance).
  (<dicod-database>): Add more fields.
  (dicod-configuration-file): Support convert handlers and enhanced databases
  configuration to config file.

* doc/guix.text: Add description of newly added dicod configuration.
---
 doc/guix.texi         | 57 ++++++++++++++++++++++++++++++++++++++++++++++-----
 gnu/services/dict.scm | 52 ++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 96 insertions(+), 13 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 57595b95e..f1a063581 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -14370,25 +14370,49 @@ This is the list of IP addresses and ports and possibly socket file
 names to listen to (@pxref{Server Settings, @code{listen} directive,,
 dico, GNU Dico Manual}).
 
+@item @code{handlers} (default: @var{'()})
+List of @code{<dicod-handler>} objects denoting handlers (module instances).
+
 @item @code{databases} (default: @var{(list %dicod-database:gcide)})
 List of @code{<dicod-database>} objects denoting dictionaries to be served.
 @end table
 @end deftp
 
-@deftp {Data Type} dicod-database
-Data type representing a dictionary database.
+@deftp {Data Type} dicod-handler
+Data type representing a dictionary handler (module instance).
 
 @table @asis
 @item @code{name}
-Name of the database, will be used in DICT commands.
+Name of the handler (module instance).
 
-@item @code{module}
-Name of the dicod module used by this database
+@item @code{module} (default: @var{#f})
+Name of the dicod module of the handler (instance).  If it is @code{#f},
+the module has the same name as the handler.
 (@pxref{Modules,,, dico, GNU Dico Manual}).
 
 @item @code{options}
 List of strings or gexps representing the arguments for the module handler
+@end table
+@end deftp
+
+@deftp {Data Type} dicod-database
+Data type representing a dictionary database.
+
+@table @asis
+@item @code{name}
+Name of the database, will be used in DICT commands.
+
+@item @code{handler}
+Name of the dicod handler (module instance) used by this database
 (@pxref{Handlers,,, dico, GNU Dico Manual}).
+
+@item @code{complex} (default: @var{#f})
+Whether the database configuration complex.  The complex configuration
+will need a corresponding @code{<dicod-handler>} object, otherwise not.
+
+@item @code{options}
+List of strings or gexps representing the arguments for the database
+(@pxref{Databases,,, dico, GNU Dico Manual}).
 @end table
 @end deftp
 
@@ -14397,6 +14421,29 @@ A @code{<dicod-database>} object serving the GNU Collaborative International
 Dictonary of English using the @code{gcide} package.
 @end defvr
 
+The following is an example @code{dicod-service} configuration.
+
+@example
+(dicod-service #:config
+ (dicod-configuration
+  (handlers
+   (list
+    (dicod-handler
+     (name "wordnet")
+     (module "dictorg")
+     (options
+      '("dbdir=/gnu/store/xxxx-wordnet")))))
+  (databases
+   (list
+    (dicod-database
+     (name "wordnet")
+     (complex #t)
+     (handler "wordnet")
+     (options
+      '("database=wn")))
+    %dicod-database:gcide))))
+@end example
+
 @subsubsection Version Control
 
 The @code{(gnu services version-control)} module provides the following services:
diff --git a/gnu/services/dict.scm b/gnu/services/dict.scm
index 303067037..596f901f3 100644
--- a/gnu/services/dict.scm
+++ b/gnu/services/dict.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2016 Sou Bunnbu <iyzsong@gmail.com>
 ;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2017 Huang Ying <huang.ying.caritas@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -32,6 +33,7 @@
   #:export (dicod-service
             dicod-service-type
             dicod-configuration
+            dicod-handler
             dicod-database
             %dicod-database:gcide))
 
@@ -46,21 +48,30 @@
   (dico        dicod-configuration-dico       (default dico))
   (interfaces  dicod-configuration-interfaces     ;list of strings
                (default '("localhost")))
-  (databases   dicod-configuration-databases
-               ;; list of <dicod-database>
+  (handlers    dicod-configuration-handlers       ;list of <dicod-handler>
+               (default '()))
+  (databases   dicod-configuration-databases      ;list of <dicod-database>
                (default (list %dicod-database:gcide))))
 
+(define-record-type* <dicod-handler>
+  dicod-handler make-dicod-handler
+  dicod-handler?
+  (name        dicod-handler-name)
+  (module      dicod-handler-module          (default #f))
+  (options     dicod-handler-options         (default '())))
+
 (define-record-type* <dicod-database>
   dicod-database make-dicod-database
   dicod-database?
   (name        dicod-database-name)
-  (module      dicod-database-module)
+  (handler     dicod-database-handler)
+  (complex     dicod-database-complex        (default #f))
   (options     dicod-database-options        (default '())))
 
 (define %dicod-database:gcide
   (dicod-database
    (name "gcide")
-   (module "gcide")
+   (handler "gcide")
    (options (list #~(string-append "dbdir=" #$gcide "/share/gcide")
                   "idxdir=/var/run/dicod"))))
 
@@ -76,22 +87,47 @@
          (shell (file-append shadow "/sbin/nologin")))))
 
 (define (dicod-configuration-file config)
+  (define handler->text
+    (match-lambda
+      (($ <dicod-handler> name #f '())
+       `("
+load-module " ,name ";"))
+      (($ <dicod-handler> name #f options)
+       (handler->text (dicod-handler
+                       (name name)
+                       (module name)
+                       (options options))))
+      (($ <dicod-handler> name module options)
+       `("
+load-module " ,name " {
+   command \"" ,module (string-join (list ,@options) " " 'prefix) "\";
+}\n"))))
+
   (define database->text
     (match-lambda
-      (($ <dicod-database> name module options)
+      (($ <dicod-database> name handler #f options)
+       (append
+        (handler->text (dicod-handler
+                        (name handler)))
+        (database->text (dicod-database
+                         (name name)
+                         (handler handler)
+                         (complex #t)
+                         (options options)))))
+      (($ <dicod-database> name handler complex options)
        `("
-load-module " ,module ";
 database {
    name \"" ,name "\";
-   handler \"" ,module
+   handler \"" ,handler
    (string-join (list ,@options) " " 'prefix) "\";
 }\n"))))
 
   (define configuration->text
     (match-lambda
-      (($ <dicod-configuration> dico (interfaces ...) databases)
+      (($ <dicod-configuration> dico (interfaces ...) handlers databases)
        (append `("listen ("
                  ,(string-join interfaces ", ") ");\n")
+               (append-map handler->text handlers)
                (append-map database->text databases)))))
 
   (apply mixed-text-file "dicod.conf" (configuration->text config)))
-- 
2.12.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: bug#26308: [PATCH -v2] services: dict.scm: Support more dicod configuration
  2017-03-30 11:13 [PATCH -v2] services: dict.scm: Support more dicod configuration Huang Ying
@ 2017-03-31 22:48 ` Ludovic Courtès
  2017-04-01 11:29   ` Huang, Ying
  0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2017-03-31 22:48 UTC (permalink / raw)
  To: Huang Ying; +Cc: guix-devel, 26308-done

Hello,

Huang Ying <huang.ying.caritas@gmail.com> skribis:

> * gnu/services/dict.scm (<dicod-configuration>): Add handlers to configure
>   handlers (module instances).
>   (<dicod-handler>): Add new record type to describe handler (module instance).
>   (<dicod-database>): Add more fields.
>   (dicod-configuration-file): Support convert handlers and enhanced databases
>   configuration to config file.
>
> * doc/guix.text: Add description of newly added dicod configuration.

I’ve committed with a few adjustments to the commit log and cosmetic
changes:

  https://git.savannah.gnu.org/cgit/guix.git/commit/?id=9af7ecd9591b4eff41389291bbc586dcf09e2665

> +@example
> +(dicod-service #:config
> + (dicod-configuration
> +  (handlers
> +   (list
> +    (dicod-handler
> +     (name "wordnet")
> +     (module "dictorg")
> +     (options
> +      '("dbdir=/gnu/store/xxxx-wordnet")))))

I’ve changed this to use a real example instead of “xxx”.

>  (define-record-type* <dicod-database>
>    dicod-database make-dicod-database
>    dicod-database?
>    (name        dicod-database-name)
> -  (module      dicod-database-module)
> +  (handler     dicod-database-handler)
> +  (complex     dicod-database-complex        (default #f))

I changed that to ‘complex?’, to make it clear that it’s a Boolean.

While I was at it, I wrote a simple test for the dicod service:

  https://git.savannah.gnu.org/cgit/guix.git/commit/?id=985a8599ed742053b52ac85f753c4feb54af93cb

It uses the example handler that you gave in the doc, but I think this
handler actually does nothing because WordNet does not provide data in
the dict.org format AIUI (and its data is under “/dict” anyway.)  Is
that correct?

Do you have another example in mind that could use a dict.org-formatted
database?

Thank you!

Ludo’.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: bug#26308: [PATCH -v2] services: dict.scm: Support more dicod configuration
  2017-03-31 22:48 ` bug#26308: " Ludovic Courtès
@ 2017-04-01 11:29   ` Huang, Ying
  2017-04-01 22:12     ` Ludovic Courtès
  0 siblings, 1 reply; 5+ messages in thread
From: Huang, Ying @ 2017-04-01 11:29 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel, 26308-done

ludo@gnu.org (Ludovic Courtès) writes:

> Hello,
>
> Huang Ying <huang.ying.caritas@gmail.com> skribis:
>
>> * gnu/services/dict.scm (<dicod-configuration>): Add handlers to configure
>>   handlers (module instances).
>>   (<dicod-handler>): Add new record type to describe handler (module instance).
>>   (<dicod-database>): Add more fields.
>>   (dicod-configuration-file): Support convert handlers and enhanced databases
>>   configuration to config file.
>>
>> * doc/guix.text: Add description of newly added dicod configuration.
>
> I’ve committed with a few adjustments to the commit log and cosmetic
> changes:
>
>   https://git.savannah.gnu.org/cgit/guix.git/commit/?id=9af7ecd9591b4eff41389291bbc586dcf09e2665
>
>> +@example
>> +(dicod-service #:config
>> + (dicod-configuration
>> +  (handlers
>> +   (list
>> +    (dicod-handler
>> +     (name "wordnet")
>> +     (module "dictorg")
>> +     (options
>> +      '("dbdir=/gnu/store/xxxx-wordnet")))))
>
> I’ve changed this to use a real example instead of “xxx”.
>
>>  (define-record-type* <dicod-database>
>>    dicod-database make-dicod-database
>>    dicod-database?
>>    (name        dicod-database-name)
>> -  (module      dicod-database-module)
>> +  (handler     dicod-database-handler)
>> +  (complex     dicod-database-complex        (default #f))
>
> I changed that to ‘complex?’, to make it clear that it’s a Boolean.
>
> While I was at it, I wrote a simple test for the dicod service:
>
>   https://git.savannah.gnu.org/cgit/guix.git/commit/?id=985a8599ed742053b52ac85f753c4feb54af93cb
>
> It uses the example handler that you gave in the doc, but I think this
> handler actually does nothing because WordNet does not provide data in
> the dict.org format AIUI (and its data is under “/dict” anyway.)  Is
> that correct?
>
> Do you have another example in mind that could use a dict.org-formatted
> database?

There are dict.org dict for wordnet and foldoc in Debian.  Some
conversion tool is needed to convert the dict database file.

Best Regards,
Huang, Ying

> Thank you!
>
> Ludo’.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: bug#26308: [PATCH -v2] services: dict.scm: Support more dicod configuration
  2017-04-01 11:29   ` Huang, Ying
@ 2017-04-01 22:12     ` Ludovic Courtès
  2017-04-03  2:08       ` huang ying
  0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2017-04-01 22:12 UTC (permalink / raw)
  To: Huang, Ying; +Cc: guix-devel, 26308-done

Hello,

"Huang, Ying" <huang_ying_caritas@163.com> skribis:

> ludo@gnu.org (Ludovic Courtès) writes:

[...]

>> While I was at it, I wrote a simple test for the dicod service:
>>
>>   https://git.savannah.gnu.org/cgit/guix.git/commit/?id=985a8599ed742053b52ac85f753c4feb54af93cb
>>
>> It uses the example handler that you gave in the doc, but I think this
>> handler actually does nothing because WordNet does not provide data in
>> the dict.org format AIUI (and its data is under “/dict” anyway.)  Is
>> that correct?
>>
>> Do you have another example in mind that could use a dict.org-formatted
>> database?
>
> There are dict.org dict for wordnet and foldoc in Debian.  Some
> conversion tool is needed to convert the dict database file.

OK.  Any idea of a DICT database file that we could use as an example
and as a test?

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: bug#26308: [PATCH -v2] services: dict.scm: Support more dicod configuration
  2017-04-01 22:12     ` Ludovic Courtès
@ 2017-04-03  2:08       ` huang ying
  0 siblings, 0 replies; 5+ messages in thread
From: huang ying @ 2017-04-03  2:08 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel, 26308-done

On Sun, Apr 2, 2017 at 6:12 AM, Ludovic Courtès <ludo@gnu.org> wrote:
> Hello,
>
> "Huang, Ying" <huang_ying_caritas@163.com> skribis:
>
>> ludo@gnu.org (Ludovic Courtès) writes:
>
> [...]
>
>>> While I was at it, I wrote a simple test for the dicod service:
>>>
>>>   https://git.savannah.gnu.org/cgit/guix.git/commit/?id=985a8599ed742053b52ac85f753c4feb54af93cb
>>>
>>> It uses the example handler that you gave in the doc, but I think this
>>> handler actually does nothing because WordNet does not provide data in
>>> the dict.org format AIUI (and its data is under “/dict” anyway.)  Is
>>> that correct?
>>>
>>> Do you have another example in mind that could use a dict.org-formatted
>>> database?
>>
>> There are dict.org dict for wordnet and foldoc in Debian.  Some
>> conversion tool is needed to convert the dict database file.
>
> OK.  Any idea of a DICT database file that we could use as an example
> and as a test?

I found there is freedict database file, for example,

https://downloads.sourceforge.net/project/freedict/English%20-%20French/0.1.4/freedict-eng-fra-0.1.4.tar.bz2?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Ffreedict%2Ffiles%2FEnglish%2520-%2520French%2F0.1.4%2Ffreedict-eng-fra-0.1.4.tar.bz2%2Fdownload&ts=1491090445&use_mirror=excellmedia

The home page is http://freedict.org/en/, the github page is
http://freedict.org/en/, according to
https://github.com/freedict/fd-dictionaries/blob/master/eng-fra/COPYING,
the database file is released with GPL.

Best Regards,
Huang, Ying

> Thanks,
> Ludo’.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-04-03  2:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-30 11:13 [PATCH -v2] services: dict.scm: Support more dicod configuration Huang Ying
2017-03-31 22:48 ` bug#26308: " Ludovic Courtès
2017-04-01 11:29   ` Huang, Ying
2017-04-01 22:12     ` Ludovic Courtès
2017-04-03  2:08       ` huang ying

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).