Package edu.fiu.jtlex.timeml.graph
Class TimeMLGraph
java.lang.Object
edu.fiu.jtlex.timeml.graph.TimeMLGraph
- All Implemented Interfaces:
ITimeMLGraph
,Cloneable
Represents a TimeML Graph, and the default implementation of
ITimeMLGraph
.
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 TLink
,
ALink
, and SLink
.
A graph is represented with two Hash Tables, one for Nodes and one for Links.- Since:
- jTLEX 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface edu.fiu.jtlex.timeml.graph.ITimeMLGraph
ITimeMLGraph.GraphType
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty graph.TimeMLGraph
(InputStream stream) Utilizes anITimeMLParser
to parse a stream into nodes and edges, and adds them to the graph. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addEvent
(ITimeMLEvent event) Adds an event to the graph.boolean
addLink
(ITimeMLLink link) Adds the provided link to the graph.boolean
addNode
(ITimeMLNode node) Adds a node to the graph.clone()
Creates a clone of the graph by first cloning the nodes and links and then returning them inside a new Graph object.boolean
Checks if this graph equals an object.getEventById
(String eventId) Gets a event by id.Returns a snapshot of all the events currently in the graph.Gets the Graph's type.Returns the InLinks in the graph.getLinkById
(int linkId) Gets a link by id.getLinks()
Returns a snapshot of all the links currently in the graph.getNodeById
(String nodeId) Gets a node by id.getNodes()
Returns a snapshot of all the nodes currently in the graph.Returns the OutLinks in the graph.Gets the Graph's Parent Graph.int
hashCode()
Generates a hash code for the graph, based of its nodes and edges.boolean
removeEvent
(ITimeMLEvent event) Removes a provided event from the graph.boolean
removeEventById
(String eventId) Removes an event by id.boolean
removeLink
(ITimeMLLink link) Removes a provided link from the graph.boolean
removeLinkById
(int linkId) Removes a link by id.boolean
removeNode
(ITimeMLNode node) Removes a provided node from the graph.boolean
removeNodeById
(String nodeId) Removes a node by id.subGraph
(Set<ITimeMLNode> nodes, Set<ITimeMLLink> links, Set<ITimeMLEvent> events) Creates a sub graph.toJson()
Returns the JSON (RFC 8259) representation of the graph.toString()
Gets a printable string representation of the graph.
-
Constructor Details
-
TimeMLGraph
public TimeMLGraph()Creates an empty graph. -
TimeMLGraph
Utilizes anITimeMLParser
to parse a stream into nodes and edges, and adds them to the graph.- Parameters:
stream
- The InputStream to parse- Throws:
NullPointerException
- If the stream is null- Since:
- jTLEX 1.0
-
-
Method Details
-
addLink
Adds the provided link to the graph. The endpoints of the link must already be present in the Graph.- Specified by:
addLink
in interfaceITimeMLGraph
- Parameters:
link
- The ILink to be added.- Returns:
- True if the link was added, otherwise it returns false if the link already exists or if the nodes were not in the graph, and as a result, the link is not added.
- Throws:
NullPointerException
- if the link is null.IllegalArgumentException
- if nodes are not in graph before link is added.- Since:
- jTLEX 1.0
-
getNodeById
Gets a node by id.- Specified by:
getNodeById
in interfaceITimeMLGraph
- Parameters:
nodeId
- The id of the node to retrieve.- Returns:
- The node with the given id, or null if no such node exists.
- Since:
- jTLEX 1.0
-
getLinkById
Gets a link by id.- Specified by:
getLinkById
in interfaceITimeMLGraph
- Parameters:
linkId
- The id of the link to retrieve.- Returns:
- The link with the given id, or null if no such link exists.
- Since:
- jTLEX 1.0
-
getEventById
Gets a event by id.- Specified by:
getEventById
in interfaceITimeMLGraph
- Parameters:
eventId
- The id of the event to retrieve.- Returns:
- The event with the given id, or null if no such event exists.
- Since:
- jTLEX 1.0
-
removeLink
Removes a provided link from the graph.- Specified by:
removeLink
in interfaceITimeMLGraph
- Parameters:
link
- The ILink to remove.- Returns:
- true if link is removed, false if not removed or if link was not found.
- Throws:
NullPointerException
- If ILink is null- Since:
- jTLEX 1.0
-
removeLinkById
public boolean removeLinkById(int linkId) Removes a link by id.- Specified by:
removeLinkById
in interfaceITimeMLGraph
- Parameters:
linkId
- The id of the link to remove.- Returns:
- true if the link is removed, false if not removed or if link was not found.
- Since:
- jTLEX 1.0
-
addNode
Adds a node to the graph.- Specified by:
addNode
in interfaceITimeMLGraph
- 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:
- jTLEX 1.0
-
removeNode
Removes a provided node from the graph. Removes links it is involved with as well.- Specified by:
removeNode
in interfaceITimeMLGraph
- Parameters:
node
- The node to remove.- Returns:
- True if removed, false if not removed or null input.
- Throws:
NullPointerException
- if the node is null.- Since:
- jTLEX 1.0
-
removeNodeById
Removes a node by id. Removes links it is involved with as well.- Specified by:
removeNodeById
in interfaceITimeMLGraph
- Parameters:
nodeId
- The id of the node to remove.- Returns:
- True if removed, false if not removed.
- Since:
- jTLEX 1.0
-
addEvent
Adds an event to the graph.- Specified by:
addEvent
in interfaceITimeMLGraph
- Parameters:
event
- The event to add- Returns:
- True if the event was added, or False if the event already exists.
- Throws:
NullPointerException
- If the node is null- Since:
- jTLEX 1.0
-
removeEvent
Removes a provided event from the graph. Removes instances it is involved with as well.- Specified by:
removeEvent
in interfaceITimeMLGraph
- Parameters:
event
- The event to remove.- Returns:
- True if removed, false if not removed or null input.
- Throws:
NullPointerException
- if the node is null.- Since:
- jTLEX 1.0
-
removeEventById
Removes an event by id. Removes instances it is involved with as well.- Specified by:
removeEventById
in interfaceITimeMLGraph
- Parameters:
eventId
- The id of the event to remove.- Returns:
- True if removed, false if not removed, null, or if is a timex.
- Since:
- jTLEX 1.0
-
getNodes
Returns a snapshot of all the nodes currently in the graph. Modifying this set won't modify the actual graph's node set.- Specified by:
getNodes
in interfaceITimeMLGraph
- Returns:
- A set containing the nodes currently in the graph.
- Since:
- jTLEX 1.0
-
getLinks
Returns a snapshot of all the links currently in the graph. Modifying this set won't modify the actual graph's link set.- Specified by:
getLinks
in interfaceITimeMLGraph
- Returns:
- A set containing the links currently in the graph.
- Since:
- jTLEX 1.0
-
getEvents
Returns a snapshot of all the events currently in the graph. Modifying this set won't modify the actual graph's event set.- Specified by:
getEvents
in interfaceITimeMLGraph
- Returns:
- A set containing the events currently in the graph.
- Since:
- jTLEX 1.0
-
getOutLinks
Returns the OutLinks in the graph.- Specified by:
getOutLinks
in interfaceITimeMLGraph
- Returns:
- A map with the OutLinks in the graph.
- Since:
- jTLEX 1.0
-
getInLinks
Returns the InLinks in the graph.- Specified by:
getInLinks
in interfaceITimeMLGraph
- Returns:
- A map of the InLinks in the graph.
- Since:
- jTLEX 1.0
-
getGraphType
Gets the Graph's type.- Specified by:
getGraphType
in interfaceITimeMLGraph
- Returns:
- A
ITimeMLGraph.GraphType
representing the graph type. - Since:
- jTLEX 1.0
-
getParent
Gets the Graph's Parent Graph. Used for obtaining the parent graph from Subordination Graphs.- Specified by:
getParent
in interfaceITimeMLGraph
- Returns:
- A TimeMLGraph representing the parent, or null if it is not a subordination graph, meaning there is no parent.
- Since:
- jTLEX 1.0
-
subGraph
public ITimeMLGraph subGraph(Set<ITimeMLNode> nodes, Set<ITimeMLLink> links, Set<ITimeMLEvent> events) throws IllegalArgumentException Creates a sub graph.- Specified by:
subGraph
in interfaceITimeMLGraph
- Parameters:
nodes
- The set ofITimeMLNode
.links
- The set ofITimeMLLink
.events
- The set ofITimeMLEvent
.- Returns:
- an ITimeMLGraph that is the subgraph.
- Throws:
IllegalArgumentException
- if the nodes or links are not inside the graph the subgraph is being created from- Since:
- jTLEX 1.0
-
clone
Creates a clone of the graph by first cloning the nodes and links and then returning them inside a new Graph object.- Specified by:
clone
in interfaceITimeMLGraph
- Overrides:
clone
in classObject
- Returns:
- A copy of the graph.
- Since:
- jTLEX 1.0
-
toJson
Returns the JSON (RFC 8259) representation of the graph.- Specified by:
toJson
in interfaceITimeMLGraph
- Returns:
- A flattened JSON string of the graph.
- Since:
- jTLEX 1.0
-
toString
Gets a printable string representation of the graph. -
hashCode
public int hashCode()Generates a hash code for the graph, based of its nodes and edges.- Specified by:
hashCode
in interfaceITimeMLGraph
- Overrides:
hashCode
in classObject
- Returns:
- The hash code.
- Since:
- jTLEX 1.0
-
equals
Checks if this graph equals an object.- Specified by:
equals
in interfaceITimeMLGraph
- Overrides:
equals
in 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:
- jTLEX 1.0
-