org.hypergraphdb.algorithms
Class DefaultALGenerator

java.lang.Object
  extended by org.hypergraphdb.algorithms.DefaultALGenerator
All Implemented Interfaces:
HGALGenerator, CloseMe

public class DefaultALGenerator
extends java.lang.Object
implements HGALGenerator, CloseMe

A default implementation of the HGALGenerator that should cover most common cases. In the description below, the term focus atom is used to refer to the atom whose adjency list is being generated.

The adjency list generation process is conceptually split into two main steps:

  1. Get the relevant links for the atom.
  2. For each link, get the relevant members of its outgoing set.
In the simplest case, step 1 amounts to retrieving the incidence set of the focus atom and considering only links that point to other atoms besides it (i.e. links with arity > 1), while step 2 amounts to retrieving all atoms from the currently considered link that are different from the focus atom.

Step 1 may be augmented with a filter to select links only satisfying certain criteria. This filter is configured in the form of a link predicate, a HGQueryCondition.

Step 2 may be configured to treat links as ordered. When links are interpreted as ordered, there are several further options:

In addition, step 2 may also filter the sibling atoms by a general predicate similarly to the way links from the incidence set are filtered.

All of the above mentioned options are configured at construction time. In the simplest case of no link or sibling filtering and where links are unordered, use the SimpleALGenerator instead which will be somewhat faster.

Author:
Borislav Iordanov

Constructor Summary
DefaultALGenerator()
           Default constructor available, but the class is not really default constructible - you must at least specify a HyperGraph instance on which to operate.
DefaultALGenerator(HyperGraph graph)
           Construct with default values: no link or sibling predicate, returning all siblings in their normal storage order.
DefaultALGenerator(HyperGraph hg, HGAtomPredicate linkPredicate, HGAtomPredicate siblingPredicate)
           Construct a default adjency list generator where links are considered unordered.
DefaultALGenerator(HyperGraph hg, HGAtomPredicate linkPredicate, HGAtomPredicate siblingPredicate, boolean returnPreceeding, boolean returnSucceeding, boolean reverseOrder)
           Construct a default adjency list generator where links are considered ordered.
DefaultALGenerator(HyperGraph graph, HGAtomPredicate linkPredicate, HGAtomPredicate siblingPredicate, boolean returnPreceeding, boolean returnSucceeding, boolean reverseOrder, boolean returnSource)
           Construct a default adjency list generator where links are considered ordered.
 
Method Summary
 void close()
           
 HGSearchResult<HGHandle> generate(HGHandle h)
           Return an Iterator over all atoms adjacent to the passed in atom.
 HGHandle getCurrentLink()
          Return the HGHandle of the currently examined link.
 HyperGraph getGraph()
           
 HGAtomPredicate getLinkPredicate()
           
 HGAtomPredicate getSiblingPredicate()
           
 boolean isReturnPreceeding()
           
 boolean isReturnSource()
           
 boolean isReturnSucceeding()
           
 boolean isReverseOrder()
           
 void setGraph(HyperGraph graph)
           
 void setLinkPredicate(HGAtomPredicate linkPredicate)
           
 void setReturnPreceeding(boolean returnPreceeding)
           
 void setReturnSource(boolean returnSource)
           
 void setReturnSucceeding(boolean returnSucceeding)
           
 void setReverseOrder(boolean reverseOrder)
           
 void setSiblingPredicate(HGAtomPredicate siblingPredicate)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultALGenerator

public DefaultALGenerator()

Default constructor available, but the class is not really default constructible - you must at least specify a HyperGraph instance on which to operate.


DefaultALGenerator

public DefaultALGenerator(HyperGraph graph)

Construct with default values: no link or sibling predicate, returning all siblings in their normal storage order.


DefaultALGenerator

public DefaultALGenerator(HyperGraph hg,
                          HGAtomPredicate linkPredicate,
                          HGAtomPredicate siblingPredicate)

Construct a default adjency list generator where links are considered unordered.

Parameters:
hg - The HyperGraph instance from where incidence sets are fetched.
linkPredicate - The predicate by which links are filtered. Only links satisfying this predicate will be considered. If this parameter is null, all links from the incidence set will be considered.
siblingPredicate - The predicate by which sibling atoms are filtered from the adjency list. Only atoms satisfying this predicate will be returned. If this parameter is null, all sibling atoms will be considered.

DefaultALGenerator

public DefaultALGenerator(HyperGraph hg,
                          HGAtomPredicate linkPredicate,
                          HGAtomPredicate siblingPredicate,
                          boolean returnPreceeding,
                          boolean returnSucceeding,
                          boolean reverseOrder)

Construct a default adjency list generator where links are considered ordered.

The constructor does NOT allow both returnSucceeding and returnPreceeding to be set to false. This will always return empty adjency lists and does not make any sense. Even, in a more complex situation where those parameters are determined at run-time following some unforeseen logic, the caller must make sure that not both of those parameters are false.

Parameters:
hg - The HyperGraph instance from where incidence sets are fetched.
linkPredicate - The predicate by which links are filtered. Only links satisfying this predicate will be considered. If this parameter is null, all links from the incidence set will be considered.
siblingPredicate - The predicate by which sibling atoms are filtered from the adjency list. Only atoms satisfying this predicate will be returned. If this parameter is null, all sibling atoms will be considered.
returnPreceeding - Whether or not to return siblings that appear before the focus atom in an ordered link.
returnSucceding - Whether or not to return siblings that appear after the focus atom in an ordered link.
reverseOrder - Whether or not to reverse the default order implied by a link's target array. Note that this parameter affects the meaning of preceeding and succeeding in the above two parameters.

DefaultALGenerator

public DefaultALGenerator(HyperGraph graph,
                          HGAtomPredicate linkPredicate,
                          HGAtomPredicate siblingPredicate,
                          boolean returnPreceeding,
                          boolean returnSucceeding,
                          boolean reverseOrder,
                          boolean returnSource)

Construct a default adjency list generator where links are considered ordered.

The constructor does NOT allow both returnSucceeding and returnPreceeding to be set to false. This will always return empty adjency lists and does not make any sense. Even, in a more complex situation where those parameters are determined at run-time following some unforeseen logic, the caller must make sure that not both of those parameters are false.

Parameters:
hg - The HyperGraph instance from where incidence sets are fetched.
linkPredicate - The predicate by which links are filtered. Only links satisfying this predicate will be considered. If this parameter is null, all links from the incidence set will be considered.
siblingPredicate - The predicate by which sibling atoms are filtered from the adjency list. Only atoms satisfying this predicate will be returned. If this parameter is null, all sibling atoms will be considered.
returnPreceeding - Whether or not to return siblings that appear before the focus atom in an ordered link.
returnSucceding - Whether or not to return siblings that appear after the focus atom in an ordered link.
reverseOrder - Whether or not to reverse the default order implied by a link's target array. Note that this parameter affects the meaning of preceeding and succeeding in the above two parameters.
returnSource - Whether to return the source/originating atom along with its siblings. The default is false.
Method Detail

getCurrentLink

public HGHandle getCurrentLink()
Description copied from interface: HGALGenerator

Return the HGHandle of the currently examined link.

Specified by:
getCurrentLink in interface HGALGenerator

generate

public HGSearchResult<HGHandle> generate(HGHandle h)
Description copied from interface: HGALGenerator

Return an Iterator over all atoms adjacent to the passed in atom.

Specified by:
generate in interface HGALGenerator
Parameters:
h - The handle of the atom of interest.

close

public void close()
Specified by:
close in interface CloseMe

getGraph

public HyperGraph getGraph()

setGraph

public void setGraph(HyperGraph graph)

getLinkPredicate

public HGAtomPredicate getLinkPredicate()

setLinkPredicate

public void setLinkPredicate(HGAtomPredicate linkPredicate)

getSiblingPredicate

public HGAtomPredicate getSiblingPredicate()

setSiblingPredicate

public void setSiblingPredicate(HGAtomPredicate siblingPredicate)

isReturnPreceeding

public boolean isReturnPreceeding()

setReturnPreceeding

public void setReturnPreceeding(boolean returnPreceeding)

isReturnSucceeding

public boolean isReturnSucceeding()

setReturnSucceeding

public void setReturnSucceeding(boolean returnSucceeding)

isReverseOrder

public boolean isReverseOrder()

setReverseOrder

public void setReverseOrder(boolean reverseOrder)

isReturnSource

public boolean isReturnSource()

setReturnSource

public void setReturnSource(boolean returnSource)