Difference between revisions of "Dict Applications"

From YobiWiki
Jump to navigation Jump to search
m
 
m
Line 1: Line 1:
Some tips about dictionnary applications...
+
Some tips about dictionary applications...
   
 
==Infos==
 
==Infos==
Line 44: Line 44:
 
===dict(e.g. Freedict) to Stardict===
 
===dict(e.g. Freedict) to Stardict===
 
Utility to convert installed dict (e.g. freedict) packages into stardict versions:
 
Utility to convert installed dict (e.g. freedict) packages into stardict versions:
#!/bin/bash
+
<source lang=bash>
  +
#!/bin/bash
 
  +
# Converts dictd files to stardict files
 
  +
# Converts dictd files to stardict files
# Usage: ./dict2stardict.sh dict1_basename dict2_basename2 ...
 
# Example: ./dict2stardict.sh freedict-hun-eng freedict-eng-hun
+
# Usage: ./dict2stardict.sh dict1_basename dict2_basename2 ...
  +
# Example: ./dict2stardict.sh freedict-hun-eng freedict-eng-hun
 
  +
# Copyright Philippe Teuwen <phil à teuwen.org>
 
  +
# Copyright Philippe Teuwen <phil à teuwen.org>
# License: GPLv3 or later
 
  +
# License: GPLv3 or later
# Version 0.92
 
  +
# Version 0.92
 
  +
# Should we install dict files?
 
  +
# Should we install dict files?
# Values are: local/deb/none
 
  +
# Values are: local/deb/none
# local: install files in /usr/local/share
 
  +
# local: install files in /usr/local/share
# deb: create a Debian package (to be installed)
 
# none: leave files here
+
# deb: create a Debian package (to be installed)
  +
# none: leave files here
INSTALL_STARDICT_DEFAULT=deb
 
INSTALL_STARDICT=${INSTALL_STARDICT:-$INSTALL_STARDICT_DEFAULT}
+
INSTALL_STARDICT_DEFAULT=deb
  +
INSTALL_STARDICT=${INSTALL_STARDICT:-$INSTALL_STARDICT_DEFAULT}
 
  +
TEMP_DIR="./stardict-temp"
 
  +
TEMP_DIR="./stardict-temp"
 
  +
if [ "$*" == "" ];then
 
  +
if [ "$*" == "" ];then
echo "Usage: $0 dict1_basename dict2_basename ..."
 
echo "Detected dict dictionaries:"
+
echo "Usage: $0 dict1_basename dict2_basename ..."
  +
echo "Detected dict dictionaries:"
ls /usr/share/dictd/*.dict* 2>/dev/null|sed 's/^.*\///;s/\.dict.*$//'
 
ls ./*.dict* 2>/dev/null|sed 's/^.*\///;s/\.dict.*$//'
+
ls /usr/share/dictd/*.dict* 2>/dev/null|sed 's/^.*\///;s/\.dict.*$//'
  +
ls ./*.dict* 2>/dev/null|sed 's/^.*\///;s/\.dict.*$//'
exit 1
 
  +
exit 1
fi
 
  +
fi
 
  +
prefix="dictd_www.freedict.de_"
 
  +
prefix="dictd_www.freedict.de_"
starprefix="dictd_"
 
  +
starprefix="dictd_"
###########################################################################
 
  +
###########################################################################
function dict_to_stardict {
 
  +
function dict_to_stardict {
local FILE="$1"
 
  +
local FILE="$1"
echo "Convert $FILE to stardict format..."
 
  +
echo "Convert $FILE to stardict format..."
local word=`/usr/lib/stardict/dictd2dic $FILE 2>&1 | grep wordcount | cut -d " " -f 2`
 
  +
local word=`/usr/lib/stardict/dictd2dic $FILE 2>&1 | grep wordcount | cut -d " " -f 2`
if [ ! -e "$prefix$FILE.dict.dz" ]||[ ! -e "$prefix$FILE.idx.gz" ];then
 
  +
if [ ! -e "$prefix$FILE.dict.dz" ]||[ ! -e "$prefix$FILE.idx.gz" ];then
echo "Error in conversion! ($word words)"
 
echo "Abort!"
+
echo "Error in conversion! ($word words)"
exit 1
+
echo "Abort!"
fi
+
exit 1
  +
fi
mv "$prefix$FILE.dict.dz" "$starprefix$FILE.dict.dz"
 
mv "$prefix$FILE.idx.gz" "$starprefix$FILE.idx.gz"
+
mv "$prefix$FILE.dict.dz" "$starprefix$FILE.dict.dz"
  +
mv "$prefix$FILE.idx.gz" "$starprefix$FILE.idx.gz"
echo " $word words"
 
  +
echo " $word words"
local size=`zcat "$starprefix$FILE.idx.gz"| wc -c`
 
  +
local size=`zcat "$starprefix$FILE.idx.gz"| wc -c`
 
cat << EOF > "$starprefix$FILE.ifo"
 
StarDict's dict ifo file
 
version=2.4.2
 
wordcount=$word
 
date=$(date "+%Y.%m.%d")
 
author=$AUTHOR
 
email=$EMAIL
 
description=$DESCRIPTION
 
website=$WEBSITE
 
idxfilesize=$size
 
bookname=$starprefix$FILE
 
sametypesequence=m
 
EOF
 
}
 
###########################################################################
 
 
mkdir -p "$TEMP_DIR"
 
cd "$TEMP_DIR"
 
 
while [ "$1" != "" ]; do
 
FILE="$1"
 
 
if [ ! -e "../$FILE.dict.dz" ];then
 
if [ ! -e "/usr/share/dictd/$FILE.dict.dz" ];then
 
echo "File /usr/share/dictd/$FILE.dict.dz not found!"
 
echo "Did you install dict-$FILE package?"
 
exit 1
 
else
 
cp -L "/usr/share/dictd/$FILE.dict.dz" .
 
fi
 
else
 
cp "../$FILE.dict.dz" .
 
fi
 
if [ ! -e "../$FILE.index" ];then
 
if [ ! -e "/usr/share/dictd/$FILE.index" ];then
 
echo "File /usr/share/dictd/$FILE.index not found!"
 
echo "Did you install dict-$FILE package?"
 
exit 1
 
else
 
cp -L "/usr/share/dictd/$FILE.index" .
 
fi
 
else
 
cp "../$FILE.index" .
 
fi
 
 
echo "Uncompress..."
 
dictunzip "$FILE.dict.dz"
 
 
if [ ! -e "$FILE.dict" ];then
 
echo "Error uncompressing $FILE.dict.dz!"
 
echo "Abort!"
 
exit 1
 
fi
 
AUTHOR=
 
EMAIL=
 
DESCRIPTION="Converted from a dictd"
 
WEBSITE=
 
dict_to_stardict "$FILE"
 
rm "$FILE.dict" "$FILE.index"
 
 
case $INSTALL_STARDICT in
 
local)
 
echo "Install stardict files..."
 
sudo mkdir -p "/usr/local/share/stardict/dic/$starprefix$FILE-2.4.2"
 
sudo ln -s "/usr/local/share/stardict/dic/$starprefix$FILE-2.4.2" /usr/share/stardict/dic
 
for i in dict.dz idx.gz ifo ; do
 
sudo mv "$starprefix$FILE.$i" "/usr/local/share/stardict/dic/$starprefix$FILE-2.4.2"
 
done
 
;;
 
deb)
 
PKG="stardict-dictd-$(echo $FILE|unaccent UTF-8)"
 
PKG=${PKG//_/-}
 
 
VERSION="1.0-1"
 
ARCH="all"
 
FULLPKG="${PKG}_${VERSION}_${ARCH}"
 
DEST="/usr/share/stardict/dic/$starprefix$FILE-2.4.2"
 
mkdir -p "$FULLPKG$DEST"
 
mkdir -p "$FULLPKG/DEBIAN"
 
for i in dict.dz idx.gz ifo ; do
 
cp "$starprefix$FILE.$i" "$FULLPKG$DEST"
 
done
 
 
SIZE=$(du -ks "$FULLPKG"|sed 's/[^0-9].*$//')
 
cd "$FULLPKG"
 
find . -type f -not -path "DEBIAN"|xargs md5sum|sed 's/ \.\// /' > DEBIAN/md5sums
 
cat <<EOF > "DEBIAN/control"
 
Package: $PKG
 
Version: $VERSION
 
Section: text
 
Priority: extra
 
Architecture: $ARCH
 
Depends: stardict
 
Installed-Size: $SIZE
 
Maintainer: Anonymous <anonymous@web>
 
Description: Stardict version of a dictd dictionary
 
This package contains a Stardict formatted dictionary
 
converted from a dictd dictionary.
 
 
EOF
 
cd -
 
dpkg-deb -b "$FULLPKG"
 
if $DELETE_TEMP; then
 
rm -rf "$FULLPKG"
 
rm -f "$starprefix$FILE.dict.dz" \
 
"$starprefix$FILE.idx.gz" \
 
"$starprefix$FILE.ifo"
 
fi
 
echo "Debian package created and left in $TEMP_DIR"
 
;;
 
none)
 
echo "Files left in $TEMP_DIR"
 
;;
 
*)
 
echo "Error: unknown installation method $INSTALL_STARDICT"
 
echo "Assuming no install"
 
;;
 
esac
 
 
shift
 
done
 
   
  +
cat << EOF > "$starprefix$FILE.ifo"
  +
StarDict's dict ifo file
  +
version=2.4.2
  +
wordcount=$word
  +
date=$(date "+%Y.%m.%d")
  +
author=$AUTHOR
  +
email=$EMAIL
  +
description=$DESCRIPTION
  +
website=$WEBSITE
  +
idxfilesize=$size
  +
bookname=$starprefix$FILE
  +
sametypesequence=m
  +
EOF
  +
}
  +
###########################################################################
  +
  +
mkdir -p "$TEMP_DIR"
  +
cd "$TEMP_DIR"
  +
  +
while [ "$1" != "" ]; do
  +
FILE="$1"
  +
  +
if [ ! -e "../$FILE.dict.dz" ];then
  +
if [ ! -e "/usr/share/dictd/$FILE.dict.dz" ];then
  +
echo "File /usr/share/dictd/$FILE.dict.dz not found!"
  +
echo "Did you install dict-$FILE package?"
  +
exit 1
  +
else
  +
cp -L "/usr/share/dictd/$FILE.dict.dz" .
  +
fi
  +
else
  +
cp "../$FILE.dict.dz" .
  +
fi
  +
if [ ! -e "../$FILE.index" ];then
  +
if [ ! -e "/usr/share/dictd/$FILE.index" ];then
  +
echo "File /usr/share/dictd/$FILE.index not found!"
  +
echo "Did you install dict-$FILE package?"
  +
exit 1
  +
else
  +
cp -L "/usr/share/dictd/$FILE.index" .
  +
fi
  +
else
  +
cp "../$FILE.index" .
  +
fi
  +
  +
echo "Uncompress..."
  +
dictunzip "$FILE.dict.dz"
  +
  +
if [ ! -e "$FILE.dict" ];then
  +
echo "Error uncompressing $FILE.dict.dz!"
  +
echo "Abort!"
  +
exit 1
  +
fi
  +
AUTHOR=
  +
EMAIL=
  +
DESCRIPTION="Converted from a dictd"
  +
WEBSITE=
  +
dict_to_stardict "$FILE"
  +
rm "$FILE.dict" "$FILE.index"
  +
  +
case $INSTALL_STARDICT in
  +
local)
  +
echo "Install stardict files..."
  +
sudo mkdir -p "/usr/local/share/stardict/dic/$starprefix$FILE-2.4.2"
  +
sudo ln -s "/usr/local/share/stardict/dic/$starprefix$FILE-2.4.2" /usr/share/stardict/dic
  +
for i in dict.dz idx.gz ifo ; do
  +
sudo mv "$starprefix$FILE.$i" "/usr/local/share/stardict/dic/$starprefix$FILE-2.4.2"
  +
done
  +
;;
  +
deb)
  +
PKG="stardict-dictd-$(echo $FILE|unaccent UTF-8)"
  +
PKG=${PKG//_/-}
  +
  +
VERSION="1.0-1"
  +
ARCH="all"
  +
FULLPKG="${PKG}_${VERSION}_${ARCH}"
  +
DEST="/usr/share/stardict/dic/$starprefix$FILE-2.4.2"
  +
mkdir -p "$FULLPKG$DEST"
  +
mkdir -p "$FULLPKG/DEBIAN"
  +
for i in dict.dz idx.gz ifo ; do
  +
cp "$starprefix$FILE.$i" "$FULLPKG$DEST"
  +
done
  +
  +
SIZE=$(du -ks "$FULLPKG"|sed 's/[^0-9].*$//')
  +
cd "$FULLPKG"
  +
find . -type f -not -path "DEBIAN"|xargs md5sum|sed 's/ \.\// /' > DEBIAN/md5sums
  +
cat <<EOF > "DEBIAN/control"
  +
Package: $PKG
  +
Version: $VERSION
  +
Section: text
  +
Priority: extra
  +
Architecture: $ARCH
  +
Depends: stardict
  +
Installed-Size: $SIZE
  +
Maintainer: Anonymous <anonymous@web>
  +
Description: Stardict version of a dictd dictionary
  +
This package contains a Stardict formatted dictionary
  +
converted from a dictd dictionary.
  +
  +
EOF
  +
cd -
  +
dpkg-deb -b "$FULLPKG"
  +
if $DELETE_TEMP; then
  +
rm -rf "$FULLPKG"
  +
rm -f "$starprefix$FILE.dict.dz" \
  +
"$starprefix$FILE.idx.gz" \
  +
"$starprefix$FILE.ifo"
  +
fi
  +
echo "Debian package created and left in $TEMP_DIR"
  +
;;
  +
none)
  +
echo "Files left in $TEMP_DIR"
  +
;;
  +
*)
  +
echo "Error: unknown installation method $INSTALL_STARDICT"
  +
echo "Assuming no install"
  +
;;
  +
esac
  +
  +
shift
  +
done
  +
</source>
 
===dict (e.g. Freedict) to Wordtrans===
 
===dict (e.g. Freedict) to Wordtrans===
 
(old scripts)
 
(old scripts)
#!/bin/bash
+
<source lang=bash>
  +
#!/bin/bash
# Exemple: dict2wt.sh freedict-eng-hun.dict.dz
 
  +
# Exemple: dict2wt.sh freedict-eng-hun.dict.dz
 
 
 
if [ "$1" == "" ]; then
 
if [ "$1" == "" ]; then
Line 244: Line 246:
 
}' \
 
}' \
 
| gzip > $FILEOUT
 
| gzip > $FILEOUT
  +
</source>
 
 
Put the converted dicts in /usr/local/share/wordtrans
 
Put the converted dicts in /usr/local/share/wordtrans
 
<br>For wordtrans: remove spaces in filenames!
 
<br>For wordtrans: remove spaces in filenames!
 
<br>For converted dicts: " :: " is the separator & files are UTF-8
 
<br>For converted dicts: " :: " is the separator & files are UTF-8
----
 
 
back to [[Software]]
 

Revision as of 18:33, 28 March 2008

Some tips about dictionary applications...

Infos

Sources of dictionaries

A good source of freeware Bilingual dictionaries based on French is FreeLang
But they work only under Windows.
Check e.g. on the French-English page, you'll find a link to a similar website based on English, same for Spanish.

Others (to be checked)

Links for the relationship between languages and charsets

Dictionaries programs under Linux

Dict & Freedict

dict: /usr/share/dictd

  • apt-cache search dict-freedict

To use dictd I had to hack a bit in /etc/init.d/dictd:

OPTIONS="--locale fr_FR"
start-stop-daemon --start --quiet -o  -c dictd --exec $DAEMON -- $OPTIONS

Apparently dict & dictd don't support yet correctly UTF8

Stardict

Stardict (mirror here).
Stardict is an offline dictionary program running under Gnome, a Windows port exists as well.
Very good support of UTF-8, searches and on-the-fly scanning

  • apt-get install stardict stardict-tools sdcv

Get some dicts at http://stardict.sourceforge.net/Dictionaries.php and move them to /usr/share/stardict/dic (most are already packaged for Debian, check first!)
For pronounciation database, you can take WyabdcRealPeopleTTS rpm on http://stardict.sourceforge.net/ and use alien.
Stardict needs esd daemon to run to play sounds.

Automatic American<>English<>Canadian "translators"

  • VarCon
    VarCon (Variant Conversion Info) contains tables to convert between American, British (both "ise" and "ize" spellings), and Canadian spellings and vocabulary as well as well as a table listing the equivalent forms of other variants.
  • Respell
    A tool to convert English text from one spelling system to another. At present, there are spelling files for american, british, and canadian spellings.

Others

I used wordtrans but now I'm using Stardict

  • apt-get install wordtrans-qt

Try maybe also "serpento"?

My own conversion scripts

dict(e.g. Freedict) to Stardict

Utility to convert installed dict (e.g. freedict) packages into stardict versions:

#!/bin/bash

# Converts dictd files to stardict files
# Usage: ./dict2stardict.sh dict1_basename dict2_basename2 ...
# Example: ./dict2stardict.sh freedict-hun-eng freedict-eng-hun

# Copyright Philippe Teuwen <phil à teuwen.org>
# License: GPLv3 or later
# Version 0.92

# Should we install dict files?
# Values are: local/deb/none
#       local: install files in /usr/local/share
#       deb:   create a Debian package (to be installed)
#       none:  leave files here
INSTALL_STARDICT_DEFAULT=deb
INSTALL_STARDICT=${INSTALL_STARDICT:-$INSTALL_STARDICT_DEFAULT}

TEMP_DIR="./stardict-temp"

if [ "$*" == "" ];then
    echo "Usage: $0 dict1_basename dict2_basename ..."
    echo "Detected dict dictionaries:"
    ls /usr/share/dictd/*.dict* 2>/dev/null|sed 's/^.*\///;s/\.dict.*$//'
    ls ./*.dict* 2>/dev/null|sed 's/^.*\///;s/\.dict.*$//'
    exit 1
fi

prefix="dictd_www.freedict.de_"
starprefix="dictd_"
###########################################################################
function dict_to_stardict {
    local FILE="$1"
    echo "Convert $FILE to stardict format..."
    local word=`/usr/lib/stardict/dictd2dic $FILE 2>&1 | grep wordcount | cut -d " " -f 2`
    if [ ! -e "$prefix$FILE.dict.dz" ]||[ ! -e "$prefix$FILE.idx.gz" ];then
        echo "Error in conversion! ($word words)"
        echo "Abort!"
        exit 1
    fi
    mv "$prefix$FILE.dict.dz" "$starprefix$FILE.dict.dz"
    mv "$prefix$FILE.idx.gz" "$starprefix$FILE.idx.gz"
    echo "       $word words"
    local size=`zcat "$starprefix$FILE.idx.gz"| wc -c`

    cat << EOF > "$starprefix$FILE.ifo"
StarDict's dict ifo file
version=2.4.2
wordcount=$word
date=$(date "+%Y.%m.%d")
author=$AUTHOR
email=$EMAIL
description=$DESCRIPTION
website=$WEBSITE
idxfilesize=$size
bookname=$starprefix$FILE
sametypesequence=m
EOF
}
###########################################################################

mkdir -p "$TEMP_DIR"
cd "$TEMP_DIR"

while [ "$1" != "" ]; do
FILE="$1"

    if [ ! -e "../$FILE.dict.dz" ];then
        if [ ! -e "/usr/share/dictd/$FILE.dict.dz" ];then
            echo "File /usr/share/dictd/$FILE.dict.dz not found!"
            echo "Did you install dict-$FILE package?"
            exit 1
        else
            cp -L "/usr/share/dictd/$FILE.dict.dz" .
        fi
    else
        cp "../$FILE.dict.dz" .
    fi
    if [ ! -e "../$FILE.index" ];then
        if [ ! -e "/usr/share/dictd/$FILE.index" ];then
            echo "File /usr/share/dictd/$FILE.index not found!"
            echo "Did you install dict-$FILE package?"
            exit 1
        else
            cp -L "/usr/share/dictd/$FILE.index" .
        fi
    else
        cp "../$FILE.index" .
    fi

    echo "Uncompress..."
    dictunzip "$FILE.dict.dz"

    if [ ! -e "$FILE.dict" ];then
        echo "Error uncompressing $FILE.dict.dz!"
        echo "Abort!"
        exit 1
    fi
    AUTHOR=
    EMAIL=
    DESCRIPTION="Converted from a dictd"
    WEBSITE=
    dict_to_stardict "$FILE"
    rm "$FILE.dict" "$FILE.index"

case $INSTALL_STARDICT in
    local)
echo "Install stardict files..."
sudo mkdir -p "/usr/local/share/stardict/dic/$starprefix$FILE-2.4.2"
sudo ln -s "/usr/local/share/stardict/dic/$starprefix$FILE-2.4.2" /usr/share/stardict/dic
for i in dict.dz idx.gz ifo ; do
    sudo mv "$starprefix$FILE.$i" "/usr/local/share/stardict/dic/$starprefix$FILE-2.4.2"
done
    ;;
    deb)
PKG="stardict-dictd-$(echo $FILE|unaccent UTF-8)"
PKG=${PKG//_/-}

VERSION="1.0-1"
ARCH="all"
FULLPKG="${PKG}_${VERSION}_${ARCH}"
DEST="/usr/share/stardict/dic/$starprefix$FILE-2.4.2"
mkdir -p "$FULLPKG$DEST"
mkdir -p "$FULLPKG/DEBIAN"
for i in dict.dz idx.gz ifo ; do
    cp "$starprefix$FILE.$i" "$FULLPKG$DEST"
done

SIZE=$(du -ks "$FULLPKG"|sed 's/[^0-9].*$//')
cd "$FULLPKG"
find . -type f -not -path "DEBIAN"|xargs md5sum|sed 's/  \.\//  /' > DEBIAN/md5sums
cat <<EOF > "DEBIAN/control"
Package: $PKG
Version: $VERSION
Section: text
Priority: extra
Architecture: $ARCH
Depends: stardict
Installed-Size: $SIZE
Maintainer: Anonymous <anonymous@web>
Description: Stardict version of a dictd dictionary
 This package contains a Stardict formatted dictionary
 converted from a dictd dictionary.

EOF
cd -
dpkg-deb -b "$FULLPKG"
if $DELETE_TEMP; then
    rm -rf "$FULLPKG"
    rm -f "$starprefix$FILE.dict.dz" \
        "$starprefix$FILE.idx.gz" \
        "$starprefix$FILE.ifo"
fi
echo "Debian package created and left in $TEMP_DIR"
    ;;
    none)
        echo "Files left in $TEMP_DIR"
    ;;
    *)
        echo "Error: unknown installation method $INSTALL_STARDICT"
        echo "Assuming no install"
    ;;
esac

    shift
done

dict (e.g. Freedict) to Wordtrans

(old scripts)

#!/bin/bash
# Exemple: dict2wt.sh freedict-eng-hun.dict.dz
 
 if [ "$1" == "" ]; then
     echo "Syntax: $0 dict-file.dict.dz"
     exit
 fi
 
 FILE="$1"
 FILEOUT="${FILE%%.dict.dz}.wt.gz"
 
 zcat "$FILE" \
 | gawk '
     /^00-database/      {
                             do getline;
                             while ($0 !~ /^$/);
                             next;
                         }
     /^     /            {
                             gsub(/^     /,"");
                             print word " :: " $0;
                             next;
                         }
     /^$/                {
                             word="!!!";
                             next;
                         }
                         {
                             word=$0;
                         }' \
 | gzip > $FILEOUT

Put the converted dicts in /usr/local/share/wordtrans
For wordtrans: remove spaces in filenames!
For converted dicts: " :: " is the separator & files are UTF-8