Package edu.fiu.jtlex.data
Class Graph
java.lang.Object
edu.fiu.jtlex.data.Graph
Represents a TimeML Graph, and the default implementation of
IGraph.
A TimeML temporal graph is a graph T = (V,E) where: V is a set of temporal events and
time expressions. E is a set of TimeML links: a tuple (u,v,w) where u, v belong to V
and w is a link type.
There are 25 link types, refer to TLinkType,
ALinkType, and SLinkType.
A graph is represented with two Hash Tables, one for Nodes and one for Links.- Since:
- Revision 33
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a link to the graph.booleanAdds a node to the graph.clone()Creates a clone of the graph.booleancontainsLink(ILink link) Checks if the graph contains a link.booleanChecks if this graph equals an object.edu.fiu.jtlex.data.GraphTypeGets the Graph's type.getLinkById(int linkId) Gets a link by id.getLinks()Returns all the links in the graph.intReturns the number of links in the graph.Gets the link count per link type.getNodeById(int nodeId) Gets a node by id.getNodes()Returns all the nodes in the graph.intGets the number of nodes in a graph.inthashCode()Generates a hash code for the graph, based of its nodes and edges.removeLink(ILink link) Removes a link from the graph.removeNode(INode node) Removes a node from the graph.removeNodeById(int nodeId) Removes a node by id.voidsetGraphType(edu.fiu.jtlex.data.GraphType graphType) Changes the graph type.toJson()Returns the JSON (RFC 8259) representation of the graph.toString()Gets a printable string representation of the graph.
-
Constructor Details
-
Graph
public Graph()Creates an empty graph. -
Graph
Creates a new Graph from a TimeML file.- Parameters:
timeMLFile- The TimeML file- Throws:
FileNotFoundException- If the file does not exist.NullPointerException- If the file is null.- Since:
- Revision 750
-
Graph
Creates a new Graph from a String.- Parameters:
timeMLString- The string of TimeML data.- Throws:
NullPointerException- If the string is null- Since:
- Revision 750
-
Graph
Creates a new Graph from an input stream. The input stream must be closed by the caller.- Parameters:
timeMLData- The InputStream of TimeML data- Throws:
NullPointerException- If the Stream is null- Since:
- Revision 750
-
-
Method Details
-
addLink
Adds a link to the graph.- Specified by:
addLinkin interfaceIGraph- Parameters:
link- The ILink to be added.- Returns:
- True if the link was added, or false if the link already exist.
- Throws:
NullPointerException- If the link is null- Since:
- Revision 750
-
containsLink
Checks if the graph contains a link.- Specified by:
containsLinkin interfaceIGraph- Parameters:
link- The ILink to check.- Returns:
- True if the link is in the graph, else false
- Throws:
NullPointerException- If the link is null- Since:
- Revision 750
-
getNodeById
Gets a node by id.- Specified by:
getNodeByIdin interfaceIGraph- Parameters:
nodeId- The id of the node to retrieve.- Returns:
- The node with the given id, or null if no such node exist.
- Since:
- Revision 750
-
getLinkById
Gets a link by id.- Specified by:
getLinkByIdin interfaceIGraph- Parameters:
linkId- The id of the link to retrieve.- Returns:
- The link with the given id, or null if no such link exist.
- Since:
- Revision 750
-
removeLink
Removes a link from the graph.- Specified by:
removeLinkin interfaceIGraph- Parameters:
link- The ILink to remove.- Returns:
- The removed link, or null if the link is not in the graph.
- Throws:
NullPointerException- If ILink is null- Since:
- Revision 750
-
addNode
Adds a node to the graph.- Specified by:
addNodein interfaceIGraph- Parameters:
node- The node to add- Returns:
- True if the node was added, or False if the node already exists.
- Throws:
NullPointerException- If the node is null- Since:
- Revision 750
-
removeNode
Removes a node from the graph.- Specified by:
removeNodein interfaceIGraph- Parameters:
node- The node to remove.- Returns:
- The removed node, or null if the node is not in the graph.
- Throws:
NullPointerException- If the node is null- Since:
- Revision 750
-
removeNodeById
Removes a node by id.- Specified by:
removeNodeByIdin interfaceIGraph- Parameters:
nodeId- The id of the node to remove.- Returns:
- The removed node, or null, if the node is not in the graph.
- Since:
- Revision 750
-
getNodes
Returns all the nodes in the graph. -
getLinks
Returns all the links in the graph. -
getLinksCount
public int getLinksCount()Returns the number of links in the graph.- Specified by:
getLinksCountin interfaceIGraph- Returns:
- The number of links in the graph.
- Since:
- Revision 750
-
getNodesCount
public int getNodesCount()Gets the number of nodes in a graph.- Specified by:
getNodesCountin interfaceIGraph- Returns:
- The number of nodes in the graph.
- Since:
- Revision 750
-
getGraphType
public edu.fiu.jtlex.data.GraphType getGraphType()Gets the Graph's type.- Specified by:
getGraphTypein interfaceIGraph- Returns:
- A
GraphTyperepresenting the graph type. - Since:
- Revision 750
-
getLinkTypesCount
Gets the link count per link type.- Specified by:
getLinkTypesCountin interfaceIGraph- Returns:
- A map containing the number of A-Link, S-Link, and T-Link.
- Since:
- Revision 750
-
setGraphType
public void setGraphType(edu.fiu.jtlex.data.GraphType graphType) Changes the graph type.- Specified by:
setGraphTypein interfaceIGraph- Parameters:
graphType- TheGraphTypeenum.- Since:
- Revision 750
-
clone
Creates a clone of the graph. -
toJson
Returns the JSON (RFC 8259) representation of the graph. -
toString
Gets a printable string representation of the graph. -
equals
Checks if this graph equals an object.- Overrides:
equalsin classObject- Parameters:
o- The object to compare against.- Returns:
- True if both graphs are equal, i.e. same set of nodes and links, or else false.
- Throws:
NullPointerException- If the object to compare against is false.- Since:
- Revision 750
-
hashCode
public int hashCode()Generates a hash code for the graph, based of its nodes and edges.
-