Cambridge SMT System
TargetFeatureList.java
Go to the documentation of this file.
1 /*******************************************************************************
2  * Licensed under the Apache License, Version 2.0 (the "License");
3  * you may not use these files except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  *
14  * Copyright 2014 - Juan Pino, Aurelien Waite, William Byrne
15  *******************************************************************************/
16 package uk.ac.cam.eng.extraction.hadoop.datatypes;
17 
18 import java.io.DataInput;
19 import java.io.DataOutput;
20 import java.io.IOException;
21 import java.util.ArrayList;
22 
23 import org.apache.hadoop.io.Writable;
24 import org.apache.hadoop.io.WritableUtils;
25 
26 import uk.ac.cam.eng.extraction.RuleString;
27 import uk.ac.cam.eng.util.Pair;
28 
38 public class TargetFeatureList extends
39  ArrayList<Pair<RuleString, RuleData>> implements Writable {
40 
41  private static final long serialVersionUID = 1L;
42 
43  @Override
44  public void write(DataOutput out) throws IOException {
45  WritableUtils.writeVInt(out, size());
46  for (Pair<RuleString, RuleData> entry : this) {
47  entry.getFirst().write(out);
48  entry.getSecond().write(out);
49  }
50  }
51 
52  @Override
53  public void readFields(DataInput in) throws IOException {
54  clear();
55  int size = WritableUtils.readVInt(in);
56  for (int i = 0; i < size; ++i) {
57  RuleString target = new RuleString();
58  target.readFields(in);
59  RuleData alignmentAndFeatures = new RuleData();
60  alignmentAndFeatures.readFields(in);
61  add(Pair.createPair(target, alignmentAndFeatures));
62  }
63  }
64 
65 }
static< F, S > Pair< F, S > createPair(F first, S second)
Definition: Pair.java:46