📄 jobinstructionshandler.java
字号:
* Handles the lattice element events.
*/
private class LatticeHandler extends ElementHandler
{
/**
* Start of an element.
*/
public void startElement (String namespaceURI,String name,String qName,Attributes atts) throws SAXException
{
if(init)
{
if(atts.getValue(0).toLowerCase().equals("rectangular"))
{
lattice = "rect";
}
else
{
lattice = "hexa";
}
}
}
}
/*********************************************************************************/
/*
* Handles the neighbourhood element events.
*/
private class NeighbourhoodHandler extends ElementHandler
{
/**
* Start of an element.
*/
public void startElement (String namespaceURI,String name,String qName,Attributes atts) throws SAXException
{
if(init)
{
if(atts.getValue(0).toLowerCase().equals("gaussian"))
{
neighbourhood = "gaussian";
}
else
{
neighbourhood = "step";
}
}
}
}
/*********************************************************************************/
/*
* Handles the training element events.
*/
private class TrainingHandler extends ElementHandler
{
/**
* Start of an element.
*/
public void startElement (String namespaceURI,String name,String qName,Attributes atts) throws SAXException
{
training = true;
job = new JSomTraining(reference,inputVectors);
}
/**
* End of an element.
*/
public void endElement (String uri,String name,String qName) throws SAXException
{
training = false;
job.setTrainingInstructions(steps,lrate,radius,lrateType,neighbourhood);
reference = job.doTraining();
}
}
/*********************************************************************************/
/*
* Handles the steps element events.
*/
private class StepsHandler extends ElementHandler
{
/**
* Character data.
*/
public void characters (char[] chars,int start,int len) throws SAXException
{
if(training)
{
try
{
steps = (Integer.valueOf(String.valueOf(chars,start,len).toLowerCase())).intValue();
}
catch(NumberFormatException nfe)
{
System.out.println(nfe.getMessage());
}
}
}
}
/*********************************************************************************/
/*
* Handles the Lrate element events.
*/
private class LrateHandler extends ElementHandler
{
/**
* Start of an element.
*/
public void startElement (String namespaceURI,String name,String qName,Attributes atts) throws SAXException
{
if(training)
{
if(atts.getValue(0).toLowerCase().equals("exponential"))
{
lrateType = "exponential";
}
else if(atts.getValue(0).toLowerCase().equals("linear"))
{
lrateType = "linear";
}
else
{
lrateType = "inverse";
}
}
}
/**
* Character data.
*/
public void characters (char[] chars,int start,int len) throws SAXException
{
if(training)
{
try
{
lrate = (Double.valueOf(String.valueOf(chars,start,len).toLowerCase())).doubleValue();
}
catch(NumberFormatException nfe)
{
System.out.println(nfe.getMessage());
}
}
}
}
/*********************************************************************************/
/*
* Handles the radius element events.
*/
private class RadiusHandler extends ElementHandler
{
/**
* Character data.
*/
public void characters (char[] chars,int start,int len) throws SAXException
{
if(training)
{
try
{
radius = (Integer.valueOf(String.valueOf(chars,start,len).toLowerCase())).intValue();
}
catch(NumberFormatException nfe)
{
System.out.println(nfe.getMessage());
}
}
}
}
/*********************************************************************************/
/*
* Handles the output element events.
*/
private class OutputHandler extends ElementHandler
{
/**
* Start of an element.
*/
public void startElement (String namespaceURI,String name,String qName,Attributes atts) throws SAXException
{
output = true;
for(int i=0;i<atts.getLength();i++)
{
if(atts.getLocalName(i).toLowerCase().equals("paper"))
{
paper = atts.getValue(i).toLowerCase().trim();
if(paper.equals("a4") || paper.equals("letter"))
{
//left empty purposely
}
else
{
paper = "a4";
}
}
else //orientation
{
orientation = atts.getValue(i).toLowerCase().trim();
if(orientation.equals("portrait") || orientation.equals("landscape"))
{
//left empty purposely
}
else
{
orientation = "landscape";
}
}
}
//labels the weight vectors
labels = new JSomLabeling(reference,inputVectors);
reference = labels.doLabeling();
}
/**
* End of an element.
*/
public void endElement (String uri,String name,String qName) throws SAXException
{
output = false;
/* Create a DOM tree of the generated map */
JSomCreateDomTree domino = new JSomCreateDomTree(reference,map,30.0);
/* Output */
JSomMapOutput gogo = new JSomMapOutput(folder,domino,paper,orientation,map);
if(xml)
{
gogo.outputMap("xml",fileName);
}
if(svg)
{
gogo.outputMap("svg",fileName);
}
if(pdf)
{
gogo.outputMap("pdf",fileName);
}
}
}
/*********************************************************************************/
/*
* Handles the folder element events.
*/
private class FolderHandler extends ElementHandler
{
/**
* Character data.
*/
public void characters (char[] chars,int start,int len) throws SAXException
{
File cache = new File(String.valueOf(chars,start,len));
if(cache.isDirectory())
{
if(output)
{
try
{
folder = cache;
}
catch(NullPointerException npe)
{
System.out.println(npe.getMessage());
}
}
}
else
{
System.out.println("Output path is not a folder !");
}
}
}
/*********************************************************************************/
/*
* Handles the identifier element events.
*/
private class IdentifierHandler extends ElementHandler
{
/**
* Character data.
*/
public void characters (char[] chars,int start,int len) throws SAXException
{
if(output)
{
fileName = String.valueOf(chars,start,len);
}
}
}
/*********************************************************************************/
/*
* Handles the output format type element events.
*/
private class TypeHandler extends ElementHandler
{
/**
* Start of an element.
*/
public void startElement (String namespaceURI,String name,String qName,Attributes atts) throws SAXException
{
if(output)
{
if(atts.getValue(0).toLowerCase().equals("xml"))
{
xml = true;
}
if(atts.getValue(0).toLowerCase().equals("svg"))
{
svg = true;
}
if(atts.getValue(0).toLowerCase().equals("pdf"))
{
pdf = true;
}
}
}
}
/*********************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -