Quick links: Examples - Files.
Classes: Hierarchy - Index - List - Members.
Packages: Index - base - jni.

JavaIO.java

Basic input-output operations.This example shows how to use basic input-output operations. Its source code is under the samples/java directory.

import java.util.Collection;
import java.util.Iterator;
public class JavaIO
{
public static void run(String prefix) throws Exception
{
Environment environment = new cogitant.jni.Environment();
// Input operation
environment.loadSupport(prefix + "/xml/bucolic/bucolic_id.cogxml");
Collection<SupportObject> concepttypes = environment.support().conceptTypes();
System.out.println(concepttypes);
Collection<SupportObject> relationtypes = environment.support().relationTypes();
System.out.println(relationtypes);
Collection<SupportObject> nestingtypes = environment.support().nestingTypes();
System.out.println(nestingtypes);
Collection<SupportObject> individuals = environment.support().individuals();
System.out.println(individuals);
Collection<EnvironmentObject> loadedgraphs = environment.loadObjects(prefix + "/bcgct/bucolic/petitsfaits.bcg");
System.out.println("loaded graphs: " + loadedgraphs.toString());
environment.loadObjects(prefix + "/bcgct/bucolic/fact.bcg");
environment.loadObjects(prefix + "/bcgct/bucolic/query.bcg");
// Print loaded graphs.
System.out.println("graphs:");
Collection<Graph> graphs = environment.graphs();
for (Iterator<Graph> i=graphs.iterator(); i.hasNext(); )
{
Graph g = i.next();
System.out.println(g.toString() + ": " + g.nodes().toString());
// Print nodes of the current graph.
Collection<GraphObject> nodes = g.nodes();
for (Iterator<GraphObject> j=nodes.iterator(); j.hasNext(); )
{
GraphObject go = j.next();
System.out.print(" " + go + " " + go.objectType());
if ((go.objectType() == GraphObject.Type.CONCEPT) || (go.objectType() == GraphObject.Type.RELATION) || (go.objectType() == GraphObject.Type.NESTING))
System.out.print("-" + go.type().label() + "(" + go.type().identifier() + ")");
if (go.objectType() == GraphObject.Type.CONCEPT)
if (go.referentType() == GraphObject.ReferentType.INDIVIDUAL)
System.out.print(":" + go.individual().label() + "(" + go.individual().identifier() + ")");
else
System.out.print(":*");
System.out.print(" ");
System.out.println(go.neighbourhood());
}
System.out.println();
}
System.out.println(environment.findGraph("doesnotexist")); // -> null
Environment e2 = environment;
}
public static void main(String args[]) throws Exception
{
String prefix = "..";
if (args.length == 1)
prefix = args[0];
System.out.println("prefix: " + prefix);
run(prefix);
}
}