Class Graph

java.lang.Object
edu.fiu.jtlex.data.Graph
All Implemented Interfaces:
IGraph, Cloneable

public class Graph extends Object implements IGraph
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 Details

    • Graph

      public Graph()
      Creates an empty graph.
    • Graph

      public Graph(File timeMLFile) throws FileNotFoundException
      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

      public Graph(String timeMLString)
      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

      public Graph(InputStream timeMLData)
      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

      public boolean addLink(ILink link)
      Adds a link to the graph.
      Specified by:
      addLink in interface IGraph
      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

      public boolean containsLink(ILink link)
      Checks if the graph contains a link.
      Specified by:
      containsLink in interface IGraph
      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

      public INode getNodeById(int nodeId)
      Gets a node by id.
      Specified by:
      getNodeById in interface IGraph
      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

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

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

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

      public INode removeNode(INode node)
      Removes a node from the graph.
      Specified by:
      removeNode in interface IGraph
      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

      public INode removeNodeById(int nodeId)
      Removes a node by id.
      Specified by:
      removeNodeById in interface IGraph
      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

      public Set<INode> getNodes()
      Returns all the nodes in the graph.
      Specified by:
      getNodes in interface IGraph
      Returns:
      A set of the nodes in the graph.
      Since:
      Revision 750
    • getLinks

      public Set<ILink> getLinks()
      Returns all the links in the graph.
      Specified by:
      getLinks in interface IGraph
      Returns:
      A set of the links in the graph.
      Since:
      Revision 750
    • getLinksCount

      public int getLinksCount()
      Returns the number of links in the graph.
      Specified by:
      getLinksCount in interface IGraph
      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:
      getNodesCount in interface IGraph
      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:
      getGraphType in interface IGraph
      Returns:
      A GraphType representing the graph type.
      Since:
      Revision 750
    • getLinkTypesCount

      public Map<String,Integer> getLinkTypesCount()
      Gets the link count per link type.
      Specified by:
      getLinkTypesCount in interface IGraph
      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:
      setGraphType in interface IGraph
      Parameters:
      graphType - The GraphType enum.
      Since:
      Revision 750
    • clone

      public IGraph clone()
      Creates a clone of the graph.
      Specified by:
      clone in interface IGraph
      Returns:
      A deep copy of the graph.
      Since:
      Revision 750
    • toJson

      public String toJson()
      Returns the JSON (RFC 8259) representation of the graph.
      Specified by:
      toJson in interface IGraph
      Returns:
      A flattened JSON string of the graph.
      Since:
      Revision 750
    • 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:
      Revision 750
    • equals

      public boolean equals(Object o)
      Checks if this graph equals an object.
      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:
      Revision 750
    • hashCode

      public int hashCode()
      Generates a hash code for the graph, based of its nodes and edges.
      Overrides:
      hashCode in class Object
      Returns:
      The hash code.
      Since:
      Revision 750