use of edu.rice.cs.caper.floodgage.application.floodgage.draft_building.DraftBuilder in project bayou by capergroup.
the class FloodGage method makeTrials.
/*
* Convert the trials specified in the given Directive to a list of Trials. Use a DraftBuilder returned by
* makeDraftBuilder (one per trial) to rewrite the draft program from the format used inside a trialpack
* to the format the synthesis system expects as input.
*/
private List<Trial> makeTrials(Directive directive, Function<String, DraftBuilder> makeDraftBuilder) throws IOException {
// to be returned
List<Trial> trialsAccum = new LinkedList<>();
// build one Trial for every trial specified by the user as found in the directive
for (edu.rice.cs.caper.floodgage.application.floodgage.model.directive.Trial trial : directive.getTrials()) {
/*
* Retrieve the description of the trial, if any.
*/
// from <description> in trails.xml (if present)
String description = trial.getDescription();
// if description not specified, use empty string
description = description == null ? "" : description;
/*
* Build the draft program source as it should be sent to the synthesizer. This is a two step process:
*
* 1.) Retrieve the "proto" draft program source from the trialpack that uses the "/// #" hole notation.
* An example might looks like:
*
* import java.util.function.*;
*
* public class ReadFileLinesDraft implements Consumer<String>
* {
* public void accept(String filePath)
* {
* /// 1
* }
* }
*
* 2.) Replace each hole in the "/// #" notation with the hole format that the synthesis system expects
* as guided by the hole definition in trials.xml. The returned DraftBuilder from the given
* makeDraftBuilder parameter should know how to do this conversion for us.
*
* For example, with Bayou 1.1.0 that would be (with the trials.xml above)
*
* import java.util.function.*;
*
* public class ReadFileLinesDraft implements Consumer<String>
* {
* public void accept(String filePath)
* {
* { call:readLine type:FileReader }
* }
* }
*
*/
String draftProgramSource;
{
// We expect the trialpack jar file to be on the classpath. That jar file should have all draft
// programs in its root directory. So look for it at a path that is just the contents of the xml entry.
// / using the "// #" notation
String protoDraftProgramSrc = new String(getResource(trial.getDraftProgramPath()), StandardCharsets.UTF_8);
DraftBuilder draftBuilder = makeDraftBuilder.apply(protoDraftProgramSrc);
for (Hole hole : trial.getHoles()) {
// convert evidences from the directive structure to the trial structure
List<Evidence> evidence = hole.getEvidence().stream().map(this::makeEvidence).collect(Collectors.toList());
draftBuilder.setHole(hole.getId(), evidence);
}
draftProgramSource = draftBuilder.buildDraft();
}
/*
* Retrieve other elements from user defined trial.
*/
// FileReaderDraft in example above
String assumeDraftProgramClassName = getFilenameWithoutExtension(trial.getDraftProgramPath());
// look for optional sketch entry. null if not present.
String sketchProgramPath = trial.getSketchProgramPath();
/*
* Create Trial instance and append to trialsAccum.
*/
Trial trialToAppend;
{
if (// has a sketch specified
sketchProgramPath != null) {
String sketchProgramSource = new String(getResource(trial.getSketchProgramPath()), StandardCharsets.UTF_8);
trialToAppend = TrialWithSketch.make(description, draftProgramSource, assumeDraftProgramClassName, sketchProgramSource);
} else // does not have a sketch specified
{
trialToAppend = TrialWithoutSketch.make(description, draftProgramSource, assumeDraftProgramClassName);
}
}
trialsAccum.add(trialToAppend);
}
return trialsAccum;
}
Aggregations