File: tOntologyPrinterLISP.h

package info (click to toggle)
fact%2B%2B 1.6.5~dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 4,496 kB
  • sloc: cpp: 28,000; java: 22,674; xml: 3,268; makefile: 102; ansic: 61; sh: 3
file content (138 lines) | stat: -rw-r--r-- 7,231 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* This file is part of the FaCT++ DL reasoner
Copyright (C) 2009-2015 Dmitry Tsarkov and The University of Manchester
Copyright (C) 2015-2016 Dmitry Tsarkov

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef TONTOLOGYPRINTERLISP_H
#define TONTOLOGYPRINTERLISP_H

#include "tExpressionPrinterLISP.h"
#include "tDLAxiom.h"
#include "tOntology.h"

class TLISPOntologyPrinter: public DLAxiomVisitor
{
protected:	// members
		/// main stream
	std::ostream& o;
		/// printer for the expressions
	TLISPExpressionPrinter LEP;
		/// if true, print declarations
	bool printDeclarations;
		/// if true, print logical axioms
	bool printAxioms;

protected:	// methods
		/// helper to print several expressions in a row
	template<class Expression>
	TLISPOntologyPrinter& operator << ( const TDLNAryExpression<Expression>& c )
	{
		if (printAxioms)
			for ( typename TDLNAryExpression<Expression>::iterator p = c.begin(), p_end = c.end(); p != p_end; ++p )
				(*p)->accept(LEP);
		return *this;
	}
		/// helper to print a string
	TLISPOntologyPrinter& operator << ( const char* str )
	{
		if (printAxioms)
			o << str;
		return *this;
	}
		/// helper to print an expression
	TLISPOntologyPrinter& operator << ( const TDLExpression* expr )
	{
		if (printAxioms)
			expr->accept(LEP);
		return *this;
	}

public:		// visitor interface
	virtual void visit ( const TDLAxiomDeclaration& axiom )
	{
		if (!printDeclarations)
			return;
		const TDLExpression* decl = axiom.getDeclaration();
		// print only declarations for non-constant entities, ignore datatypes
		if (const TDLConceptName* concept = dynamic_cast<const TDLConceptName*>(decl))
			o << "(defprimconcept " << concept->getName() << ")\n";
		else if (const TDLIndividualName* individual = dynamic_cast<const TDLIndividualName*>(decl))
			o << "(defindividual " << individual->getName() << ")\n";
		else if (const TDLObjectRoleName* objectRole = dynamic_cast<const TDLObjectRoleName*>(decl))
			o << "(defprimrole " << objectRole->getName() << ")\n";
		else if (const TDLDataRoleName* dataRole = dynamic_cast<const TDLDataRoleName*>(decl))
			o << "(defdatarole " << dataRole ->getName() << ")\n";
	}

	virtual void visit ( const TDLAxiomEquivalentConcepts& axiom ) { *this << "(equal_c" << axiom << ")\n"; }
	virtual void visit ( const TDLAxiomDisjointConcepts& axiom ) { *this  << "(disjoint_c" << axiom << ")\n"; }
	virtual void visit ( const TDLAxiomDisjointUnion& axiom )
		{ *this << "(disjoint_c" << axiom << ")\n(equal_c" << axiom.getC() << " (or" << axiom << "))\n"; }
	virtual void visit ( const TDLAxiomEquivalentORoles& axiom ) { *this << "(equal_r" << axiom << ")\n"; }
	virtual void visit ( const TDLAxiomEquivalentDRoles& axiom ) { *this << "(equal_r" << axiom << ")\n"; }
	virtual void visit ( const TDLAxiomDisjointORoles& axiom ) { *this << "(disjoint_r" << axiom << ")\n"; }
	virtual void visit ( const TDLAxiomDisjointDRoles& axiom ) { *this << "(disjoint_r" << axiom << ")\n"; }
	virtual void visit ( const TDLAxiomSameIndividuals& axiom ) { *this << "(same" << axiom << ")\n"; }
	virtual void visit ( const TDLAxiomDifferentIndividuals& axiom ) { *this << "(different" << axiom << ")\n"; }
	virtual void visit ( const TDLAxiomFairnessConstraint& axiom ) { *this << "(fairness" << axiom << ")\n"; }

	virtual void visit ( const TDLAxiomRoleInverse& axiom ) { *this << "(equal_r" << axiom.getRole() << " (inv" << axiom.getInvRole() << "))\n"; }
	virtual void visit ( const TDLAxiomORoleSubsumption& axiom ) { *this << "(implies_r" << axiom.getSubRole() << axiom.getRole() << ")\n"; }
	virtual void visit ( const TDLAxiomDRoleSubsumption& axiom ) { *this << "(implies_r" << axiom.getSubRole() << axiom.getRole() << ")\n"; }
	virtual void visit ( const TDLAxiomORoleDomain& axiom ) { *this << "(domain" << axiom.getRole() << axiom.getDomain() << ")\n"; }
	virtual void visit ( const TDLAxiomDRoleDomain& axiom ) { *this << "(domain" << axiom.getRole() << axiom.getDomain() << ")\n"; }
	virtual void visit ( const TDLAxiomORoleRange& axiom ) { *this << "(range" << axiom.getRole() << axiom.getRange() << ")\n"; }
	virtual void visit ( const TDLAxiomDRoleRange& axiom ) { *this << "(range" << axiom.getRole() << axiom.getRange() << ")\n"; }
	virtual void visit ( const TDLAxiomRoleTransitive& axiom ) { *this << "(transitive" << axiom.getRole() << ")\n"; }
	virtual void visit ( const TDLAxiomRoleReflexive& axiom ) { *this << "(reflexive" << axiom.getRole() << ")\n"; }
	virtual void visit ( const TDLAxiomRoleIrreflexive& axiom ) { *this << "(irreflexive" << axiom.getRole() << ")\n"; }
	virtual void visit ( const TDLAxiomRoleSymmetric& axiom ) { *this << "(symmetric" << axiom.getRole() << ")\n"; }
	virtual void visit ( const TDLAxiomRoleAsymmetric& axiom ) { *this << "(asymmetric" << axiom.getRole() << ")\n"; }
	virtual void visit ( const TDLAxiomORoleFunctional& axiom ) { *this << "(functional" << axiom.getRole() << ")\n"; }
	virtual void visit ( const TDLAxiomDRoleFunctional& axiom ) { *this << "(functional" << axiom.getRole() << ")\n"; }
	virtual void visit ( const TDLAxiomRoleInverseFunctional& axiom ) { *this << "(functional (inv" << axiom.getRole() << "))\n"; }

	virtual void visit ( const TDLAxiomConceptInclusion& axiom ) { *this << "(implies_c" << axiom.getSubC() << axiom.getSupC() << ")\n"; }
	virtual void visit ( const TDLAxiomInstanceOf& axiom ) { *this << "(instance" << axiom.getIndividual()  << axiom.getC() << ")\n"; }
	virtual void visit ( const TDLAxiomRelatedTo& axiom )
		{ *this << "(related" << axiom.getIndividual() << axiom.getRelation() << axiom.getRelatedIndividual() << ")\n"; }
	virtual void visit ( const TDLAxiomRelatedToNot& axiom )
		{ *this<< "(instance" << axiom.getIndividual() << " (all" << axiom.getRelation() << "(not" << axiom.getRelatedIndividual() << ")))\n"; }
	virtual void visit ( const TDLAxiomValueOf& axiom )
		{ *this << "(instance" << axiom.getIndividual() << " (some" << axiom.getAttribute() << axiom.getValue() << "))\n"; }
	virtual void visit ( const TDLAxiomValueOfNot& axiom )
		{ *this << "(instance" << axiom.getIndividual() << " (all" << axiom.getAttribute() << "(not " << axiom.getValue() << ")))\n"; }

public:		// interface
		/// init c'tor
	TLISPOntologyPrinter ( std::ostream& o_ )
		: o(o_)
		, LEP(o_)
		, printDeclarations(true)
		, printAxioms(true)
		{}
	virtual ~TLISPOntologyPrinter ( void ) {}

		/// instruct printer whether to print/ignore declarations and axioms
	void setPrintFlags(bool declarations, bool axioms)
	{
		printDeclarations = declarations;
		printAxioms = axioms;
	}
}; // TLISPOntologyPrinter

#endif