1 module fact_test;
2 
3 import fact;
4 import std.stdio,
5 	std.string;
6 import core.stdc.stdarg;
7 
8 void print2Darray ( const char*** names ) {
9 	writefln("[");
10 	int n=0;
11 	const (char*)* syns = names[0];
12 	while ( syns != null )
13 	{
14 		printf("[");
15 		int m = 0;
16 		const (char)* name;
17 		while ( (name = syns[m++]) != null)
18 			printf("%s ", name);
19 		writefln("]");
20 		syns=names[++n];
21 	}
22 	writefln("]");
23 }
24 
25 int main ( ) {
26 	puts("Starting FaCT++ C interface tests");
27 	// create kernel
28 	fact_reasoning_kernel* k = fact_reasoning_kernel_new();
29 
30 	// create classes C,D, property R
31 	puts("Creating entities");
32 	fact_concept_expression* c = fact_concept(k,"C");
33 	fact_concept_expression* d = fact_concept(k,"D");
34 	fact_individual_expression* i = fact_individual(k,"I");
35 	fact_o_role_expression* r = fact_object_role(k,"R");
36 
37 	// create C [= ER.T, ER.T [= D
38 	puts("Creating axioms");
39 	fact_concept_expression* some = fact_o_exists ( k, r, fact_top(k));
40 	fact_implies_concepts ( k, c, some );
41 	fact_implies_concepts ( k, some, d );
42 	fact_instance_of ( k, i, c );
43 
44 	// classify KB is not necessary: it's done automatically depending on a query
45 	puts("Classifying ontology");
46 	fact_classify_kb(k);
47 	
48 	
49 	// check whether C [= D
50 	puts("Is C subsumed by D?");
51 	if ( fact_is_subsumed_by(k,c,d) )
52 		puts("Yes!\n");
53 	else
54 		puts("No...\n");
55 
56 	// create a concept actor and use it to get all superclasses of C
57 	puts("All superclasses of C:");
58 	fact_actor* actor = _fact_concept_actor_new();
59 	fact_get_sup_concepts(k,c,0,&actor);
60 	print2Darray(fact_get_elements_2d(actor));
61 	fact_actor_free(actor);
62 
63 	// create an individual actor and use it to get all instances of C
64 	puts("All instances of C:");
65 	fact_actor* i_actor = _fact_individual_actor_new();
66 	fact_get_instances(k, c, &i_actor);
67 	print2Darray(fact_get_elements_2d(i_actor));
68 	fact_actor_free(i_actor);
69 
70 	// get all the properties
71 	puts("All object properties:");
72 	fact_o_role_expression* o_top = fact_object_role_top(k);
73 	actor = _fact_o_role_actor_new();
74 	fact_get_sub_roles(k,cast(fact_role_expression*)o_top,0,&actor);
75 	print2Darray(fact_get_elements_2d(actor));
76 	fact_actor_free(actor);
77 
78 	// we done so let's free memory
79 	puts("Destroying reasoning kernel");
80 	fact_reasoning_kernel_free(k);
81 	puts("All done");
82 	return 0;
83 }