|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectmyShell.Interpreter
public class Interpreter
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).
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 |
---|
private MediaBase mediaBase
MediaBase
in which the names and other characteristics of the media sorted are stored.
private java.lang.Integer numberOfMedia
Constructor Detail |
---|
public Interpreter(MediaBase database)
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.
database
- The MediaBase instance to be aggregated to the Interpreter.Method Detail |
---|
public static java.util.Map<java.lang.String,java.lang.String> getConfig()
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).
public static java.util.List<java.lang.String> getAxes()
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.
public static java.util.List<java.lang.String> getFields(java.lang.String fields)
What is returned depends on the value of the parameter fields. If it equals :
fields
- The name of the field to retrieve. It must have one of these values : "SQLfield",
"CSVfield" or "SQLtype"
public static java.lang.Boolean checkFile(LogWriter log)
This function verifies if the configuration file contains :
log
- The LogWriter instance where the results are saved.
public static java.lang.Integer getLastJob()
public static void setLastJob(java.lang.Integer id)
id
- The identifier of the job to save.private java.util.List<java.lang.Integer[]> parsePrevious(java.lang.String 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.
axis
- The axis from which we want to retrieve the results.
public java.util.List<java.lang.Integer[]> getCurrentState(LogWriter log, java.lang.String axis)
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.
log
- The LogWriter instance in which save the advancement.axis
- The axis from which we want to retrieve the results.
public void generateIntermediaryXMLs(java.lang.String xmlFile, java.util.List<java.lang.Integer[]> content)
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.
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] }.private java.lang.Double rank2value(java.lang.Integer rank)
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.
rank
- The rank of the media along an 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)
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.
sortResults
- The map to modify. Its structure is :
{axis considered, [order of the media along this axis]}.
Interpreter.#generateFinalXML(String, Map)
public java.lang.String generateFinalXML(java.lang.String xmlFile, java.util.Map<java.lang.String,java.lang.Integer[]> sortResults)
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>
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"].
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |