Sunday, May 27, 2012

How to use bitBucket with EGit in Eclipse

Git is becoming more and more popular these days, and when we really use version control systems like Git or SVN, we actually want to share our codes with other developers. Thus, we do need a Git server to host the codes, like, which is a Git server offering free limited use.

To set up a project in Eclipse, and push the project to bitBucket, you need to do the following steps:
(1) install EGit in Eclipse (;
(2) create an Eclipse project, e.g. HelloWorld; right click the project, and select Team->Share project... to add the project under Git control; right click the project again, and select Team->Add to index to add all the files of the project under version control; right click the project again, and select Team->Commit... to commit all the files;
(3) open an account on, e.g. your account name is myaccount;
(4) configure the SSH in Eclipse:
click your project HelloWorld;
open menu Window->Preference->General->Network Connections->SSH2;
since now you have no SSH keys (bitBucket needs SSH keys for SSH authorization), select Key Management tab and click the button Generate RSA Key... (You can also use DSA keys);
then you can see the public key in the text area, and you need to copy the public key and save it in your account on bitBucket (Account->SSH keys); you also need to click the button Save Private Key... to save the private key to your local directory;
click the General tab, and click the Add Private Key... button to choose the private key that you just saved;
click the OK button to apply all the changes;
(5) on bitBucket, create a repository named HelloWorld, and then you can get the SSH address of the repository as:
(6)right click the project in Eclipse, and select Team->Remote->Push...;
then enter the SSH address and choose SSH as the protocol; Click the Next> button;
(7) click Add all branches spec button only, and then click the Next> button;
(8) click OK

Till now, other developers can clone the project resided on bitBucket, and they can also push changes to the repository.
However, although you can push changes to the remote repository, you cannot pull changes from the repository, since the pull operation is not configured to work with the remote repository.
To solve this problem, you have to add the following lines to the Git configuration file (in your eclipse project folder .git/config):
[remote "origin"]
url = ssh://
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master

Sunday, May 20, 2012

How to add a open file dialog in a Netbeans project

Adding the File Chooser

  1. Choose Window > Navigating > Inspector to open the Inspector window, if it is not open yet.
  2. In the Inspector, right-click the JFrame node. Choose Add From Palette > Swing Windows > File Chooser from the context menu
    GUI Builder Tip: As an alternative to the 'Add From Palette' context menu, you can also drag and drop a JFileChooser component from the Swing Window category of the Palette to the white area of the GUI builder. It will have the same result, but it is a bit harder, because the preview of the JFileChooser is rather big and you might accidentally insert the window into one of the panels, which is not what you want.
  3. A look in the Inspector confirms that a JFileChooser was added to the form.
  4. Right-click the JFileChooser node and rename the variable to fileChooser.
  5. File Chooser added - Inspector View
You have added a File Chooser. Next you tune the File Chooser to display the title that you want, add a custom file filter, and integrate the File Chooser into your application.

Configuring the File Chooser

Implementing the Open Action

  1. Click to select the JFileChooser in the Inspector window, and then edit its properties in the Properties dialog box. Change the 'dialogTitle' property to This is my open dialog, press Enter and close the Properties dialog box.
  2. Click the Source button in the GUI Builder to switch to the Source mode. To integrate the File Chooser into your application, paste the following code snippet into the existing OpenActionPerformed() method.
    private void OpenActionPerformed(java.awt.event.ActionEvent evt) {
        int returnVal = fileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fileChooser.getSelectedFile();
            try {
              // What to do with the file, e.g. display it in a TextArea
     new FileReader( file.getAbsolutePath() ), null );
            } catch (IOException ex) {
              System.out.println("problem accessing file"+file.getAbsolutePath());
        } else {
            System.out.println("File access cancelled by user.");
  3. Note: Remove the first and last lines of the code snippet that duplicate the existing ones in the source file.
  4. If the editor reports errors in your code, right-click anywhere in the code and select Fix Imports or press Ctrl+Shift+I. In the Fix All Imports dialog box accept the defaults to update the import statements and click OK.
As you can see, you call the FileChooser's getSelectedFile() method to determine which file the user clicked, so you can work with it. This example reads the file contents and displays them in the TextArea.

Implementing a File Filter

Now you add a custom file filter that makes the File Chooser display only *.txt files.
  1. Switch to the Design mode and select the FileChooser in the Inspector window.
  2. In the Properties window, click the elipsis ("...") button next to the File Filter property.
  3. In the File Filter dialog box, select Custom Code from the combobox.
    A screenshot of the combobox open
  4. Type new MyCustomFilter() in the text field. Click OK.
  5. To make the custom code work, you write an inner (or outer) class MyCustomFilter that extends the FileFilter class. Copy and paste the following code snippet into the source of your class below the import statements to create an inner class implementing the filter.
        class MyCustomFilter extends javax.swing.filechooser.FileFilter {
            public boolean accept(File file) {
                // Allow only directories, or files with ".txt" extension
                return file.isDirectory() || file.getAbsolutePath().endsWith(".txt");
            public String getDescription() {
                // This description will be displayed in the dialog,
                // hard-coded = ugly, should be done via I18N
                return "Text documents (*.txt)";
    Forwarded from: 

Tuesday, May 8, 2012

sentence-level alignment tools for statistical machine translation

Recently, I have found the following sentence-level alignment tools for statistical machine translation (SMT). These tools can pair sentences which have the same meaning but in different languages from parallel documents. This is also the first step of building an SMT system.

(1) CTK: Champollion Tool Kit
Note: this tool (from LDC) uses translation lexicons to align sentences, and one disadvantage is that when the two documents are very different in the number of sentences, this tool can not work well.
CTK v1.2 supports three language pairs:
    English Chinese(GB)
    English Chinese(UTF8)
    English Arabic (UTF8)
    English Hindi (UTF8)

(2) Gale-Church Aligner
This is a very old sentence-level alignment algorithm, and fortunately Chris Crowner has implemented it in the NLTK.
Note that the python code is in the nltk_contrib, not in the main release of NLTK.

(3) MTTK: Machine Translation Toolkit
Note: this tool is supposed to have the ability to do sentence-level alignment, but I still can not figure out how to do it using the tool.

(4) Align
Note: this tool was developed by Adam Berger, and can be downloaded from:
It supports sentence-level alignment using some anchor labels.

(5) Bleualign
This tool requires automatic translations of one side of the unaligned corpus and then uses a modified BLEU evaluation to find the sentence-level alignments. Of course, you need a seed SMT system to generate the automatic translations. The tool is written in Python.
I found a problem when using this aligner which could use the same sentence on the target side multiple times in the output alignments.

(6) Microsoft Bilingual Sentence Aligner
This is a sentence aligner written in Perl. It uses sentence length.