it.unipi.di.graph
Class GraphLabeler

java.lang.Object
  extended by it.unipi.di.graph.GraphLabeler

public class GraphLabeler
extends Object

A graph labeler for vertices and edges. The graph is represented as a list of N vertices identified by integers in the range [0, N-1] and a list of edges identified by the two vertices they connect. Each vertex can be associated with a textual label, and each edge can be associated with one or more textual attributes, each identified by a unique name. This class offers access to these informations by means of a GraphLabelerConfig object, which defines how the labels and the attribute values are stored on disk. Concrete access to these data is implemented by means of the TextDB interface.

We note that the structure of the graph, namely its vertices and edges, is not stored in this class.

Author:
Claudio Corsi, Paolo Ferragina
See Also:
GraphLabelerConfig, TextDB

Constructor Summary
GraphLabeler(GraphLabelerConfig conf)
          Create a new GraphLabeler using the provided configuration.
 
Method Summary
 void close()
          Closes the labeler and releases all the resources associated to it.
 GraphLabelerConfig getConfig()
          Returns the current configuration.
 String getEdgeAttribute(int v, int rank, String attribute)
          Returns the attribute value of an edge.
 String[] getOutgoingAttribute(int vertex, String attribute)
          Returns the attribute values defined for the outgoing edges starting from a vertex.
 String getVertexLabel(int v)
          Returns the label associated to the input vertex, or null if the label is not defined.
 String[] getVertexLabels(int[] vertices)
          Returns the labels for a sorted list of vertices.
 String[] getVertexLabels(int[] vertices, int offset, int length)
          Returns the labels for a sorted list of vertices.
 String[] getVertexLabels(int i, int j)
          Returns the labels for the vertices in range [i, j] (bounds included).
 String getVertexType(int v)
          Returns a String object identifying the type of a vertex.
static GraphLabeler load(String confFile)
          Create a new GraphLabeler loading its configuration from a textual file.
static void main(String[] args)
           
 String[] splitAttributeValues(String attribute, String sep)
          Given a multi-value attribute, this method returns its individual values in an array of strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphLabeler

public GraphLabeler(GraphLabelerConfig conf)
             throws IOException
Create a new GraphLabeler using the provided configuration.

Parameters:
conf - the configuration defining the data sources.
Throws:
IOException
Method Detail

load

public static GraphLabeler load(String confFile)
                         throws IOException
Create a new GraphLabeler loading its configuration from a textual file.

Parameters:
confFile - the name of the configuration file
Returns:
a new GraphLabeler object
Throws:
IOException
See Also:
GraphLabelerConfig.load(String)

getConfig

public GraphLabelerConfig getConfig()
Returns the current configuration.

Returns:
the current graph configuration.

close

public void close()
           throws IOException
Closes the labeler and releases all the resources associated to it.

Throws:
IOException

getVertexLabel

public String getVertexLabel(int v)
                      throws IOException
Returns the label associated to the input vertex, or null if the label is not defined.

Parameters:
v - vertex id.
Returns:
the label for the requested vertex.
Throws:
IOException - if some I/O error occur.
ArrayIndexOutOfBoundsException - if the requested vertex is outside the current configuration.

getVertexLabels

public String[] getVertexLabels(int i,
                                int j)
                         throws IOException
Returns the labels for the vertices in range [i, j] (bounds included). The returned array will has the same length of the passed range. The array will contains null references for vertices not defined in this labeler. The requested range must be positive with a lower bound greater or equals than zero and an upper bound no bigger than the defined maximum position for this labeler. The bounds are checked by this method and an ArrayIndexOutOfBoundsException will be thrown in case the bounds doesn't respect such limits.

Parameters:
i - the lower bound of the range.
j - the upper bound of the range.
Returns:
the labels for the vertices in range [i, j].
Throws:
IOException - if some I/O errors occur.
ArrayIndexOutOfBoundsException - in case the requested ids are out of the bounds defined in the current configuration.
See Also:
GraphLabelerConfig.getSpanningRange()

getVertexLabels

public String[] getVertexLabels(int[] vertices)
                         throws IOException
Returns the labels for a sorted list of vertices.

Parameters:
vertices - sorted list of vertex ids.
Returns:
the labels for those vertices.
Throws:
IOException - if some I/O errors occur.
ArrayIndexOutOfBoundsException - in case the requested ids are out of the bounds defined in the current configuration.

getVertexLabels

public String[] getVertexLabels(int[] vertices,
                                int offset,
                                int length)
                         throws IOException
Returns the labels for a sorted list of vertices. The passed array is considered from position offset to length-1. A ArrayIndexOutOfBoundsException will be thrown if the input vertex ids are out of the bounds of the current configuration.
The returned array of StringS will contains exactly length references. Null references are used in case no labels are defined for the corresponding requested vertex.

Parameters:
vertices - sorted list of vertex ids (at least in the positions from 0 to length).
offset - the starting position of the input array.
length - the number of positions to consider in the passed array starting from 0. Must be non negative.
Returns:
the labels for those vertices.
Throws:
IOException - if some I/O errors occur.
ArrayIndexOutOfBoundsException - in case the requested ids are out of the bounds defined in the current configuration.
See Also:
GraphLabelerConfig.getSpanningRange()

getVertexType

public String getVertexType(int v)
                     throws IOException
Returns a String object identifying the type of a vertex. Vertices of the same type will returns the same String object (i.e. String objects resulting equal respect the "equals()" method).

The TextDB storing the vertex label determines the type of the vertex. Two vertices with labels stored into the same TextDB will result of the same type.

Parameters:
v - a vertex ID
Returns:
a String representing the vertex type or null if the vertex is not labeled
Throws:
IOException
See Also:
TextDB.getName()

getEdgeAttribute

public String getEdgeAttribute(int v,
                               int rank,
                               String attribute)
                        throws IOException
Returns the attribute value of an edge. The edge is defined by means of the pair (v, rank) where v is the source vertex of the edge and rank is the cardinal position of the target vertex of this edge among the neighbors of v (counting from 0). For instance, if v has neighbors u,w,z, then (v,2) identifies (v,z). A null value is returned in case the pair (v,rank) does not define any edge.

Parameters:
v - source vertex of the edge
rank - the rank of the target node defining the edge among the neighbors of v
attribute - the attribute name
Returns:
the value for the requested attribute of a given edge
Throws:
IOException
See Also:
getOutgoingAttribute(int, String)

getOutgoingAttribute

public String[] getOutgoingAttribute(int vertex,
                                     String attribute)
                              throws IOException
Returns the attribute values defined for the outgoing edges starting from a vertex. That values will be returned ordered accordingly to the adjacency list of the vertex.

Parameters:
vertex - the starting vertex
attribute - the name of the attribute to extract from the outgoing edges
Returns:
the attribute values for all the outgoing edges
Throws:
IOException

splitAttributeValues

public String[] splitAttributeValues(String attribute,
                                     String sep)
Given a multi-value attribute, this method returns its individual values in an array of strings.

This implementation is based on the method TextDB.getFieldValues(String, String).

Parameters:
attribute - the attribute to be parsed
sep - the character-sequence used to separate the values in the input attribute
Returns:
the array of values

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception