Why KeyGen is Needed?

When we do caching, key/value pair is a common way to identify unique value. Therefore, a key is needed for each translate text when cache comes into play. To let user do the caching flexibly, an interface IKeyGen is introduced.

 

public interface IKeyGen 
   { 
       String getKey(String input); 
   }

 

By this, users can generate the key to meet their need.

notice: [String input] is combination of translating text, its from language code & to language code

Why Port to Java?

Since Android is popular and wide-used mobile framework, we decided porting this kit to Java for developing on Android later on. Also, the kit has been refined during the porting development.

 

How to Read From a Text File?

here is a simple example to demonstrate how to read input from a txt file

input:

Chile is preparing to celebrate the rescue of 33 workers who spent the last 68 days trapped in an underground mining site, in what is expected to test the South America nation's capability.

Wives, children, parents and friends are waiting on an arid, rocky hillside around 625-metre directly
above them at a tent settlement dubbed "Camp Hope." An entire nation, still recovering from a devastating February earthquake, is ready to celebrate.

Engineers have completed reinforcing the top of the rescue shaft for the 33 trapped miners.

The work on installing 15 steel tubes was completed on Monday to secure the top 295ft of the shaft.

"The next step is to build a platform above the shaft to support the rescue capsule," the navy commander in charge of part of the rescue operation, Renato Navarro, said.

Andres Sougarett, the engineer leading the rescue efforts, said his team had successfully tested a rescue capsule almost all the way down to where the miners are trapped and brought it back to the surface.

Laurence Golborne, the Chilean mines minister, said that all is set for the start of the rescue operation of the men around Tuesday midnight (0300 GMT Wednesday), after their over two-month-long ordeal.

output:

code:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using CtpGglTranslate.Ggl;

namespace CtpSample
{
    public partial class FileRead : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            String filePath = Server.MapPath("/data/p.txt");
            //read from file 
            try
            {
                if (!String.IsNullOrEmpty(filePath))
                {
                    using (StreamReader sr = new StreamReader(filePath))
                    {
                        sb.Append(sr.ReadToEnd());
                    }
                }
            }
            catch(Exception excep){
                //handling exception
                String errorMessage = "Something went wrong with reading file, exception:";
                errorMessage += excep.Message;
            }
            //translate
            String input = sb.ToString();
            Translator gt = new Translator();
            Translator.TranslatedPost post = gt.GetTranslatedPost(input, LanguageConst.ENGLISH, LanguageConst.CHINESE);
            //write output
            Response.Write(post.text);
        }
    }
}

 

download:

Last edited Oct 13, 2010 at 1:15 AM by jebberwocky, version 10

Comments

No comments yet.