import java.io.FileInputStream;
import java.util.Collection;
class SampleObserver
implements cogitant.base.Observer
{
public void messageAttached()
{
System.out.println("Attached");
}
public void messageDetached()
{
System.out.println("Detached");
}
public void message(ObserverMessage msg)
{
try
{
System.out.println("Message: " + msg.toString());
if (msg instanceof ObserverMessageGraphRuleApplication)
{
ObserverMessageGraphRuleApplication m = (ObserverMessageGraphRuleApplication) msg;
System.out.print("Hypothesis: ");
Collection<GraphObject> nodes = m.rule().hypothesis().nodes();
for (GraphObject go:nodes)
System.out.print(go + ":" + go.label() + " ");
System.out.println();
System.out.print("Conclusion: ");
nodes = m.rule().conclusion().nodes();
for (GraphObject go:nodes)
System.out.print(go + ":" + go.label() + " ");
System.out.println();
}
}
catch (Exception e)
{
System.out.println(e);
}
}
public boolean wantsMessage(ObserverMessage.Type mt)
{
return true;
}
}
public class JavaObserver
{
public static void run(String prefix) throws Exception
{
environment.
loadSupport(prefix +
"/bcgct/sisyphus/sisyphus.bcs");
Collection<EnvironmentObject> loadedgraphs = environment.loadObjects(prefix + "/bcgct/sisyphus/locals.bcg");
Graph g = loadedgraphs.iterator().next().asGraph();
environment.loadObjects(prefix + "/bcgct/sisyphus/near_1.bcr");
environment.loadObjects(prefix + "/bcgct/sisyphus/near_2.bcr");
environment.loadObjects(prefix + "/bcgct/sisyphus/near_3.bcr");
System.out.println("locals.bcg");
SampleObserver so = new SampleObserver();
g.attachObserver(so);
environment.rulesClosureNormalize(g, null, 0, 0);
g.detachObserver(so);
System.out.println("locals_same_individual.bcg");
loadedgraphs = environment.loadObjects(prefix + "/bcgct/sisyphus/locals_same_individual.bcg");
Graph g2 = loadedgraphs.iterator().next().asGraph();
g2.attachObserver(so);
environment.rulesClosureNormalize(g2, null, 0, 0);
g2.detachObserver(so);
System.out.println("locals_veryredundant.bcg");
loadedgraphs = environment.loadObjects(prefix + "/bcgct/sisyphus/locals_veryredundant.bcg");
Graph g3 = loadedgraphs.iterator().next().asGraph();
g3.attachObserver(so);
environment.graphIrredundant(g3);
g3.detachObserver(so);
}
public static void main(String args[]) throws Exception
{
String prefix = "..";
if (args.length == 1)
prefix = args[0];
System.out.println("prefix: " + prefix);
run(prefix);
}
}