com.googlecode.whatswrong
Class Edge

java.lang.Object
  extended by com.googlecode.whatswrong.Edge

public class Edge
extends java.lang.Object

An Edge is a labelled and typed pair of tokens. It can represent dependencies edges as well as spans. Along with a start and end (to and from) token an edge has the following three attributes:

  1. Type: The type of a edge denotes the type of information the edge represents. For example, the type could be "dep" for edges that represent syntactic dependencies, or "role" for edges that represent semantic roles (a la CoNLL 2008).
  2. Render Type: The render type of an edge controls how the edge will be rendered. For example, both "dep" and "role" edges could have the render type Edge.RenderType.dependency
  3. . Then they are both drawn as directed edges in a dependency style graph.
  4. Label: This attribute classifies edges within a certain type. For example, in the case of "dep" edges we could use the label "SUBJ" to denote subject dependencies.

Author:
Sebastian Riedel

Nested Class Summary
static class Edge.RenderType
          The RenderType enum can be used to specify how the edge should be rendered.
 
Constructor Summary
Edge(Token from, Token to, java.lang.String label, java.lang.String type)
          Creates a new edge with default render type (dependency).
Edge(Token from, Token to, java.lang.String label, java.lang.String type, Edge.RenderType renderType)
          Create new edge.
Edge(Token from, Token to, java.lang.String label, java.lang.String note, java.lang.String type, Edge.RenderType renderType)
          Create new edge.
Edge(Token from, Token to, java.lang.String label, java.lang.String note, java.lang.String type, Edge.RenderType renderType, java.lang.String description)
          Create new edge.
 
Method Summary
 boolean covers(Edge edge)
          Check whether this edge completely covers the specified edge.
 boolean coversExactly(Edge edge)
          Check whether this edge spans the same sequence of tokens as the given edge.
 boolean coversSemi(Edge edge)
          Checks whether this edge covers the given edge and is aligned with it on one side.
 boolean crosses(Edge edge)
          Checks whether the given edge crosses this edge.
 boolean equals(java.lang.Object o)
          Checks whether to edges are equal
 java.lang.String getDescription()
          A description of the edge
 Token getFrom()
          Returns the start token of the edge.
 java.lang.String getLabel()
          Returns the label of the edge.
 java.lang.String getLabelWithNote()
          Returns the label with an additional note if available.
 int getLength()
          Returns the distance between the from and to token.
 int getMaxIndex()
          Returns the maximal index of both tokens in this edge.
 int getMinIndex()
          Returns the mimimal index of both tokens in this edge.
 java.lang.String getNote()
          Returns the note that is appended to the label.
 Edge.RenderType getRenderType()
          Returns the render type of this edge.
 Token getTo()
          Returns the end token of the edge.
 java.lang.String getType()
          Returns the type of the edge.
 java.lang.String getTypePostfix()
          If the type of label is "prefix:postfix" this method returns "postfix".
 java.lang.String getTypePrefix()
          If the type of label is qualified with a "qualifier:" prefix this method returns "qualifier".
 int hashCode()
          Returns a hashcode based on type, label, note, from and to token.
 boolean leftOf(Token token)
          Checks whether the edge is to the left of the given token.
 int lexicographicOrder(Edge edge)
          Compares the type and label of this edge and the passed edge.
 boolean overlaps(Edge edge)
          Checks whether this edge overlaps the given edge.
 boolean rightOf(Token token)
          Checks whether the edge is to the right of the given token.
 void setDescription(java.lang.String description)
          Sets the description of this edge
 void setRenderType(Edge.RenderType renderType)
          Sets the render type of this edge.
 boolean strictlyCovers(Edge edge)
          Checks whether the given edge is covered by this edge and at least one token is not aligned.
 java.lang.String toString()
          Returns a string representation of this edge.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Edge

public Edge(Token from,
            Token to,
            java.lang.String label,
            java.lang.String type,
            Edge.RenderType renderType)
Create new edge.

Parameters:
from - from token.
to - to token
label - the label of the edge
type - the type of the edge (say, 'semantic role').
renderType - the render type.

Edge

public Edge(Token from,
            Token to,
            java.lang.String label,
            java.lang.String note,
            java.lang.String type,
            Edge.RenderType renderType)
Create new edge.

Parameters:
from - from token.
to - to token
label - the label of the edge
note - the note to add to the edge
type - the type of the edge (say, 'semantic role').
renderType - the render type.

Edge

public Edge(Token from,
            Token to,
            java.lang.String label,
            java.lang.String note,
            java.lang.String type,
            Edge.RenderType renderType,
            java.lang.String description)
Create new edge.

Parameters:
from - from token.
to - to token
label - the label of the edge
note - the note to add to the edge
type - the type of the edge (say, 'semantic role').
renderType - the render type.
description - a description of the edge.

Edge

public Edge(Token from,
            Token to,
            java.lang.String label,
            java.lang.String type)
Creates a new edge with default render type (dependency).

Parameters:
from - from token.
to - to token.
label - the label of the edge.
type - the type of the edge.
Method Detail

getTypePrefix

public java.lang.String getTypePrefix()
If the type of label is qualified with a "qualifier:" prefix this method returns "qualifier". Else it returns the complete type string.

Returns:
the prefix until ":" of the type string, or the complete type string if no ":" is contained in the string.

getTypePostfix

public java.lang.String getTypePostfix()
If the type of label is "prefix:postfix" this method returns "postfix". Else it returns the empty string.

Returns:
postfix after ":" or empty string if no ":" is contained in the type string.

getDescription

public java.lang.String getDescription()
A description of the edge

Returns:
edge description

getMinIndex

public int getMinIndex()
Returns the mimimal index of both tokens in this edge.

Returns:
the mimimal index of both tokens in this edge.

getMaxIndex

public int getMaxIndex()
Returns the maximal index of both tokens in this edge.

Returns:
the maximal index of both tokens in this edge.

getRenderType

public Edge.RenderType getRenderType()
Returns the render type of this edge. For example, if this edge should be drawn as span it would return Edge.RenderType.span.

Returns:
the render type of this edge.

setRenderType

public void setRenderType(Edge.RenderType renderType)
Sets the render type of this edge. For example, if this edge should be drawn as span it should be Edge.RenderType.span.

Parameters:
renderType - the render type of this edge.

getFrom

public Token getFrom()
Returns the start token of the edge.

Returns:
the start token of the edge.

setDescription

public void setDescription(java.lang.String description)
Sets the description of this edge

Parameters:
description - a text describing this edge.

getTo

public Token getTo()
Returns the end token of the edge.

Returns:
the end token of the edge.

getLabel

public java.lang.String getLabel()
Returns the label of the edge. For example, for a dependency edge this could be "SUBJ".

Returns:
the label of the edge.

getNote

public java.lang.String getNote()
Returns the note that is appended to the label.

Returns:
note to be appended to the label.

getLabelWithNote

public java.lang.String getLabelWithNote()
Returns the label with an additional note if available.

Returns:
label with note in parentheses.

getType

public java.lang.String getType()
Returns the type of the edge. This differs from the render type. For example, we can represent semantic and syntactic dependencies both using the dependency render type. However, the first one could have the edge type "semantic" and the second one "syntactic".

Returns:
the type of the edge.

lexicographicOrder

public int lexicographicOrder(Edge edge)
Compares the type and label of this edge and the passed edge.

Parameters:
edge - the edge to compare to.
Returns:
an integer indicating the lexicographic order of this edge and the given edge.

leftOf

public boolean leftOf(Token token)
Checks whether the edge is to the left of the given token.

Parameters:
token - the token to compare to
Returns:
true iff both tokens of this edge are to the left of the given token.

rightOf

public boolean rightOf(Token token)
Checks whether the edge is to the right of the given token.

Parameters:
token - the token to compare to
Returns:
true iff both tokens of this edge are to the right of the given token.

getLength

public int getLength()
Returns the distance between the from and to token.

Returns:
the distance between the from and to token.

covers

public boolean covers(Edge edge)
Check whether this edge completely covers the specified edge.

Parameters:
edge - the edge to check whether it is covered by this edge.
Returns:
true iff the given edge is completely covered by this edge.

coversExactly

public boolean coversExactly(Edge edge)
Check whether this edge spans the same sequence of tokens as the given edge.

Parameters:
edge - the edge to compare with.
Returns:
true iff this edge covers the same sequence of tokens as the given edge.

coversSemi

public boolean coversSemi(Edge edge)
Checks whether this edge covers the given edge and is aligned with it on one side.

Parameters:
edge - the edge to compare with.
Returns:
true iff this edge covers the given edge and exactly one of their tokens are equal.

overlaps

public boolean overlaps(Edge edge)
Checks whether this edge overlaps the given edge.

Parameters:
edge - the edge to compare with.
Returns:
true iff the edges overlapn.

strictlyCovers

public boolean strictlyCovers(Edge edge)
Checks whether the given edge is covered by this edge and at least one token is not aligned.

Parameters:
edge - the edge to compare with.
Returns:
true if this edge covers the given edge and at least one token is not aligned.

toString

public java.lang.String toString()
Returns a string representation of this edge.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this edge that shows label, type and the indices of the start and end tokens.

crosses

public boolean crosses(Edge edge)
Checks whether the given edge crosses this edge.

Parameters:
edge - the edge to compare to.
Returns:
true iff this edge crosses the given edge.

equals

public boolean equals(java.lang.Object o)
Checks whether to edges are equal

Overrides:
equals in class java.lang.Object
Parameters:
o - the other edge
Returns:
true if both edges have the same type, label, note and the same from and to tokens.

hashCode

public int hashCode()
Returns a hashcode based on type, label, note, from and to token.

Overrides:
hashCode in class java.lang.Object
Returns:
a hashcode based on type, label, note, from and to token.


Copyright © 2010. All Rights Reserved.