⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selectoperator.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	        removeWithValues.setNominalIndices(selection);
	        
	    }else {
	        removeWithValues.setSplitPoint(splitPoint);
	        
	    }
	    
		return removeWithValues;
	}

	
	public RemoveRange prepareRemoveRange(MiningDataSpecification a_MetaData, IOperatorNode a_Node) throws MiningException{
	    RemoveRange removeRange = new RemoveRange();
	    String value = null;
	    int from = -1;
	    int to = -1;
//		boolean invertSelection = true;
		
		value = (String) a_Node.getParameterValue("from");
		if(value == null)
		    throw new MiningException("The lower range should be an integer\n");
		from = Integer.parseInt(value);
		
		value = (String) a_Node.getParameterValue("to");
		if(value == null)
		    throw new MiningException("The upper range should be an integer\n");
		to = Integer.parseInt(value );
		
		value = (String) a_Node.getParameterValue("keep");
		if(value.equals("false"))
		    m_InvertSelection = false;
		else if (value.equals("true"))
		    m_InvertSelection = true;
		
		if(from!=-1 && to!=-1)
		    removeRange.setInstancesIndices(from + "-" + to);
		removeRange.setInvertSelection(m_InvertSelection);
			
		return removeRange;
	}
	
	
	private String parseSelection(String a_Selection){
	    String parsed = "";
	    for(int i=0; i<a_Selection.length(); i++){
	        if(a_Selection.charAt(i)=='1'){
	            parsed += Integer.toString(i+1) +",";
	        }
	        
	    }
	    
	    if(parsed.length() >0 && parsed.charAt(parsed.length()-1)==','){
	        parsed = parsed.substring(0, parsed.length()-1);
	    }
	    return parsed;
	}
		
	private void validateParameters(MiningDataSpecification a_MetaData, IOperatorNode a_Node, MiningStoredData a_msd) 
		throws AppException
	{
	    String value = null;
	    String from = null;
	    String to = null;
//	    int mode;
	    String sourceName = null;
	    String targetType = null;
	    MiningAttribute mAtt = null;
	    String selection = null; 
	    @SuppressWarnings("unused") boolean valid = true;
	    
	    String message ="";
	    
	    value = (String) a_Node.getParameterValue("mode");
//	    if(value ==null  || !ValueValidator.isNumeric(value)){
	    if(value !=null && !ValueValidator.isNumeric(value)){
		    message += "Please select a sampling method\n";
		    throw new AppException(message);
	    }
	    if(value !=null  && ValueValidator.isNumeric(value)){
	        m_Mode = Integer.parseInt(value );
	    }
	    
//	    value = a_Node.getParameterValue("mode");
//	    if(value == null || !ValueValidator.isNumeric(value)){
//		    message += "Please select a select method\n";
//		    throw new AppException(message);
//	    }
//	    mode = Integer.parseInt(value);
	    
	    value = (String) a_Node.getParameterValue("keep");
		if(value != null 
		        && (!value.equalsIgnoreCase("true") 
		                && !value.equalsIgnoreCase("false"))){
		    message += "Please select keep or remove\n";
		    throw new AppException(message);
		}
	    
	    switch(m_Mode){
	    	case BY_RANGE:
	    	    
	    	 		
	    		to = (String) a_Node.getParameterValue("to");
	    		 if (to ==null
	    		         || !ValueValidator.isNumeric(to) 
	    		         || !ValueValidator.largerThan(to, 1, true)
	    		         || !ValueValidator.smallerThan(to, a_msd.getVectorsNumber(), true)) {
	    		     	message += "The upper range should be an integer between 1 and " + a_msd.getVectorsNumber() +"\n";
		    		    valid = false;
		    		    throw new AppException(message);
	    	            }
	    		
	    		 from = (String) a_Node.getParameterValue("from");
	    		 if (!ValueValidator.isNumeric(from) 
	    		         || !ValueValidator.largerThan(from, 1, true)
	    		         || !ValueValidator.isNumeric(to) 
	    		         || !ValueValidator.smallerThan(from, Integer.parseInt(to), true)) 
	    		 {
	    	                   
	                    if(ValueValidator.isNumeric(to)){
	                        message += "The lower range should be an integer between 1 and " + to + "\n";
	                    }
	                    else{ 
	                        message += "The lower range should be an integer between 1 and " + a_msd.getVectorsNumber() +"\n";
	                    }
	                   
		                valid = false;
		    		    throw new AppException(message);
	            } 
	    		
	    		break;
	    		
	    	case BY_VALUE:
	    	    sourceName = (String) a_Node.getParameterValue("target");
	    	    if (sourceName == null){
	    	        message += Resource.srcStr("AttributeMessage");
	    	        throw new AppException(message);
	    	    }
	    	    else {
	    	        mAtt = a_MetaData.getMiningAttribute(sourceName);
	    	        if(mAtt == null) {
	    	            message += Resource.srcStr("AttributeMessage");
	    	            throw new AppException(message);
	    	        }
	    	    }
	    		

	    	    value = (String) a_Node.getParameterValue("missingValue");
	    	    if(value == null 
	    	            || (!value.equalsIgnoreCase("true") 
	    	                    && !value.equalsIgnoreCase("false"))){
	    		    message += "Missing values should not be null\n";
	    		    throw new AppException(message);
	    	    }
	    	  
	    	    
//	    	    value = a_Node.getParameterValue("valKeep");
//	    	    if(value == null 
//	    	            || (!value.equalsIgnoreCase("true") 
//	    	                    && !value.equalsIgnoreCase("false"))){
//	    		    message += "Please select keep or remove\n";
//	    		    throw new AppException(message);
//	    	    }
    		    	    	    
	    	   
	    		if ( mAtt != null ){
	    		    
	    		    if(mAtt instanceof CategoricalAttribute) {
	    		        targetType = (String) a_Node.getParameterValue("targetType");
	    		        
	    		        if(targetType ==null
	    	                    || !targetType.equals(CATEG)){
	    		                message += Resource.srcStr("AttributeMessage");
	    			            throw new AppException (message);	
	    	            }
	    		        
	    		        selection = (String) a_Node.getParameterValue("selection");
            	        if(selection == null 
            	                || selection.length() != ((CategoricalAttribute) mAtt).getCategoriesNumber() ){
            			    message += "Please select categories to be matched\n";
            			    throw new AppException(message);
            	        }      
	        	    	    
                        for (int i = 0; i < selection.length(); i++) {
                            if (selection.charAt(i) != '1'
                                    && selection.charAt(i) != '0') {
                                message += "Please select categories to be matched\n";
                                throw new AppException(message);
                               
                            }
                        }
	                    
	    	        
	    		    }else {
	    		        targetType = (String) a_Node.getParameterValue("targetType");
	    		        
	    		        if(targetType ==null
	    	                    || !targetType.equals(NUM)){
	    		                message += Resource.srcStr("AttributeMessage");
	    			            throw new AppException (message);	
	    	            }
	    		        
	    		        value = (String) a_Node.getParameterValue("smallerThan");
	    		        if(value == null 
	    		                || !ValueValidator.isDouble(value)){
	    		            message += "Smaller than should be a double\n";
	    		            throw new AppException(message);
	    		        }
	    		    }
	    		
	    	
	    		}
	    		
	    		break;
	    	default: 
	    	    message += "Please select a select method";
	    	 	throw new AppException(message);
	    	}
	    
//	    if(!message.equals("")){
//	        throw new AppException(message);
//	    }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -