gov.sandia.cognition.text.term.relation
Class MatrixBasedTermSimilarityNetwork

java.lang.Object
  extended by gov.sandia.cognition.text.term.relation.MatrixBasedTermSimilarityNetwork
All Implemented Interfaces:
RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>

public class MatrixBasedTermSimilarityNetwork
extends Object
implements RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>

A relation network between terms based on their similarity. The similarity values are stored in an underlying matrix.

Since:
3.0
Author:
Justin Basilico

Field Summary
protected  Matrix similarities
          The similarities between terms.
protected  TermIndex termIndex
          The index of terms.
 
Constructor Summary
MatrixBasedTermSimilarityNetwork(TermIndex termIndex, Matrix similarities)
          Creates a new MatrixBasedTermSimilarityNetwork.
 
Method Summary
 Set<IndexedTermSimilarityRelation> getAllRelations(IndexedTerm source, IndexedTerm target)
          Gets all the relation between the source and the target.
 int getObjectCount()
          Gets the number of objects that the relations are between.
 Set<IndexedTerm> getObjects()
          Gets the set of objects that make up the nodes in the network.
 IndexedTermSimilarityRelation getRelation(IndexedTerm source, IndexedTerm target)
          Gets a relation between the source and the target.
 IndexedTerm getRelationSource(IndexedTermSimilarityRelation relation)
          Gets the source of a given relation.
 IndexedTerm getRelationTarget(IndexedTermSimilarityRelation relation)
          Gets the target of a given relation.
 Matrix getSimilarities()
          Gets the similarities between terms.
 double getSimilarity(IndexedTerm source, IndexedTerm target)
          Gets the similarity between the two given terms.
 double getSimilarity(int sourceIndex, int targetIndex)
          Gets the similarity between the two given terms.
 double getSimilarity(Term sourceTerm, Term targetTerm)
          Gets the similarity between the two given terms.
 TermIndex getTermIndex()
          Gets the index of terms.
 boolean hasRelation(IndexedTerm source, IndexedTerm target)
          Determines if the network has a relation between the two given objects.
 boolean isObject(Object o)
          Determines whether or not the given object is a node in the relation network.
 Set<IndexedTermSimilarityRelation> relationsFrom(IndexedTerm source)
          Gets all of the relations where the given object is the source.
 Set<IndexedTermSimilarityRelation> relationsOf(IndexedTerm term)
          Gets all of the relations that involve the given object.
 Set<IndexedTermSimilarityRelation> relationsTo(IndexedTerm target)
          Gets all of the relations where the given object is the target.
protected  void setSimilarities(Matrix similarities)
          Gets the similarities between terms.
protected  void setTermIndex(TermIndex termIndex)
          Sets the index of terms.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

termIndex

protected TermIndex termIndex
The index of terms.


similarities

protected Matrix similarities
The similarities between terms.

Constructor Detail

MatrixBasedTermSimilarityNetwork

public MatrixBasedTermSimilarityNetwork(TermIndex termIndex,
                                        Matrix similarities)
Creates a new MatrixBasedTermSimilarityNetwork.

Parameters:
termIndex - The index of terms that contains the nodes of the network.
similarities - The square matrix of similarities between terms. Must have a number of rows and columns equal to the number of terms in the term index.
Method Detail

getSimilarity

public double getSimilarity(Term sourceTerm,
                            Term targetTerm)
Gets the similarity between the two given terms.

Parameters:
sourceTerm - The source term.
targetTerm - The target term.
Returns:
The similarity between the two given terms if both exist in the term index. Otherwise, 0.0 is returned.

getSimilarity

public double getSimilarity(IndexedTerm source,
                            IndexedTerm target)
Gets the similarity between the two given terms.

Parameters:
source - The source term.
target - The target term.
Returns:
The similarity between the two given terms if both exist in the term index. Otherwise, 0.0 is returned.

getSimilarity

public double getSimilarity(int sourceIndex,
                            int targetIndex)
Gets the similarity between the two given terms.

Parameters:
sourceIndex - The index of the source term.
targetIndex - The index of the target term.
Returns:
The similarity between the two given terms if both exist in the term index. Otherwise, 0.0 is returned.

getObjectCount

public int getObjectCount()
Description copied from interface: RelationNetwork
Gets the number of objects that the relations are between. It is the number of nodes in the network.

Specified by:
getObjectCount in interface RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>
Returns:
The number of objects the relations are between.

getObjects

public Set<IndexedTerm> getObjects()
Description copied from interface: RelationNetwork
Gets the set of objects that make up the nodes in the network.

Specified by:
getObjects in interface RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>
Returns:
The set of objects that make up the nodes in the network.

isObject

public boolean isObject(Object o)
Description copied from interface: RelationNetwork
Determines whether or not the given object is a node in the relation network.

Specified by:
isObject in interface RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>
Parameters:
o - An object.
Returns:
True if the object is a node in the relation network. Otherwise, false.

hasRelation

public boolean hasRelation(IndexedTerm source,
                           IndexedTerm target)
Description copied from interface: RelationNetwork
Determines if the network has a relation between the two given objects.

Specified by:
hasRelation in interface RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>
Parameters:
source - The source object.
target - The target object.
Returns:
True if the source and target are in the network and there exists is a relation from the source to the target. Otherwise, false.

getRelation

public IndexedTermSimilarityRelation getRelation(IndexedTerm source,
                                                 IndexedTerm target)
Description copied from interface: RelationNetwork
Gets a relation between the source and the target.

Specified by:
getRelation in interface RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>
Parameters:
source - The source object.
target - The target object.
Returns:
A relation between the source and target objects, if one exists. Otherwise, false.

getAllRelations

public Set<IndexedTermSimilarityRelation> getAllRelations(IndexedTerm source,
                                                          IndexedTerm target)
Description copied from interface: RelationNetwork
Gets all the relation between the source and the target.

Specified by:
getAllRelations in interface RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>
Parameters:
source - The source object.
target - The target object.
Returns:
All the relations between the source and target objects, if they exist. Otherwise, an empty set is returned.

getRelationSource

public IndexedTerm getRelationSource(IndexedTermSimilarityRelation relation)
Description copied from interface: RelationNetwork
Gets the source of a given relation.

Specified by:
getRelationSource in interface RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>
Parameters:
relation - A relation from the network.
Returns:
The source of the relation.

getRelationTarget

public IndexedTerm getRelationTarget(IndexedTermSimilarityRelation relation)
Description copied from interface: RelationNetwork
Gets the target of a given relation.

Specified by:
getRelationTarget in interface RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>
Parameters:
relation - A relation from the network.
Returns:
The target of the relation.

relationsOf

public Set<IndexedTermSimilarityRelation> relationsOf(IndexedTerm term)
Description copied from interface: RelationNetwork
Gets all of the relations that involve the given object. This includes both the relations where the object is the source and the relations where the object is the destination.

Specified by:
relationsOf in interface RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>
Parameters:
term - An object (node) from the network.
Returns:
The all of the relations involving that node.

relationsFrom

public Set<IndexedTermSimilarityRelation> relationsFrom(IndexedTerm source)
Description copied from interface: RelationNetwork
Gets all of the relations where the given object is the source.

Specified by:
relationsFrom in interface RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>
Parameters:
source - An object (node) from the network.
Returns:
A set of all the relations where the object is the source.

relationsTo

public Set<IndexedTermSimilarityRelation> relationsTo(IndexedTerm target)
Description copied from interface: RelationNetwork
Gets all of the relations where the given object is the target.

Specified by:
relationsTo in interface RelationNetwork<IndexedTerm,IndexedTermSimilarityRelation>
Parameters:
target - An object (node) from the network.
Returns:
A set of all the relations where the object is the target.

getTermIndex

public TermIndex getTermIndex()
Gets the index of terms.

Returns:
The index of terms.

setTermIndex

protected void setTermIndex(TermIndex termIndex)
Sets the index of terms.

Parameters:
termIndex - The index of terms.

getSimilarities

public Matrix getSimilarities()
Gets the similarities between terms.

Returns:
The similarities between terms.

setSimilarities

protected void setSimilarities(Matrix similarities)
Gets the similarities between terms.

Parameters:
similarities - The similarities between terms.