Package edu.fiu.jtlex.data
Class Graph
java.lang.Object
edu.fiu.jtlex.data.Graph
- All Implemented Interfaces:
IGraph,java.lang.Cloneable
public class Graph extends java.lang.Object implements IGraph
Default implementation of
IGraph.
Represents a TimeML Graph.
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.
- Author:
- Luis Robaina
-
Nested Class Summary
-
Constructor Summary
Constructors Constructor Description Graph()Generates a blank graph object for manual computation.Graph(java.io.File timeMLFile)Generates a graph based on a TimeML annotated text file.Graph(java.io.InputStream timeMLData)Generates a graph based on a TimeML annotated text file.Graph(java.lang.String timeMLString)Generates a graph based on a TimeML annotated text file. -
Method Summary
Modifier and Type Method Description booleanaddLink(int NodeOneID, int NodeTwoID, ILink.LinkTag linktag, ILinkType linkType, java.lang.String syntax, ISignal signal, ILink.Origintype orig)Adds aLinkinto the graph, givenNodeidentification numbers.booleanaddLink(ILink link)Adds aLinkinto the graph.booleanaddLink(INode NodeOne, INode NodeTwo, ILink.LinkTag linktag, ILinkType linkType, java.lang.String syntax, ISignal signal, ILink.Origintype orig)Adds aLinkinto the graph, givenNodeobjects.booleanaddNode(INode node)Adds a node to the graph.Graphclone()Returns a deep-copy of the current Graph object.booleancontainsLink(ILink link)Return true if the given link exists in the graph.booleanequalLinks(Graph obj)Returns true if the clone graph contains all the links in graph, returns false otherwisebooleanequalNodes(Graph obj)Returns true if the clone graph contains all the node IDs in graph, returns false otherwisebooleanequals(java.lang.Object o)booleangetConsistency()Returns true if the graph is consistent.java.util.ArrayList<IGraph>getConsistentPartitions()Returns the set of consistent subordinate subgraphs.IGraph.GraphTypegetGraphType()Returns the type of graph.java.util.ArrayList<IGraph>getInconsistentPartitions()Returns the set of inconsistent subordinate subgraphs.java.util.Set<IGraph>getInconsistentSubgraphs()Returns the set of inconsistent subgraphs.java.lang.DoublegetIndeterminacyScore()Returns a percent value representing the indeterminacy score.intgetIndeterminantSections()java.util.ArrayList<java.lang.String>getIndeterminantTimePairs()Returns a list of Indeterminant Time Pairs.java.util.List<java.lang.String>getIndeterminantTimePoints()java.util.Set<ILink>getLinks()Returns a set with all the Links in the TimeML graph, (null) if the TimeML graph is empty.intgetLinksCount()Returns the number of links.java.util.HashMap<java.lang.String,java.lang.Integer>getLinkTypesCount()Returns the count of each type of links, formatted as a string.INodegetNodeByID(int NodeID)Returns a INode reference if a node with ID NodeID exists in the graph returns null otherwise.java.util.Set<INode>getNodes()Returns a set with all the Nodes in the TimeML graph, (null) if the TimeML graph is empty.intgetNodesCount()Returns the number of nodes.java.util.Set<ILink>getPartitionlinks()Returns the set of subordination links.java.util.ArrayList<IGraph>getPartitions()Returns the set of subordinate subgraphs.java.util.ArrayList<java.util.List<java.lang.String>>getSolutionList()Return the string representations of timeline solututions viaGraphTCSP.stringTimeLine().java.util.ArrayList<ILink>getSuggestedLinks()Returns a list of suggested links to increase graph connectivity.java.lang.StringgetText()Returns the article text without TimeML tags.TimelinegetTimeline()Returns the computed timeline.intgetTimelineLength()Returns the length of the main timeline.java.lang.BooleanhasSelfLoops()Returns whether the graph has self loops or not.java.lang.StringinconsistentSubGraphsToJSON()Formats and returns the JSON representation of the inconsistent subgraphs.booleanisConsistent()Returns true if the graph is consistent.ILinkremoveLink(ILink link)Removes the given link from the graph.INoderemoveNode(INode node)Removes a node object from the graph.INoderemoveNodeByID(int ID)Removes a node from the graph, by node identification number.voidsetConsistency(boolean consistency)Sets the consistency of the graph.voidsetGraphType(IGraph.GraphType graphType)Sets the type of graph toIGraph.GraphType.MainGraphorIGraph.GraphType.SubbordinationGraphvoidsetIndeterminancyScore(double indeterminacyScore)Sets the percent value representing the indeterminacy score.voidsetIndeterminantTimePairs(java.util.ArrayList<java.lang.String> iTimePairs)Sets the Indeterminant Time Pairs for the current Graph.voidsetSuggestedLinks(ILink x)voidsetTimeline(Timeline newTimeline)Sets the Timeline of the current Graph.java.lang.StringsuggestedLinksToString()Returns the string representation of the suggested links.voidsuggestLinks()java.lang.StringtoJSON()Returns the JSON (RFC 8259) representation of the Graph.java.lang.StringtoString()inttotalSelfLoops()Returns the number of self loops in the graph.
-
Constructor Details
-
Graph
public Graph()Generates a blank graph object for manual computation. Nodes and links must be added via theaddNode(INode)andaddLink(INode, INode, LinkTag, ILinkType, String, ISignal, Origintype)functions, respectively.- See Also:
IGraph
-
Graph
public Graph(java.io.File timeMLFile) throws java.io.FileNotFoundExceptionGenerates a graph based on a TimeML annotated text file. This constructor:- converts the File object into a FileStream
- parses the text file via
TimeMLParser.parse(InputStream) - adds the parsed Timex nodes, Instance nodes, and Links
- finds the subordinate partitions via
Partitioner.partitionGraph(IGraph) - finds inconsistent subgraphs via
InconsistencyDetector.isConsistent(IGraph) - finds indeterminacies via
IndeterminacyDetector.detect()()} - builds the Timeline object via
GraphTCSP.stringTimeLine()
- Parameters:
timeMLFile- The TimeML file to be analyzed.- Throws:
java.io.FileNotFoundException- if there is a problem reading the given file.- See Also:
TimeMLParser,Partitioner,InconsistencyDetector,IndeterminacyDetector,GraphTCSP,Timeline
-
Graph
public Graph(java.lang.String timeMLString)Generates a graph based on a TimeML annotated text file. This constructor:- converts the String object into an InputStream
- parses the text file via
TimeMLParser.parse(InputStream) - adds the parsed Timex nodes, Instance nodes, and Links
- finds the subordinate partitions via
Partitioner.partitionGraph(IGraph) - finds inconsistent subgraphs via
InconsistencyDetector.isConsistent(IGraph) - finds indeterminacies via
IndeterminacyDetector.detect()()} - builds the Timeline object via
GraphTCSP.stringTimeLine()
- Parameters:
timeMLString- The TimeML string to be analyzed.- See Also:
TimeMLParser,Partitioner,InconsistencyDetector,IndeterminacyDetector,GraphTCSP,Timeline
-
Graph
public Graph(java.io.InputStream timeMLData)Generates a graph based on a TimeML annotated text file. This constructor:- parses the text file via
TimeMLParser.parse(InputStream) - adds the parsed Timex nodes, Instance nodes, and Links
- finds the subordinate partitions via
Partitioner.partitionGraph(IGraph) - finds inconsistent subgraphs via
InconsistencyDetector.isConsistent(IGraph) - finds indeterminacies via
IndeterminacyDetector.detect()()} - builds the Timeline object via
GraphTCSP.stringTimeLine()
- Parameters:
timeMLData- The TimeML InputStream to be analyzed.- See Also:
TimeMLParser,Partitioner,InconsistencyDetector,IndeterminacyDetector,GraphTCSP,Timeline
- parses the text file via
-
-
Method Details
-
getLinksCount
public int getLinksCount()Returns the number of links.- Specified by:
getLinksCountin interfaceIGraph- Returns:
- the number of links.
-
getNodesCount
public int getNodesCount()Returns the number of nodes.- Specified by:
getNodesCountin interfaceIGraph- Returns:
- the number of nodes.
-
getNodeByID
Returns a INode reference if a node with ID NodeID exists in the graph returns null otherwise.- Specified by:
getNodeByIDin interfaceIGraph- Parameters:
NodeID- : An Integer ID for a given node.- Returns:
- A INode reference if a node with ID NodeID exists in the graph returns null otherwise.
-
addLink
Adds aLinkinto the graph. -
addLink
public boolean addLink(INode NodeOne, INode NodeTwo, ILink.LinkTag linktag, ILinkType linkType, java.lang.String syntax, ISignal signal, ILink.Origintype orig)Adds aLinkinto the graph, givenNodeobjects.- Specified by:
addLinkin interfaceIGraph- Parameters:
NodeOne- The firstNode. This is referred to as theEvent Instance.NodeTwo- The secondNode. This is referred to as theRelated to Event.linktag- The type of link (TLink, ALink, SLink)linkType- The type of link (TLink, ALink, SLink)syntax- the syntactic pattern that was used in generating the linksignal- ID of the signal, if the temporal relation is explicitly signaled in the text.orig- whether a TLink was generated manually or by closure.- Returns:
- True on successful insertion, False if link already exists.
-
addLink
public boolean addLink(int NodeOneID, int NodeTwoID, ILink.LinkTag linktag, ILinkType linkType, java.lang.String syntax, ISignal signal, ILink.Origintype orig)Adds aLinkinto the graph, givenNodeidentification numbers.- Specified by:
addLinkin interfaceIGraph- Parameters:
NodeOneID- The firstNodeID. This is referred to as theEvent Instance.NodeTwoID- The secondNodeID. This is referred to as theRelated to Event.linktag- The type of link (TLink, ALink, SLink)linkType- The type of link (TLink, ALink, SLink)syntax- the syntactic pattern that was used in generating the linksignal- ID of the signal, if the temporal relation is explicitly signaled in the text.orig- whether a TLink was generated manually or by closure.- Returns:
- True on successful insertion, False if link already exists.
-
containsLink
Return true if the given link exists in the graph.- Specified by:
containsLinkin interfaceIGraph- Parameters:
link- the link to find.- Returns:
- true if the given link exists in the graph.
-
removeLink
Removes the given link from the graph.- Specified by:
removeLinkin interfaceIGraph- Parameters:
link- the link to remove.- Returns:
- the link that was removed, Null if link was not found.
-
addNode
Adds a node to the graph. -
removeNode
Removes a node object from the graph.- Specified by:
removeNodein interfaceIGraph- Parameters:
node- the node object to remove.- Returns:
- the node that was removed, Null if node was not found.
-
removeNodeByID
Removes a node from the graph, by node identification number.- Specified by:
removeNodeByIDin interfaceIGraph- Parameters:
ID- the identification number of the node to be removed.- Returns:
- the node that was removed, Null if node was not found.
-
setConsistency
public void setConsistency(boolean consistency)Sets the consistency of the graph.- Specified by:
setConsistencyin interfaceIGraph- Parameters:
consistency- the consistency of the graph.
-
getConsistency
public boolean getConsistency()Returns true if the graph is consistent.- Specified by:
getConsistencyin interfaceIGraph- Returns:
- true if the graph is consistent.
-
getLinks
Returns a set with all the Links in the TimeML graph, (null) if the TimeML graph is empty. -
getNodes
Returns a set with all the Nodes in the TimeML graph, (null) if the TimeML graph is empty. -
getLinkTypesCount
public java.util.HashMap<java.lang.String,java.lang.Integer> getLinkTypesCount()Returns the count of each type of links, formatted as a string.- Specified by:
getLinkTypesCountin interfaceIGraph- Returns:
- the count of each type of links
ILink.ALinkType,ILink.SLinkType,ILink.TLinkTypeformatted as a string.
-
getGraphType
Returns the type of graph.- Specified by:
getGraphTypein interfaceIGraph- Returns:
- the type of graph.
- See Also:
IGraph.GraphType
-
setGraphType
Description copied from interface:IGraphSets the type of graph toIGraph.GraphType.MainGraphorIGraph.GraphType.SubbordinationGraph- Specified by:
setGraphTypein interfaceIGraph- Parameters:
graphType- the type of graph.- See Also:
IGraph.GraphType
-
getPartitions
Returns the set of subordinate subgraphs.- Specified by:
getPartitionsin interfaceIGraph- Returns:
- the set of subordinate subgraphs.
- See Also:
Partitioner.partitionGraph(IGraph)
-
getConsistentPartitions
Returns the set of consistent subordinate subgraphs.- Specified by:
getConsistentPartitionsin interfaceIGraph- Returns:
- the set of consistent subordinate subgraphs.
- See Also:
InconsistencyDetector
-
getInconsistentPartitions
Returns the set of inconsistent subordinate subgraphs.- Specified by:
getInconsistentPartitionsin interfaceIGraph- Returns:
- the set of inconsistent subordinate subgraphs.
- See Also:
InconsistencyDetector
-
getSolutionList
public java.util.ArrayList<java.util.List<java.lang.String>> getSolutionList()Return the string representations of timeline solututions viaGraphTCSP.stringTimeLine().- Specified by:
getSolutionListin interfaceIGraph- Returns:
- the string representations of timeline solututions
via
GraphTCSP.stringTimeLine().
-
getPartitionlinks
Returns the set of subordination links.- Specified by:
getPartitionlinksin interfaceIGraph- Returns:
- the set of subordination links.
-
setTimeline
Sets the Timeline of the current Graph.- Specified by:
setTimelinein interfaceIGraph- Parameters:
newTimeline- the new Timeline.
-
getTimeline
Returns the computed timeline.- Specified by:
getTimelinein interfaceIGraph- Returns:
- the computed timeline.
- See Also:
GraphTCSP
-
getTimelineLength
public int getTimelineLength()Returns the length of the main timeline.- Specified by:
getTimelineLengthin interfaceIGraph- Returns:
- the length of the main timeline, -1 if graph is inconsistent.
-
getIndeterminantTimePairs
public java.util.ArrayList<java.lang.String> getIndeterminantTimePairs()Returns a list of Indeterminant Time Pairs.- Specified by:
getIndeterminantTimePairsin interfaceIGraph- Returns:
- a list of Indeterminant Time Pairs.
-
getIndeterminantTimePoints
public java.util.List<java.lang.String> getIndeterminantTimePoints() -
getIndeterminacyScore
public java.lang.Double getIndeterminacyScore()Returns a percent value representing the indeterminacy score.- Specified by:
getIndeterminacyScorein interfaceIGraph- Returns:
- a percent value representing the indeterminacy score.
-
getIndeterminantSections
public int getIndeterminantSections() -
setIndeterminancyScore
public void setIndeterminancyScore(double indeterminacyScore)Sets the percent value representing the indeterminacy score.- Specified by:
setIndeterminancyScorein interfaceIGraph- Parameters:
indeterminacyScore- the percent value representing the indeterminacy score.
-
setIndeterminantTimePairs
public void setIndeterminantTimePairs(java.util.ArrayList<java.lang.String> iTimePairs)Sets the Indeterminant Time Pairs for the current Graph.- Specified by:
setIndeterminantTimePairsin interfaceIGraph- Parameters:
iTimePairs- List of Indeterminant Time Pairs.- See Also:
IndeterminacyDetector.detect(),IndeterminacyDetector.indeterminantTimePairs()
-
isConsistent
public boolean isConsistent()Description copied from interface:IGraphReturns true if the graph is consistent.- Specified by:
isConsistentin interfaceIGraph- Returns:
- true if the graph is consistent.
-
getInconsistentSubgraphs
Returns the set of inconsistent subgraphs.- Specified by:
getInconsistentSubgraphsin interfaceIGraph- Returns:
- the set of inconsistent subgraphs.
-
clone
Returns a deep-copy of the current Graph object. Only contains the nodes and links. -
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o) -
equalNodes
Returns true if the clone graph contains all the node IDs in graph, returns false otherwise- Parameters:
obj- , graph clone- Returns:
- true if the clone graph contains all the node IDs in graph, returns false otherwise
-
equalLinks
Returns true if the clone graph contains all the links in graph, returns false otherwise- Parameters:
obj- , graph clone- Returns:
- true if the clone graph contains all the links in graph, returns false otherwise
-
getText
public java.lang.String getText()Returns the article text without TimeML tags. -
toJSON
public java.lang.String toJSON()Returns the JSON (RFC 8259) representation of the Graph. -
inconsistentSubGraphsToJSON
public java.lang.String inconsistentSubGraphsToJSON()Formats and returns the JSON representation of the inconsistent subgraphs.- Returns:
- the JSON formatted representation of the inconsistent subgraphs.
-
suggestLinks
public void suggestLinks() -
suggestedLinksToString
public java.lang.String suggestedLinksToString()Returns the string representation of the suggested links.- Returns:
- the string representation of the suggested links.
-
getSuggestedLinks
Returns a list of suggested links to increase graph connectivity.- Returns:
- a list of suggested links.
-
setSuggestedLinks
-
hasSelfLoops
public java.lang.Boolean hasSelfLoops()Description copied from interface:IGraphReturns whether the graph has self loops or not.- Specified by:
hasSelfLoopsin interfaceIGraph- Returns:
- true if graph contains self loops.
-
totalSelfLoops
public int totalSelfLoops()Description copied from interface:IGraphReturns the number of self loops in the graph.- Specified by:
totalSelfLoopsin interfaceIGraph- Returns:
- the number of self loops in the graph.
-