1 module facttests;
2 
3 import fact;
4 
5 unittest {
6 /*
7 
8 https://bitbucket.org/wrobell/factplusplus/src/05a702533ef4e13a2466cd1df7379b18a37f9177/factpp/examples/test.py?at=factpp&fileviewer=file-view-default
9 
10 k = lib.fact_reasoning_kernel_new()
11 
12 c = lib.fact_concept(k, b'C');
13 d = lib.fact_concept(k, b'D');
14 r = lib.fact_object_role(k, b'R');
15 
16 top = lib.fact_top(k)
17 some = lib.fact_o_exists(k, r, top);
18 lib.fact_implies_concepts(k, c, some);
19 lib.fact_implies_concepts(k, some, d);
20 
21 if lib.fact_is_subsumed_by(k, c, d):
22     print('yes!\n')
23 else:
24 */
25   fact_reasoning_kernel* k = fact_reasoning_kernel_new();
26   fact_concept_expression* c = fact_concept(k,"C");
27   fact_concept_expression* d = fact_concept(k,"D");
28   fact_o_role_expression* r = fact_object_role(k,"R");
29   auto top = fact_top(k);
30   auto some = fact_o_exists(k,r,top);
31   fact_implies_concepts(k,c,some);
32   fact_implies_concepts(k,some,d);
33   assert(fact_is_subsumed_by(k,c,d));
34 }
35 
36 unittest {
37 /*
38 
39 
40 https://bitbucket.org/wrobell/factplusplus/src/05a702533ef4e13a2466cd1df7379b18a37f9177/factpp/examples/test-object-cardinality.py
41 
42 
43 reasoner = factpp.Reasoner()
44 
45 
46 cls_a = reasoner.concept('CLS-A')
47 cls_b = reasoner.concept('CLS-B')
48 reasoner.disjoint_concepts([cls_a, cls_b])
49 
50 
51 r = reasoner.object_role('R')
52 reasoner.set_o_domain(r, cls_a)
53 reasoner.set_o_range(r, cls_b)
54 
55 
56 c = reasoner.individual('C')
57 reasoner.instance_of(c, cls_a)
58 
59 
60 restriction_max_one_cls_b = reasoner.max_o_cardinality(1, r, cls_b)
61 reasoner.implies_concepts(cls_a, restriction_max_one_cls_b)
62 
63 
64 d = reasoner.individual('D')
65 reasoner.instance_of(d, cls_b)
66 reasoner.related_to(c, r, d)
67 print('consistent after 1st instance:', reasoner.is_consistent())
68 
69 
70 # add another individual to class C, making ontology inconsistent
71 x = reasoner.individual('X')
72 reasoner.instance_of(x, cls_b)
73 reasoner.related_to(c, r, x)
74 reasoner.different_individuals([d, x])
75 print('consistent after 2nd instance:', reasoner.is_consistent())
76 
77 # add another individual to class C, making ontology inconsistent
78 x = reasoner.individual('X')
79 reasoner.instance_of(x, cls_b)
80 reasoner.related_to(c, r, x)
81 reasoner.different_individuals([d, x])
82 print('consistent after 2nd instance:', reasoner.is_consistent())
83 
84 */
85   fact_reasoning_kernel* k = fact_reasoning_kernel_new();
86   fact_concept_expression* cls_a = k.fact_concept("CLS-A");
87   fact_concept_expression* cls_b = k.fact_concept("CLS-B");
88   k.fact_new_arg_list();
89   k.fact_add_arg(cls_a);
90   k.fact_add_arg(cls_b);
91   k.fact_disjoint_concepts();
92 
93   fact_o_role_expression* r = k.fact_object_role("R");
94   k.fact_set_o_domain(r,cls_a);
95   k.fact_set_o_range(r,cls_b);
96   
97   auto c = k.fact_individual("C");
98   k.fact_instance_of(c, cls_a);
99   
100   auto restriction_max_one_cls_b = k.fact_o_max_cardinality(1, r, cls_b);
101   k.fact_implies_concepts(cls_a, restriction_max_one_cls_b);
102   
103   auto d = k.fact_individual("D");
104   k.fact_instance_of(d, cls_b);
105   k.fact_related_to(c,r,d);
106   assert(k.fact_is_kb_consistent());
107   
108   auto x = k.fact_individual("X");
109   k.fact_instance_of(x,cls_b);
110   k.fact_related_to(c,r,x);
111   
112   k.fact_new_arg_list();
113   k.fact_add_arg(d);
114   k.fact_add_arg(x);
115   k.fact_process_different();
116   assert(!k.fact_is_kb_consistent());
117 }
118 
119 unittest {
120   // Test property
121   // https://bitbucket.org/wrobell/factplusplus/src/05a702533ef4e13a2466cd1df7379b18a37f9177/factpp/examples/test-property.py
122   fact_reasoning_kernel* k = fact_reasoning_kernel_new();
123   fact_concept_expression* c = fact_concept(k,"C");
124   fact_concept_expression* d = fact_concept(k,"D");
125   fact_concept_expression* e = fact_concept(k,"E");
126   fact_o_role_expression* r = fact_object_role(k,"R");
127   fact_set_symmetric(k,r);
128   fact_set_transitive(k,r);
129   fact_related_to(k,c,r,d);
130   fact_related_to(k,d,r,e);
131   //fact_individual_set* res;
132   //fact_get_role_fillers(k,d,r,&res);
133   //assert(0);
134 }
135 
136 unittest {
137   // Test disjoint concepts
138   fact_reasoning_kernel* k = fact_reasoning_kernel_new();
139   fact_concept_expression* a = fact_concept(k,"A");
140   fact_concept_expression* b = fact_concept(k,"B");
141   fact_concept_expression* c = fact_concept(k,"C");
142   //assert(0);
143 }