public Event read() throws IOException { Event event = samples.read(); if (event != null) { writer.write(event.toString()); writer.write("\n"); } return event; }
@Override public Event read() throws IOException { Event event = super.read(); if (event != null) { digest.update(event.toString().getBytes(StandardCharsets.UTF_8)); } return event; }
@Test public void testSimpleReading() throws IOException { try (FileEventStream feStream = new FileEventStream(new StringReader(EVENTS))) { Assert.assertEquals("other [wc=ic=1 w&c=he,ic=2 n1wc=lc=3 n1w&c=belongs,lc=4 n2wc=lc=5]", feStream.read().toString()); Assert.assertEquals("other [wc=lc=1 w&c=belongs,lc=2 p1wc=ic=3 p1w&c=he,ic=4 n1wc=lc=5]", feStream.read().toString()); Assert.assertEquals("other [wc=lc=1 w&c=to,lc=2 p1wc=lc=3 p1w&c=belongs,lc=4 p2wc=ic=5]", feStream.read().toString()); Assert.assertEquals("org-start [wc=ic=1 w&c=apache,ic=2 p1wc=lc=3 p1w&c=to,lc=4]", feStream.read().toString()); Assert.assertEquals("org-cont [wc=ic=1 w&c=software,ic=2 p1wc=ic=3 p1w&c=apache,ic=4]", feStream.read().toString()); Assert.assertEquals("org-cont [wc=ic=1 w&c=foundation,ic=2 p1wc=ic=3 p1w&c=software,ic=4]", feStream.read().toString()); Assert.assertEquals("other [wc=other=1 w&c=.,other=2 p1wc=ic=3]", feStream.read().toString()); Assert.assertNull(feStream.read()); } }
@Test public void testSimpleReading() throws IOException { try (FileEventStream feStream = new FileEventStream(new StringReader(EVENTS))) { Assert.assertEquals("other [wc=ic w&c=he,ic n1wc=lc n1w&c=belongs,lc n2wc=lc]", feStream.read().toString()); Assert.assertEquals("other [wc=lc w&c=belongs,lc p1wc=ic p1w&c=he,ic n1wc=lc]", feStream.read().toString()); Assert.assertEquals("other [wc=lc w&c=to,lc p1wc=lc p1w&c=belongs,lc p2wc=ic]", feStream.read().toString()); Assert.assertEquals("org-start [wc=ic w&c=apache,ic p1wc=lc p1w&c=to,lc]", feStream.read().toString()); Assert.assertEquals("org-cont [wc=ic w&c=software,ic p1wc=ic p1w&c=apache,ic]", feStream.read().toString()); Assert.assertEquals("org-cont [wc=ic w&c=foundation,ic p1wc=ic p1w&c=software,ic]", feStream.read().toString()); Assert.assertEquals("other [wc=other w&c=.,other p1wc=ic]", feStream.read().toString()); Assert.assertNull(feStream.read()); } }
@Test public void testWithValues() { Event event = new Event("o1", new String[]{"aa", "bb", "cc"}); Assert.assertEquals("o1", event.getOutcome()); Assert.assertArrayEquals(new String[]{"aa", "bb", "cc"}, event.getContext()); Assert.assertNull(event.getValues()); Assert.assertEquals("o1 [aa bb cc]", event.toString()); }
@Test public void testWithoutValues() { Event event = new Event("o1", new String[]{"aa", "bb", "cc"}, new float[]{0.2F, 0.4F, 0.4F}); Assert.assertEquals("o1", event.getOutcome()); Assert.assertArrayEquals(new String[]{"aa", "bb", "cc"}, event.getContext()); Assert.assertArrayEquals(new float[]{0.2F, 0.4F, 0.4F}, event.getValues(), 0.001F); Assert.assertEquals("o1 [aa=0.2 bb=0.4 cc=0.4]", event.toString()); } }
@Override public Event read() throws IOException { Event event = super.read(); if (event != null) { digest.update(event.toString().getBytes(StandardCharsets.UTF_8)); } return event; }
public Event read() throws IOException { Event event = samples.read(); if (event != null) { writer.write(event.toString()); writer.write("\n"); } return event; }
public Event read() throws IOException { Event event = samples.read(); if (event != null) { writer.write(event.toString()); writer.write("\n"); } return event; }
@Override public Event read() throws IOException { Event event = super.read(); if (event != null) { digest.update(event.toString().getBytes(StandardCharsets.UTF_8)); } return event; }
public void trainModel() throws IOException { if (debugOn) { FileWriter writer = new FileWriter(modelName + ".events"); for (Iterator<Event> ei = events.iterator();ei.hasNext();) { Event e = ei.next(); writer.write(e.toString() + "\n"); } writer.close(); } new SuffixSensitiveGISModelWriter( // GIS.trainModel((EventStream)new CollectionEventStream(events), true)).persist(); (AbstractModel) GIS.trainModel(ObjectStreamUtils.createObjectStream(events), true), new File(modelName + modelExtension)).persist(); }
public void train() throws IOException { if (ResolverMode.TRAIN == mode) { System.err.println(this + " referential"); if (debugOn) { FileWriter writer = new FileWriter(modelName + ".events"); for (Iterator<Event> ei = events.iterator(); ei.hasNext();) { Event e = ei.next(); writer.write(e.toString() + "\n"); } writer.close(); } new SuffixSensitiveGISModelWriter(GIS.trainModel( ObjectStreamUtils.createObjectStream(events),100,10), new File(modelName + modelExtension)).persist(); } } }
/** * Train a model based on the previously supplied evidence. * @see #setExtents(Context[]) */ public void trainModel() throws IOException { if (debugOn) { FileWriter writer = new FileWriter(modelName + ".events"); for (Iterator<Event> ei = events.iterator();ei.hasNext();) { Event e = ei.next(); writer.write(e.toString() + "\n"); } writer.close(); } new SuffixSensitiveGISModelWriter(GIS.trainModel( ObjectStreamUtils.createObjectStream(events),100,10), new File(modelName + modelExtension)).persist(); }
@Override public void train() throws IOException { if (ResolverMode.TRAIN == mode) { if (debugOn) { System.err.println(this + " referential"); FileWriter writer = new FileWriter(modelName + ".events"); for (Iterator<Event> ei = events.iterator(); ei.hasNext();) { Event e = ei.next(); writer.write(e.toString() + "\n"); } writer.close(); } (new SuffixSensitiveGISModelWriter(GIS.trainModel(ObjectStreamUtils.createObjectStream(events), 100,10),new File(modelName + modelExtension))).persist(); nonReferentialResolver.train(); } }