| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2011-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include "fact.h" |
| 22 | |
| 23 | void print2Darray ( const char*** names ) |
| 24 | { |
| 25 | printf("[\n"); |
| 26 | int n=0; |
| 27 | const char** syns = names[0]; |
| 28 | while ( syns != NULL ) |
| 29 | { |
| 30 | printf("["); |
| 31 | int m = 0; |
| 32 | const char* name; |
| 33 | while ( (name = syns[m++]) != NULL ) |
| 34 | printf("%s ", name); |
| 35 | printf("]\n"); |
| 36 | syns=names[++n]; |
| 37 | } |
| 38 | printf("]\n"); |
| 39 | } |
| 40 | |
| 41 | int main ( void ) |
| 42 | { |
| 43 | puts("Starting FaCT++ C interface tests"); |
| 44 | // create kernel |
| 45 | fact_reasoning_kernel* k = fact_reasoning_kernel_new(); |
| 46 | |
| 47 | // create classes C,D, property R |
| 48 | puts("Creating entities"); |
| 49 | fact_concept_expression* c = fact_concept(k,"C"); |
| 50 | fact_concept_expression* d = fact_concept(k,"D"); |
| 51 | fact_individual_expression* i = fact_individual(k,"I"); |
| 52 | fact_o_role_expression* r = fact_object_role(k,"R"); |
| 53 | |
| 54 | // create C [= ER.T, ER.T [= D |
| 55 | puts("Creating axioms"); |
| 56 | fact_concept_expression* some = fact_o_exists ( k, r, fact_top(k)); |
| 57 | fact_implies_concepts ( k, c, some ); |
| 58 | fact_implies_concepts ( k, some, d ); |
| 59 | fact_instance_of ( k, i, c ); |
| 60 | |
| 61 | // classify KB is not necessary: it's done automatically depending on a query |
| 62 | puts("Classifying ontology"); |
| 63 | fact_classify_kb(k); |
| 64 | |
| 65 | // check whether C [= D |
| 66 | puts("Is C subsumed by D?"); |
| 67 | if ( fact_is_subsumed_by(k,c,d) ) |
| 68 | puts("Yes!\n"); |
| 69 | else |
| 70 | puts("No...\n"); |
| 71 | |
| 72 | // create a concept actor and use it to get all superclasses of C |
| 73 | puts("All superclasses of C:"); |
| 74 | fact_actor* actor = fact_concept_actor_new(); |
| 75 | fact_get_sup_concepts(k,c,0,&actor); |
| 76 | print2Darray(fact_get_elements_2d(actor)); |
| 77 | fact_actor_free(actor); |
| 78 | |
| 79 | // create an individual actor and use it to get all instances of C |
| 80 | puts("All instances of C:"); |
| 81 | fact_actor* i_actor = fact_individual_actor_new(); |
| 82 | fact_get_instances(k, c, &i_actor); |
| 83 | print2Darray(fact_get_elements_2d(i_actor)); |
| 84 | fact_actor_free(i_actor); |
| 85 | |
| 86 | // get all the properties |
| 87 | puts("All object properties:"); |
| 88 | fact_o_role_expression* o_top = fact_object_role_top(k); |
| 89 | actor = fact_o_role_actor_new(); |
| 90 | fact_get_sub_roles(k,(fact_role_expression*)o_top,0,&actor); |
| 91 | print2Darray(fact_get_elements_2d(actor)); |
| 92 | fact_actor_free(actor); |
| 93 | |
| 94 | // we done so let's free memory |
| 95 | puts("Destroying reasoning kernel"); |
| 96 | fact_reasoning_kernel_free(k); |
| 97 | puts("All done"); |
| 98 | return 0; |
| 99 | } |