Quick links: Tutorial - Examples - Files - Symbols.
Classes: Hierarchy - Index - List - Members.
Namespaces: Index - base - cs - display.

minimal.cpp

Un exemple minimal (ou presque).Cet exemple illustre le chargement de support et graphes (au format BCGCT) ainsi que la recherche de projections. Le code source de ce programme, accompagné de makefiles se trouve dans "samples/minimal".

// ==============
// CoGITaNT 5
// ==============
// This program is a small program using Cogitant at its minimum.
// This program creates an environment and loads a support and two
// (nested typed) graphs. The two graphs are displayed and the
// projections on one another are calculated and displayed.
#include <iostream>
// All header files are available in the "cogitant" directory
// present in the search paths of the compiler.
// "cogitant.h" allows access to all Cogitant classes without having
// to include the different .h files corresponding to the different classes.
using namespace std;
static void ret()
{
cout << "Press Return" << endl;
cin.get();
}
int main(int, char* [])
{
// ----------------------------------------------------------------------
// Creating the environment
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Loading files in the BCGCT format.
// ----------------------------------------------------------------------
// The analysis of the syntax of theses files is protected by a "try" block.
// In this way, if an analysis error occurs, it will be handled by the
// "catch" block.
try
{
// Loading the support
env.readSupport("bucolic/bucolic.bcs");
// Loading two graphs
// Here, each file contains one graph per file.
// The identifier of the first graph read, is returned by readGraphs.
g1 = env.readGraphs("bucolic/sleepandfish.bcg");
g2 = env.readGraphs("bucolic/sapquery.bcg");
}
{
// An error has occurred while loading one of the files.
// Details on the error can be found via the error code.
// Here, the exception is simply displayed while exiting.
cerr << e;
exit(1);
}
// ----------------------------------------------------------------------
// Displaying graphs
// ----------------------------------------------------------------------
// Graphs can be displayed under different formats: Internal format (in
// which appear the identifiers of each vertex), BCGCT (native format of Cogitant),
// CoGXML, CGIF or Linear form (which is the simplest to read in the case of
// small graphs).
cout << "Fact graph (linear form)" << endl;
env.writeGraph(cout, g1);
ret();
cout << "Query graph (internal form)" << endl;
cout << *(env.graphs(g2)) << endl ;
ret();
// ----------------------------------------------------------------------
// Projection
// ----------------------------------------------------------------------
// Calculation of g2 in g1 projections
env.projections(g2, g1, proj);
// Displaying the result of projection calculations
cout << "There is/are " << proj.size() << " projection(s) of the query graph in the fact graph." << endl;
ret();
// Looping through projections and displaying results
for (cogitant::iSet i=proj.projections()->iBegin();
i!=proj.projections()->iEnd(); proj.projections()->iNext(i))
{
cout << "Projection #" << (i+1) << endl;
cout << *(proj.projections(i)) << endl;
ret();
}
// ----------------------------------------------------------------------
// Destroying objects
// ----------------------------------------------------------------------
// It is not necessary to delete graphs because they will be deleted at
// the same time as the environment. The deletion of the environment is automatic.
cout << "End of the sample program" << endl;
return 0;
}