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

📄 bimldaofile.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		{
			comparedItem++;
			match = match.toUpperCase().trim();
			
			source = aCaseInfo.getIndustry();
			source = source.toUpperCase().trim();
			finalScore += matchScore(source,match);
		}
		match = aSearchCriteria.getProblemType();
		if (match!=null)
		{
			comparedItem++;
			match = match.toUpperCase().trim();
			
			source = aCaseInfo.getProblemType();
			source = source.toUpperCase().trim();
			finalScore += matchScore(source,match);
		}
		match = aSearchCriteria.getDataMiningGoal();
		if (match!=null)
		{
			comparedItem++;
			match = match.toUpperCase().trim();
			
			source = aCaseInfo.getDataMiningGoal();
			source = source.toUpperCase().trim();
			finalScore += matchScore(source,match);
		}
		match = aSearchCriteria.getCompanyName();
		if (match!=null)
		{
			comparedItem++;
			match = match.toUpperCase().trim();
			
			source = aCaseInfo.getCompanyName();
			source = source.toUpperCase().trim();
			finalScore += matchScore(source,match);
		}
		match = aSearchCriteria.getDepartmentName();
		if (match!=null)
		{
			comparedItem++;
			match = match.toUpperCase().trim();
			
			source = aCaseInfo.getDepartmentName();
			source = source.toUpperCase().trim();
			finalScore += matchScore(source,match);
		}
		
		finalScore = finalScore/comparedItem * 100;
		aCaseInfo.setScore(finalScore);
	}

	
	private double matchScore(String source, String matcher){
		if(source==null||matcher==null){
			return 0;
		}
		if(source.length()<matcher.length()){
			if(matcher.contains(source)){
				return (double)source.length()/2*matcher.length();
			}
			else{
				return 0;
			}
		}
		if(source.length()==matcher.length()){
			return source.equals(matcher)?1:0;
		}
		if(source.contains(matcher)){
			return (double)matcher.length()/source.length();
		}
		else{
			return 0;
		}
	}
	
/*	
 *  The below methods is remarked because these are replaced by the method getBIMLString
 *   because content in String is necessary for the JSP page to handle the XML content.
 * 	These methods can be deleted later.
	
	public Document getBIMLById(String aBimlId, String aType) throws BIMLException
	{
		String aBimlName = Constants.BIML_FILE_PREFIX + aBimlId + "_" +aType + ".xml";
		return getBIMLByName(aBimlName);		
	}

	public Document getBIMLByName(String aBimlName) throws BIMLException
	{
		try {
			String aDirname = SysConfig.getProperty(Constants.BIML_REPOSITORY_KEY);


			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = factory.newDocumentBuilder();
			File aFile = new File(aDirname, aBimlName);
			log.debug("Parsing file: " + aFile.getName());
			Document aDocument = builder.parse(aFile);
			return aDocument;
				
		} catch (Exception e) {
			log.error("Error getting or parsing the BIML file with name: " + aBimlName + " Exception: " + e);
			throw new BIMLException("Error getting or parsing the BIML file with name: " + aBimlName, e);
		}
		
	}

	public Reader getBIMLReaderByName(String aBimlName) throws BIMLException
	{
		try {
			String aDirname = SysConfig.getProperty(Constants.BIML_REPOSITORY_KEY);


			File aFile = new File(aDirname, aBimlName);
			BufferedReader aBufferedReader = new BufferedReader(new FileReader(aFile));
			StringBuffer aFileContent = new StringBuffer();
			String aLine = null;
			while ((aLine = aBufferedReader.readLine()) != null)
			{
			
				aFileContent.append(aLine + "\n");
			}
			
			StringReader aStringReader = new StringReader(aFileContent.toString());
			
			return aStringReader;
				
		} catch (Exception e) {
			log.error("Error getting or parsing the BIML file with name: " + aBimlName + " Exception: " + e);
			throw new BIMLException("Error getting or parsing the BIML file with name: " + aBimlName, e);
		}
		
	}	
	
	public Reader getBIMLReaderById(String aBimlId, String aType) throws BIMLException
	{
		String aBimlName = Constants.BIML_FILE_PREFIX + aBimlId + "_" + aType + ".xml";
		return getBIMLReaderByName(aBimlName);		
	}	
*/

	/**
	 * Find the BIML by the specified name. It finds the file with name aBimlName in
	 * the BIML repository directory. The "activate" subdirectories is searched first
	 * followed by the "inprogress" subdirectories.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#getBIMLStringByName(String)
	 */
	public String getBIMLStringByName(String aBimlName) throws BIMLException
	{
		BufferedReader aBufferedReader = null;
		try {
			String aDirname = SysConfig.getProperty(Constants.BIML_REPOSITORY_KEY);
			File aDir = new File(aDirname, "activate");

			File aBIMLFile = new File(aDir, aBimlName);
			if (!aBIMLFile.exists())
			{
				aDir = new File(aDirname, "inprogress");
				aBIMLFile = new File(aDir, aBimlName);
				if (!aBIMLFile.exists())
				{
					throw new BIMLException("BIML file " + aBimlName + " does not exist");
				}
			}



			aBufferedReader = new BufferedReader(new FileReader(aBIMLFile));
			StringBuffer aFileContent = new StringBuffer();
			String aLine = null;
			while ((aLine = aBufferedReader.readLine()) != null)
			{
			
				aFileContent.append(aLine + "\n");
			}
		
			return aFileContent.toString();
				
		} catch (Exception e) {
			SysLog.error("Error getting or parsing the BIML file with name: " + aBimlName + " Exception: " + e);
			throw new BIMLException("Error getting or parsing the BIML file with name: " + aBimlName, e);
		}finally
		{
			try
			{
				aBufferedReader.close();
			}catch(IOException e)
			{}
		}
		
	}	


	/**
	 * Find the BIML by the specified ID. It finds the file with name 
	 * <prefix>_<aBimlId>_<aType>.xml in the 
	 * the BIML repository directory. The "activate" subdirectories is searched first
	 * followed by the "inprogress" subdirectories.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#getBIMLStringByName(String)
	 */
	public String getBIMLStringById(String aBimlId, String aType, String aBIMLStyleSheet) throws BIMLException
	{
		String aBimlName = Constants.BIML_FILE_PREFIX + aBimlId + "_" + aType + ".xml";
		return getBIMLStringByName(aBimlName, aBIMLStyleSheet);		
	}	

	/**
	 * Find the BIML by the specified name and transform it using the input XSLT style
	 * sheet. It finds the file with name aBimlName in
	 * the BIML repository directory. The "activate" subdirectories is searched first
	 * followed by the "in progress" subdirectories. Then it uses the file with the
	 * name aBIMLStyleSheet for the XSLT transformation. The style sheet should be 
	 * within the same directory of the BIML file.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#getBIMLStringByName(String, String)
	 */
	public String getBIMLStringByName(String aBimlName, String aBIMLStyleSheet) throws BIMLException
	{
//		System.out.println("getBIMLStringByName()");
//		if (aBIMLStyleSheet == null)
//		{
//			aBIMLStyleSheet = aBimlName.substring(0, aBimlName.length()-3) + "xsl";
//		}
//		
//		try {
//			String aDirname = SysConfig.getProperty(Constants.BIML_REPOSITORY_KEY);
//
//			File aDir = new File(aDirname, "activate");
//
//			File aBIMLFile = new File(aDir, aBimlName);
//			if (!aBIMLFile.exists())
//			{
//				aDir = new File(aDirname, "inprogress");
//				aBIMLFile = new File(aDir, aBimlName);
//				if (!aBIMLFile.exists())
//				{
//					throw new BIMLException("BIML file " + aBimlName + " does not exist");
//				}
//			}
//			File aStyleSheetFile = new File(aDir, aBIMLStyleSheet);
//			if (!aStyleSheetFile.exists())
//			{
//				String aType = aBimlName.substring(aBimlName.length()-7, aBimlName.length()-4);
//				aDir = new File(aDirname, "activate");
//				
//				if (!aType.equals("PML"))
//				{
//					aStyleSheetFile = new File(aDir, Constants.BIML_FILE_PREFIX + aType + ".xsl");
//				}
//				else
//				{
//					BIMLDAO aBIMLDAO = (BIMLDAO) DAOFactory.getDAO("BIML", Constants.BIML_DAO_TYPE);
//					String aModelTechnique = SearchUtil.getBIMLModelingTechniqueByName(aBIMLDAO, aBimlName);
//					
//					if (aModelTechnique != null)
//						aStyleSheetFile = new File(aDir, Constants.BIML_FILE_PREFIX + aModelTechnique + "_" + aType + ".xsl");	
//					else
//						aStyleSheetFile = new File(aDir, Constants.BIML_FILE_PREFIX + aType + ".xsl");
//				}
//			}
//			return BIMLTransformer.xsltTransform(aBIMLFile, aStyleSheetFile);	
//		}
	/*		
    		Document document;
    
    		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		    String htmlResult = null;
        	try {
	 
	            DocumentBuilder builder = factory.newDocumentBuilder();
	            document = builder.parse(aBIMLFile);
	 
	            // Use a Transformer for output
	            TransformerFactory tFactory =
	                TransformerFactory.newInstance();
	            StreamSource stylesource = new StreamSource(aStyleSheetFile);
	            Transformer transformer = tFactory.newTransformer(stylesource);
	 
	            DOMSource source = new DOMSource(document);
	            ByteArrayOutputStream outstream = new ByteArrayOutputStream();
	
	            StreamResult result = new StreamResult(outstream);
	            transformer.transform(source, result);
	            htmlResult = outstream.toString();
	           
	        } catch (TransformerConfigurationException tce) {
	           // Error generated by the parser
	           System.err.println ("\n** Transformer Factory error");
	           System.err.println("   " + tce.getMessage() );
	
	           // Use the contained exception, if any
	           Throwable x = tce;
	           if (tce.getException() != null)
	               x = tce.getException();
	           x.printStackTrace();
	      
	        } catch (TransformerException te) {
	           // Error generated by the parser
	           System.err.println ("\n** Transformation error");
	           System.err.println("   " + te.getMessage() );
	
	           // Use the contained exception, if any
	           Throwable x = te;
	           if (te.getException() != null)
	               x = te.getException();
	           x.printStackTrace();
	           
	         } catch (SAXException sxe) {
	           // Error generated by this application
	           // (or a parser-initialization error)
	           Exception  x = sxe;
	           if (sxe.getException() != null)
	               x = sxe.getException();
	           x.printStackTrace();
	
	        } catch (ParserConfigurationException pce) {
	            // Parser with specified options can't be built
	            pce.printStackTrace();
	
	        } catch (IOException ioe) {
	           // I/O error
	           ioe.printStackTrace();
	        }
	
			return htmlResult;				
		}*/
//		catch (Exception e) {
//			log.error("Error getting or parsing the BIML file with name: " + aBimlName + " Exception: " + e);
//			throw new BIMLException("Error getting or parsing the BIML file with name: " + aBimlName, e);
//		}
		
		return "NOT Implemented.";
	}	

	/**
	 * Find the BIML by the specified ID and transform it using the input XSLT style
	 * sheet. It finds the file with ID aBimlId in
	 * the BIML repository directory. The "activate" subdirectories is searched first
	 * followed by the "in progress" subdirectories. Then it uses the file with the
	 * name aBIMLStyleSheet for the XSLT transformation. The style sheet should be 
	 * within the same directory of the BIML file.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#getBIMLStringById(String, String)
	 */
	public String getBIMLStringById(String aBimlId, String aType) throws BIMLException
	{
		String aBimlName = Constants.BIML_FILE_PREFIX + aBimlId + "_" + aType + ".xml";
		return getBIMLStringByName(aBimlName);		
	}	
	
	
	/**

⌨️ 快捷键说明

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