|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnetkit.graph.Graph
public final class Graph
This class represents the relational network in memory. It contains Node objects connected via Edge objects. The Graph object also keeps track of valid node types represented by Attributes containers and valid edge types represented by the EdgeType class.
Node
,
Edge
,
Attributes
,
EdgeType
,
SchemaReader
,
SchemaWriter
Constructor Summary | |
---|---|
Graph()
|
Method Summary | |
---|---|
void |
addAttribute(java.lang.String nodeType,
Attribute a)
Adds an Attribute to the Attributes container represented by the supplied nodeType name. |
void |
addAttributes(Attributes a)
Adds the supplied Attributes container (or node type) to this Graph; Attributes must be added to the Graph before Nodes that utilize them can be added. |
void |
addEdge(Edge e)
Deprecated. Use of this method is deprecated, use addEdge(EdgeType,Node,Node,double) instead |
Edge |
addEdge(EdgeType et,
Node source,
Node dest,
double weight)
Add an edge created from the supplied parameters to the graph; if the nodes are already connected, then simply add the weight to the existing Edge. |
void |
addEdgeType(EdgeType et)
Add the supplied EdgeType to this Graph; EdgeTypes must be added to the Graph before Edges that utilize them can be added. |
Node |
addNode(java.lang.String nodeName,
Attributes a)
Adds a new Node to the Graph using the supplied node name and Attributes container. |
Graph |
clone()
|
Attributes[] |
getAllAttributes()
Gets an array of Attributes containing the node types in this graph. |
AttributeMetaInfo |
getAttributeMetaInfo(java.lang.String nodeTypeName,
Attribute attribute)
Factory method which gets the meta info object for the supplied nodeType name and attribute. |
AttributeCategoricalMetaInfo |
getAttributeMetaInfo(java.lang.String nodeTypeName,
AttributeCategorical attribute)
Factory method which gets the meta info object for the supplied nodeType name and attribute. |
Attributes |
getAttributes(java.lang.String nodeType)
Get the Attributes container matching the string provided. |
HistogramCategorical |
getClassReferenceVector(AttributeCategorical sourceAttrib,
int sourceAttribValue,
AttributeCategorical destAttrib,
java.util.List<EdgeType> path,
boolean normalized)
Gets a class reference vector for the supplied parameters; returns a histogram on the results. |
Edge |
getEdge(java.lang.String edgeTypeName,
Node source,
Node dest)
Gets the edge connecting two nodes in the graph; if the nodes aren't connected return null. |
Edge[] |
getEdges()
Gets all of the edges in the graph, irrespective of the EdgeType; the order is unspecified. |
Edge[] |
getEdges(EdgeType et)
Gets all the of the edges in the graph having a particular EdgeType; the order is unspecified. |
Edge[] |
getEdges(java.lang.String edgeTypeName)
Gets all the of the edges in the graph having a particular EdgeType; the order is unspecified. |
EdgeType |
getEdgeType(java.lang.String edgeType)
Get the EdgeType matching the provided edge type name. |
java.lang.String[] |
getEdgeTypeNames()
Gets an array of String containing the list of names of all EdgeTypes. |
java.lang.String[] |
getEdgeTypeNames(java.lang.String sourceNodeType)
Gets an array of String containing the list of names of the EdgeTypes whose source node type is the supplied parameter. |
java.lang.String[] |
getEdgeTypeNames(java.lang.String sourceNodeType,
java.lang.String destNodeType)
Gets an array of String containing the list of names of the EdgeTypes whose source and destination node types are the supplied parameters. |
EdgeType[] |
getEdgeTypes()
Gets an array of EdgeType containing the list of EdgeTypes in this graph. |
EdgeType[] |
getEdgeTypes(java.lang.String sourceNodeType)
Gets an array of EdgeTypes containing the list of the EdgeTypes whose source node type is the supplied parameter. |
EdgeType[] |
getEdgeTypes(java.lang.String sourceNodeType,
java.lang.String destNodeType)
Gets an array of EdgeType containing the list of EdgeTypes whose source and destination node types are the supplied parameters. |
GraphMetrics |
getMetrics()
Get the metrics encapsulating statistics about this graph. |
Node |
getNode(int index)
Gets the node corresponding to the supplied int index. |
Node |
getNode(java.lang.String nodeName,
java.lang.String nodeType)
Gets the node coresponding to the supplied node name and node type. |
Node[] |
getNodes()
Gets all of the nodes in the graph; the order is unspecified. |
Node[] |
getNodes(Attributes attrs)
Gets all of the Nodes whose Attributes container matches the supplied parameter. |
Node[] |
getNodes(java.lang.String type)
Gets all of the Nodes matching the supplied node type. |
Node[] |
getNodes(java.lang.String nodeType,
NodeFilter nf)
Gets all of the Nodes matching the supplied node type and which also are accepted by the supplied NodeFilter. |
java.lang.String[] |
getNodeTypes()
Gets an array of String containing the list of names of the node types in this graph. |
java.util.List<java.util.List<EdgeType>> |
getPaths(java.lang.String sourceNodeType,
java.lang.String destNodeType,
int maxLength)
Gets all paths in this Graph from the supplied source node type to the supplied destination node type that fit within the supplied maximum length. |
HistogramCategorical |
getUnconditionalReferenceVector(AttributeCategorical destAttrib,
java.util.List<EdgeType> path,
boolean normalized)
Gets an unconditional reference vector for the supplied parameters; returns a histogram on the results. |
double[] |
getValues(java.lang.String nodeType,
int index)
Gets a double array of values from Nodes in this Graph matching the supplied node type; the values are obtained from the Attribute at the supplied index offset into the Node's fields. |
double[] |
getValues(java.lang.String nodeType,
NodeFilter nf,
int index)
Gets a double array of values from Nodes in this Graph matching the supplied node type and which also are accepted by the supplied NodeFilter; the values are obtained from the Attribute at the supplied index offset into the Node's fields. |
double[] |
getValues(java.lang.String nodeType,
NodeFilter nf,
java.lang.String fieldName)
Gets a double array of values from Nodes in this Graph matching the supplied node type and which also are accepted by the supplied NodeFilter; the values are obtained from the Attribute matching the supplied field name. |
double[] |
getValues(java.lang.String nodeType,
java.lang.String fieldName)
Gets a double array of values from Nodes in this Graph matching the supplied node type; the values are obtained from the Attribute matching the supplied field name. |
static void |
main(java.lang.String[] args)
|
int |
numEdges()
Gets the total number of edges in this graph. |
int |
numEdges(java.lang.String edgeTypeName)
Gets the number of Edges in this graph for the supplied EdgeType name. |
int |
numNodes()
Gets the total number of nodes in this graph. |
int |
numNodes(java.lang.String nodeType)
Gets the number of nodes in the graph for the supplied node type. |
void |
removeAttribute(java.lang.String nodeType,
int index)
Remove an Attribute at the supplied index from the Attributes container represented by the supplied nodeType name. |
void |
removeAttributes(java.lang.String nodeType,
boolean force)
Remove the supplied Attributes container (AKA nodeType) from this Graph. |
void |
removeEdge(java.lang.String edgeTypeName,
Node source,
Node dest)
Removes the Edge connecting the supplied source Node and destination Node through the supplied EdgeType. |
void |
removeEdges(java.lang.String edgeTypeName)
Removes all Edges from this Graph sharing the supplied EdgeType. |
void |
removeEdgeType(java.lang.String edgeTypeName,
boolean force)
Remove the supplied EdgeType from this Graph. |
void |
removeNodes(java.lang.String nodeType,
boolean force)
Remove all Nodes in this Graph whose Attributes container (AKA nodeType) matches the supplied nodeType. |
Graph |
subGraph(java.util.Collection<Node> nodeSet)
Create a sub-graph consisting only of the given nodes and the edges between those nodes. |
static void |
testGetPaths(int maxLength)
|
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Graph()
Method Detail |
---|
public Graph clone()
clone
in class java.lang.Object
public Graph subGraph(java.util.Collection<Node> nodeSet)
nodeSet
-
public GraphMetrics getMetrics()
public void addAttributes(Attributes a)
a
- an Attributes container to add.
java.lang.RuntimeException
- if an Attributes container with the
same name has already been added to this Graph.public Attributes[] getAllAttributes()
public Attributes getAttributes(java.lang.String nodeType)
nodeType
- the string name identifying the node type to search for.
public void addAttribute(java.lang.String nodeType, Attribute a)
nodeType
- a String representing the Attributes container
to be extended.a
- an Attribute field to be added to the container.
java.lang.NullPointerException
- if the specified nodeType doesn't
exist in this Graph.public void removeAttribute(java.lang.String nodeType, int index)
nodeType
- a String representing the Attributes container.index
- an integer field index to be removed.
java.lang.NullPointerException
- if the index is out of bounds or
if the supplied nodeType doesn't exist.
java.lang.RuntimeException
- if the supplied index represents the
KEY field.public java.lang.String[] getNodeTypes()
public java.lang.String[] getEdgeTypeNames()
public java.lang.String[] getEdgeTypeNames(java.lang.String sourceNodeType)
sourceNodeType
- the String name of the source node type.
public EdgeType[] getEdgeTypes(java.lang.String sourceNodeType)
sourceNodeType
- the String name of the source node type.
public EdgeType[] getEdgeTypes(java.lang.String sourceNodeType, java.lang.String destNodeType)
destNodeType
- the String name of the destination node type.
public java.lang.String[] getEdgeTypeNames(java.lang.String sourceNodeType, java.lang.String destNodeType)
destNodeType
- the String name of the destination node type.
public EdgeType getEdgeType(java.lang.String edgeType)
edgeType
- the string edge type name to lookup.
public EdgeType[] getEdgeTypes()
public void addEdgeType(EdgeType et)
et
- the EdgeType to add.
java.lang.RuntimeException
- if an EdgeType with the same name has
already been added to this Graph; or if the EdgeType's source
or destination node types are invalid for this Graph.public void removeEdgeType(java.lang.String edgeTypeName, boolean force)
edgeTypeName
- a String representing the EdgeType to be
removed.force
- if false and Edges using the supplied EdgeType
exist, then throw.
java.lang.NullPointerException
- if the supplied EdgeType does not
exist in this Graph.
java.lang.RuntimeException
- if force is false and Edges using the
supplied EdgeType exist.public int numNodes()
public int numNodes(java.lang.String nodeType)
java.lang.NullPointerException
- if the supplied node type doesn't exist.public int numEdges()
public int numEdges(java.lang.String edgeTypeName)
edgeTypeName
- the EdgeType name Edges must have to be
included in this count.
public Node addNode(java.lang.String nodeName, Attributes a)
nodeName
- the string name for the new Node.a
- the Attributes container for the new Node.
java.lang.NullPointerException
- if the supplied Attributes
container doesn't exist in the Graph.
java.lang.RuntimeException
- if a Node matching the supplied
parameters already exists in this Graph.public void removeNodes(java.lang.String nodeType, boolean force)
nodeType
- a String representing the nodeType of the Nodes
to be removed.force
- if false and components using the supplied
nodeType exist, then throw. Otherwise, remove the components.
java.lang.RuntimeException
- if the supplied nodeType does not
exist in this Graph. Also throws if force is false and
components using the supplied nodeType exist.public void removeAttributes(java.lang.String nodeType, boolean force)
nodeType
- a String representing the nodeType to be removed.force
- if false and components using the supplied
nodeType exist, then throw. Otherwise, remove the components.
java.lang.NullPointerException
- if the supplied nodeType does not
exist in this Graph.
java.lang.RuntimeException
- if force is false and components using
the supplied nodeType exist.public Node getNode(int index)
index
- an int indicating which node is being requested.
java.lang.ArrayIndexOutOfBoundsException
- if the index is invalid.public Node getNode(java.lang.String nodeName, java.lang.String nodeType)
nodeName
- the name of the Node to lookup.nodeType
- the type of the Node to lookup.
java.lang.NullPointerException
- if the supplied type doesn't exist.public Node[] getNodes()
public Node[] getNodes(java.lang.String type)
type
- a string node type name to match against.
java.lang.NullPointerException
- if the supplied node type doesn't exist.public Node[] getNodes(java.lang.String nodeType, NodeFilter nf)
nodeType
- a String node type name to match against.nf
- a NodeFilter to match against.
java.lang.NullPointerException
- if the supplied node type doesn't exist.public Node[] getNodes(Attributes attrs)
attrs
- the Attributes container to match against.
java.lang.NullPointerException
- if the Attributes is not in this Graph.@Deprecated public void addEdge(Edge e)
addEdge(EdgeType,Node,Node,double)
instead
e
- the edge to be added to the graph.public Edge addEdge(EdgeType et, Node source, Node dest, double weight)
et
- the EdgeType of the Edge.source
- the source Node for the Edge.dest
- the destination Node for the Edge.weight
- the weight for the Edge.
java.lang.NullPointerException
- if the Edge's EdgeType hasn't
already been added to the Graph.public void removeEdge(java.lang.String edgeTypeName, Node source, Node dest)
edgeTypeName
- a String representing the EdgeType for the
connecting Edge to be removed.source
- the source Node for the connecting Edge.dest
- the destination Node for the connecting Edge.
java.lang.NullPointerException
- if the supplied EdgeType name
doesn't exist.
java.lang.RuntimeException
- if there is no connecting edge for the
supplied Nodes.public void removeEdges(java.lang.String edgeTypeName)
edgeTypeName
- a String representing the EdgeType for
Edges to be removed.
java.lang.NullPointerException
- if the supplied EdgeType name
doesn't exist.public Edge getEdge(java.lang.String edgeTypeName, Node source, Node dest)
edgeTypeName
- the EdgeType name of the Edge being sought.source
- the source Node for the Edge being sought.dest
- the destination Node for the Edge being sought.
public Edge[] getEdges()
public Edge[] getEdges(EdgeType et)
et
- an EdgeType for the returned Edges.
java.lang.NullPointerException
- if the supplied EdgeType doesn't
exist in the Graph.public Edge[] getEdges(java.lang.String edgeTypeName)
edgeTypeName
- a String representing the EdgeType name for
the returned Edges.
java.lang.NullPointerException
- if the supplied EdgeType doesn't
exist in the Graph.public double[] getValues(java.lang.String nodeType, int index)
nodeType
- a String representation of the node type.index
- the field index to lookup in each Node.
java.lang.NullPointerException
- if the supplied node type doesn't exist.
java.lang.ArrayIndexOutOfBoundsException
- if the supplied index is
outside the bounds of the values in the Nodes.public double[] getValues(java.lang.String nodeType, NodeFilter nf, int index)
nodeType
- a String representation of the node type.nf
- a NodeFilter to match against.index
- the field index to lookup in each Node.
java.lang.NullPointerException
- if the supplied node type doesn't exist.
java.lang.ArrayIndexOutOfBoundsException
- if the supplied index is
outside the bounds of the values in the Nodes.public double[] getValues(java.lang.String nodeType, java.lang.String fieldName)
nodeType
- a String representation of the node type.fieldName
- the field name to lookup in each Node.
java.lang.NullPointerException
- if the supplied node type doesn't exist.
java.lang.RuntimeException
- if the supplied field name doesn't exist.public double[] getValues(java.lang.String nodeType, NodeFilter nf, java.lang.String fieldName)
nodeType
- a String representation of the node type.nf
- a NodeFilter to match against.fieldName
- the field name to lookup in each Node.
java.lang.NullPointerException
- if the supplied node type doesn't exist.
java.lang.RuntimeException
- if the supplied field name doesn't exist.public java.util.List<java.util.List<EdgeType>> getPaths(java.lang.String sourceNodeType, java.lang.String destNodeType, int maxLength)
List<EdgeType>
which order EdgeType
elements by matching the predecessor's destination node type to
the successor's source node type. A suitable path must also
have it's first element's source node type and it's last
element's destination node type match the supplied parameters.
If the source node type equals the destination node type then
the resulting paths are loops.
sourceNodeType
- a String name representing the source
node type of the path.destNodeType
- a String name representing the destination
node type of the path.maxLength
- an int for the maximum path length to clamp
the recursive search.
public HistogramCategorical getClassReferenceVector(AttributeCategorical sourceAttrib, int sourceAttribValue, AttributeCategorical destAttrib, java.util.List<EdgeType> path, boolean normalized)
sourceAttrib
- the source attribute on which to restrict
the possible starting Nodes.sourceAttribValue
- the value that the starting Nodes must
have for the source attribute.destAttrib
- the destination attribute for the vector.path
- an EdgeType path for the vector.normalized
- true if the resulting histogram should be
normalized.
public HistogramCategorical getUnconditionalReferenceVector(AttributeCategorical destAttrib, java.util.List<EdgeType> path, boolean normalized)
destAttrib
- the destination attribute for the vector.path
- an EdgeType path for the vector.normalized
- true if the resulting histogram should be
normalized.
public AttributeMetaInfo getAttributeMetaInfo(java.lang.String nodeTypeName, Attribute attribute)
nodeTypeName
- a String representing the nodeType (AKA Attributes object).attribute
- an Attribute object within the supplied nodeType.
java.lang.NullPointerException
- if the supplied nodeTypeName does
not exist within this Graph.
java.lang.RuntimeException
- if the supplied attribute does not
exist within the supplied nodeType.public AttributeCategoricalMetaInfo getAttributeMetaInfo(java.lang.String nodeTypeName, AttributeCategorical attribute)
nodeTypeName
- a String representing the nodeType (AKA Attributes object).attribute
- an Attribute object within the supplied nodeType.
java.lang.NullPointerException
- if the supplied nodeTypeName does
not exist within this Graph.
java.lang.RuntimeException
- if the supplied attribute does not
exist within the supplied nodeType.public static final void testGetPaths(int maxLength)
public static final void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |