package edu.vt.marian.search; import java.util.*; import java.io.*; import edu.vt.marian.common.*; /** * An Unweighted Link Class Manager manages a class of "absolute" links: that is, links that either exist or do not. As such, each set of nodes linked to another node by links of this class is a "flat" (not weighted) set. This results in efficiencies of storage and searching. * * @author Robert France * @see ClassManager * @see LinkClassManager * @see FlatSetSequencer */ public class UnwtdLinkClassManager implements LinkClassManager { protected Debug debug; /** The class of links that this can manage. */ protected ClassID classID; /** Create a LinkClassManager for a particular class of unweighted links. */ // I'm not sure these parameters are sufficient. public UnwtdLinkClassManager(ClassID linkClID, Debug d) { debug = d; classID = linkClID; } /** Create (or find in the local cache) a set of matches to description. @param description An abstract description of the links we're looking for: specifically, the link class (presumably this.classID), the direction, and a description of what is on one end. @return a WtdObjSet of nodes on the other end. */ public WtdObjSet match(LinkDesc description) { return( null ); } /** * Take a single node on one end of this link to all the nodes at the other * end. * * @param key The node as a WtdObj. * @param dir Whether key functions as source or sink. * @return The set of all nodes linked to key by instances of this link * class, weighted by link weights (if any) and key.wt(). */ public WtdObjSet keyNodeToTargetSet(WtdObj key, int dir) { // Call to local database. return( null ); } /** * Take a weighted object set of nodes on one end of the links in this class * to all the nodes at the other end. *

* NOTE: Where two nodes in keySet are both linked to the same "target" * node, some function must be applied to compute the node's weight in the * combined set. The default for links is max(), but any implementing * LinkClassManager class may use any function that suits its semantics. * * @param key the node as a WtdObj. * @param dir Whether key functions as source or sink. * @return The set of all nodes linked to any node in keySet by instances * of this link class, weighted by link weights (if any) and key.wt(). */ public WtdObjSet keySetToTargetSet(WtdObjSet keySet, int dir) { // Create a new (or find an existing) UnwtdLinkSearcher and return it. long nodeClassSize; if (dir == LinkDesc.SOURCE_TO_SINK) nodeClassSize = numSinks(); else nodeClassSize = numSources(); FlatSetSequencer seq = new FlatSetSequencer( //**DEVEL: What is the real approximation here? - RKF Nov00 keySet.approxSize()*nodeClassSize, debug); seq.addSets(keySet, new LinkSetMapping(this, dir, debug) ); return( new MaxUnionSearcher(seq, debug) ); } /** * Syntactic sugar on keyNodeToTargetSet(). */ public WtdObjSet sourceToSinks(WtdObj sourceNode) { return( keyNodeToTargetSet(sourceNode, LinkDesc.SOURCE_TO_SINK) ); } /** * Syntactic sugar on keySetToTargetSet(). */ public WtdObjSet sourcesToSinks(WtdObjSet sourceSet) { return( keySetToTargetSet(sourceSet, LinkDesc.SOURCE_TO_SINK) ); } /** * Syntactic sugar on keyNodeToTargetSet(). */ public WtdObjSet sinkToSources(WtdObj sinkNode) { return( keyNodeToTargetSet(sinkNode, LinkDesc.SINK_TO_SOURCE) ); } /** * Syntactic sugar on keySetToTargetSet(). */ public WtdObjSet sinksToSources(WtdObjSet sinkSet) { return( keySetToTargetSet(sinkSet, LinkDesc.SINK_TO_SOURCE) ); } /** * Return the number of class instances currently in the factory. * Syntactic sugar on super.classSize(). */ public long numLinks() { return( ReturnCodes.NOT_YET_IMPLEMENTED ); } /** * Return the number of unique source nodes currently in the factory. */ public long numSources() { return( ReturnCodes.NOT_YET_IMPLEMENTED ); } /** * Return the number of unique sink nodes currently in the factory. */ public long numSinks() { return( ReturnCodes.NOT_YET_IMPLEMENTED ); } /** * Return the average number of links in this class that impinge on * a source node currently (== numLinks / numSources). */ public double avgSourceDegree() { return( ((double) numLinks()) / ((double) numSources()) ); } /** * Return the average number of links in this class that impinge on * a sinknode currently (== numLinks / numSinks). */ public double avgSinkDegree() { return( ((double) numLinks()) / ((double) numSinks()) ); } /** * Return the number of class instances currently in the factory. */ public long classSize() { return( numLinks() ); } }