use of java.io.DataInputStream in project Cloud9 by lintool.
the class AnchorTextTest method testClone.
@Test
public void testClone() {
AnchorText anchor1 = new AnchorText(AnchorTextConstants.Type.EXTERNAL_OUT_LINK.val, "text", 1);
AnchorText anchor2 = anchor1.clone();
anchor2.setText("some text");
assertTrue(anchor2.equals(anchor1));
anchor2.addDocument(2);
assertNull(anchor2.getText());
assertEquals(anchor2.getSize(), 2);
assertTrue(anchor2.equalsIgnoreSources(anchor1));
AnchorText anchor3 = new AnchorText(AnchorTextConstants.Type.DOCNO_FIELD.val, "text");
anchor3.addDocumentsFrom(anchor2);
anchor3.addDocument(2);
assertNull(anchor3.getText());
assertEquals(anchor3.getSize(), 2);
anchor3.setWeight(1);
assertEquals(anchor3.getWeight(), 0, 1e-100);
assertEquals(anchor3.compareTo(anchor2), 1);
ByteArrayOutputStream bstream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bstream);
try {
anchor3.write(out);
out.close();
} catch (Exception e) {
}
DataInputStream in = new DataInputStream(new ByteArrayInputStream(bstream.toByteArray()));
AnchorText readAnchor = new AnchorText();
try {
readAnchor.readFields(in);
in.close();
} catch (Exception e) {
}
assertEquals(anchor3, readAnchor);
assertTrue(anchor3.intersects(anchor2));
assertTrue(anchor3.containsDocument(2));
anchor3.resetToType(AnchorTextConstants.Type.IN_DEGREE.val);
assertNull(anchor3.getText());
anchor3.resetToType(AnchorTextConstants.Type.INTERNAL_IN_LINK.val);
assertEquals(anchor3.getText(), AnchorTextConstants.EMPTY_STRING);
assertTrue(anchor3.isInternalInLink());
assertEquals(anchor3.getSize(), 0);
assertEquals(anchor3.getWeight(), 0, 1e-100);
assertFalse(anchor3.containsDocument(3));
assertFalse(anchor3.intersects(anchor2));
}
use of java.io.DataInputStream in project Cloud9 by lintool.
the class PhrasePairTest method testWrite.
public void testWrite() {
try {
File temp = File.createTempFile("phrpr", null);
temp.deleteOnExit();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(temp));
pp.write(dos);
pp2.write(dos);
PhrasePair px = new PhrasePair(pp.getF(), pp.getE());
px.write(dos);
System.out.println(pp.toString(vf, ve));
System.out.println(pp2.toString(vf, ve));
System.out.println(px.toString(vf, ve));
dos.close();
System.err.println("Size of PPs on disk: " + dos.size());
DataInputStream dis = new DataInputStream(new FileInputStream(temp));
PhrasePair pl = new PhrasePair();
pl.readFields(dis);
assertEquals(pp.toString(vf, ve), pl.toString(vf, ve));
assertTrue(pl.equals(pp));
} catch (IOException e) {
e.printStackTrace();
fail("Caught " + e);
}
}
use of java.io.DataInputStream in project Cloud9 by lintool.
the class VocabularyWritableTest method testReadFields.
public void testReadFields() {
try {
File temp = File.createTempFile("phrpr", null);
temp.deleteOnExit();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(temp));
v.write(dos);
dos.close();
System.err.println("Size of voc on disk: " + dos.size());
DataInputStream dis = new DataInputStream(new FileInputStream(temp));
VocabularyWritable vw = new VocabularyWritable();
vw.readFields(dis);
assertEquals(v.get(bar), vw.get(bar));
dis.close();
} catch (IOException e) {
e.printStackTrace();
fail("Caught " + e);
}
}
use of java.io.DataInputStream in project Cloud9 by lintool.
the class IndexedFloatArrayTest method testReadFields.
public void testReadFields() {
try {
File temp = File.createTempFile("fat", null);
temp.deleteOnExit();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(temp));
int[] i = { 1, 4, 8, 9, 10 };
IndexedFloatArray fa = new IndexedFloatArray(i);
IndexedFloatArray fa2 = new IndexedFloatArray(10);
fa.set(1, 0.5f);
fa.set(10, 1.0f);
fa.add(8, 0.1f);
fa.add(8, 0.4f);
fa2.set(4, 2.0f);
fa.write(dos);
fa2.write(dos);
dos.close();
DataInputStream dis = new DataInputStream(new FileInputStream(temp));
fa2 = new IndexedFloatArray();
IndexedFloatArray fa3 = new IndexedFloatArray();
fa2.readFields(dis);
fa3.readFields(dis);
assertEquals(0.5f, fa2.get(1));
assertEquals(0.5f, fa2.get(8));
assertEquals(1.0f, fa2.get(10));
System.err.println(fa2);
assertEquals(2.0f, fa3.get(4));
} catch (IOException e) {
fail("Caught " + e);
}
}
use of java.io.DataInputStream in project Cloud9 by lintool.
the class HadoopAlign method loadVocab.
public static Vocab loadVocab(Path path, Configuration job) throws IOException {
org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration(job);
FileSystem fileSys = FileSystem.get(conf);
DataInput in = new DataInputStream(new BufferedInputStream(fileSys.open(path)));
VocabularyWritable at = new VocabularyWritable();
at.readFields(in);
return at;
}
Aggregations