Class TimeMLGraph

java.lang.Object
edu.fiu.jtlex.timeml.graph.TimeMLGraph
All Implemented Interfaces:
ITimeMLGraph, Cloneable

public class TimeMLGraph extends Object implements ITimeMLGraph
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
  • Constructor Details

    • TimeMLGraph

      public TimeMLGraph()
      Creates an empty graph.
    • TimeMLGraph

      public TimeMLGraph(InputStream stream)
      Utilizes an ITimeMLParser 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

      public boolean addLink(ITimeMLLink link) throws IllegalArgumentException
      Adds the provided link to the graph. The endpoints of the link must already be present in the Graph.
      Specified by:
      addLink in interface ITimeMLGraph
      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

      public ITimeMLNode getNodeById(String nodeId)
      Gets a node by id.
      Specified by:
      getNodeById in interface ITimeMLGraph
      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

      public ITimeMLLink getLinkById(int linkId)
      Gets a link by id.
      Specified by:
      getLinkById in interface ITimeMLGraph
      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

      public ITimeMLEvent getEventById(String eventId)
      Gets a event by id.
      Specified by:
      getEventById in interface ITimeMLGraph
      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

      public boolean removeLink(ITimeMLLink link)
      Removes a provided link from the graph.
      Specified by:
      removeLink in interface ITimeMLGraph
      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 interface ITimeMLGraph
      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

      public boolean addNode(ITimeMLNode node)
      Adds a node to the graph.
      Specified by:
      addNode in interface ITimeMLGraph
      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

      public boolean removeNode(ITimeMLNode node)
      Removes a provided node from the graph. Removes links it is involved with as well.
      Specified by:
      removeNode in interface ITimeMLGraph
      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

      public boolean removeNodeById(String nodeId)
      Removes a node by id. Removes links it is involved with as well.
      Specified by:
      removeNodeById in interface ITimeMLGraph
      Parameters:
      nodeId - The id of the node to remove.
      Returns:
      True if removed, false if not removed.
      Since:
      jTLEX 1.0
    • addEvent

      public boolean addEvent(ITimeMLEvent event)
      Adds an event to the graph.
      Specified by:
      addEvent in interface ITimeMLGraph
      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

      public boolean removeEvent(ITimeMLEvent event)
      Removes a provided event from the graph. Removes instances it is involved with as well.
      Specified by:
      removeEvent in interface ITimeMLGraph
      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

      public boolean removeEventById(String eventId)
      Removes an event by id. Removes instances it is involved with as well.
      Specified by:
      removeEventById in interface ITimeMLGraph
      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

      public Set<ITimeMLNode> 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 interface ITimeMLGraph
      Returns:
      A set containing the nodes currently in the graph.
      Since:
      jTLEX 1.0
    • getLinks

      public Set<ITimeMLLink> 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 interface ITimeMLGraph
      Returns:
      A set containing the links currently in the graph.
      Since:
      jTLEX 1.0
    • getEvents

      public Set<ITimeMLEvent> 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 interface ITimeMLGraph
      Returns:
      A set containing the events currently in the graph.
      Since:
      jTLEX 1.0
    • getOutLinks

      public Map<String,Set<ITimeMLLink>> getOutLinks()
      Returns the OutLinks in the graph.
      Specified by:
      getOutLinks in interface ITimeMLGraph
      Returns:
      A map with the OutLinks in the graph.
      Since:
      jTLEX 1.0
    • getInLinks

      public Map<String,Set<ITimeMLLink>> getInLinks()
      Returns the InLinks in the graph.
      Specified by:
      getInLinks in interface ITimeMLGraph
      Returns:
      A map of the InLinks in the graph.
      Since:
      jTLEX 1.0
    • getGraphType

      public ITimeMLGraph.GraphType getGraphType()
      Gets the Graph's type.
      Specified by:
      getGraphType in interface ITimeMLGraph
      Returns:
      A ITimeMLGraph.GraphType representing the graph type.
      Since:
      jTLEX 1.0
    • getParent

      public ITimeMLGraph getParent()
      Gets the Graph's Parent Graph. Used for obtaining the parent graph from Subordination Graphs.
      Specified by:
      getParent in interface ITimeMLGraph
      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 interface ITimeMLGraph
      Parameters:
      nodes - The set of ITimeMLNode.
      links - The set of ITimeMLLink.
      events - The set of ITimeMLEvent.
      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

      public ITimeMLGraph 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 interface ITimeMLGraph
      Overrides:
      clone in class Object
      Returns:
      A copy of the graph.
      Since:
      jTLEX 1.0
    • toJson

      public String toJson()
      Returns the JSON (RFC 8259) representation of the graph.
      Specified by:
      toJson in interface ITimeMLGraph
      Returns:
      A flattened JSON string of the graph.
      Since:
      jTLEX 1.0
    • toString

      public String toString()
      Gets a printable string representation of the graph.
      Overrides:
      toString in class Object
      Returns:
      A printable string representation of the graph.
      Since:
      jTLEX 1.0
    • hashCode

      public int hashCode()
      Generates a hash code for the graph, based of its nodes and edges.
      Specified by:
      hashCode in interface ITimeMLGraph
      Overrides:
      hashCode in class Object
      Returns:
      The hash code.
      Since:
      jTLEX 1.0
    • equals

      public boolean equals(Object o)
      Checks if this graph equals an object.
      Specified by:
      equals in interface ITimeMLGraph
      Overrides:
      equals in class Object
      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