@@ -0,0 +1,2406 @@
+package joshua.phrase.decode;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.FileReader;%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A// complete%0A%0Apublic class Weights %7B%0A  %0A  private List%3CFloat%3E phrase_table_weights;%0A  private float lm_weight;%0A  private float distortion_weight;%0A  private float target_word_insertion_weight;%0A  private Map%3CString, List%3CFloat%3E%3E weights_map;%0A  %0A  public Weights() %7B%0A    phrase_table_weights = new ArrayList%3CFloat%3E();%0A    weights_map = new HashMap%3CString, List%3CFloat%3E%3E();%0A  %7D%0A  %0A  public void ReadFromFile(String file_name) throws Exception %7B%0A    BufferedReader br = null;%0A    try %7B%0A      br = new BufferedReader(new FileReader(file_name));%0A      String line;%0A      while ((line = br.readLine()) != null) %7B%0A        String%5B%5D token = line.split(%22 %22);%0A        String name = token%5B0%5D;%0A        List%3CFloat%3E weights = new ArrayList%3CFloat%3E();%0A        for (int i = 1; i %3C token.length; i++) %7B%0A          float weight = kConverter(token%5Bi%5D);%0A          if (Float.isNaN(weight)) %7B%0A            throw new Exception(%22Bad feature weight: %22 + token%5Bi%5D);%0A          %7D%0A          weights.add(weight);%0A        %7D%0A        if (weights.isEmpty()) %7B%0A          throw new Exception(%22No weights found for weight type %22 + name);%0A        %7D%0A        weights_map.put(name, weights);%0A      %7D%0A      br.close();%0A    %7D finally %7B%0A      if (br != null) br.close();%0A    %7D%0A    %0A    PopulateWeights();%0A  %7D%0A  %0A  private static float kConverter(String s) %7B%0A    if (s.equalsIgnoreCase(%22inf%22)) return Float.POSITIVE_INFINITY;%0A    if (s.equalsIgnoreCase(%22nan%22)) return Float.NaN;%0A    return Float.parseFloat(s);%0A  %7D%0A  %0A  public List%3CFloat%3E PhraseTableWeights() %7B%0A    return phrase_table_weights;%0A  %7D%0A  %0A  public float LMWeight() %7B%0A    return lm_weight;%0A  %7D%0A  %0A  public float DistortionWeight() %7B%0A    return distortion_weight;%0A  %7D%0A  %0A  public float TargetWordInsertionWeight() %7B%0A    return target_word_insertion_weight;%0A  %7D%0A  %0A  private void PopulateWeights() %7B%0A    phrase_table_weights = GetWeights(%22phrase_table%22);%0A    lm_weight = GetSingleWeight(%22lm%22);%0A    distortion_weight = GetSingleWeight(%22distortion%22);%0A    target_word_insertion_weight = GetSingleWeight(%22target_word_insertion%22);%0A  %7D%0A  %0A  public List%3CFloat%3E GetWeights(String name) %7B%0A    return weights_map.get(name);%0A  %7D%0A  %0A  public float GetSingleWeight(String name) %7B%0A    return GetWeights(name).get(0);%0A  %7D%0A%0A%7D%0A

Implement Weights