Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Path query_infer(Graph G, Concept currentConcept, Concept finalConcept, Path path, bool isA)
- {
- Concept[] adjTrue = currentConcept.get_adjTrue;
- Concept[] adjFalse = currentConcept.get_adjFalse;
- Concept[] adj = adjTrue ~ adjFalse;
- Concept closestConcept = finalConcept;
- if(currentConcept.compare_concept(finalConcept))
- return path;
- if(!isA)
- return path;
- if(adj.length > 0)
- {
- while(adj.length > 0)
- {
- int closestIndex = 0;
- foreach(index, c; adj)
- {
- closestConcept = closest(G, currentConcept, closestConcept, c);
- closestIndex = index;
- }
- if(adjFalse.contain_concept(closestConcept))
- isA = false;
- path.add(closestConcept);
- query_infer(G, closestConcept, finalConcept, path, isA);
- isA = true;
- if(!path.get_tail.get_concept.compare_concept(finalConcept))
- {
- path.pop;
- adj = adj[0..closestIndex] ~ adj[closestIndex+1..$];
- }
- else
- return path;
- }
- }
- return path;
- }
- Concept closest(Graph G, Concept currentConcept, Concept nextA, Concept nextB)
- {
- Edge query = new Edge(currentConcept, nextA, true);
- if(currentConcept.get_adjFalse.contain_concept(nextB))
- return nextB;
- Path[] pathList = [];
- pathList = query_path(query, G, false);
- foreach(p; pathList)
- if(p.get_conceptList[0..$-1].contain_concept(nextB))
- return nextB;
- return nextA;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement