| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef JNIACTOR_H |
| 21 |
#define JNIACTOR_H |
| 22 |
|
| 23 |
#include "tJNICache.h" |
| 24 |
|
| 25 |
|
| 26 |
template <typename AccessPolicy> |
| 27 |
class JTaxonomyActor: public WalkerInterface |
| 28 |
{ |
| 29 |
protected: |
| 30 |
|
| 31 |
typedef std::vector<TExpr*> SynVector; |
| 32 |
|
| 33 |
typedef std::vector<SynVector> SetOfNodes; |
| 34 |
|
| 35 |
protected: |
| 36 |
|
| 37 |
TJNICache* J; |
| 38 |
|
| 39 |
SetOfNodes acc; |
| 40 |
|
| 41 |
SynVector plain; |
| 42 |
|
| 43 |
SynVector syn; |
| 44 |
|
| 45 |
protected: |
| 46 |
|
| 47 |
jobjectArray getArray ( const SynVector& vec ) const |
| 48 |
{ return J->buildArray ( vec, AccessPolicy::getIDs(J) ); } |
| 49 |
|
| 50 |
void tryEntry ( const ClassifiableEntry* p ) |
| 51 |
{ |
| 52 |
if ( p->isSystem() ) |
| 53 |
return; |
| 54 |
if ( AccessPolicy::applicable(p) ) |
| 55 |
syn.push_back(AccessPolicy::buildTree(J,p)); |
| 56 |
} |
| 57 |
|
| 58 |
public: |
| 59 |
|
| 60 |
explicit JTaxonomyActor ( TJNICache* cache ) : J(cache) {} |
| 61 |
|
| 62 |
void clear ( void ) { acc.clear(); plain.clear(); } |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
jobjectArray getSynonyms ( void ) const { return getArray ( acc.empty() ? SynVector() : acc[0] ); } |
| 67 |
|
| 68 |
jobjectArray getElements ( void ) const |
| 69 |
{ |
| 70 |
if ( AccessPolicy::needPlain() ) |
| 71 |
return getArray(plain); |
| 72 |
jobjectArray ret = J->env->NewObjectArray ( (jsize)acc.size(), AccessPolicy::getIDs(J).ArrayClassID, nullptr ); |
| 73 |
for ( unsigned int i = 0; i < acc.size(); ++i ) |
| 74 |
J->env->SetObjectArrayElement ( ret, (jsize)i, getArray(acc[i]) ); |
| 75 |
return ret; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
bool apply ( const TaxonomyVertex& v ) override |
| 82 |
{ |
| 83 |
syn.clear(); |
| 84 |
tryEntry(v.getPrimer()); |
| 85 |
|
| 86 |
for ( auto synonym: v.synonyms() ) |
| 87 |
tryEntry(synonym); |
| 88 |
|
| 89 |
|
| 90 |
if ( syn.empty() ) |
| 91 |
return false; |
| 92 |
|
| 93 |
if ( AccessPolicy::needPlain() ) |
| 94 |
plain.insert ( plain.end(), syn.begin(), syn.end() ); |
| 95 |
else |
| 96 |
acc.push_back(syn); |
| 97 |
return true; |
| 98 |
} |
| 99 |
}; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
class ClassPolicy |
| 105 |
{ |
| 106 |
public: |
| 107 |
static const TClassFieldMethodIDs& getIDs ( const TJNICache* J ) { return J->ClassPointer; } |
| 108 |
static bool applicable ( const ClassifiableEntry* p ) |
| 109 |
{ return !static_cast<const TConcept*>(p)->isSingleton(); } |
| 110 |
static bool needPlain ( void ) { return false; } |
| 111 |
static TExpr* buildTree ( TJNICache* J, const ClassifiableEntry* p ) |
| 112 |
{ |
| 113 |
if ( p->getId() >= 0 ) |
| 114 |
return J->getCName(p->getName()); |
| 115 |
|
| 116 |
|
| 117 |
std::string name(p->getName()); |
| 118 |
|
| 119 |
if ( name == std::string("TOP") ) |
| 120 |
return J->EM->Top(); |
| 121 |
else if ( name == std::string("BOTTOM") ) |
| 122 |
return J->EM->Bottom(); |
| 123 |
else |
| 124 |
return nullptr; |
| 125 |
} |
| 126 |
}; |
| 127 |
|
| 128 |
|
| 129 |
template<bool plain> |
| 130 |
class IndividualPolicy |
| 131 |
{ |
| 132 |
public: |
| 133 |
static const TClassFieldMethodIDs& getIDs ( const TJNICache* J ) { return J->IndividualPointer; } |
| 134 |
static bool applicable ( const ClassifiableEntry* p ) |
| 135 |
{ return static_cast<const TConcept*>(p)->isSingleton(); } |
| 136 |
static bool needPlain ( void ) { return plain; } |
| 137 |
static TExpr* buildTree ( TJNICache* J, const ClassifiableEntry* p ) |
| 138 |
{ return J->getIName(p->getName()); } |
| 139 |
}; |
| 140 |
|
| 141 |
|
| 142 |
class ObjectPropertyPolicy |
| 143 |
{ |
| 144 |
public: |
| 145 |
static const TClassFieldMethodIDs& getIDs ( const TJNICache* J ) { return J->ObjectPropertyPointer; } |
| 146 |
static bool applicable ( const ClassifiableEntry* ) { return true; } |
| 147 |
static bool needPlain ( void ) { return false; } |
| 148 |
static TExpr* buildTree ( TJNICache* J, const ClassifiableEntry* p ) |
| 149 |
{ |
| 150 |
return p->getId() >= 0 ? |
| 151 |
J->getOName(p->getName()) : |
| 152 |
J->EM->Inverse(J->getOName(static_cast<const TRole*>(p)->realInverse()->getName())); |
| 153 |
} |
| 154 |
}; |
| 155 |
|
| 156 |
|
| 157 |
class DataPropertyPolicy |
| 158 |
{ |
| 159 |
public: |
| 160 |
static const TClassFieldMethodIDs& getIDs ( const TJNICache* J ) { return J->DataPropertyPointer; } |
| 161 |
static bool applicable ( const ClassifiableEntry* p ) { return p->getId() >= 0; } |
| 162 |
static bool needPlain ( void ) { return false; } |
| 163 |
static TExpr* buildTree ( TJNICache* J, const ClassifiableEntry* p ) |
| 164 |
{ return J->getDName(p->getName()); } |
| 165 |
}; |
| 166 |
|
| 167 |
#endif |