Debian Codegraph @

FaCT++.Python/lib/Kernel/tOntologyPrinterLISP.h

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2009-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 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
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 #ifndef TONTOLOGYPRINTERLISP_H
21 #define TONTOLOGYPRINTERLISP_H
22
23 #include "tExpressionPrinterLISP.h"
24 #include "tDLAxiom.h"
25 #include "tOntology.h"
26
27 class TLISPOntologyPrinter: public DLAxiomVisitor
28 {
29 protected: // members
30 /// main stream
31 std::ostream& o;
32 /// printer for the expressions
33 TLISPExpressionPrinter LEP;
34 /// if true, print declarations
35 bool printDeclarations = true;
36 /// if true, print logical axioms
37 bool printAxioms = true;
38
39 protected: // methods
40 /// helper to print several expressions in a row
41 template <typename Expression>
42 TLISPOntologyPrinter& operator << ( const TDLNAryExpression<Expression>& c )
43 {
44 if (printAxioms)
45 for ( const auto& expr: c )
46 expr->accept(LEP);
47 return *this;
48 }
49 /// helper to print a string
50 TLISPOntologyPrinter& operator << ( const char* str )
51 {
52 if (printAxioms)
53 o << str;
54 return *this;
55 }
56 /// helper to print an expression
57 TLISPOntologyPrinter& operator << ( const TDLExpression* expr )
58 {
59 if (printAxioms)
60 expr->accept(LEP);
61 return *this;
62 }
63
64 public: // visitor interface
65 void visit ( const TDLAxiomDeclaration& axiom ) override
66 {
67 if (!printDeclarations)
68 return;
69 const TDLExpression* decl = axiom.getDeclaration();
70 // print only declarations for non-constant entities, ignore datatypes
71 if (const TDLConceptName* concept = dynamic_cast<const TDLConceptName*>(decl))
72 o << "(defprimconcept " << concept->getName() << ")\n";
73 else if (const TDLIndividualName* individual = dynamic_cast<const TDLIndividualName*>(decl))
74 o << "(defindividual " << individual->getName() << ")\n";
75 else if (const TDLObjectRoleName* objectRole = dynamic_cast<const TDLObjectRoleName*>(decl))
76 o << "(defprimrole " << objectRole->getName() << ")\n";
77 else if (const TDLDataRoleName* dataRole = dynamic_cast<const TDLDataRoleName*>(decl))
78 o << "(defdatarole " << dataRole ->getName() << ")\n";
79 }
80
81 void visit ( const TDLAxiomEquivalentConcepts& axiom ) override { *this << "(equal_c" << axiom << ")\n"; }
82 void visit ( const TDLAxiomDisjointConcepts& axiom ) override { *this << "(disjoint_c" << axiom << ")\n"; }
83 void visit ( const TDLAxiomDisjointUnion& axiom ) override
84 { *this << "(disjoint_c" << axiom << ")\n(equal_c" << axiom.getC() << " (or" << axiom << "))\n"; }
85 void visit ( const TDLAxiomEquivalentORoles& axiom ) override { *this << "(equal_r" << axiom << ")\n"; }
86 void visit ( const TDLAxiomEquivalentDRoles& axiom ) override { *this << "(equal_r" << axiom << ")\n"; }
87 void visit ( const TDLAxiomDisjointORoles& axiom ) override { *this << "(disjoint_r" << axiom << ")\n"; }
88 void visit ( const TDLAxiomDisjointDRoles& axiom ) override { *this << "(disjoint_r" << axiom << ")\n"; }
89 void visit ( const TDLAxiomSameIndividuals& axiom ) override { *this << "(same" << axiom << ")\n"; }
90 void visit ( const TDLAxiomDifferentIndividuals& axiom ) override { *this << "(different" << axiom << ")\n"; }
91 void visit ( const TDLAxiomFairnessConstraint& axiom ) override { *this << "(fairness" << axiom << ")\n"; }
92
93 void visit ( const TDLAxiomRoleInverse& axiom ) override { *this << "(equal_r" << axiom.getRole() << " (inv" << axiom.getInvRole() << "))\n"; }
94 void visit ( const TDLAxiomORoleSubsumption& axiom ) override { *this << "(implies_r" << axiom.getSubRole() << axiom.getRole() << ")\n"; }
95 void visit ( const TDLAxiomDRoleSubsumption& axiom ) override { *this << "(implies_r" << axiom.getSubRole() << axiom.getRole() << ")\n"; }
96 void visit ( const TDLAxiomORoleDomain& axiom ) override { *this << "(domain" << axiom.getRole() << axiom.getDomain() << ")\n"; }
97 void visit ( const TDLAxiomDRoleDomain& axiom ) override { *this << "(domain" << axiom.getRole() << axiom.getDomain() << ")\n"; }
98 void visit ( const TDLAxiomORoleRange& axiom ) override { *this << "(range" << axiom.getRole() << axiom.getRange() << ")\n"; }
99 void visit ( const TDLAxiomDRoleRange& axiom ) override { *this << "(range" << axiom.getRole() << axiom.getRange() << ")\n"; }
100 void visit ( const TDLAxiomRoleTransitive& axiom ) override { *this << "(transitive" << axiom.getRole() << ")\n"; }
101 void visit ( const TDLAxiomRoleReflexive& axiom ) override { *this << "(reflexive" << axiom.getRole() << ")\n"; }
102 void visit ( const TDLAxiomRoleIrreflexive& axiom ) override { *this << "(irreflexive" << axiom.getRole() << ")\n"; }
103 void visit ( const TDLAxiomRoleSymmetric& axiom ) override { *this << "(symmetric" << axiom.getRole() << ")\n"; }
104 void visit ( const TDLAxiomRoleAsymmetric& axiom ) override { *this << "(asymmetric" << axiom.getRole() << ")\n"; }
105 void visit ( const TDLAxiomORoleFunctional& axiom ) override { *this << "(functional" << axiom.getRole() << ")\n"; }
106 void visit ( const TDLAxiomDRoleFunctional& axiom ) override { *this << "(functional" << axiom.getRole() << ")\n"; }
107 void visit ( const TDLAxiomRoleInverseFunctional& axiom ) override { *this << "(functional (inv" << axiom.getRole() << "))\n"; }
108
109 void visit ( const TDLAxiomConceptInclusion& axiom ) override { *this << "(implies_c" << axiom.getSubC() << axiom.getSupC() << ")\n"; }
110 void visit ( const TDLAxiomInstanceOf& axiom ) override { *this << "(instance" << axiom.getIndividual() << axiom.getC() << ")\n"; }
111 void visit ( const TDLAxiomRelatedTo& axiom ) override
112 { *this << "(related" << axiom.getIndividual() << axiom.getRelation() << axiom.getRelatedIndividual() << ")\n"; }
113 void visit ( const TDLAxiomRelatedToNot& axiom ) override
114 { *this<< "(instance" << axiom.getIndividual() << " (all" << axiom.getRelation() << "(not (one-of" << axiom.getRelatedIndividual() << "))))\n"; }
115 void visit ( const TDLAxiomValueOf& axiom ) override
116 { *this << "(instance" << axiom.getIndividual() << " (some" << axiom.getAttribute() << axiom.getValue() << "))\n"; }
117 void visit ( const TDLAxiomValueOfNot& axiom ) override
118 { *this << "(instance" << axiom.getIndividual() << " (all" << axiom.getAttribute() << "(not " << axiom.getValue() << ")))\n"; }
119
120 public: // interface
121 /// init c'tor
122 explicit TLISPOntologyPrinter ( std::ostream& o_ )
123 : o(o_)
124 , LEP(o_)
125 {}
126
127 /// instruct printer whether to print/ignore declarations and axioms
128 void setPrintFlags(bool declarations, bool axioms)
129 {
130 printDeclarations = declarations;
131 printAxioms = axioms;
132 }
133 }; // TLISPOntologyPrinter
134
135 #endif