gov.sandia.cognition.framework
Class DefaultSemanticNetwork

java.lang.Object
  extended by gov.sandia.cognition.framework.DefaultSemanticNetwork
All Implemented Interfaces:
SemanticNetwork, Serializable

public class DefaultSemanticNetwork
extends Object
implements SemanticNetwork

This class contains a default implementation of a SemanticNetwork. It uses a sparse graph representation using TreeMaps to map from nodes to links. All of the links are doubly linked, being stored by both their from and to nodes. This allows for fast addition, removal, and lookup.

Since:
1.0
Author:
Justin Basilico, Kevin R. Dixon
See Also:
Serialized Form

Constructor Summary
DefaultSemanticNetwork()
          Creates a new instance of DefaultSemanticNetwork
 
Method Summary
 void addNode(SemanticLabel nodeLabel)
          Adds a node to the semantic network.
 double getAssociation(SemanticLabel from, SemanticLabel to)
          Gets the association between two nodes in the network.
 Collection<SemanticLabel> getNodes()
          Gets the nodes that are in the network.
 int getNumNodes()
          Gets the total number of nodes in the network.
 Collection<SemanticLabel> getOutLinks(SemanticLabel nodeLabel)
          Gets the outgoing links from a given node.
 boolean isNode(SemanticLabel label)
          Returns true if the given SemanticLabel is a node in the SemanticNetwork.
 void removeNode(SemanticLabel nodeLabel)
          Removes a node from the semantic network including all of the incoming and outgoing links of the node.
 void setAssociation(SemanticLabel from, SemanticLabel to, double weight)
          Sets the association between two nodes in the network.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultSemanticNetwork

public DefaultSemanticNetwork()
Creates a new instance of DefaultSemanticNetwork

Method Detail

getNumNodes

public int getNumNodes()
Gets the total number of nodes in the network.

Specified by:
getNumNodes in interface SemanticNetwork
Returns:
The total number of nodes in the network

isNode

public boolean isNode(SemanticLabel label)
Returns true if the given SemanticLabel is a node in the SemanticNetwork.

Specified by:
isNode in interface SemanticNetwork
Parameters:
label - The label to evaluate.
Returns:
True if the given label is a node in the network and false otherwise.

getNodes

public Collection<SemanticLabel> getNodes()
Gets the nodes that are in the network.

Specified by:
getNodes in interface SemanticNetwork
Returns:
The collection of nodes in the network.

getOutLinks

public Collection<SemanticLabel> getOutLinks(SemanticLabel nodeLabel)
Gets the outgoing links from a given node.

Specified by:
getOutLinks in interface SemanticNetwork
Parameters:
nodeLabel - The node to get the outgoing links from
Returns:
The collection of outgoing links from the given node. If the given node is not in the network, null is to be returned.

getAssociation

public double getAssociation(SemanticLabel from,
                             SemanticLabel to)
Gets the association between two nodes in the network.

Specified by:
getAssociation in interface SemanticNetwork
Parameters:
from - The node the association is from
to - The node the association is to
Returns:
The association between the given nodes

addNode

public void addNode(SemanticLabel nodeLabel)
Adds a node to the semantic network. If the node is already in the network then nothing changes.

Parameters:
nodeLabel - The semantic label of the node.

removeNode

public void removeNode(SemanticLabel nodeLabel)
Removes a node from the semantic network including all of the incoming and outgoing links of the node. If the node is not in the network then nothing changes.

Parameters:
nodeLabel - The node to remove from the network.

setAssociation

public void setAssociation(SemanticLabel from,
                           SemanticLabel to,
                           double weight)
Sets the association between two nodes in the network.

Parameters:
from - The node that the link is from.
to - The node that the link is to.
weight - The weight of the association.
Throws:
IllegalArgumentException - Thrown if either the from or to node is not in the network.