📄 miningalgorithmspecification.java
字号:
return true;
};
};
return false;
}
// -----------------------------------------------------------------------
// Various import and export methods
// -----------------------------------------------------------------------
/**
* Returns mining algorithm specification for a specified algorithm.
* This is realized via the file 'algorithms.xml'.
*
* @param applicationName name of the algorithm specified by the XML element
* AlgorithmSpecification of the algorithms.xml document
* @param operatorinfo informatio of this operator
* @return mining algorithm specification of the specified algorithm, null if not found
* @exception MiningException exception if cannot read algorithms.xml
* @throws IOException
*/
public static MiningAlgorithmSpecification getMiningAlgorithmSpecification( String applicationName ,INodeInfo nodeinfo) throws MiningException
{
MiningAlgorithms algorithms = null;
try {
algorithmsFileURL = SysConfig.getAlgorithmURL(nodeinfo);
if (algorithmsFileURL!=null)
{
InputStream in = algorithmsFileURL.openStream();
algorithms = MiningAlgorithms.unmarshal(in);
in.close();
}else
{
throw new MiningException( "algorithms file path is undefined.");
}
}
catch( Exception ex )
{
if(nodeinfo==null||nodeinfo.getJafFile()==null) {
throw new MiningException( "Can't read algorithms descriptions: "+ algorithmsFileURL.getFile());
}
else {
try {
algorithmsFileURL = SysConfig.getAlgorithmURL(null);
if (algorithmsFileURL!=null)
{
InputStream in = algorithmsFileURL.openStream();
algorithms = MiningAlgorithms.unmarshal(in);
in.close();
}else
{
throw new MiningException( "algorithms file path is undefined.");
}
}
catch( Exception ex1 )
{
throw new MiningException( "Can't read algorithms descriptions: "+ algorithmsFileURL.getFile());
}
}
}
AlgorithmSpecification algorithmSpecification = null;
MiningAlgorithmSpecification inputSpecification = null;
if( algorithms!=null && algorithms.isValid() )
{
int count = algorithms.getAlgorithmSpecificationCount();
for(int i = 0; i < count; i++)
{
algorithmSpecification = algorithms.getAlgorithmSpecification( i );
if( algorithmSpecification!=null && algorithmSpecification.getName().equalsIgnoreCase( applicationName ) )
{
inputSpecification = new MiningAlgorithmSpecification();
inputSpecification.setName( algorithmSpecification.getName() );
inputSpecification.setFunction( algorithmSpecification.getFunction() );
inputSpecification.setAlgorithm( algorithmSpecification.getAlgorithm() );
inputSpecification.setClassname( algorithmSpecification.getClassname() );
inputSpecification.setVersion( algorithmSpecification.getVersion() );
inputSpecification.setDescription( algorithmSpecification.getDescription() );
int parameterCount = algorithmSpecification.getAlgorithmParameterCount();
MiningAlgorithmParameter[] attributes = new MiningAlgorithmParameter[parameterCount];
for(int j = 0; j < parameterCount; j++)
{
AlgorithmParameter parameter = algorithmSpecification.getAlgorithmParameter( j );
attributes[j] = new MiningAlgorithmParameter();
attributes[j].setName( parameter.getName() );
attributes[j].setType( parameter.getType() );
attributes[j].setValue( parameter.getValue() );
attributes[j].setMethod( parameter.getMethod() );
attributes[j].setDescr( parameter.getDescr() );
attributes[j].setInputSpec( inputSpecification );
}
inputSpecification.setInputAttribute( attributes );
break;
}
}
}
else
{
throw new MiningException( "Not valid algorithms specification XML document." );
}
return inputSpecification;
}
/**
* Returns the names of all mining algorithms contained in the
* 'algorithms.xml' document.
*
* @return names of all algorithms (elements AlgorithmsSpecification)
* contained in algoritms.xml
* @exception MiningException exception if cannot read algorithms.xml
*/
public static String[] getMiningAlgorithms() throws MiningException
{
String[] algorithm = null;
MiningAlgorithms algorithms = null;
try
{
InputStream in = algorithmsFileURL.openStream();
algorithms = MiningAlgorithms.unmarshal(in);
in.close();
}
catch( IOException ex )
{
throw new MiningException( "Can't read algorithms descriptions." );
}
AlgorithmSpecification algorithmSpecification = null;
if( algorithms.isValid() )
{
int count = algorithms.getAlgorithmSpecificationCount();
algorithm = new String[count];
for(int i = 0; i < count; i++)
{
algorithmSpecification = algorithms.getAlgorithmSpecification( i );
algorithm[i] = algorithmSpecification.getName();
}
}
else
{
throw new MiningException( "Not valid PMML document." );
}
return algorithm;
}
/**
* Returns the names of all mining algorithms for a given mining function
* contained in the 'algorithms.xml' document.
*
* @param function mining function the algorithms should belong to
* @return names of all algorithms (elements AlgorithmsSpecification)
* of the given function contained in 'algoritms.xml'
* @exception MiningException exception if cannot read algorithms.xml
*/
public static Object[] getMiningAlgorithms( String function ) throws MiningException
{
Object[] algorithm = null;
MiningAlgorithms algorithms = null;
try
{
InputStream in = algorithmsFileURL.openStream();
algorithms = MiningAlgorithms.unmarshal(in);
in.close();
}
catch( IOException ex )
{
throw new MiningException( "Can't read algorithms descriptions." );
}
// algorithms.setPublicId( "congig/algorithms.dtd" );
// algorithms.setSystemId( "congig/algorithms.dtd" );
AlgorithmSpecification algorithmSpecification = null;
if( algorithms.isValid() )
{
Vector<String> v = new Vector<String>();
int count = algorithms.getAlgorithmSpecificationCount();
algorithm = new String[count];
for(int i = 0; i < count; i++)
{
algorithmSpecification = algorithms.getAlgorithmSpecification( i );
if( algorithmSpecification.getFunction().equalsIgnoreCase( function) )
{
v.add(algorithmSpecification.getName());
}
}
algorithm = v.toArray();
}
else
{
throw new MiningException( "Not valid PMML document." );
}
return algorithm;
}
/**
* Returns string representation of mining algorithm specification.
*
* @return string representation of this class
*/
public String toString()
{
String s = getName() + " (";
for (int i = 0; i < inputAttribute.length; i++)
{
s = s + inputAttribute[i].getName() + "=" + inputAttribute[i].getValue() + " ";
}
s = s + ")";
return s;
}
/**
* Returns HTML string representation of mining algorithm specification.
*
* @return HTML string representation of this class
*/
public String toHtmlString()
{
String description = "<html>";
description = description + "Algorithm: " + getName() + "<br>";
for (int i = 0; i < inputAttribute.length; i++)
{
description = description + "<a href=http://this?" + i + ">" + inputAttribute[i].getName() + " = <font color=blue><b>" + inputAttribute[i].getValue() + "</b></color></a><br>";
}
description = description + "</html>";
return description;
}
}
class AlgorithmInformation{
String path;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -