开发者

hypergraphdb: How to traverse all links between 2 atoms?

I'm currently working with HperGraphDB 1.1 under Java SE 1.6.

I stored 3 atoms in the graph and created multiple links between them. When I traverse the graph using the DefaultALGenerator the hypergraph returns for each atom linked to my start atom only 1 link. I think this comes from the implementation of the DefaultALGenerator since it marks already visited atoms so they won't be visited again using another link.

Is there a way to retrieve all links between 2 atoms or have I to store the atom(or maybe another link to the same atom) multiple times under different handles?

Edit:

public class MyAtom { ... }
public class MyLink extends HGPlainLink { ... }

// initialisation somewhere else
HyperGraph hg = ...

// Create some atoms
MyAtom a = new MyAtom();
MyAtom b = new MyAtom();
MyAtom c = new MyAtom();

// Store the atoms
HGHandle handleA = hg.add(a);
HGHandle handleB = hg.add(b);
HGHandle handleC = hg.add(c);

// Create some links with additional information
hg.add(new MyLink(handleA, handleB, "First directed link from A to B"));
hg.add(new MyLink(handleA, handleB, "Second directed link from A to B"));

hg.add(new MyLink(handleB, handleC, "First directed link from B to C"));
hg.add(new MyLink(handleB, handleC, "Second directed link from B to C"));

// Traverse the graph
// I want to get all paths starting at A and ending in C
DefaultALGenerator alGen = new DefaultALGenerator(
                         hg, /* The graph */
                         null, /* No link predicate */
                         null, /* No atom predicate */
                         true, /* Traverse preceeding */
                         false, /* Don't traverse succeeding */
                         false); /* Use normal order */

HGDepthFirstTraversal traversal = new HGDepthFirstTraversal(
                                    handleC,    alGen);

while (traversal.hasNext()) {
    Pair current = traversal.next();

    HGLink l = (HGLink) hg.get((HGHandle) current.getFirst());
    Object atom = hg.get((HGHandle) current.getSecond());
    System.out.println(l + " -> " + atom);
}

I want to get all paths, considering the direction of the links, that start at A 开发者_如何学Cand end in C.

I ordered the atoms in the link so that the last atom is the one the link is pointing to. Therefore I use the DefaultALGenerator to consider the direction of the links.

Best regards


You probably should post some code, and a clearer description of what you're trying to do, since what you seem to be describing doesn't seem fully consistent with how DefaultALGenerator should work. But regardless, SimpleALGenerator may be a better fit for what you're trying to do - have you tried that?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜