// (C) Copyright 2008-2009 SDML (www.sdml.info) // // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include // Clean up the include stuff a little better. It might be worthwhile, for // example to include a single context type and have that construct all of // the code required for its correct operation. #include #include #include #include #include #include using namespace std; using namespace boost; using namespace boost::fca; using namespace boost::graph; // A sample data set from the FCA web page. template void simple_data(Context& cxt, Relation& rel) { string objs[] = {"girl", "boy", "woman", "man", /* "shemale" */ }; const size_t nobjs = sizeof(objs) / sizeof(string); string atts[] = { "juvenile", "adult", "female", "male" }; const size_t natts = sizeof(atts) / sizeof(string); pair rels[] = { make_pair("boy", "juvenile"), make_pair("boy", "male"), make_pair("girl", "juvenile"), make_pair("girl", "female"), make_pair("man", "adult"), make_pair("man", "male"), make_pair("woman", "adult"), make_pair("woman", "female") }; const size_t nrels = sizeof(rels) / sizeof(pair); cxt = Context(objs, objs + nobjs, atts, atts + natts); rel = Relation(cxt, rels, rels + nrels); } // A sample data set from wikipedia. template void number_data(Context& cxt, Relation& rel) { string objs[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }; const size_t nobjs = sizeof(objs) / sizeof(string); string atts[] = { "c", "p", "e", "o", "s" }; const size_t natts = sizeof(atts) / sizeof(string); pair rels[] = { make_pair("1", "o"), make_pair("1", "s"), make_pair("2", "p"), make_pair("2", "e"), make_pair("3", "p"), make_pair("3", "o"), make_pair("4", "c"), make_pair("4", "e"), make_pair("4", "s"), make_pair("5", "p"), make_pair("5", "o"), make_pair("6", "c"), make_pair("6", "e"), make_pair("7", "p"), make_pair("7", "o"), make_pair("8", "c"), make_pair("8", "e"), make_pair("9", "c"), make_pair("9", "o"), make_pair("9", "s"), make_pair("10", "c"), make_pair("10", "e"), }; const size_t nrels = sizeof(rels) / sizeof(pair); cxt = Context(objs, objs + nobjs, atts, atts + natts); rel = Relation(cxt, rels, rels + nrels); } template void run() { typedef relation Relation; typedef lattice Lattice; // Declare the context and relation. Context cxt; Relation rel(cxt); // Fill the context and relation from a redirected input file. read_concepts(cin, cxt, rel); // Construct a lattice over the relation by recursively building it in // a top-down fashion. Lattice lat(rel, true); // Write out the lattice as a graphviz file. write_graphviz(cout, lat); } int main(int argc, char *argv[]) { bool bits = false; if(argc >= 2) { if(string(argv[1]) == "bitset") { bits = true; } } if(bits) { run< bitset_context >(); } else { run< set_context >(); } return 0; }