myShell
Class Interpreter

java.lang.Object
  extended by myShell.Interpreter

public class Interpreter
extends java.lang.Object

Deals with several xml files, either reading or writing them.

This class reads the configuration file config.xml to retrieve the constants used in this program, as well as the axes along which comparisons must be performed and the structure of the information used (i.e : fields of the hit table and their matching elements in the csv file retrieved from the Antechamber).

It also writes intermediary results in order for the splitsort to continue where it stopped as well as final results (those you want if you are using this software).

Author:
Leo Perrin (perrin.leo@gmail.com)

Field Summary
private  MediaBase mediaBase
          The MediaBase in which the names and other characteristics of the media sorted are stored.
private  java.lang.Integer numberOfMedia
          The number of media sorted.
 
Constructor Summary
Interpreter(MediaBase database)
          Creates an Interpreter instance.
 
Method Summary
static java.lang.Boolean checkFile(LogWriter log)
          Checks if the config.xml file contains all the fields necessary for CPS to work.
 java.lang.String generateFinalXML(java.lang.String xmlFile, java.util.Map<java.lang.String,java.lang.Integer[]> sortResults)
          Writes an xml file containing the position of each media along each axis as well as all their characteristics stored in the dbMedia; returns also the content of this file in a String for further treatment.
 void generateIntermediaryXMLs(java.lang.String xmlFile, java.util.List<java.lang.Integer[]> content)
          Generates an xml file containing the current state of the splitsort.
static java.util.List<java.lang.String> getAxes()
          Returns a List of String containing the axes considered during the comparisons.
static java.util.Map<java.lang.String,java.lang.String> getConfig()
          Reads the value of several parameters in the "..
 java.util.List<java.lang.Integer[]> getCurrentState(LogWriter log, java.lang.String axis)
          Returns the current state of the SplitSort along the axis axis if there is a file containing it in ..
static java.util.List<java.lang.String> getFields(java.lang.String fields)
          Returns a List of String containing the names of the fields used to retrieve hard data from the HIT results file.
static java.lang.Integer getLastJob()
          Returns the Integer saved in the '..
private  java.util.List<java.lang.Integer[]> parsePrevious(java.lang.String axis)
          Parses the xml file containing the current state of the sort along the axis axis.
private  java.util.List<java.util.Map<java.lang.String,java.lang.Integer>> preformating(java.util.Map<java.lang.String,java.lang.Integer[]> sortResults)
          Transforms the map firstMap into a List in order it to be used by the generateFinalXML() method.
private  java.lang.Double rank2value(java.lang.Integer rank)
          Transforms a rank among the other media into a real value along an axis.
static void setLastJob(java.lang.Integer id)
          Saves a job identifier in the '..
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mediaBase

private MediaBase mediaBase
The MediaBase in which the names and other characteristics of the media sorted are stored.


numberOfMedia

private java.lang.Integer numberOfMedia
The number of media sorted.

Constructor Detail

Interpreter

public Interpreter(MediaBase database)
Creates an Interpreter instance.

This instance will use the MediaBase MediaBase to get (among other tings) the names of the media. It also parses previous results in order to know how much media are to be sorted this time.

Parameters:
database - The MediaBase instance to be aggregated to the Interpreter.
Method Detail

getConfig

public static java.util.Map<java.lang.String,java.lang.String> getConfig()
Reads the value of several parameters in the "../data/config.xml" file.

This method reads the content of the "constants" node of the config.xml file. It should contain all the constants used by CPS, such as the path to file where media are stored the login used to connect with the database.

The results are stored in a map : each parameter is in the field which key is its identifier (for example, result["mediaPath"] = "../data/media.xml" (default).


getAxes

public static java.util.List<java.lang.String> getAxes()
Returns a List of String containing the axes considered during the comparisons.

Returns all the children of the "axes" node of the config.xml file whose name is "axis". They correspond to the axes along which the sorting is to be performed.

Returns:
A list of String, each String being an axis.

getFields

public static java.util.List<java.lang.String> getFields(java.lang.String fields)
Returns a List of String containing the names of the fields used to retrieve hard data from the HIT results file.

What is returned depends on the value of the parameter fields. If it equals :

Parameters:
fields - The name of the field to retrieve. It must have one of these values : "SQLfield", "CSVfield" or "SQLtype"
Returns:
The list of the fields wanted.

checkFile

public static java.lang.Boolean checkFile(LogWriter log)
Checks if the config.xml file contains all the fields necessary for CPS to work.

This function verifies if the configuration file contains :

Parameters:
log - The LogWriter instance where the results are saved.
Returns:
true if everything is fine in the config.xml file, false otherwise.

getLastJob

public static java.lang.Integer getLastJob()
Returns the Integer saved in the '../data/previously/lastJob' file.

Returns:
The identifier of the last job used.

setLastJob

public static void setLastJob(java.lang.Integer id)
Saves a job identifier in the '../data/previously/lastJob' file.

Parameters:
id - The identifier of the job to save.

parsePrevious

private java.util.List<java.lang.Integer[]> parsePrevious(java.lang.String axis)
Parses the xml file containing the current state of the sort along the axis axis.

Reads the '../data/previously/$AXIS.xml' file and returns its content. This file should be formatted so as to contain a list of arrays of Integer.

Parameters:
axis - The axis from which we want to retrieve the results.
Returns:
The state of the splitsort along this axis.

getCurrentState

public java.util.List<java.lang.Integer[]> getCurrentState(LogWriter log,
                                                           java.lang.String axis)
Returns the current state of the SplitSort along the axis axis if there is a file containing it in ../data/previously, otherwise returns the result of getAllMedia().

This function checks if an axis.xml file in the ../data/previously/ directory exists. If so, it parses its content and returns it in a list of arrays. Each element of this list is an array waiting for a splitsort iteration (or not, if its size is too small).

If there is no such file, it calls mediaBase.getAllMedia() in order to get a new list of the media to sort.

Parameters:
log - The LogWriter instance in which save the advancement.
axis - The axis from which we want to retrieve the results.
Returns:
The state of the media along the axis at the end of the previous iteration or, in its absence, all media's Id.

generateIntermediaryXMLs

public void generateIntermediaryXMLs(java.lang.String xmlFile,
                                     java.util.List<java.lang.Integer[]> content)
Generates an xml file containing the current state of the splitsort.

Generates a file formatted so as to store the content of a list of array. The aim is for this file to be used as a starting point in a next splitsort iteration by the getCurrentState() method.

Parameters:
xmlFile - The file in which the current state of an axis is being saved right now.
content - The organization of the media along a given axis during the current iteration. For instance, if there are three arrays at the end of this iteration along the axis axis, it must contain the following entry : { [2,1,3],[4],[7,6,5] }.

rank2value

private java.lang.Double rank2value(java.lang.Integer rank)
Transforms a rank among the other media into a real value along an axis.

In this case, we assume that the media follow a uniform distribution in [-1,1], therefore the abscissa is given by: \f${ {2 \times rank} \over {numberOfMedia - 1} } - 1\f$ The first media, at the 0thth rank, will have -1 as abscissa and the last one, at the (numberOfMedia - 1)th rank, will have 1.

Parameters:
rank - The rank of the media along an axis
Returns:
The value corresponding to this rank.

preformating

private java.util.List<java.util.Map<java.lang.String,java.lang.Integer>> preformating(java.util.Map<java.lang.String,java.lang.Integer[]> sortResults)
Transforms the map firstMap into a List in order it to be used by the generateFinalXML() method.

The Map of Arrays returned by the last loop of the main function has a structure that is not suited for writing with a correct formatting in the results.xml file. Therefore, this method returns a List of Map that is suited for such a writing. The structure of the input and output is explained below.

Parameters:
sortResults - The map to modify. Its structure is : {axis considered, [order of the media along this axis]}.
Returns:
A list of map corresponding to the input map of arrays. Its structure is : [ {axis,rank along this axis of the media whose ID is its rank in the list of map}... ]
See Also:
Interpreter.#generateFinalXML(String, Map)

generateFinalXML

public java.lang.String generateFinalXML(java.lang.String xmlFile,
                                         java.util.Map<java.lang.String,java.lang.Integer[]> sortResults)
Writes an xml file containing the position of each media along each axis as well as all their characteristics stored in the dbMedia; returns also the content of this file in a String for further treatment.

The results.xml file has the following structure :

< sorted >< media >< characteristic >a first characteristic< /characteristic > < othercharac >a second characteristic< /othercharac >< axis >abscissa along this axis< /axis > < otherAxis >abscissa along this other axis< /otherAxis >< /media >...< /sorted>

Parameters:
xmlFile - The path where the xml file will be written.
sortResults - The results to be written in the xml file. It must have the following structure: [ "axis considered", "order of the media along this axis"].
Returns:
An XML formatted String which is identical to what is written in the file.