| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU General Public License |
| 7 | as published by the Free Software Foundation; either version 2 |
| 8 | of the License, or (at your option) any later version. |
| 9 | |
| 10 | This program 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 |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | // methods to work with Atomic Decomposition |
| 21 | |
| 22 | #include <fstream> |
| 23 | |
| 24 | #include "AtomicDecomposer.h"cxx . . $ `<file>/Kernel/AtomicDecomposer.h`/ |
| 25 | #include "tOntologyPrinterLISP.h"cxx . . $ `<file>/Kernel/tOntologyPrinterLISP.h`/ // AD prints |
| 26 | #include "procTimer.h"cxx . . $ `<file>/Kernel/procTimer.h`/ |
| 27 | #include "cppi.h"cxx . . $ `<file>/Kernel/cppi.h`/ |
| 28 | |
| 29 | // defined in FaCT.cpp |
| 30 | extern stdcxx . . $ std/::ofstreamcxx . . $ std/ofstream# Outcxx . . $ Out.; |
| 31 | |
| 32 | // print axioms of an atom |
| 33 | static void |
| 34 | printAtomAxiomscxx . . $ printAtomAxioms(b963b3dd7533a896). ( const TOntologyAtomcxx . . $ TOntologyAtom#::AxiomSetcxx . . $ TOntologyAtom#AxiomSet#& Axioms ) |
| 35 | { |
| 36 | static TLISPOntologyPrintercxx . . $ TLISPOntologyPrinter# LPcxx . . $ TLISPOntologyPrinter#TLISPOntologyPrinter(f7f45734e6842120).(Outcxx . . $ Out.); |
| 37 | // do cycle via set to keep the order |
| 38 | typedef stdcxx . . $ std/::setcxx . . $ std/set#<TDLAxiomcxx . . $ TDLAxiom#*> AxSetcxx . . $ printAtomAxioms(b963b3dd7533a896).AxSet#; |
| 39 | const AxSetcxx . . $ printAtomAxioms(b963b3dd7533a896).AxSet# Mcxx . . $ std/set#set(50ef72ff69bc573d). ( Axioms.begincxx . . $ std/vector#begin(359ca5030082c9f).(), Axioms.endcxx . . $ std/vector#end(359ca5030082c9f).() ); |
| 40 | for ( const TDLAxiomcxx . . $ TDLAxiom#* axiom : M ) |
| 41 | axiom->acceptcxx . . $ TDLAxiom#accept(9e2d550937cc1fea).(LP); |
| 42 | } |
| 43 | |
| 44 | /// print dependencies of an atom |
| 45 | static void |
| 46 | printAtomDepscxx . . $ printAtomDeps(d8877f455b303089). ( const TOntologyAtomcxx . . $ TOntologyAtom#::AtomSetcxx . . $ TOntologyAtom#AtomSet#& Dep ) |
| 47 | { |
| 48 | if ( unlikelycxx . . $ `Kernel/globaldef.h:29:10`!(Dep.empty()) ) |
| 49 | Outcxx . . $ Out. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Ground"; |
| 50 | else |
| 51 | Outcxx . . $ Out. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Depends on:"; |
| 52 | for ( const TOntologyAtomcxx . . $ TOntologyAtom#* atom : Dep ) |
| 53 | Outcxx . . $ Out. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). atom->getIdcxx . . $ TOntologyAtom#getId(fe4d2d262d4164a8).(); |
| 54 | Outcxx . . $ Out. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 55 | } |
| 56 | |
| 57 | /// print the atom with an index INDEX of the AD |
| 58 | static void |
| 59 | printADAtomcxx . . $ printADAtom(a6a3ca6e1aeed0ea). ( const TOntologyAtomcxx . . $ TOntologyAtom#* atom ) |
| 60 | { |
| 61 | const TOntologyAtomcxx . . $ TOntologyAtom#::AxiomSetcxx . . $ TOntologyAtom#AxiomSet#& Axioms = atom->getAtomAxiomscxx . . $ TOntologyAtom#getAtomAxioms(73e4577bb59fbb07).(); |
| 62 | Outcxx . . $ Out. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Atom " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). atom->getIdcxx . . $ TOntologyAtom#getId(fe4d2d262d4164a8).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " (size " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). Axioms.sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", module size " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). atom->getModulecxx . . $ TOntologyAtom#getModule(73e4577bb59fbb07).().sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "):\n"; |
| 63 | printAtomAxiomscxx . . $ printAtomAxioms(b963b3dd7533a896).(Axioms); |
| 64 | printAtomDepscxx . . $ printAtomDeps(d8877f455b303089).(atom->getDepAtomscxx . . $ TOntologyAtom#getDepAtoms(87724da9ee6d316b).()); |
| 65 | } |
| 66 | |
| 67 | /// @return all the axioms in the AD |
| 68 | static size_t |
| 69 | sizeADcxx . . $ sizeAD(73d949e1a12f51ce). ( AOStructurecxx . . $ AOStructure#* AOS ) |
| 70 | { |
| 71 | size_t ret = 0; |
| 72 | for ( const TOntologyAtomcxx . . $ TOntologyAtom#* atom : *AOS ) |
| 73 | ret += atom->getAtomAxiomscxx . . $ TOntologyAtom#getAtomAxioms(73e4577bb59fbb07).().sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); |
| 74 | return ret; |
| 75 | } |
| 76 | |
| 77 | void |
| 78 | CreateADcxx . . $ CreateAD(282b0c8dcc64148e). ( TOntologycxx . . $ TOntology#* Ontology, ModuleMethodcxx . . $ ModuleMethod# moduleMethod ) |
| 79 | { |
| 80 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 81 | // do the atomic decomposition |
| 82 | TsProcTimercxx . . $ TsProcTimer# timer; |
| 83 | timer.Startcxx . . $ TsProcTimer#Start(49f6e7a06ebc5aa8).(); |
| 84 | TModularizercxx . . $ TModularizer# modcxx . . $ TModularizer#TModularizer(95217cfac156eddf).(moduleMethod); |
| 85 | AtomicDecomposercxx . . $ AtomicDecomposer#* AD = new AtomicDecomposercxx . . $ AtomicDecomposer#(&mod); |
| 86 | AD->setProgressIndicatorcxx . . $ AtomicDecomposer#setProgressIndicator(db54dee042fd4fc2).(new CPPIcxx . . $ CPPI#()); |
| 87 | AOStructurecxx . . $ AOStructure#* AOS = AD->getAOScxx . . $ AtomicDecomposer#getAOS(54e527a6df0aab25). ( Ontology, M_BOTcxx . . $ M_BOT. ); |
| 88 | timer.Stopcxx . . $ TsProcTimer#Stop(49f6e7a06ebc5aa8).(); |
| 89 | Outcxx . . $ Out. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Atomic structure built in " <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). timer <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " seconds\n"; |
| 90 | size_t sz = sizeADcxx . . $ sizeAD(73d949e1a12f51ce).(AOS); |
| 91 | Outcxx . . $ Out. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Atomic structure (" <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). sz <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " axioms in " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). AOS->sizecxx . . $ AOStructure#size(fe4d2d262d4164a8).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " atoms; " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). Ontology->sizecxx . . $ TOntology#size(fe4d2d262d4164a8).()-sz <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " tautologies):\n"; |
| 92 | for ( const TOntologyAtomcxx . . $ TOntologyAtom#* atom : *AOS ) |
| 93 | printADAtomcxx . . $ printADAtom(a6a3ca6e1aeed0ea).(atom); |
| 94 | delete AD; |
| 95 | } |