| Algorithm 1 Rule Insertion (r) |
| 1 Input: vector<string> Input //string of rule input; 2 Output: RETE net and updated Node Indexing; /* Based on node identification, build each node*/ 3 expVec = new vector<pair<string,string>> //node type and rule input; 4 While (Input != end) { 5 extracted=DecomposeRule(Input[i]); 6 expVec.push(extracted); 7 } 8 nodeVec = new vector<Node*> //created node; 9 scalarVec = new vector<Node*> //created CQ node; 10 spatialVec = new vector<Node*> //created Spatial node; 11 While (expVec != NULL && nodeVec.size()—1){ 12 If (expVec.first == “Alpha”) { 13 tempAlphaNode = new AlphaNode(expVec.second); 14 nodeVec.push(tempAlphaNode); 15 scalarVec.push(tempAlphaNode); 16 expVec.pop(); 17 } 18 Else { /* check whether the previous node is an existing node */ 19 If (expVec.first == “spatial”) { 20 tempBetaNode = new BetaNode(expVec.second); 21 nodeVec.push(tempBetaNode); 22 spatialVec.push(tempBetaNode); 23 expVec.pop() 24 } 25 Else { 26 If (isExist(expVec.second)) { 27 nodeVec.push(findNode(expVec.second)); 28 } 29 Else { 30 tempBetaNode = new BetaNode(expVec.second); 31 nodeVec.push(tempBetaNode); 32 } 33 expVec.pop(); 34 } 35 } 36 tempBetaNode = newBetaNode(nodeVec.top(), nodeVec.top()-1); 37 connectNode(nodeVec.top, nodeVec.top()-1, tempBetaNode); 38 nodeVec.pop(); 39 nodeVec.pop(); 40 nodeVec.push(tempBetaNode); 41 } /*Spatial Node Index Construction */ 42 While (spatialVec.size() > 0) { 43 pointVec = Utilities::decomposeNode(spatialVec.top); /*Get the entity name from the CQ node */ 44 observedEntityName = getEntityName(spatialVec.top); /*from the existing node indexing tree, insert the CQ area */ 45 *(spatialIndex[observedEntityName]).insert(pointVec); /*remove the node from the vector */ 46 spatialVec.pop(); 47 } |