File: tExpressionPrinterLISP.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 (156 lines) | stat: -rw-r--r-- 8,161 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* This file is part of the FaCT++ DL reasoner
Copyright (C) 2010-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 TEXPRESSIONPRINTERLISP_H
#define TEXPRESSIONPRINTERLISP_H

#include <ostream>

#include "tDLExpression.h"

class TLISPExpressionPrinter: public DLExpressionVisitor
{
protected:	// members
		/// main stream
	std::ostream& o;
		/// define str-str map
	typedef std::map<std::string, std::string> SSMap;
		/// map between OWL datatype names and FaCT++ ones
	SSMap DTNames;
		/// helper class for brackets
	class BR
	{
	protected:
		std::ostream& o;
	public:
		BR ( std::ostream& o_, const char* command ) : o(o_) { o << " (" << command; }
		~BR () { o << ")"; }
	}; // BR
protected:	// methods
		/// array helper
	template <class Argument>
	void printArray ( const TDLNAryExpression<Argument>& expr )
	{
		for ( typename TDLNAryExpression<Argument>::iterator p = expr.begin(), p_end = expr.end(); p != p_end; ++p )
			(*p)->accept(*this);
	}
		/// datatype helper to get a LISP datatype name by a OWL one
	const char* getDTName ( const char* owlName ) const
	{
		SSMap::const_iterator p = DTNames.find(owlName);
		if ( p != DTNames.end() )	// known name
			return p->second.c_str();
		return owlName;
	}

public:		// interface
		/// init c'tor
	TLISPExpressionPrinter ( std::ostream& o_ ) : o(o_)
	{
		DTNames["http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral"] = "string";
		DTNames["http://www.w3.org/2001/XMLSchema#string"] = "string";
		DTNames["http://www.w3.org/2001/XMLSchema#anyURI"] = "string";

		DTNames["http://www.w3.org/2001/XMLSchema#integer"] = "number";
		DTNames["http://www.w3.org/2001/XMLSchema#int"] = "number";

		DTNames["http://www.w3.org/2001/XMLSchema#float"] = "real";
		DTNames["http://www.w3.org/2001/XMLSchema#double"] = "real";
		DTNames["http://www.w3.org/2001/XMLSchema#real"] = "real";
	}
		/// empty d'tor
	virtual ~TLISPExpressionPrinter ( void ) {}

public:		// visitor interface
	// concept expressions
	virtual void visit ( const TDLConceptTop& ) { o << " *TOP*"; }
	virtual void visit ( const TDLConceptBottom& ) { o << " *BOTTOM*"; }
	virtual void visit ( const TDLConceptName& expr ) { o << " " << expr.getName(); }
	virtual void visit ( const TDLConceptNot& expr ) { BR b(o,"not"); expr.getC()->accept(*this); }
	virtual void visit ( const TDLConceptAnd& expr ) { BR b(o,"and"); printArray(expr); }
	virtual void visit ( const TDLConceptOr& expr ) { BR b(o,"or"); printArray(expr); }
	virtual void visit ( const TDLConceptOneOf& expr ) { BR b(o,"one-of"); printArray(expr); }
	virtual void visit ( const TDLConceptObjectSelf& expr ) { BR b(o,"self-ref"); expr.getOR()->accept(*this); }
	virtual void visit ( const TDLConceptObjectValue& expr ) { BR b(o,"some"); expr.getOR()->accept(*this); BR i(o,"one-of"); expr.getI()->accept(*this); }
	virtual void visit ( const TDLConceptObjectExists& expr ) { BR b(o,"some"); expr.getOR()->accept(*this); expr.getC()->accept(*this); }
	virtual void visit ( const TDLConceptObjectForall& expr ) { BR b(o,"all"); expr.getOR()->accept(*this); expr.getC()->accept(*this); }
	virtual void visit ( const TDLConceptObjectMinCardinality& expr )
		{ BR b(o,"atleast"); o << " " << expr.getNumber(); expr.getOR()->accept(*this); expr.getC()->accept(*this); }
	virtual void visit ( const TDLConceptObjectMaxCardinality& expr )
		{ BR b(o,"atmost"); o << " " << expr.getNumber(); expr.getOR()->accept(*this); expr.getC()->accept(*this); }
	virtual void visit ( const TDLConceptObjectExactCardinality& expr )
	{
		BR a(o,"and");
		{ BR b(o,"atleast"); o << " " << expr.getNumber(); expr.getOR()->accept(*this); expr.getC()->accept(*this); }
		{ BR b(o,"atmost"); o << " " << expr.getNumber(); expr.getOR()->accept(*this); expr.getC()->accept(*this); }
	}
	virtual void visit ( const TDLConceptDataValue& expr ) { BR b(o,"some"); expr.getDR()->accept(*this); expr.getExpr()->accept(*this); }
	virtual void visit ( const TDLConceptDataExists& expr ) { BR b(o,"some"); expr.getDR()->accept(*this); expr.getExpr()->accept(*this); }
	virtual void visit ( const TDLConceptDataForall& expr ) { BR b(o,"all"); expr.getDR()->accept(*this); expr.getExpr()->accept(*this); }
	virtual void visit ( const TDLConceptDataMinCardinality& expr )
		{ BR b(o,"atleast"); o << " " << expr.getNumber(); expr.getDR()->accept(*this); expr.getExpr()->accept(*this); }
	virtual void visit ( const TDLConceptDataMaxCardinality& expr )
		{ BR b(o,"atmost"); o << " " << expr.getNumber(); expr.getDR()->accept(*this); expr.getExpr()->accept(*this); }
	virtual void visit ( const TDLConceptDataExactCardinality& expr )
	{
		BR a(o,"and");
		{ BR b(o,"atleast"); o << " " << expr.getNumber(); expr.getDR()->accept(*this); expr.getExpr()->accept(*this); }
		{ BR b(o,"atmost"); o << " " << expr.getNumber(); expr.getDR()->accept(*this); expr.getExpr()->accept(*this); }
	}

	// individual expressions
	virtual void visit ( const TDLIndividualName& expr ) { o << " " << expr.getName(); }

	// object role expressions
	virtual void visit ( const TDLObjectRoleTop& ) { o << " *UROLE*"; }
	virtual void visit ( const TDLObjectRoleBottom& ) { o << " *EROLE*"; }
	virtual void visit ( const TDLObjectRoleName& expr ) { o << " " << expr.getName(); }
	virtual void visit ( const TDLObjectRoleInverse& expr ) { BR b(o,"inv"); expr.getOR()->accept(*this); }
	virtual void visit ( const TDLObjectRoleChain& expr ) { BR b(o,"compose"); printArray(expr); }
	virtual void visit ( const TDLObjectRoleProjectionFrom& expr )
		{ BR b(o,"project_from"); expr.getOR()->accept(*this); expr.getC()->accept(*this); }
	virtual void visit ( const TDLObjectRoleProjectionInto& expr )
		{ BR b(o,"project_into"); expr.getOR()->accept(*this); expr.getC()->accept(*this); }

	// data role expressions
	virtual void visit ( const TDLDataRoleTop& ) { o << " *UDROLE*";  }
	virtual void visit ( const TDLDataRoleBottom& ) { o << " *EDROLE*"; }
	virtual void visit ( const TDLDataRoleName& expr ) { o << " " << expr.getName(); }

	// data expressions
	virtual void visit ( const TDLDataTop& ) { o << " *TOP*"; }
	virtual void visit ( const TDLDataBottom& ) { o << " *BOTTOM*"; }
	virtual void visit ( const TDLDataTypeName& expr ) { o << " (" << getDTName(expr.getName()) << ")"; }
		// no need to use a type of a restriction here, as all contains in constants
	virtual void visit ( const TDLDataTypeRestriction& expr ) { BR b(o,"and"); printArray(expr); }
	virtual void visit ( const TDLDataValue& expr )
		{ o << " (" << getDTName(getBasicDataType(const_cast<TDLDataTypeExpression*>(expr.getExpr()))->getName()) << " " << expr.getName() << ")"; }
	virtual void visit ( const TDLDataNot& expr ) { BR b(o,"not"); expr.getExpr()->accept(*this); }
	virtual void visit ( const TDLDataAnd& expr ) { BR b(o,"and"); printArray(expr); }
	virtual void visit ( const TDLDataOr& expr ) { BR b(o,"or"); printArray(expr); }
	virtual void visit ( const TDLDataOneOf& expr ) { BR b(o,"d-one-of"); printArray(expr); }

	// facets
	virtual void visit ( const TDLFacetMinInclusive& expr ) { BR b(o,"ge"); expr.getExpr()->accept(*this); }
	virtual void visit ( const TDLFacetMinExclusive& expr ) { BR b(o,"gt"); expr.getExpr()->accept(*this); }
	virtual void visit ( const TDLFacetMaxInclusive& expr ) { BR b(o,"le"); expr.getExpr()->accept(*this); }
	virtual void visit ( const TDLFacetMaxExclusive& expr ) { BR b(o,"lt"); expr.getExpr()->accept(*this); }
}; // TLISPExpressionPrinter

#endif