ActionScript 3 programming language
ActionScript 3 programming language
The recursive method (from the CrystalMind topic map engine in the Topics application) provided below builds an XML snippet that the Kap Lab Visualizer component uses to display the currently selected topic's graph. However, this is a depth-first search (DFS) algorithm and should be modified to a breadth-first search (BFS) algorithm.
buildTopicGraph method in package com.polishedcode.topicmap.map.store:
public function buildTopicGraph(identifier:String,
showVisitedNodes:Boolean = false,
levelsTravelled:int = 0,
graph:XML = null,
maxDepth:int = MAX_DEPTH,
nodes:Array = null):XML
{
var topic:Topic = this.getTopic(identifier);
var result:XML = graph == null ?
<node identifier={identifier} instanceOf=
{topic.instanceOf} baseName={topic.firstName} /> : graph;
var visitedNodes:Array = nodes == null ? new Array() : nodes;
// exit case
if (levelsTravelled <= maxDepth)
{
var associations:ArrayCollection = this.getAssociationsFor(identifier);
for each (var association:Association in associations)
{
var resolvedTopicRefs:Array = this.resolveTopicRefs(association);
for each (var resolvedTopicRef:Array in resolvedTopicRefs)
{
var topicRef:String = resolvedTopicRef[TOPIC_REF];
var topicRefTopic:Topic = this.getTopic(topicRef);
graph = <node identifier={topicRef} instanceOf={topic.instanceOf}
baseName={topicRefTopic.firstName} />;
if (showVisitedNodes)
{
if (topicRef != identifier)
{
// recursive case
result.appendChild(
this.buildTopicGraph(
topicRef,
true,
levelsTravelled + 1,
graph));
}
}
else
{
if ((topicRef != identifier)
&& (visitedNodes.indexOf(topicRef) == -1))
{
visitedNodes.push(topicRef);
// recursive case
result.appendChild(
this.buildTopicGraph(
topicRef,
false,
levelsTravelled + 1,
graph,
MAX_DEPTH,
visitedNodes));
}
}
}
}
}
return result;
}
Click here to be able to create pages, upload images and file attachments, and link to other users and their pages.
blog comments powered by Disqus
Page trail: