edu.umd.cloud9.webgraph.data
Class AnchorText

java.lang.Object
  extended by edu.umd.cloud9.webgraph.data.AnchorText
All Implemented Interfaces:
AnchorTextConstants, Comparable<AnchorText>, Iterable<Integer>, Writable, WritableComparable<AnchorText>

public class AnchorText
extends Object
implements WritableComparable<AnchorText>, AnchorTextConstants, Iterable<Integer>

This data structure represents a line of anchor text. A line of anchor text has some text, a weight, and a set of sources (targets) associated with it. Sources (targets) are the pages a line of anchor text originates from (points to) when the underlying link is an incoming (outgoing) link.

The implemented iterator makes it possible to iterate through the source or target documents for each line of anchor text.

Author:
Nima Asadi

Nested Class Summary
 
Nested classes/interfaces inherited from interface edu.umd.cloud9.webgraph.data.AnchorTextConstants
AnchorTextConstants.Type
 
Field Summary
 
Fields inherited from interface edu.umd.cloud9.webgraph.data.AnchorTextConstants
EMPTY_STRING, MAXIMUM_SOURCES_PER_PACKET
 
Constructor Summary
AnchorText()
          Creates an empty Internal Incoming Link AnchorText object
AnchorText(byte type, String text)
          Creates a new AnchorText object
AnchorText(byte type, String text, int docno)
          Creates a new AnchorText object and adds a new source/target document if the AnchorText object is allowed to have text.
 
Method Summary
 void addDocument(int docno)
          Adds a new source/target to this anchor text.
 void addDocumentsFrom(AnchorText other)
          Adds the sources/targets from another AnchorText to the current object
 AnchorText clone()
          Clones (deep copies) this object and returns a new AnchorText object.
 int compareTo(AnchorText obj)
          For sorting purposes, the comparison is only limited to the type and the text of two AnchorText objects.
 boolean containsDocument(int docno)
          Checks whether a document is a source or a target for this anchor text
 boolean equals(Object obj)
          Does a thorough comparison of two AnchorText objects.
 boolean equalsIgnoreSources(AnchorText other)
          Checks whether two lines of anchor text are equal, regardless of their source/target lists.
 int[] getDocuments()
          Returns a list of all the sources/targets
 int getSize()
           
 String getText()
           
 byte getType()
           
 float getWeight()
           
 int hashCode()
           
 boolean intersects(AnchorText other)
          Checks whether two lines of anchor text share a source/target document
 boolean isDocnoField()
           
 boolean isExternalInLink()
           
 boolean isExternalOutLink()
           
 boolean isInDegree()
           
 boolean isInternalInLink()
           
 boolean isInternalOutLink()
           
 boolean isOfOtherTypes()
           
 boolean isOutDegree()
           
 boolean isURL()
           
 boolean isWeighted()
           
 Iterator<Integer> iterator()
          Creates a new iterator for the current object.
 void readFields(DataInput in)
          Deserializes an AnchorText object.
 void resetToType(byte type)
          Clears this object and initializes the type
 void setText(String text)
          Sets the text for this line of anchor text
 void setWeight(float weight)
          Sets a new weight for this line of anchor text and changes the type to "weighted"
 String toString()
           
 void write(DataOutput out)
          Serializes an AnchorText object
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AnchorText

public AnchorText()
Creates an empty Internal Incoming Link AnchorText object


AnchorText

public AnchorText(byte type,
                  String text)
Creates a new AnchorText object

Parameters:
type - Internal or external, incoming or outgoing, etc. (Use AnchorTextConstants interface)
text - Text associated with a line of anchor text

AnchorText

public AnchorText(byte type,
                  String text,
                  int docno)
Creates a new AnchorText object and adds a new source/target document if the AnchorText object is allowed to have text. (Please refer to AnchorTextConstants interface)

Parameters:
type - Internal or external, incoming or outgoing, etc. (Use AnchorTextConstants interface)
text - Text associated with a line of anchor text
docno - Source/Target document id
Method Detail

readFields

public void readFields(DataInput in)
                throws IOException
Deserializes an AnchorText object.

Specified by:
readFields in interface Writable
Parameters:
in - Input Stream
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException
Serializes an AnchorText object

Specified by:
write in interface Writable
Parameters:
out - Output Stream
Throws:
IOException

getType

public byte getType()
Returns:
the type of this AnchorText

resetToType

public void resetToType(byte type)
Clears this object and initializes the type

Parameters:
type - New type

getText

public String getText()
Returns:
the text of this line of anchor text. Null if the AnchorText object does not have any text associated with it.

setText

public void setText(String text)
Sets the text for this line of anchor text

Parameters:
text - New text for this anchor text

getWeight

public float getWeight()
Returns:
the weight for this anchor text

setWeight

public void setWeight(float weight)
Sets a new weight for this line of anchor text and changes the type to "weighted"

Parameters:
weight - New weight

getSize

public int getSize()
Returns:
the cardinality of the set of sources/targets

getDocuments

public int[] getDocuments()
Returns a list of all the sources/targets

Returns:
An array of ints that contains all the sources/targets of the current object

addDocument

public void addDocument(int docno)
Adds a new source/target to this anchor text.

Parameters:
docno - The new document id to be added to the source/target list

addDocumentsFrom

public void addDocumentsFrom(AnchorText other)
Adds the sources/targets from another AnchorText to the current object

Parameters:
other - The other AnchorText object from which the sources/targets are to be copied.

containsDocument

public boolean containsDocument(int docno)
Checks whether a document is a source or a target for this anchor text

Parameters:
docno - Document to be checked
Returns:
True if the document is a source/target of this anchor text

intersects

public boolean intersects(AnchorText other)
Checks whether two lines of anchor text share a source/target document

Parameters:
other - The other anchor text
Returns:
True if this line of anchor text has a common source/target with the other line of anchor text.

equalsIgnoreSources

public boolean equalsIgnoreSources(AnchorText other)
Checks whether two lines of anchor text are equal, regardless of their source/target lists.

Parameters:
other - The other anchor text to check against.
Returns:
True if the text fields, weights, and types of two AnchorText objects are equal, regardless of their source/targets lists.

equals

public boolean equals(Object obj)
Does a thorough comparison of two AnchorText objects.

Overrides:
equals in class Object

compareTo

public int compareTo(AnchorText obj)
For sorting purposes, the comparison is only limited to the type and the text of two AnchorText objects. To check complete equality of the objects use the equals method.

Specified by:
compareTo in interface Comparable<AnchorText>

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

clone

public AnchorText clone()
Clones (deep copies) this object and returns a new AnchorText object.

Overrides:
clone in class Object
Returns:
A new AnchorText object that is a copy of the current object.

isExternalInLink

public boolean isExternalInLink()
Returns:
True if the current object is any type of external incoming link (i.e., Weighted, non-weighted, etc.).

isInternalInLink

public boolean isInternalInLink()
Returns:
True if the current object is any type of internal incoming link.

isExternalOutLink

public boolean isExternalOutLink()
Returns:
True if the current object is any type of external outgoing link.

isInternalOutLink

public boolean isInternalOutLink()
Returns:
True if the current object is any type of internal outgoing link.

isWeighted

public boolean isWeighted()
Returns:
True if the current line of anchor text has a weight associated with it.

isInDegree

public boolean isInDegree()
Returns:
True if the current object is a special type of AnchorText (i.e., is not a real line of anchor text) - InDegree

isOutDegree

public boolean isOutDegree()
Returns:
True if the current object is a special type of AnchorText (i.e., is not a real line of anchor text) - OutDegree

isDocnoField

public boolean isDocnoField()
Returns:
True if the current object is a special type of AnchorText (i.e., is not a real line of anchor text) - Holds document number

isURL

public boolean isURL()
Returns:
True if the current object is a special type of AnchorText (i.e., is not a real line of anchor text) - Holds a URL address

isOfOtherTypes

public boolean isOfOtherTypes()
Returns:
True if the current object is a special type of AnchorText (i.e., is not a real line of anchor text) - Any other types of AnchorText

iterator

public Iterator<Integer> iterator()
Creates a new iterator for the current object. The iterator can be used to iterate through the list of sources/targets associated with the current line of anchor text.

Specified by:
iterator in interface Iterable<Integer>
Returns:
A new iterator object.