Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Path query_infer(Graph G, Concept currentConcept, Concept finalConcept, Path path, bool isA)
  2. {
  3.     Concept[] adjTrue = currentConcept.get_adjTrue;
  4.     Concept[] adjFalse = currentConcept.get_adjFalse;
  5.     Concept[] adj = adjTrue ~ adjFalse;
  6.    
  7.     Concept closestConcept = finalConcept;
  8.    
  9.     if(currentConcept.compare_concept(finalConcept))
  10.         return path;
  11.    
  12.     if(!isA)
  13.         return path;
  14.    
  15.     if(adj.length > 0)
  16.     {
  17.         while(adj.length > 0)
  18.         {
  19.             int closestIndex = 0;
  20.            
  21.             foreach(index, c; adj)
  22.             {
  23.                 closestConcept = closest(G, currentConcept, closestConcept, c);
  24.                 closestIndex = index;
  25.             }
  26.            
  27.             if(adjFalse.contain_concept(closestConcept))
  28.                 isA = false;
  29.            
  30.             path.add(closestConcept);
  31.            
  32.             query_infer(G, closestConcept, finalConcept, path, isA);
  33.             isA = true;
  34.            
  35.             if(!path.get_tail.get_concept.compare_concept(finalConcept))
  36.             {
  37.                 path.pop;
  38.                 adj = adj[0..closestIndex] ~ adj[closestIndex+1..$];
  39.             }
  40.             else
  41.                 return path;
  42.         }
  43.     }
  44.     return path;
  45. }
  46.  
  47. Concept closest(Graph G, Concept currentConcept, Concept nextA, Concept nextB)
  48. {
  49.     Edge query = new Edge(currentConcept, nextA, true);
  50.    
  51.     if(currentConcept.get_adjFalse.contain_concept(nextB))
  52.         return nextB;
  53.    
  54.     Path[] pathList = [];
  55.     pathList = query_path(query, G, false);
  56.    
  57.     foreach(p; pathList)
  58.         if(p.get_conceptList[0..$-1].contain_concept(nextB))
  59.             return nextB;
  60.     return nextA;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement