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

📄 deobfuscator.java

📁 一个很好的LIBSVM的JAVA源码。对于要研究和改进SVM算法的学者。可以参考。来自数据挖掘工具YALE工具包。
💻 JAVA
字号:
/*
 *  YALE - Yet Another Learning Environment
 *  Copyright (C) 2001-2004
 *      Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, 
 *          Katharina Morik, Oliver Ritthoff
 *      Artificial Intelligence Unit
 *      Computer Science Department
 *      University of Dortmund
 *      44221 Dortmund,  Germany
 *  email: yale-team@lists.sourceforge.net
 *  web:   http://yale.cs.uni-dortmund.de/
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as 
 *  published by the Free Software Foundation; either version 2 of the
 *  License, or (at your option) any later version. 
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 *  USA.
 */
package edu.udo.cs.yale.operator.preprocessing;

import edu.udo.cs.yale.operator.Operator;
import edu.udo.cs.yale.operator.IOObject;
import edu.udo.cs.yale.operator.OperatorException;
import edu.udo.cs.yale.operator.UserError;
import edu.udo.cs.yale.operator.parameter.*;
import edu.udo.cs.yale.example.ExampleSet;
import edu.udo.cs.yale.example.Attribute;
import edu.udo.cs.yale.tools.LogService;
import edu.udo.cs.yale.tools.RandomGenerator;

import java.util.List;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import java.io.*;

/** This operator takes an <code>ExampleSet</code> as input and maps all nominal values
 *  to randomly created strings. The names and the construction descriptions of all attributes
 *  will also replaced by random strings. This operator can be used to anonymize your data.
 *  It is possible to save the obfuscating map into a file which can be used to remap the old 
 *  values and names. Please use the operator <code>Deobfuscator</code> for this purpose. 
 *  The new example set can be written with an <code>ExampleSetWriter</code>.
 *
 *  @version $Id: Deobfuscator.java,v 1.3 2004/09/17 12:57:42 ingomierswa Exp $
 */
public class Deobfuscator extends Operator {

    public IOObject[] apply() throws OperatorException {
	// init
	ExampleSet exampleSet = (ExampleSet)getInput(ExampleSet.class);
	String filename = getParameterAsString("obfuscation_map_file");
	File file = getExperiment().resolveFileName(filename);
	Map obfuscatorMap = null;
	try {
	    obfuscatorMap = readObfuscatorMap(file);
	} catch (IOException e) {
	    throw new UserError(this, 302, filename, e.getMessage());
	}

	// de-obfuscate regular attributes
	for (int i = 0; i < exampleSet.getNumberOfAttributes(); i++) {
	    deObfuscateAttribute(exampleSet.getAttribute(i), obfuscatorMap);
	}

	// de-obfuscate special attributes	
	Iterator i = exampleSet.getSpecialAttributeNames().iterator();
	while (i.hasNext()) {
	    deObfuscateAttribute(exampleSet.getAttribute((String)i.next()), obfuscatorMap);
	}

	exampleSet.recalculateAllAttributeStatistics();
	
        return new IOObject[] { exampleSet };
    }
    
    private void deObfuscateAttribute(Attribute attribute, Map obfuscatorMap) {
	String obfuscatedName = attribute.getName();
	String newName = (String)obfuscatorMap.get(obfuscatedName);
	if (newName != null) {
	    attribute.setName(newName);
	    attribute.clearConstructionDescription();
	} else {
	    LogService.logMessage("No name found in obfuscating map for attribute '"+obfuscatedName+"'.", 
				  LogService.WARNING);
	}
	
	if (attribute.isNominal()) {
	    Iterator v = attribute.getValues().iterator();
	    while (v.hasNext()) {
		String obfuscatedValue = (String)v.next();
		String newValue = (String)obfuscatorMap.get(newName + ":" + obfuscatedValue);
		if (newValue != null) {
		    attribute.replaceValue(obfuscatedValue, newValue);
		} else {
		    LogService.logMessage("No value found in obfuscating map for value '"+obfuscatedValue+"' of attribute '" + attribute.getName() + "'.", 
					  LogService.WARNING);
		}
	    }
	}
    }

    private Map readObfuscatorMap(File file) throws IOException {
	Map map = new HashMap();
	BufferedReader in = new BufferedReader(new FileReader(file));
	String line = null;
	while ((line = in.readLine()) != null) {
	    String[] parts = line.trim().split("\\s");
	    map.put(parts[0], parts[1]);
	}
	in.close();
	return map;
    }

    public Class[] getInputClasses() {  return new Class[] { ExampleSet.class };  }
    public Class[] getOutputClasses() {  return new Class[] { ExampleSet.class };  }


    public List getParameterTypes() {
	List types = super.getParameterTypes();
	ParameterType type = new ParameterTypeFile("obfuscation_map_file", "File where the obfuscator map was written to.", false);
	type.setExpert(false);
	types.add(type);
	return types;
    }
}

⌨️ 快捷键说明

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