File: tDag2Interface.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 (110 lines) | stat: -rw-r--r-- 3,815 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
/* This file is part of the FaCT++ DL reasoner
Copyright (C) 2011-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 TDAG2INTERFACE_H
#define TDAG2INTERFACE_H

#include "tDLExpression.h"
#include "tExpressionManager.h"
#include "dlDag.h"

/// class to translate DAG entities into the TDL* expressions
class TDag2Interface
{
protected:	// members
		/// DAG to be translated
	const DLDag& Dag;
		/// expression manager
	TExpressionManager* Manager;
		/// vector of cached concept expressions
	std::vector<const TDLConceptExpression*> TransC;
		/// vector of cached data expressions
	std::vector<const TDLDataExpression*> TransD;

protected:	// methods
		/// build concept expression by a vertex V
	const TDLConceptExpression* buildCExpr ( const DLVertex& v );
		/// build data expression by a vertex V
	const TDLDataExpression* buildDExpr ( const DLVertex& v );
		/// create concept name by named entry
	static const TDLConceptName* CName ( const TNamedEntry* p ) { return dynamic_cast<const TDLConceptName*>(p->getEntity()); }
		/// create individual name by named entry
	static const TDLIndividualName* IName ( const TNamedEntry* p ) { return dynamic_cast<const TDLIndividualName*>(p->getEntity()); }
		/// create object role name by named entry
	static const TDLObjectRoleName* ORName ( const TNamedEntry* p ) { return dynamic_cast<const TDLObjectRoleName*>(p->getEntity()); }
		/// create data role name by named entry
	static const TDLDataRoleName* DRName ( const TNamedEntry* p ) { return dynamic_cast<const TDLDataRoleName*>(p->getEntity()); }

public:		// interface
		/// init c'tor
	TDag2Interface ( const DLDag& dag, TExpressionManager* manager )
		: Dag(dag)
		, Manager(manager)
		, TransC(dag.size(),NULL)
		, TransD(dag.size(),NULL)
		{}
		/// empty d'tor: every newly created thing will be destroyed by manager
	~TDag2Interface ( void ) {}

		/// make sure that size of expression cache is the same as the size of a DAG
	void ensureDagSize ( void )
	{
		size_t ds = Dag.size(), ts = TransC.size();
		if ( likely(ds == ts) )
			return;
		TransC.resize(ds);
		TransD.resize(ds);
		if ( unlikely(ds>ts) )
			for ( ; ts != ds; ++ts )
			{
				TransC[ts] = NULL;
				TransD[ts] = NULL;
			}
	}
		/// get concept expression corresponding index of vertex
	const TDLConceptExpression* getCExpr ( BipolarPointer p )
	{
		if ( isNegative(p) )
			return Manager->Not(getCExpr(inverse(p)));
		unsigned int i = (unsigned int)p;
		if ( TransC[i] == NULL )
			TransC[i] = buildCExpr(Dag[p]);
		return TransC[i];
	}
		/// get data expression corresponding index of vertex
	const TDLDataExpression* getDExpr ( BipolarPointer p )
	{
		if ( isNegative(p) )
			return Manager->DataNot(getDExpr(inverse(p)));
		unsigned int i = (unsigned int)p;
		if ( TransD[i] == NULL )
			TransD[i] = buildDExpr(Dag[p]);
		return TransD[i];
	}
		/// get expression corresponding index of vertex given the DATA flag
	const TDLExpression* getExpr ( BipolarPointer p, bool data )
	{
		if ( data )
			return getDExpr(p);
		else
			return getCExpr(p);
	}
}; // TDag2Interface

#endif