npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

moses

v0.1.3

Published

Moses Statistical Machine Translation (SMT) library for Node.js

Downloads

37

Readme

moses.js

Moses Statistical Machine Translation (SMT) library for Node.js

Moses is a statistical machine translation system written in C++. This module enables usage of Moses in Node.js using the JavaScript language. In addition, it also adds the capability of loading multiple translation systems into the same node process. This means the same process (or web server built with node and express) can hold multiple distinctly different translation models (e.g., Chinese to English in IT and English to French in medicine) at the same time, and be able to use those models to translate user-given sentences or paragraphs on-demand.

Moses Installation

The installation process is a little tricky, because this module depends on Moses, and Moses has a few dependencies. The instructions below originally come from Moses' Moses Installation and Training Run-Through page.

Mac OSX

Supposing $WORK (which may be set to $HOME/translation) is the directory to hold source and build files, and $TRANSLATION (which may be set to /opt/translation) is the directory where executables, libraries and header files are to be stored.

Before proceeding, Xcode must be installed. After installing Xcode, launch it, and install Command Line Tools in Xcode -> Preferences -> Downloads -> Components tab. This will provide the standard build tool for command line usage (with some modifications).

MacPorts

MacPorts is provides additional necessary build tools. After installing MacPorts, install autoconf and automake.

$ sudo /opt/local/bin/port install autoconf automake

Boost

Download latest version of Boost library from boost.org. Suppose the package is $WORK/boost_1_54_0.tar.gz.

$ cd $WORK
$ tar -zxvf boost_1_54_0.tar.gz
$ cd boost_1_54_0
$ ./bootstrap.sh --prefix=$TRANSLATION/boost
$ sudo ./b2 install

GIZA++

Download the latest version of GIZA++. Suppose the package is $WORK/giza-pp-v1.0.7.tar.gz.

$ cd $WORK
$ tar -zxvf giza-pp-v1.0.7.tar.gz
$ cd giza-pp
$ make
$ sudo mkdir -p $TRANSLATION/giza-pp/bin
$ sudo cp GIZA++-v2/{GIZA++,snt2cooc.out} mkcls-v2/mkcls $TRANSLATION/giza-pp/bin

SRILM

Download the latest version of SRILM. Suppose the package is $WORK/srilm.tgz.

$ cd $WORK
$ mkdir srilm
$ tar -zxvf srilm.tgz -C srilm
$ env SRILM=`pwd` make
$ sudo mkdir $TRANSLATION/srilm
$ sudo cp -r {bin,include,lib} $TRANSLATION/srilm
$ cd $TRANSLATION/srilm
$ sudo ln -s lib/macosx lib64

IRSTLM

Download the latest version of IRSTLM. Suppose the package is $WORK/irstlm-5.80.03.tgz.

$ cd $WORK
$ tar -zxvf irstlm-5.80.03.tgz
$ ./regenerate-makefiles.sh
$ ./configure --prefix=$TRANSLATION/irstlm
$ make
$ sudo make install

Moses

Download Moses release 1.0 (with the Download ZIP button). Suppose the package is $WORK/mosesdecoder-RELEASE-1.0.zip.

$ cd $WORK
$ unzip mosesdecoder-RELEASE-1.0.zip
$ cd mosesdecoder-RELEASE-1.0
$ ./bjam --with-srilm=$TRANSLATION/srilm --with-irstlm=$TRANSLATION/irstlm --with-giza=$TRANSLATION/giza-pp --with-boost=$TRANSLATION/boost --prefix=$TRANSLATION/moses -j2 -sLDFLAGS="-liconv -lboost_program_options"
$ sudo ./bjam --with-srilm=$TRANSLATION/srilm --with-irstlm=$TRANSLATION/irstlm --with-giza=$TRANSLATION/giza-pp --with-boost=$TRANSLATION/boost --prefix=$TRANSLATION/moses -j2 -sLDFLAGS="-liconv -lboost_program_options" install

Environment

The following script sets up the environment for running the command-line tools.

#!/bin/sh

where=$TRANSLATION

DYLD_LIBRARY_PATH=
for lib in $where/*/lib; do
  if [ x"$DYLD_LIBRARY_PATH" == x ]; then
    DYLD_LIBRARY_PATH=$lib
  else
    DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$lib
  fi
done
export DYLD_LIBRARY_PATH

for bin in $where/*/bin $where/*/bin/macosx; do
  PATH=$bin:$PATH
done
export PATH

export BOOST=$where/boost
export MOSES=$where/moses
export SRILM=$where/srilm

Put this file in $TRANSLATION/setenv.sh. With this, each time a new command-line console is open, execute the following command to set up.

$ . $TRANSLATION/setenv.sh

Testing Moses

Download Moses' sample models package. Suppose the package is $WORK/sample-models.tgz.

$ cd $WORK
$ tar -zxvf sample-models.tgz
$ cd sample-models
$ . $TRANSLATION/setenv.sh
$ moses -f phrase-model/moses.ini < phrase-model/in

If all is set up correctly, near the end of the output, there should be a line containing text BEST TRANSLATION: this is a small house.

moses.js Installation

Patching Moses

As of release 1.0, Moses supports only one translation system per OS process. After the system is initialized, all subsequent translation must be performed in the same system. Though advanced features such as Using Multiple Translation Systems in the Same Server and Alternate Weight Settings allow users to have multiple translation tables, all those tables must be loaded at the same time, and once loaded, they cannot be changed in the entire life of the process.

A patch shipped with moses.js provides an enhancement that allows users to create and destroy translation systems on demand. This is especially useful for a Node.js server that runs for an extended period of time, and is expected to update its translation system dynamically (e.g., as result of a user request or service update). The patch also enables loading multiple translation systems at the same time, and selecting one of them for use with any given translation task.

To apply the patch, download the latest version from moses.js' github server. Suppose the patch file is saved at $WORK/moses-1.0.patch.

$ cd $WORK/mosesdecoder-RELEASE-1.0
$ patch -p1 < ../moses-1.0.patch
$ sudo ./bjam --with-srilm=$TRANSLATION/srilm --with-irstlm=$TRANSLATION/irstlm --with-giza=$TRANSLATION/giza-pp --with-boost=$TRANSLATION/boost --prefix=$TRANSLATION/moses -j2 -sLDFLAGS="-liconv -lboost_program_options" install

This will rebuild Moses and reinstall it in $TRANSLATION/moses. After this, it is recommended to return to Testing Moses to test moses again. The patch also modifies the main moses program so that it runs in the legacy single-translation-system mode, instead of the enhanced multi-translation-system mode.

Installing moses.js

Install latest release of moses.js from npm.

$ cd $WORK
$ mkdir test-moses-js
$ . $TRANSLATION/setenv.sh
$ npm install moses
$ node node_modules/moses/sample/test-phrase-model.js