ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vjapa...@apache.org
Subject svn commit: r1551254 [25/26] - in /ctakes/branches/ytex: ctakes-ytex-res/ ctakes-ytex-res/.settings/ ctakes-ytex-res/src/ ctakes-ytex-res/src/main/ ctakes-ytex-res/src/main/resources/ ctakes-ytex-res/src/main/resources/org/ ctakes-ytex-res/src/main/res...
Date Mon, 16 Dec 2013 16:30:40 GMT
Added: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/GramMatrixExporterImpl.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/GramMatrixExporterImpl.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/GramMatrixExporterImpl.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/GramMatrixExporterImpl.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,263 @@
+package org.apache.ctakes.ytex.weka;
+
+import java.io.BufferedWriter;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeMap;
+
+import javax.sql.DataSource;
+
+import org.apache.ctakes.ytex.kernel.BagOfWordsDecorator;
+import org.apache.ctakes.ytex.kernel.BagOfWordsExporter;
+import org.apache.ctakes.ytex.kernel.dao.KernelEvaluationDao;
+import org.apache.ctakes.ytex.kernel.model.KernelEvaluation;
+import org.apache.ctakes.ytex.kernel.model.KernelEvaluationInstance;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowCallbackHandler;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+
+/**
+ * @deprecated don't know if this works ...
+ * @author vijay
+ *
+ */
+public class GramMatrixExporterImpl extends WekaBagOfWordsExporterImpl implements
+		GramMatrixExporter {
+	private JdbcTemplate jdbcTemplate;
+	private KernelEvaluationDao kernelEvaluationDao;
+	private WekaBagOfWordsExporter bagOfWordsExporter;
+
+	public enum GramMatrixType {
+		WEKA, LIBSVM
+	};
+
+	public KernelEvaluationDao getKernelEvaluationDao() {
+		return kernelEvaluationDao;
+	}
+
+	public BagOfWordsExporter getBagOfWordsExporter() {
+		return bagOfWordsExporter;
+	}
+
+	public void setBagOfWordsExporter(WekaBagOfWordsExporter bagOfWordsExporter) {
+		this.bagOfWordsExporter = bagOfWordsExporter;
+	}
+
+	public void setKernelEvaluationDao(KernelEvaluationDao kernelEvaluationDao) {
+		this.kernelEvaluationDao = kernelEvaluationDao;
+	}
+
+	public void setDataSource(DataSource ds) {
+		this.jdbcTemplate = new JdbcTemplate(ds);
+	}
+
+	public DataSource getDataSource(DataSource ds) {
+		return this.jdbcTemplate.getDataSource();
+	}
+
+	/**
+	 * add gramIndex attribute to arff file
+	 * 
+	 * @author vijay
+	 */
+	public static class GramMatrixArffDecorator implements BagOfWordsDecorator {
+		public static final String INDEX_NAME = "gramIndex";
+		public static final String INDEX_NAME_NOMINAL = "gramIndexN";
+		Map<Long, Integer> instanceIdToIndexMap;
+
+		public GramMatrixArffDecorator(
+				Map<Long, Integer> instanceIdToIndexMap) {
+			this.instanceIdToIndexMap = instanceIdToIndexMap;
+		}
+
+		@Override
+		public void decorateNumericInstanceWords(
+				Map<Long, SortedMap<String, Double>> instanceNumericWords,
+				SortedSet<String> numericWords) {
+			for (Map.Entry<Long, Integer> instanceIdToIndex : instanceIdToIndexMap
+					.entrySet()) {
+				long instanceId = instanceIdToIndex.getKey();
+				int index = instanceIdToIndex.getValue();
+				if (!instanceNumericWords.containsKey(instanceId)) {
+					instanceNumericWords.put(instanceId,
+							new TreeMap<String, Double>());
+				}
+				instanceNumericWords.get(instanceId).put(INDEX_NAME,
+						(double) index);
+			}
+			numericWords.add(INDEX_NAME);
+		}
+
+		/**
+		 * do nothing
+		 */
+		@Override
+		public void decorateNominalInstanceWords(
+				Map<Long, SortedMap<String, String>> instanceNominalWords,
+				Map<String, SortedSet<String>> nominalWordValueMap) {
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.ctakes.ytex.kernel.GramMatrixExporter#exportGramMatrix(java.lang.String)
+	 */
+	@Override
+	public void exportGramMatrix(String propertyFile) throws IOException {
+		Properties props = new Properties();
+		BufferedWriter matrixWriter = null;
+		InputStream in = null;
+		try {
+			// map of instance id -> index in gram matrix
+			final Map<Long, Integer> instanceIdToIndexMap = new HashMap<Long, Integer>();
+			// map of instance id -> class label
+			final Map<Long, String> instanceIDClassLabel = new TreeMap<Long, String>();
+			in = new FileInputStream(propertyFile);
+			if (propertyFile.endsWith(".xml"))
+				props.loadFromXML(in);
+			else
+				props.load(in);
+			matrixWriter = new BufferedWriter(new FileWriter(props
+					.getProperty("matrixFile")));
+			String kernelEvaluationNames = props
+					.getProperty("kernelEvaluationNames");
+			//TODO
+			KernelEvaluation kernelEvaluation = null;
+			Set<String> setKernelEvaluationNames = new HashSet<String>();
+			Collections.addAll(setKernelEvaluationNames, kernelEvaluationNames
+					.split(","));
+			initializeInstanceIndices(props.getProperty("instanceClassQuery"),
+					instanceIDClassLabel, instanceIdToIndexMap);
+			this.bagOfWordsExporter.exportBagOfWords(propertyFile,
+					new GramMatrixArffDecorator(instanceIdToIndexMap));
+			exportGramMatrix(matrixWriter, kernelEvaluation,
+					GramMatrixType.WEKA, instanceIDClassLabel,
+					instanceIdToIndexMap);
+		} finally {
+			try {
+				if (in != null)
+					in.close();
+			} catch (Exception e) {
+			}
+			try {
+				if (matrixWriter != null)
+					matrixWriter.close();
+			} catch (Exception e) {
+			}
+		}
+	}
+
+	protected Map<Long, Integer> exportGramMatrix(BufferedWriter writer,
+			final KernelEvaluation kernelEvaluation, GramMatrixType matrixType,
+			final Map<Long, String> instanceIDClassLabel,
+			final Map<Long, Integer> instanceToIndexMap) throws IOException {
+		// allocate gram matrix
+		final double[][] gramMatrix = new double[instanceIDClassLabel.size()][instanceIDClassLabel
+				.size()];
+		// fill in gram matrix
+		// do this row by row - pulling the entire matrix at once is too slow
+		// do this in a separate transaction so that the 1st level cache doesn't
+		// fill up
+		for (Map.Entry<Long, Integer> instanceIdIndex : instanceToIndexMap
+				.entrySet()) {
+			final int indexThis = instanceIdIndex.getValue();
+			final long instanceId = instanceIdIndex.getKey();
+			txNew.execute(new TransactionCallback<Object>() {
+				@Override
+				public Object doInTransaction(TransactionStatus arg0) {
+					for (KernelEvaluationInstance keval : getKernelEvaluationDao()
+							.getAllKernelEvaluationsForInstance(
+									kernelEvaluation, instanceId)) {
+						Integer indexOther = null;
+						if (instanceId != keval.getInstanceId1()) {
+							indexOther = instanceToIndexMap.get(keval
+									.getInstanceId1());
+						} else if (instanceId != keval.getInstanceId2()) {
+							indexOther = instanceToIndexMap.get(keval
+									.getInstanceId2());
+						} else {
+							indexOther = indexThis;
+						}
+						if (indexOther != null) {
+							gramMatrix[indexThis][indexOther] = keval
+									.getSimilarity();
+							gramMatrix[indexOther][indexThis] = keval
+									.getSimilarity();
+						}
+					}
+					return null;
+				}
+			});
+		}
+		// may run into memory issues/ transaction timeout with getting all
+		// kernel evals in one go
+		// for (KernelEvaluation keval : this.getKernelEvaluationDao()
+		// .getAllKernelEvaluations(kernelEvaluationNames)) {
+		// Integer index1 = instanceToIndexMap.get(keval.getInstanceId1());
+		// Integer index2 = instanceToIndexMap.get(keval.getInstanceId2());
+		// if (index1 != null && index2 != null) {
+		// gramMatrix[index1][index2] = keval.getSimilarity();
+		// gramMatrix[index2][index1] = keval.getSimilarity();
+		// }
+		// }
+		// set diagonal if not set (typically K<x,x> = 1 so this need not be
+		// stored
+		for (int j = 0; j < gramMatrix.length; j++) {
+			if (gramMatrix[j][j] == 0)
+				gramMatrix[j][j] = 1;
+		}
+		if (matrixType == GramMatrixType.WEKA) {
+			exportWekaGramMatrix(gramMatrix, writer);
+		}
+		return instanceToIndexMap;
+	}
+
+	private void initializeInstanceIndices(String instanceClassQuery,
+			final Map<Long, String> instanceIDClassLabel,
+			final Map<Long, Integer> instanceToIndexMap) {
+		// read in all instance ids
+		jdbcTemplate.query(instanceClassQuery, new RowCallbackHandler() {
+			@Override
+			public void processRow(ResultSet rs) throws SQLException {
+				instanceIDClassLabel.put(rs.getLong(1), rs.getString(2));
+			}
+		});
+		int i = 0;
+		for (Long instanceId : instanceIDClassLabel.keySet()) {
+			instanceToIndexMap.put(instanceId, i);
+			i++;
+		}
+	}
+
+	private void exportWekaGramMatrix(double[][] gramMatrix,
+			BufferedWriter writer) throws IOException {
+		// header contains rows columns
+		writer.write(Integer.toString(gramMatrix.length));
+		writer.write("\t");
+		writer.write(Integer.toString(gramMatrix.length));
+		writer.write("\t");
+		writer.newLine();
+		for (int nRow = 0; nRow < gramMatrix.length; nRow++) {
+			double row[] = gramMatrix[nRow];
+			for (int nCol = 0; nCol < row.length; nCol++) {
+				writer.write(Double.toString(row[nCol]));
+				writer.write("\t");
+			}
+			writer.newLine();
+		}
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/ImportWekaResults.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/ImportWekaResults.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/ImportWekaResults.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/ImportWekaResults.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,181 @@
+package org.apache.ctakes.ytex.weka;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.ctakes.ytex.kernel.KernelContextHolder;
+
+
+/**
+ * Runs org.apache.ctakes.ytex.weka.WekaResultsImporter for the specified task and result file.
+ * 
+ * @see WekaResultsImporter
+ * @author vijay
+ * 
+ */
+public class ImportWekaResults  {
+
+	/**
+	 * @param args
+	 */
+	public static void docPredImport(String predictions, String task)
+			throws Exception {
+		WekaResultsImporter importer = (WekaResultsImporter) KernelContextHolder
+				.getApplicationContext().getBean("wekaResultsImporter");
+		BufferedReader reader = null;
+		try {
+			reader = new BufferedReader(new FileReader(predictions));
+			importer.importDocumentResults(task, reader);
+		} finally {
+			if (reader != null) {
+				reader.close();
+			}
+		}
+	}
+
+	private static Options initOptions() {
+		Options options = new Options();
+		OptionGroup og = new OptionGroup();
+		og.addOption(OptionBuilder.withArgName("cvDir").hasArg()
+				.withDescription("fold cross-validation results directory")
+				.create("cvDir"));
+		og.addOption(OptionBuilder.withArgName("document").hasArg()
+				.withDescription("document prediction output")
+				.create("docPred"));
+		og.addOption(OptionBuilder.withArgName("document").hasArg()
+				.withDescription("prediction").create("pred"));
+		options.addOptionGroup(og);
+		options.addOption(OptionBuilder.withArgName("algo").hasArg()
+				.withDescription("algorithm").create("algo"));
+		options.addOption(OptionBuilder.withArgName("name").hasArg()
+				.withDescription("name").isRequired().create("name"));
+		options.addOption(OptionBuilder.withArgName("experiment").hasArg()
+				.withDescription("experiment").create("experiment"));
+		options.addOption(OptionBuilder.withArgName("label").hasArg()
+				.withDescription("label / task").create("label"));
+		options.addOption(OptionBuilder.withArgName("yes/no").hasArg()
+				.withDescription("store probabilities, default yes").create(
+						"storeProb"));
+		return options;
+	}
+
+	/**
+	 * @param args
+	 * @throws Exception
+	 */
+	public static void main(String[] args) throws Exception {
+		Options options = initOptions();
+		if (args.length == 0) {
+			printHelp(options);
+		} else {
+			CommandLineParser oparser = new GnuParser();
+			try {
+				CommandLine line = oparser.parse(options, args);
+				if (line.hasOption("cvDir")) {
+					importDirectory(line);
+				} else if (line.hasOption("docPred")) {
+					docPredImport(options.getOption("docPred").getValue(),
+							options.getOption("label").getValue());
+				} else if (line.hasOption("pred")) {
+					importPred(line);
+				}
+			} catch (ParseException e) {
+				printHelp(options);
+				throw e;
+			}
+		}
+	}
+
+	private static void importPred(CommandLine line) {
+		// TODO Auto-generated method stub
+
+	}
+
+	/**
+	 * Expect directory with subdirectories for each evaluation. Subdirectories
+	 * must contain following in order for results to be processed:
+	 * <ul>
+	 * <li>
+	 * model.txt: libsvm model trained on training set
+	 * <li>predict.txt: libsvm predictions on test set
+	 * <li>options.properties: libsvm command line options
+	 * </ul>
+	 * 
+	 * @param line
+	 * @throws Exception
+	 */
+	private static void importDirectory(CommandLine line) throws Exception {
+		WekaResultsImporter importer = (WekaResultsImporter) KernelContextHolder
+				.getApplicationContext().getBean("wekaResultsImporter");
+		File cvDir = new File(line.getOptionValue("cvDir"));
+		if (cvDir.listFiles() == null || cvDir.listFiles().length == 0) {
+			System.err.println("directory is empty: " + cvDir);
+		} else {
+			for (File resultDir : cvDir.listFiles()) {
+				String model = resultDir + File.separator + "model.obj";
+				String output = resultDir + File.separator + "predict.txt";
+				String optionsFile = resultDir + File.separator
+						+ "options.properties";
+				if (checkFileRead(output) && checkFileRead(optionsFile)) {
+					String options = null;
+					Integer fold = null;
+					InputStream isOptions = null;
+					try {
+						isOptions = new FileInputStream(optionsFile);
+						Properties props = new Properties();
+						props.load(isOptions);
+						options = props.getProperty("options");
+						String strFold = props.getProperty("fold");
+						if(strFold != null) {
+							try {
+								fold = Integer.parseInt(strFold);
+							} catch(NumberFormatException nfe) {
+								
+							}
+						}
+					} finally {
+						isOptions.close();
+					}
+					if (options != null) {
+						BufferedReader r = null;
+						try {
+							r = new BufferedReader(new FileReader(output));
+							importer.importClassifierEvaluation(line
+									.getOptionValue("name"), fold, line
+									.getOptionValue("algo", "weka"), line
+									.getOptionValue("label"), options, line
+									.getOptionValue("experiment"), r);
+						} finally {
+							try {
+								r.close();
+							} catch (Exception e) {
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+
+	private static boolean checkFileRead(String file) {
+		return (new File(file)).canRead();
+	}
+
+	private static void printHelp(Options options) {
+		HelpFormatter formatter = new HelpFormatter();
+		formatter.printHelp("java org.apache.ctakes.ytex.weka.ImportWekaResults\n", options);
+	}
+
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaAttributeEvaluator.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaAttributeEvaluator.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaAttributeEvaluator.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaAttributeEvaluator.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,36 @@
+package org.apache.ctakes.ytex.weka;
+
+import java.util.Properties;
+
+public interface WekaAttributeEvaluator {
+
+	/**
+	 * evaluate attributes in an arff file, save rank in db
+	 * 
+	 * @param name
+	 *            corresponds to feature_eval.name
+	 * @param corpusName
+	 *            cv_fold.name
+	 * @param arffFile
+	 * @throws Exception
+	 */
+	public abstract void evaluateAttributesFromFile(String corpusName,
+			String featureSetName, String splitName, String arffFile)
+			throws Exception;
+
+	/**
+	 * create instances from properties file, evaluate, save in db
+	 * 
+	 * @param name
+	 *            feature set name. corresponds to feature_eval.name
+	 * @param corpusName
+	 *            cv_fold.name
+	 * @param propFile
+	 *            for SparseDataExporter
+	 * @throws Exception
+	 */
+	public abstract void evaluateAttributesFromProps(String corpusName,
+			String splitName, String featureSetName, Properties props)
+			throws Exception;
+
+}
\ No newline at end of file

Added: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaAttributeEvaluatorImpl.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaAttributeEvaluatorImpl.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaAttributeEvaluatorImpl.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaAttributeEvaluatorImpl.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,273 @@
+package org.apache.ctakes.ytex.weka;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.SortedMap;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ctakes.ytex.kernel.FileUtil;
+import org.apache.ctakes.ytex.kernel.KernelContextHolder;
+import org.apache.ctakes.ytex.kernel.KernelUtil;
+import org.apache.ctakes.ytex.kernel.SparseData;
+import org.apache.ctakes.ytex.kernel.SparseDataExporter;
+import org.apache.ctakes.ytex.kernel.SparseDataFormatter;
+import org.apache.ctakes.ytex.kernel.dao.ClassifierEvaluationDao;
+import org.apache.ctakes.ytex.kernel.model.ClassifierEvaluation;
+import org.apache.ctakes.ytex.kernel.model.CrossValidationFold;
+import org.apache.ctakes.ytex.kernel.model.FeatureEvaluation;
+import org.apache.ctakes.ytex.kernel.model.FeatureRank;
+import org.apache.ctakes.ytex.weka.WekaFormatterFactory.WekaFormatter;
+
+import weka.attributeSelection.ASEvaluation;
+import weka.attributeSelection.AttributeSelection;
+import weka.core.Instances;
+import weka.core.converters.ConverterUtils.DataSource;
+
+public class WekaAttributeEvaluatorImpl implements WekaAttributeEvaluator {
+	public class WekaAttributeEvaluatorFormatter extends WekaFormatter {
+		String corpusName;
+
+		String featureSetName;
+
+		String splitName;
+
+		public WekaAttributeEvaluatorFormatter(String corpusName,
+				String featureSetName, String splitName) {
+			super(getKernelUtil());
+			this.featureSetName = featureSetName;
+			this.corpusName = corpusName;
+			this.splitName = splitName;
+		}
+
+		@Override
+		public void exportFold(SparseData sparseData,
+				SortedMap<Long, String> instanceClasses, boolean train,
+				String label, Integer run, Integer fold) throws IOException {
+			if (train) {
+				Instances inst = this.initializeInstances(sparseData,
+						instanceClasses, train, label, run, fold);
+				try {
+					evaluateAttributes(corpusName, featureSetName, splitName,
+							inst, label, run, fold);
+				} catch (Exception e) {
+					throw new IOException(e);
+				}
+			}
+		}
+
+	}
+
+	private static final Log log = LogFactory
+			.getLog(WekaAttributeEvaluatorImpl.class);
+
+	/**
+	 * @param args
+	 * @throws Exception
+	 */
+	@SuppressWarnings("static-access")
+	public static void main(String[] args) throws Exception {
+		Options options = new Options();
+		options.addOption(OptionBuilder
+				.withArgName("property file")
+				.hasArg()
+				.withDescription(
+						"load parameters from property file.  If queries defiend as for SparseDataExporter, use them to load the instances")
+				.create("prop"));
+		options.addOption(OptionBuilder
+				.withArgName("train_data.arff")
+				.hasArg()
+				.withDescription(
+						"use specified weka arff file to load instances for evaluation.")
+				.create("arff"));
+		try {
+			CommandLineParser parser = new GnuParser();
+			CommandLine line = parser.parse(options, args);
+			Properties props = FileUtil.loadProperties(
+					line.getOptionValue("prop"), true);
+			String corpusName = props.getProperty("org.apache.ctakes.ytex.corpusName");
+			String splitName = props.getProperty("org.apache.ctakes.ytex.splitName");
+			String featureSetName = props.getProperty("org.apache.ctakes.ytex.featureSetName");
+			WekaAttributeEvaluator wekaEval = KernelContextHolder
+					.getApplicationContext().getBean(
+							WekaAttributeEvaluator.class);
+			if (line.hasOption("arff")) {
+				wekaEval.evaluateAttributesFromFile(corpusName, splitName,
+						featureSetName, line.getOptionValue("arff"));
+			} else {
+				wekaEval.evaluateAttributesFromProps(corpusName, splitName,
+						featureSetName, props);
+			}
+		} catch (ParseException pe) {
+			printHelp(options);
+		}
+	}
+
+	private static void printHelp(Options options) {
+		HelpFormatter formatter = new HelpFormatter();
+		formatter
+				.printHelp(
+						"java "
+								+ WekaAttributeEvaluatorImpl.class.getName()
+								+ " evaluate attributes using a weka AttributeEvaluator",
+						options);
+	}
+
+	private ASEvaluation asEvaluation;
+	private AttributeSelection attributeSelection;
+
+	private ClassifierEvaluationDao classifierEvaluationDao;
+
+	private KernelUtil kernelUtil;
+
+	private SparseDataExporter sparseDataExporter;
+
+	/**
+	 * evaluate attributes, store in db
+	 * 
+	 * @param inst
+	 *            instances
+	 * @param label
+	 *            {@link FeatureEvaluation#getLabel()}
+	 * @param run
+	 *            {@link ClassifierEvaluation#getRun()} to map to fold
+	 * @param fold
+	 *            {@link ClassifierEvaluation#getFold()} to map to fold
+	 * @throws Exception
+	 */
+	public void evaluateAttributes(String corpusName, String featureSetName,
+			String splitName, Instances inst, String label, Integer run,
+			Integer fold) throws Exception {
+		AttributeSelection ae = this.getAttributeSelection();
+		ae.SelectAttributes(inst);
+		double rankedAttributes[][] = ae.rankedAttributes();
+		FeatureEvaluation fe = initializeFeatureEvaluation(corpusName,
+				featureSetName, splitName, label, run, fold);
+		List<FeatureRank> featureRanks = new ArrayList<FeatureRank>(
+				rankedAttributes.length);
+		for (int i = 0; i < rankedAttributes.length; i++) {
+			int index = (int) rankedAttributes[i][0];
+			double eval = rankedAttributes[i][1];
+			FeatureRank r = new FeatureRank();
+			r.setFeatureEval(fe);
+			r.setFeatureName(inst.attribute(index).name());
+			r.setRank(i + 1);
+			r.setEvaluation(eval);
+			featureRanks.add(r);
+		}
+		// delete this feature evaluation if it exists
+		classifierEvaluationDao.deleteFeatureEvaluation(corpusName,
+				featureSetName, label, fe.getEvaluationType(),
+				fe.getCrossValidationFoldId(), fe.getParam1(), fe.getParam2());
+		classifierEvaluationDao.saveFeatureEvaluation(fe, featureRanks);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.ctakes.ytex.weka.WekaAttributeEvaluator#evaluateAttributesFromFile(java.lang
+	 * .String, java.lang.String)
+	 */
+	@Override
+	public void evaluateAttributesFromFile(String corpusName,
+			String featureSetName, String splitName, String file)
+			throws Exception {
+		DataSource ds = new DataSource(file);
+		Instances inst = ds.getDataSet();
+		String label = FileUtil.parseLabelFromFileName(inst.relationName());
+		Integer run = FileUtil.parseRunFromFileName(inst.relationName());
+		Integer fold = FileUtil.parseFoldFromFileName(inst.relationName());
+		evaluateAttributes(corpusName, featureSetName, splitName, inst, label,
+				run, fold);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.ctakes.ytex.weka.WekaAttributeEvaluator#evaluateAttributesFromProps(java.lang
+	 * .String, java.lang.String)
+	 */
+	@Override
+	public void evaluateAttributesFromProps(String corpusName,
+			String splitName, String featureSetName, Properties props)
+			throws Exception {
+		sparseDataExporter.exportData(props,
+				new WekaAttributeEvaluatorFormatter(corpusName, featureSetName,
+						splitName), null);
+	}
+
+	public ASEvaluation getAsEvaluation() {
+		return asEvaluation;
+	}
+
+	public AttributeSelection getAttributeSelection() {
+		return attributeSelection;
+	}
+
+	public ClassifierEvaluationDao getClassifierEvaluationDao() {
+		return classifierEvaluationDao;
+	}
+
+	public KernelUtil getKernelUtil() {
+		return kernelUtil;
+	}
+
+	public SparseDataExporter getSparseDataExporter() {
+		return sparseDataExporter;
+	}
+
+	public FeatureEvaluation initializeFeatureEvaluation(String corpusName,
+			String featureSetName, String splitName, String label, Integer run,
+			Integer fold) {
+		FeatureEvaluation fe = new FeatureEvaluation();
+		fe.setCorpusName(corpusName);
+		fe.setFeatureSetName(featureSetName);
+		fe.setEvaluationType(this.getAsEvaluation().getClass().getSimpleName());
+		fe.setLabel(label);
+		if (run != null && fold != null) {
+			CrossValidationFold cvFold = this.classifierEvaluationDao
+					.getCrossValidationFold(corpusName, splitName, label, run,
+							fold);
+			if (cvFold != null)
+				fe.setCrossValidationFoldId(cvFold.getCrossValidationFoldId());
+			else {
+				log.warn("could not obtain cv_fold_id. label=" + label
+						+ ", run=" + run + ", fold=" + fold);
+			}
+		}
+		return fe;
+	}
+
+	public void setAsEvaluation(ASEvaluation asEvaluation) {
+		this.asEvaluation = asEvaluation;
+	}
+
+	public void setAttributeSelection(AttributeSelection attributeSelection) {
+		this.attributeSelection = attributeSelection;
+	}
+
+	public void setClassifierEvaluationDao(
+			ClassifierEvaluationDao classifierEvaluationDao) {
+		this.classifierEvaluationDao = classifierEvaluationDao;
+	}
+
+	public void setKernelUtil(KernelUtil kernelUtil) {
+		this.kernelUtil = kernelUtil;
+	}
+
+	public void setSparseDataExporter(SparseDataExporter sparseDataExporter) {
+		this.sparseDataExporter = sparseDataExporter;
+	}
+
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaBagOfWordsExporter.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaBagOfWordsExporter.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaBagOfWordsExporter.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaBagOfWordsExporter.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,39 @@
+package org.apache.ctakes.ytex.weka;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+
+import org.apache.ctakes.ytex.kernel.BagOfWordsDecorator;
+import org.apache.ctakes.ytex.kernel.BagOfWordsExporter;
+
+
+/**
+ * @author vhacongarlav
+ * 
+ */
+public interface WekaBagOfWordsExporter extends BagOfWordsExporter {
+
+	/**
+	 * @param arffRelation
+	 *            relation of arff file to generate
+	 * @param instanceClassQuery
+	 *            query with result columns: column 1 - integer instance id,
+	 *            column 2 - string class label
+	 * @param numericWordQuery
+	 *            query with result colums: column 1 - integer instance id,
+	 *            column 2 - word, column 3 - numeric word value
+	 * @param nominalWordQuery
+	 *            query with result colums: column 1 - integer instance id,
+	 *            column 2 - word, column 3 - string word value
+	 * @param writer
+	 *            where arff file will be written
+	 * @throws IOException
+	 */
+	public abstract void exportBagOfWords(String arffRelation,
+			String instanceClassQuery, String numericWordQuery,
+			String nominalWordQuery, BufferedWriter writer) throws IOException;
+
+	public abstract void exportBagOfWords(String propertyFile,
+			BagOfWordsDecorator bDecorator) throws IOException;
+
+}
\ No newline at end of file

Added: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaBagOfWordsExporterImpl.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaBagOfWordsExporterImpl.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaBagOfWordsExporterImpl.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaBagOfWordsExporterImpl.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,269 @@
+package org.apache.ctakes.ytex.weka;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.SortedSet;
+
+import org.apache.ctakes.ytex.kernel.AbstractBagOfWordsExporter;
+import org.apache.ctakes.ytex.kernel.BagOfWordsData;
+import org.apache.ctakes.ytex.kernel.BagOfWordsDecorator;
+import org.springframework.jdbc.core.PreparedStatementCreator;
+import org.springframework.jdbc.core.RowCallbackHandler;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+
+import weka.core.Attribute;
+import weka.core.FastVector;
+import weka.core.Instances;
+import weka.core.SparseInstance;
+
+public class WekaBagOfWordsExporterImpl extends AbstractBagOfWordsExporter
+		implements WekaBagOfWordsExporter {
+	private static final String INSTANCE_ID = "instance_id";
+	private static final String CLASS = "ytex_class";
+	
+	private void addWordsToInstances(Instances instances,
+			BagOfWordsData bagOfWordsData) throws IOException {
+		for (Map.Entry<Integer, String> entry : bagOfWordsData
+				.getDocumentClasses().entrySet()) {
+			double[] zeroValues = new double[instances.numAttributes()];
+			Arrays.fill(zeroValues, 0.0d);
+			SparseInstance wekaInstance = new SparseInstance(1.0d, zeroValues);
+			wekaInstance.setDataset(instances);
+			// set instance id
+			Attribute instanceId = instances.attribute(INSTANCE_ID);
+			wekaInstance.setValue(instanceId.index(), entry.getKey()
+					.doubleValue());
+			// set document class
+			Attribute classAttr = instances.attribute(CLASS);
+			wekaInstance.setValue(classAttr.index(),
+					classAttr.indexOfValue(entry.getValue()));
+			// set numeric words
+			if (bagOfWordsData.getInstanceNumericWords().get(entry.getKey()) != null) {
+				for (Map.Entry<String, Double> word : bagOfWordsData
+						.getInstanceNumericWords().get(entry.getKey())
+						.entrySet()) {
+					Attribute wordAttr = instances.attribute(word.getKey());
+					wekaInstance.setValue(wordAttr.index(), word.getValue()
+							.doubleValue());
+				}
+			}
+			// set nominal words
+			if (bagOfWordsData.getInstanceNominalWords().get(entry.getKey()) != null) {
+				for (Map.Entry<String, String> word : bagOfWordsData
+						.getInstanceNominalWords().get(entry.getKey())
+						.entrySet()) {
+					Attribute wordAttr = instances.attribute(word.getKey());
+					int valueIndex = wordAttr.indexOfValue(word.getValue());
+					if (valueIndex == -1) {
+						throw new IOException("oops! " + word);
+					}
+					wekaInstance.setValue(wordAttr.index(), valueIndex);
+				}
+			}
+			instances.add(wekaInstance);
+		}
+	}
+
+	public void exportBagOfWords(String arffRelation,
+			String instanceClassQuery, String instanceNumericWordQuery,
+			String instanceNominalWordQuery, BufferedWriter writer)
+			throws IOException {
+		exportBagOfWords(arffRelation, instanceClassQuery,
+				instanceNumericWordQuery, instanceNominalWordQuery, writer,
+				null);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * edu.yale.cbb.uima.weka.BagOfWordsExporter#exportBagOfWords(java.lang.
+	 * String, java.lang.String, java.lang.String, java.lang.String,
+	 * java.io.BufferedWriter)
+	 */
+	public void exportBagOfWords(String arffRelation,
+			String instanceClassQuery, String instanceNumericWordQuery,
+			String instanceNominalWordQuery, BufferedWriter writer,
+			BagOfWordsDecorator bDecorator) throws IOException {
+		BagOfWordsData bagOfWordsData = new BagOfWordsData();
+		// load instance classes
+		getInstances(instanceClassQuery, bagOfWordsData);
+		loadData(bagOfWordsData, instanceNumericWordQuery,
+				instanceNominalWordQuery, bDecorator);
+		// add instance for each document
+		// initialize the instances
+		Instances instances = initializeInstances(arffRelation, bagOfWordsData,
+				bDecorator);
+		this.addWordsToInstances(instances, bagOfWordsData);
+		writer.write(instances.toString());
+	}
+
+	public void exportBagOfWords(String propertyFile) throws IOException {
+		exportBagOfWords(propertyFile, null);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * edu.yale.cbb.uima.weka.BagOfWordsExporter#exportBagOfWords(java.lang.
+	 * String)
+	 */
+	public void exportBagOfWords(String propertyFile,
+			BagOfWordsDecorator bDecorator) throws IOException {
+		Properties props = new Properties();
+		loadProperties(propertyFile, props);
+		BufferedWriter writer = null;
+		try {
+			writer = new BufferedWriter(new FileWriter(
+					props.getProperty("arffFile")));
+			exportBagOfWords(props.getProperty("arffRelation"),
+					props.getProperty("instanceClassQuery"),
+					props.getProperty("numericWordQuery", ""),
+					props.getProperty("nominalWordQuery", ""), writer,
+					bDecorator);
+		} finally {
+			if (writer != null)
+				writer.close();
+		}
+	}
+
+	/**
+	 * initialize the weka Instances
+	 * 
+	 * @param arffRelation
+	 * @param sql
+	 * @param classLabels
+	 * @param idfMap
+	 * @param docLengthMap
+	 * @return
+	 */
+	protected Instances initializeInstances(String arffRelation,
+			BagOfWordsData bagOfWordsData, BagOfWordsDecorator bDecorator) {
+		FastVector wekaAttributes = new FastVector(bagOfWordsData
+				.getNumericWords().size()
+				+ bagOfWordsData.getNominalWordValueMap().size() + 2);
+		// add instance id attribute
+		wekaAttributes.addElement(new Attribute(INSTANCE_ID));
+		// add numeric word attributes
+		for (String word : bagOfWordsData.getNumericWords()) {
+			Attribute attribute = new Attribute(word);
+			wekaAttributes.addElement(attribute);
+		}
+		// add nominal word attributes
+		for (Map.Entry<String, SortedSet<String>> nominalWordEntry : bagOfWordsData
+				.getNominalWordValueMap().entrySet()) {
+			FastVector wordValues = new FastVector(nominalWordEntry.getValue()
+					.size());
+			for (String wordValue : nominalWordEntry.getValue()) {
+				wordValues.addElement(wordValue);
+			}
+			Attribute attribute = new Attribute(nominalWordEntry.getKey(),
+					wordValues);
+			wekaAttributes.addElement(attribute);
+		}
+		// add class attribute
+		FastVector wekaClassLabels = new FastVector(bagOfWordsData.getClasses()
+				.size());
+		for (String classLabel : bagOfWordsData.getClasses()) {
+			wekaClassLabels.addElement(classLabel);
+		}
+		wekaAttributes.addElement(new Attribute(CLASS, wekaClassLabels));
+		Instances instances = new Instances(arffRelation, wekaAttributes, 0);
+		instances.setClassIndex(instances.numAttributes() - 1);
+		return instances;
+	}
+
+	protected void getInstances(final String sql,
+			final BagOfWordsData bagOfWordsData) {
+		txNew.execute(new TransactionCallback<Object>() {
+
+			@Override
+			public Object doInTransaction(TransactionStatus txStatus) {
+				jdbcTemplate.query(new PreparedStatementCreator() {
+
+					@Override
+					public PreparedStatement createPreparedStatement(
+							Connection conn) throws SQLException {
+						return conn.prepareStatement(sql,
+								ResultSet.TYPE_FORWARD_ONLY,
+								ResultSet.CONCUR_READ_ONLY);
+					}
+
+				}, new RowCallbackHandler() {
+					private Set<String> numericColumnHeaders;
+					private Set<String> nominalColumnHeaders;
+
+					private void initMetaData(ResultSet rs) throws SQLException {
+						if (numericColumnHeaders == null) {
+							numericColumnHeaders = new HashSet<String>();
+							nominalColumnHeaders = new HashSet<String>();
+
+							ResultSetMetaData rsmd = rs.getMetaData();
+							for (int i = 3; i <= rsmd.getColumnCount(); i++) {
+								int colType = rsmd.getColumnType(i);
+								if (colType == Types.CHAR
+										|| colType == Types.BOOLEAN
+										|| colType == Types.VARCHAR) {
+									nominalColumnHeaders.add(rsmd
+											.getColumnLabel(i));
+								} else if (colType == Types.DECIMAL
+										|| colType == Types.BIGINT
+										|| colType == Types.DOUBLE
+										|| colType == Types.FLOAT
+										|| colType == Types.DECIMAL
+										|| colType == Types.INTEGER
+										|| colType == Types.NUMERIC
+										|| colType == Types.REAL) {
+									numericColumnHeaders.add(rsmd
+											.getColumnLabel(i));
+								}
+							}
+						}
+
+					}
+
+					@Override
+					public void processRow(ResultSet rs) throws SQLException {
+						this.initMetaData(rs);
+						int instanceId = rs.getInt(1);
+						String classLabel = rs.getString(2);
+						bagOfWordsData.getDocumentClasses().put(instanceId,
+								classLabel);
+						bagOfWordsData.getClasses().add(classLabel);
+						// add other attributes
+						for (String columnHeader : this.numericColumnHeaders) {
+							double wordValue = rs.getDouble(columnHeader);
+							if (!rs.wasNull()) {
+								addNumericWordToInstance(bagOfWordsData,
+										instanceId, columnHeader, wordValue);
+							}
+						}
+						for (String columnHeader : this.nominalColumnHeaders) {
+							String wordValue = rs.getString(columnHeader);
+							if (!rs.wasNull()) {
+								addNominalWordToInstance(bagOfWordsData,
+										instanceId, columnHeader, wordValue);
+							}
+						}
+
+					}
+				});
+				return null;
+			}
+		});
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaFormatterFactory.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaFormatterFactory.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaFormatterFactory.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaFormatterFactory.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,252 @@
+package org.apache.ctakes.ytex.weka;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Properties;
+import java.util.SortedMap;
+import java.util.SortedSet;
+
+import org.apache.ctakes.ytex.kernel.BaseSparseDataFormatter;
+import org.apache.ctakes.ytex.kernel.FileUtil;
+import org.apache.ctakes.ytex.kernel.InstanceData;
+import org.apache.ctakes.ytex.kernel.KernelUtil;
+import org.apache.ctakes.ytex.kernel.SparseData;
+import org.apache.ctakes.ytex.kernel.SparseDataFormatter;
+import org.apache.ctakes.ytex.kernel.SparseDataFormatterFactory;
+
+import weka.core.Attribute;
+import weka.core.FastVector;
+import weka.core.Instances;
+import weka.core.SparseInstance;
+import weka.core.converters.ArffSaver;
+
+public class WekaFormatterFactory implements SparseDataFormatterFactory {
+
+	public static class WekaFormatter extends BaseSparseDataFormatter {
+		public static final String CLASS = "ytex_class";
+
+		public static final String INSTANCE_ID = "instance_id";
+		InstanceData instanceLabel = null;
+		FastVector wekaAttributes = null;
+		public WekaFormatter(KernelUtil kernelUtil) {
+			super(kernelUtil);
+		}
+
+		/**
+		 * Add a nominal attribute to the list of attributes
+		 * 
+		 * @param attributeName
+		 * @param attributeValues
+		 * @param addDummy0
+		 *            if true, add a dummy attribute as the first attribute
+		 *            value in the list of potential attribute values.
+		 */
+		private void addNominalAttribute(String attributeName,
+				SortedSet<String> attributeValues, boolean addDummy0) {
+			FastVector wordValues = new FastVector(attributeValues.size()
+					+ (addDummy0 ? 1 : 0));
+			if (addDummy0) {
+				String dummyName;
+				if (!attributeValues.contains("null"))
+					dummyName = "null";
+				else if (!attributeValues.contains("0"))
+					dummyName = "0";
+				else
+					dummyName = Long.toString(System.currentTimeMillis());
+				wordValues.addElement(dummyName);
+			}
+			for (String wordValue : attributeValues) {
+				wordValues.addElement(wordValue);
+			}
+			Attribute attribute = new Attribute(attributeName, wordValues);
+			wekaAttributes.addElement(attribute);
+		}
+
+		/**
+		 * add sparse data to instances
+		 * 
+		 * @param instances
+		 * @param bagOfWordsData
+		 * @param instanceClasses
+		 * @throws IOException
+		 */
+		private void addWordsToInstances(Instances instances,
+				SparseData bagOfWordsData,
+				SortedMap<Long, String> instanceClasses) throws IOException {
+			for (Map.Entry<Long, String> entry : instanceClasses.entrySet()) {
+				double[] zeroValues = new double[instances.numAttributes()];
+				Arrays.fill(zeroValues, 0.0d);
+				SparseInstance wekaInstance = new SparseInstance(1.0d,
+						zeroValues);
+				wekaInstance.setDataset(instances);
+				// set instance id
+				Attribute instanceId = instances.attribute(INSTANCE_ID);
+				wekaInstance.setValue(instanceId.index(), entry.getKey()
+						.doubleValue());
+				// set document class
+				Attribute classAttr = instances.attribute(CLASS);
+				wekaInstance.setValue(classAttr.index(),
+						classAttr.indexOfValue(entry.getValue()));
+				// set numeric words
+				if (bagOfWordsData.getInstanceNumericWords()
+						.get(entry.getKey()) != null) {
+					for (Map.Entry<String, Double> word : bagOfWordsData
+							.getInstanceNumericWords().get(entry.getKey())
+							.entrySet()) {
+						Attribute wordAttr = instances.attribute(word.getKey());
+						wekaInstance.setValue(wordAttr.index(), word.getValue()
+								.doubleValue());
+					}
+				}
+				// set nominal words
+				if (bagOfWordsData.getInstanceNominalWords()
+						.get(entry.getKey()) != null) {
+					for (Map.Entry<String, String> word : bagOfWordsData
+							.getInstanceNominalWords().get(entry.getKey())
+							.entrySet()) {
+						Attribute wordAttr = instances.attribute(word.getKey());
+						int valueIndex = wordAttr.indexOfValue(word.getValue());
+						if (valueIndex == -1) {
+							throw new IOException("oops! " + word);
+						}
+						wekaInstance.setValue(wordAttr.index(), valueIndex);
+					}
+				}
+				instances.add(wekaInstance);
+			}
+		}
+
+		@Override
+		public void clearFold() {
+		}
+
+		@Override
+		public void clearLabel() {
+		}
+
+		@Override
+		public void exportFold(SparseData sparseData,
+				SortedMap<Long, String> sortedMap, boolean train, String label,
+				Integer run, Integer fold) throws IOException {
+			Instances inst = initializeInstances(sparseData, sortedMap, train,
+					label, run, fold);
+			String filename = FileUtil.getDataFilePrefix(outdir, label, run,
+					fold, train) + ".arff";
+			ArffSaver saver = new ArffSaver();
+			saver.setDestination(new File(filename));
+			saver.setFile(new File(filename));
+			saver.setInstances(inst);
+			saver.writeBatch();
+		}
+
+		/**
+		 * initialize attributes
+		 * 
+		 * @param bagOfWordsData
+		 * @param classNames
+		 */
+		protected void initializeAttributes(SparseData bagOfWordsData,
+				SortedSet<String> classNames) {
+			wekaAttributes = new FastVector(bagOfWordsData.getNumericWords()
+					.size()
+					+ bagOfWordsData.getNominalWordValueMap().size()
+					+ 2);
+			// add instance id attribute
+			wekaAttributes.addElement(new Attribute(INSTANCE_ID));
+			// add numeric word attributes
+			for (String word : bagOfWordsData.getNumericWords()) {
+				Attribute attribute = new Attribute(word);
+				wekaAttributes.addElement(attribute);
+			}
+			// add nominal word attributes
+			for (Map.Entry<String, SortedSet<String>> nominalWordEntry : bagOfWordsData
+					.getNominalWordValueMap().entrySet()) {
+				addNominalAttribute(nominalWordEntry.getKey(),
+						nominalWordEntry.getValue(), true);
+			}
+			// add class attribute
+			addNominalAttribute(CLASS, classNames, false);
+		}
+
+		@Override
+		public void initializeExport(InstanceData instanceLabel,
+				Properties properties, SparseData sparseData)
+				throws IOException {
+			super.initializeExport(instanceLabel, properties, sparseData);
+			this.instanceLabel = instanceLabel;
+		}
+
+		@Override
+		public void initializeFold(SparseData sparseData, String label,
+				Integer run, Integer fold,
+				SortedMap<Boolean, SortedMap<Long, String>> foldInstanceLabelMap)
+				throws IOException {
+			if (SCOPE_FOLD.equals(exportProperties.getProperty(SCOPE))) {
+				this.initializeAttributes(sparseData, instanceLabel
+						.getLabelToClassMap().get(label));
+			}
+		}
+
+		/**
+		 * initialize the weka Instances
+		 * 
+		 * @param arffRelation
+		 * @param sql
+		 * @param classLabels
+		 * @param idfMap
+		 * @param docLengthMap
+		 * @return
+		 * @throws IOException
+		 */
+		public Instances initializeInstances(SparseData sparseData,
+				SortedMap<Long, String> instanceClasses, boolean train,
+				String label, Integer run, Integer fold) throws IOException {
+			// add label, run, fold, train/test to relation
+			String arffRelation = this.exportProperties.getProperty(
+					"arffRelation", "org.apache.ctakes.ytex");
+			String relation = arffRelation + "_"
+					+ FileUtil.getDataFilePrefix(null, label, run, fold, train);
+			Instances instances = new Instances(relation, wekaAttributes, 0);
+			instances.setClassIndex(instances.numAttributes() - 1);
+			// add instances
+			addWordsToInstances(instances, sparseData, instanceClasses);
+			return instances;
+		}
+
+		/**
+		 * initialize attributes on a per-label basis even if the data is the
+		 * same across all labels. The class ids might be different for
+		 * different labels.
+		 */
+		@Override
+		public void initializeLabel(
+				String label,
+				SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>> labelInstances,
+				Properties properties, SparseData sparseData)
+				throws IOException {
+			if (SCOPE_LABEL.equals(properties.getProperty(SCOPE))
+					|| properties.getProperty(SCOPE) == null
+					|| properties.getProperty(SCOPE).length() == 0) {
+				this.initializeAttributes(sparseData, instanceLabel
+						.getLabelToClassMap().get(label));
+			}
+		}
+
+	}
+
+	private KernelUtil kernelUtil;
+
+	public SparseDataFormatter getFormatter() {
+		return new WekaFormatter(this.getKernelUtil());
+	}
+
+	public KernelUtil getKernelUtil() {
+		return kernelUtil;
+	}
+
+	public void setKernelUtil(KernelUtil kernelUtil) {
+		this.kernelUtil = kernelUtil;
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaResultInstanceImporter.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaResultInstanceImporter.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaResultInstanceImporter.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaResultInstanceImporter.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,31 @@
+package org.apache.ctakes.ytex.weka;
+
+import java.util.List;
+
+/**
+ * Import the weka results for the specified instance.
+ */
+public interface WekaResultInstanceImporter {
+	/**
+	 * 
+	 * @param instanceNumber
+	 *            optional instance number when multiple instance classified,
+	 *            used for outputting errors/warnings
+	 * @param instanceKey
+	 *            list of attributes to resolve instance - foreign key to
+	 *            document/sentence/whatever
+	 * @param task
+	 *            classification task
+	 * @param classAuto
+	 *            classifer's predicted class
+	 * @param classGold
+	 *            gold standard class index
+	 * @param prediction
+	 *            probabilities of belonging to specified classes, if run with
+	 *            -distribution option. else just probability of belonging to
+	 *            predicted class.
+	 */
+	public void importInstanceResult(Integer instanceNumber,
+			List<String> instanceKey, String task, int classAuto,
+			int classGold, List<Double> predictions);
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaResultsImporter.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaResultsImporter.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaResultsImporter.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaResultsImporter.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,38 @@
+package org.apache.ctakes.ytex.weka;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+
+/**
+ * parse weka instance output when classifier run with -p option. load results
+ * into db.
+ */
+public interface WekaResultsImporter {
+
+	/**
+	 * load results into document class table. the document id must be the first
+	 * attribute in the column of output values.
+	 * 
+	 * @return
+	 */
+	public abstract void importDocumentResults(String task,
+			BufferedReader reader) throws IOException;
+
+	/**
+	 * Parse weka output file, pass results to the specified importer to save
+	 * results
+	 * 
+	 * @param resultInstanceImporter
+	 * @param task
+	 * @param reader
+	 * @throws IOException
+	 */
+	public abstract void importResults(
+			WekaResultInstanceImporter resultInstanceImporter, String task,
+			BufferedReader reader) throws IOException;
+
+	public void importClassifierEvaluation(String name, Integer fold,
+			String algorithm, String label, String options, String experiment,
+			BufferedReader reader) throws IOException;
+
+}
\ No newline at end of file

Added: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaResultsImporterImpl.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaResultsImporterImpl.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaResultsImporterImpl.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/weka/WekaResultsImporterImpl.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,180 @@
+package org.apache.ctakes.ytex.weka;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ctakes.ytex.kernel.model.ClassifierEvaluation;
+import org.apache.ctakes.ytex.kernel.model.ClassifierInstanceEvaluation;
+import org.hibernate.SessionFactory;
+
+
+/**
+ * parse weka instance output when classifier run with -p option. load results
+ * into db.
+ */
+public class WekaResultsImporterImpl implements WekaResultsImporter {
+	// inst# actual predicted error prediction (instance_id,C0000726,C0000731)
+	// inst#     actual  predicted error prediction (instance_id)
+	// private static final Pattern patHeader = Pattern
+	// .compile("\\sinst#\\s+actual\\s+predicted\\s+error\\s+");
+	private static final Pattern patHeader = Pattern
+			.compile("\\s*inst#.*actual.*predicted.*error");
+	// 1 1:0 1:0 0.988 (330478,101,0)
+	// private static final Pattern patResult = Pattern
+	// .compile("\\s+(\\d+)\\s+(\\d+)\\:\\d+\\s+(\\d+)\\:\\d+\\s+\\+{0,1}\\s+(\\d\\.\\d+)\\s+\\((.*)\\)");
+	private static final Pattern patResult = Pattern
+			.compile("\\s+(\\d+)\\s+(\\d+)\\:.*\\s+(\\d+)\\:.*\\s+\\+{0,1}\\s+(.*)\\s+\\((.*)\\)");
+	private SessionFactory sessionFactory;
+	private static final Log log = LogFactory
+			.getLog(DocumentResultInstanceImporter.class);
+
+	public SessionFactory getSessionFactory() {
+		return sessionFactory;
+	}
+
+	public void setSessionFactory(SessionFactory sessionFactory) {
+		this.sessionFactory = sessionFactory;
+	}
+
+	/**
+	 * this imports the classification results for a document
+	 */
+	private DocumentResultInstanceImporter docResultInstanceImporter;
+
+	public DocumentResultInstanceImporter getDocResultInstanceImporter() {
+		return docResultInstanceImporter;
+	}
+
+	public void setDocResultInstanceImporter(
+			DocumentResultInstanceImporter docResultInstanceImporter) {
+		this.docResultInstanceImporter = docResultInstanceImporter;
+	}
+
+	/**
+	 * Delegate to importResults
+	 * 
+	 * @see org.apache.ctakes.ytex.weka.WekaResultsImporter#importDocumentResults(java.lang.String,
+	 *      java.io.BufferedReader)
+	 */
+	public void importDocumentResults(String task, BufferedReader reader)
+			throws IOException {
+		this.importResults(docResultInstanceImporter, task, reader);
+	}
+
+	/**
+	 * Parse results, pass them off to WekaResultInstanceImporter
+	 * 
+	 * @see org.apache.ctakes.ytex.weka.WekaResultsImporter#importResults(org.apache.ctakes.ytex.weka.
+	 *      WekaResultInstanceImporter, java.lang.String,
+	 *      java.io.BufferedReader)
+	 */
+	public void importResults(
+			WekaResultInstanceImporter resultInstanceImporter, String task,
+			BufferedReader reader) throws IOException {
+		String line = null;
+		boolean keepGoing = true;
+		boolean inResults = false;
+		while ((line = reader.readLine()) != null && keepGoing) {
+			if (!inResults) {
+				// not yet in the results section - see if we found the header
+				inResults = patHeader.matcher(line).find();
+			} else {
+				// in results section - see if this line contains some results
+				Matcher matcher = patResult.matcher(line);
+				if (matcher.find()) {
+					// matches - parse it, pass it to the instance importer
+					int instanceNum = Integer.parseInt(matcher.group(1));
+					int classGold = Integer.parseInt(matcher.group(2));
+					int classAuto = Integer.parseInt(matcher.group(3));
+					// split something like
+					// *0.988 0.012
+					// or
+					// *0.988,0.012
+					// or just
+					// 0.988
+					String[] arrPredictionStr = matcher.group(4).split(
+							"\\*|,|\\s");
+					List<Double> listPredictions = new ArrayList<Double>(
+							arrPredictionStr.length);
+					for (String predStr : arrPredictionStr) {
+						if (predStr.length() > 0)
+							listPredictions.add(new Double(predStr));
+					}
+					List<String> instanceKey = Arrays.asList(matcher.group(5)
+							.split(","));
+					resultInstanceImporter.importInstanceResult(instanceNum,
+							instanceKey, task, classAuto, classGold,
+							listPredictions);
+				} else {
+					// hit end of results - stop
+					keepGoing = false;
+				}
+			}
+		}
+	}
+
+	public void importClassifierEvaluation(String name, Integer fold,
+			String algorithm, String label, String options, String experiment,
+			BufferedReader reader) throws IOException {
+		ClassifierEvaluation ce = new ClassifierEvaluation();
+		ce.setName(name);
+		ce.setFold(fold);
+		ce.setAlgorithm(algorithm);
+		ce.setLabel(label);
+		ce.setOptions(options);
+		ce.setExperiment(experiment);
+		this.getSessionFactory().getCurrentSession().save(ce);
+		ClassifierEvaluationInstanceImporter instanceImporter = new ClassifierEvaluationInstanceImporter(
+				ce, false);
+		this.importResults(instanceImporter, label, reader);
+	}
+
+	public class ClassifierEvaluationInstanceImporter implements
+			WekaResultInstanceImporter {
+		private ClassifierEvaluation classifierEvaluation;
+		private boolean storeProbabilities;
+
+		public ClassifierEvaluationInstanceImporter(
+				ClassifierEvaluation classifierEvaluation,
+				boolean storeProbabilities) {
+			super();
+			this.classifierEvaluation = classifierEvaluation;
+			this.storeProbabilities = storeProbabilities;
+		}
+
+		@Override
+		public void importInstanceResult(Integer instanceNumber,
+				List<String> instanceKey, String task, int classAuto,
+				int classGold, List<Double> predictions) {
+			ClassifierInstanceEvaluation ci = new ClassifierInstanceEvaluation();
+			if (instanceKey.size() > 0) {
+				try {
+					ci.setInstanceId(Integer.parseInt(instanceKey.get(0)));
+				} catch (NumberFormatException nfe) {
+				}
+			} else {
+				ci.setInstanceId(instanceNumber);
+			}
+			ci.setPredictedClassId(classAuto);
+			ci.setTargetClassId(classGold);
+			if (storeProbabilities && predictions != null
+					&& predictions.size() > 0) {
+				for (int i = 0; i < predictions.size(); i++) {
+					ci.getClassifierInstanceProbabilities().put(i,
+							predictions.get(i));
+				}
+			}
+			ci.setClassifierEvaluation(classifierEvaluation);
+			sessionFactory.getCurrentSession().save(ci);
+		}
+
+	}
+
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/AppJdlTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/AppJdlTest.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/AppJdlTest.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/AppJdlTest.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,66 @@
+package org.apache.ctakes.jdl;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.junit.Assume.assumeThat;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.xml.bind.JAXBException;
+
+
+import org.apache.ctakes.jdl.AppJdl;
+import org.apache.ctakes.jdl.common.FileUtil;
+import org.apache.ctakes.jdl.data.base.JdlConnection;
+import org.apache.ctakes.jdl.data.xml.jaxb.ObjectFactoryUtil;
+import org.apache.ctakes.jdl.schema.xdl.JdbcType;
+import org.apache.ctakes.jdl.test.PropFileMaps;
+import org.apache.ctakes.jdl.test.Resources;
+import org.apache.ctakes.jdl.test.SqlJdl;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class AppJdlTest {
+	private static JdbcType jdbc;
+	private static JdlConnection jdlConnection;
+	private static String CX = FileUtil.getFile(Resources.CONN_X).toString();
+	private static String D2C = FileUtil.getFile(Resources.DATA2C).toString();
+	private static String D2X = FileUtil.getFile(Resources.DATA2X).toString();
+	private static String L2C = FileUtil.getFile(Resources.LOAD2C).toString();
+	private static String L2X = FileUtil.getFile(Resources.LOAD2X).toString();
+
+	@BeforeClass
+	public static void initClass() throws JAXBException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException {
+		jdbc = ObjectFactoryUtil.getJdbcTypeBySrcXml(CX);
+		jdlConnection = new JdlConnection(jdbc);
+	}
+
+	@Test
+	public void execute() throws JAXBException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
+		assumeThat(jdbc.getDriver(), not(Resources.ENV_DRIVER));
+		assumeThat(jdbc.getUrl(), not(Resources.ENV_URL));
+		assumeThat(PropFileMaps.DEMO, is(true));
+		demo();
+	}
+
+	public static void demo() throws JAXBException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
+		AppJdl appJdl;
+		Connection connection = jdlConnection.getOpenConnection();
+		SqlJdl.create(connection);
+		// csv
+		appJdl = new AppJdl(CX, D2C, L2C);
+		appJdl.execute();
+		SqlJdl.select(connection, true);
+		SqlJdl.delete(connection);
+		// xml
+		appJdl = new AppJdl(CX, D2X, L2X);
+		appJdl.execute();
+		SqlJdl.select(connection, true);
+		SqlJdl.delete(connection);
+		// clear
+		SqlJdl.drop(connection);
+		jdlConnection.closeConnection();
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/AppMainTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/AppMainTest.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/AppMainTest.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/AppMainTest.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,88 @@
+package org.apache.ctakes.jdl;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeThat;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.xml.bind.JAXBException;
+
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.ParseException;
+import org.apache.ctakes.jdl.AppMain;
+import org.apache.ctakes.jdl.common.FileUtil;
+import org.apache.ctakes.jdl.data.base.JdlConnection;
+import org.apache.ctakes.jdl.data.xml.jaxb.ObjectFactoryUtil;
+import org.apache.ctakes.jdl.schema.xdl.JdbcType;
+import org.apache.ctakes.jdl.test.PropFileMaps;
+import org.apache.ctakes.jdl.test.Resources;
+import org.apache.ctakes.jdl.test.SqlJdl;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class AppMainTest {
+	private static JdbcType jdbc;
+	private static JdlConnection jdlConnection;
+	private static String CX = FileUtil.getFile(Resources.CONN_X).toString();
+	private static String D1C = FileUtil.getFile(Resources.DATA1C).toString();
+	private static String D1X = FileUtil.getFile(Resources.DATA1X).toString();
+	private static String L1C = FileUtil.getFile(Resources.LOAD1C).toString();
+	private static String L1X = FileUtil.getFile(Resources.LOAD1X).toString();
+	private static String C = "-" + AppMain.OPT_XDL_CONN;
+	private static String D = "-" + AppMain.OPT_XDL_DATA;
+	private static String L = "-" + AppMain.OPT_XDL_LOAD;
+
+	@BeforeClass
+	public static void initClass() throws JAXBException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException {
+		jdbc = ObjectFactoryUtil.getJdbcTypeBySrcXml(CX);
+		jdlConnection = new JdlConnection(jdbc);
+	}
+
+	@Test
+	public void parsingCLI() throws ParseException {
+		String[] args;
+		CommandLine cl;
+		args = new String[] { C, "conn.xml", D, "data.xml", L, "load.csv" };
+		cl = AppMain.parsingCLI(args);
+		assertThat(cl.getOptionValue(AppMain.OPT_XDL_CONN), is("conn.xml"));
+		assertThat(cl.getOptionValue(AppMain.OPT_XDL_DATA), is("data.xml"));
+		assertThat(cl.getOptionValue(AppMain.OPT_XDL_LOAD), is("load.csv"));
+		args = new String[] { C, "conn.xml", D, "data.xml", L, "load.xml" };
+		cl = AppMain.parsingCLI(args);
+		assertThat(cl.getOptionValue(AppMain.OPT_XDL_CONN), is("conn.xml"));
+		assertThat(cl.getOptionValue(AppMain.OPT_XDL_DATA), is("data.xml"));
+		assertThat(cl.getOptionValue(AppMain.OPT_XDL_LOAD), is("load.xml"));
+	}
+
+	@Test
+	public void main() throws JAXBException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
+		assumeThat(jdbc.getDriver(), not(Resources.ENV_DRIVER));
+		assumeThat(jdbc.getUrl(), not(Resources.ENV_URL));
+		assumeThat(PropFileMaps.DEMO, is(true));
+		demo();
+	}
+
+	public static void demo() throws JAXBException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
+		String[] args;
+		Connection connection = jdlConnection.getOpenConnection();
+		SqlJdl.create(connection);
+		// csv
+		args = new String[] { C, CX, D, D1C, L, L1C };
+		AppMain.main(args);
+		SqlJdl.select(connection, true);
+		SqlJdl.delete(connection);
+		// xml
+		args = new String[] { C, CX, D, D1X, L, L1X };
+		AppMain.main(args);
+		SqlJdl.select(connection, true);
+		SqlJdl.delete(connection);
+		// clear
+		SqlJdl.drop(connection);
+		jdlConnection.closeConnection();
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/AppTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/AppTest.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/AppTest.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/AppTest.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,38 @@
+package org.apache.ctakes.jdl;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest 
+    extends TestCase
+{
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public AppTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite( AppTest.class );
+    }
+
+    /**
+     * Rigourous Test :-)
+     */
+    public void testApp()
+    {
+        assertTrue( true );
+    }
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/FileUtilTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/FileUtilTest.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/FileUtilTest.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/FileUtilTest.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,56 @@
+package org.apache.ctakes.jdl.common;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+
+
+import org.apache.commons.lang.SystemUtils;
+import org.apache.ctakes.jdl.common.FileUtil;
+import org.apache.ctakes.jdl.test.Resources;
+import org.junit.Test;
+import org.junit.experimental.theories.DataPoint;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
+
+@RunWith(Theories.class)
+public class FileUtilTest {
+	@DataPoint
+	public static String CX = Resources.CONN_X;
+	@DataPoint
+	public static String L1C = Resources.LOAD1C;
+	@DataPoint
+	public static String L2C = Resources.LOAD2C;
+	@DataPoint
+	public static String L1X = Resources.LOAD1X;
+	@DataPoint
+	public static String L2X = Resources.LOAD2X;
+
+	@Test
+	public void getJavaClassPaths() {
+		assertThat(FileUtil.getJavaClassPaths(), notNullValue());
+	}
+
+	@Theory
+	public void getFile(String fileName) {
+		assertThat(FileUtil.getFile(fileName), notNullValue());
+	}
+
+	@Theory
+	public void getCanonical(String fileName) throws IOException {
+		assertThat(FileUtil.getCanonical(null, SystemUtils.USER_HOME), is(SystemUtils.USER_HOME));
+		assertThat(FileUtil.getCanonical(null), is(SystemUtils.USER_DIR));
+		assertThat(FileUtil.getCanonical(new File(fileName)), is(new File(fileName).getCanonicalPath()));
+	}
+
+	@Theory
+	public void fullPath(String fileName) throws IOException {
+		for (String token : FileUtil.getJavaClassPaths()) {
+			assertThat(FileUtil.fullPath(new File(token), fileName), is(new File(token + SystemUtils.FILE_SEPARATOR + fileName).getCanonicalPath()));
+		}
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/PropFileTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/PropFileTest.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/PropFileTest.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/PropFileTest.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,39 @@
+package org.apache.ctakes.jdl.common;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import java.util.Properties;
+
+
+import org.apache.ctakes.jdl.common.FileUtil;
+import org.apache.ctakes.jdl.common.PropFile;
+import org.apache.ctakes.jdl.test.PropFileMaps;
+import org.apache.ctakes.jdl.test.Resources;
+import org.junit.Test;
+
+public class PropFileTest {
+	@Test
+	public void getProperties() {
+		Properties properties = null;
+		assertThat(properties, nullValue());
+		properties = PropFile.getProperties("/" + Resources.MAPS_P, true);
+		assertThat(properties, notNullValue());
+		assertThat(properties.getProperty(Resources.MAP_ID), is(Resources.MAP_NAME));
+		assertThat(properties.getProperty(Resources.MAP_KEY), is(Resources.MAP_VALUE));
+		properties = PropFile.getProperties(FileUtil.getFile(Resources.MAPS_P).toString(), false);
+		assertThat(properties, notNullValue());
+		assertThat(properties.getProperty(Resources.MAP_ID), is(Resources.MAP_NAME));
+		assertThat(properties.getProperty(Resources.MAP_KEY), is(Resources.MAP_VALUE));
+	}
+
+	@Test
+	public void getProperty() {
+		assertThat(PropFileMaps.getProperty(Resources.MAP_ID), is(Resources.MAP_NAME));
+		assertThat(PropFileMaps.getProperty(Resources.MAP_KEY), is(Resources.MAP_VALUE));
+		assertThat(PropFileMaps.getProperty("code"), nullValue());
+		assertThat(PropFileMaps.getProperty("descr"), nullValue());
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/PropertiesFileTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/PropertiesFileTest.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/PropertiesFileTest.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/PropertiesFileTest.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,59 @@
+package org.apache.ctakes.jdl.common;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import java.io.IOException;
+import java.util.Properties;
+
+
+import org.apache.ctakes.jdl.common.FileUtil;
+import org.apache.ctakes.jdl.common.PropertiesFile;
+import org.apache.ctakes.jdl.test.Resources;
+import org.junit.After;
+import org.junit.Test;
+
+public class PropertiesFileTest {
+	private static final PropertiesFile propertiesFile = new PropertiesFile();
+
+	@Test
+	public void loadInputStream() throws IOException {
+		propertiesFile.loadInputStream(FileUtil.getFile(Resources.MAPS_P).toString());
+		assertThat(propertiesFile.getProperty(Resources.MAP_ID), is(Resources.MAP_NAME));
+		assertThat(propertiesFile.getProperty(Resources.MAP_KEY), is(Resources.MAP_VALUE));
+	}
+
+	@Test(expected = IOException.class)
+	public void loadInputStreamExecption() throws IOException {
+		propertiesFile.loadInputStream("/" + Resources.MAPS_P);
+	}
+
+	@Test
+	public void loadResourceAsStream() throws IOException {
+		propertiesFile.loadResourceAsStream("/" + Resources.MAPS_P);
+		assertThat(propertiesFile.getProperty(Resources.MAP_ID), is(Resources.MAP_NAME));
+		assertThat(propertiesFile.getProperty(Resources.MAP_KEY), is(Resources.MAP_VALUE));
+	}
+
+	@Test(expected = NullPointerException.class)
+	public void loadResourceAsStreamExecption() throws IOException {
+		propertiesFile.loadResourceAsStream(FileUtil.getFile(Resources.MAPS_P).toString());
+	}
+
+	@Test
+	public void property() {
+		Properties properties = new Properties();
+		properties.setProperty("code", "descr");
+		propertiesFile.setProperties(properties);
+		assertThat(propertiesFile.getProperty("code"), is("descr"));
+	}
+
+	@After
+	public void clear() {
+		propertiesFile.clear();
+		assertThat(propertiesFile.getProperty(Resources.MAP_ID), nullValue());
+		assertThat(propertiesFile.getProperty(Resources.MAP_KEY), nullValue());
+		assertThat(propertiesFile.getProperty("code"), nullValue());
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/SingletonTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/SingletonTest.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/SingletonTest.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/common/SingletonTest.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,23 @@
+package org.apache.ctakes.jdl.common;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.junit.Assert.assertThat;
+
+import org.apache.ctakes.jdl.common.Singleton;
+import org.junit.Test;
+
+public class SingletonTest {
+	private static final Singleton singleton = Singleton.getIstance();
+
+	@Test
+	public void getIstance() {
+		assertThat(singleton, notNullValue());
+		assertThat(singleton, equalTo(Singleton.getIstance()));
+		assertThat(singleton, sameInstance(Singleton.getIstance()));
+		assertThat(Singleton.getIstance(), notNullValue());
+		assertThat(Singleton.getIstance(), equalTo(Singleton.getIstance()));
+		assertThat(Singleton.getIstance(), sameInstance(Singleton.getIstance()));
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/base/JdlConnectionTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/base/JdlConnectionTest.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/base/JdlConnectionTest.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/base/JdlConnectionTest.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,61 @@
+package org.apache.ctakes.jdl.data.base;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeThat;
+
+import java.sql.SQLException;
+
+import javax.xml.bind.JAXBException;
+
+
+import org.apache.ctakes.jdl.common.FileUtil;
+import org.apache.ctakes.jdl.data.base.JdlConnection;
+import org.apache.ctakes.jdl.data.xml.jaxb.ObjectFactoryUtil;
+import org.apache.ctakes.jdl.schema.xdl.JdbcType;
+import org.apache.ctakes.jdl.test.Resources;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JdlConnectionTest {
+	private static JdbcType jdbc;
+	private static JdlConnection jdlConnection;
+	private static final String CX = FileUtil.getFile(Resources.CONN_X).toString();
+
+	@BeforeClass
+	public static void initClass() throws JAXBException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
+		jdbc = ObjectFactoryUtil.getJdbcTypeBySrcXml(CX);
+		jdlConnection = new JdlConnection(jdbc);
+	}
+
+	@Test
+	public void isConnected() throws SQLException {
+		assertThat(jdlConnection.isConnected(), is(true));
+	}
+
+	@Before
+	public void getOpenConnection() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
+		assumeThat(jdbc.getDriver(), not(Resources.ENV_DRIVER));
+		assumeThat(jdbc.getUrl(), not(Resources.ENV_URL));
+		assertThat(jdlConnection.getOpenConnection().isClosed(), is(false));
+	}
+
+	@AfterClass
+	public static void closeConnection() throws SQLException {
+		jdlConnection.closeConnection();
+		assertThat(jdlConnection.isConnected(), is(false));
+	}
+
+	@Test
+	public void autoCommit() throws SQLException {
+		jdlConnection.setAutoCommit(true);
+		assertThat(jdlConnection.isAutoCommit(), is(true));
+		jdlConnection.setAutoCommit(false);
+		assertThat(jdlConnection.isAutoCommit(), is(false));
+		jdlConnection.setAutoCommit(true);
+		assertThat(jdlConnection.isAutoCommit(), is(true));
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/loader/CsvLoaderTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/loader/CsvLoaderTest.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/loader/CsvLoaderTest.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/loader/CsvLoaderTest.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,46 @@
+package org.apache.ctakes.jdl.data.loader;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+
+import javax.xml.bind.JAXBException;
+
+
+import org.apache.ctakes.jdl.common.FileUtil;
+import org.apache.ctakes.jdl.data.base.JdlConnection;
+import org.apache.ctakes.jdl.data.loader.CsvLoader;
+import org.apache.ctakes.jdl.data.xml.jaxb.ObjectFactoryUtil;
+import org.apache.ctakes.jdl.schema.xdl.CsvLoadType;
+import org.apache.ctakes.jdl.test.Resources;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CsvLoaderTest {
+	private static final String CX = FileUtil.getFile(Resources.CONN_X).toString();
+	private static final String D1C = FileUtil.getFile(Resources.DATA1C).toString();
+	private static final String D2C = FileUtil.getFile(Resources.DATA2C).toString();
+	private static final String L1C = FileUtil.getFile(Resources.LOAD1C).toString();
+	private static final String L2C = FileUtil.getFile(Resources.LOAD2C).toString();
+	private static final String SQL = "insert into tab_test (id,name,thekey,thevalue,code,descr) values (?,?,?,?,?,?)";
+
+	@BeforeClass
+	public static void initClass() throws JAXBException, FileNotFoundException {
+		JdlConnection jdlConnection = new JdlConnection(ObjectFactoryUtil.getJdbcTypeBySrcXml(CX));
+		jdlConnection.getClass();
+	}
+
+	@Test
+	public void getSqlInsert() throws JAXBException, FileNotFoundException {
+		CsvLoadType loader;
+		CsvLoader csvLoader;
+		loader = ObjectFactoryUtil.getLoadTypeBySrcXml(L1C).getCsv();
+		csvLoader = new CsvLoader(loader, new File(D1C));
+		assertThat(csvLoader.getSqlInsert(loader), is(SQL));
+		loader = ObjectFactoryUtil.getLoadTypeBySrcXml(L2C).getCsv();
+		csvLoader = new CsvLoader(loader, new File(D2C));
+		assertThat(csvLoader.getSqlInsert(loader), is(SQL));
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/loader/XmlLoaderTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/loader/XmlLoaderTest.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/loader/XmlLoaderTest.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/loader/XmlLoaderTest.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,46 @@
+package org.apache.ctakes.jdl.data.loader;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.io.FileNotFoundException;
+
+import javax.xml.bind.JAXBException;
+
+
+import org.apache.ctakes.jdl.common.FileUtil;
+import org.apache.ctakes.jdl.data.base.JdlConnection;
+import org.apache.ctakes.jdl.data.loader.XmlLoader;
+import org.apache.ctakes.jdl.data.xml.DomUtil;
+import org.apache.ctakes.jdl.data.xml.jaxb.ObjectFactoryUtil;
+import org.apache.ctakes.jdl.schema.xdl.XmlLoadType;
+import org.apache.ctakes.jdl.test.Resources;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class XmlLoaderTest {
+	private static final String CX = FileUtil.getFile(Resources.CONN_X).toString();
+	private static final String D1X = FileUtil.getFile(Resources.DATA1X).toString();
+	private static final String D2X = FileUtil.getFile(Resources.DATA2X).toString();
+	private static final String L1X = FileUtil.getFile(Resources.LOAD1X).toString();
+	private static final String L2X = FileUtil.getFile(Resources.LOAD2X).toString();
+	private static final String SQL = "insert into tab_test (id,name,thekey,thevalue,code,descr) values (?,?,?,?,?,?)";
+
+	@BeforeClass
+	public static void initClass() throws JAXBException, FileNotFoundException {
+		JdlConnection jdlConnection = new JdlConnection(ObjectFactoryUtil.getJdbcTypeBySrcXml(CX));
+		jdlConnection.getClass();
+	}
+
+	@Test
+	public void getSqlInsert() throws JAXBException, FileNotFoundException {
+		XmlLoadType loader;
+		XmlLoader xmlLoader;
+		loader = ObjectFactoryUtil.getLoadTypeBySrcXml(L1X).getXml();
+		xmlLoader = new XmlLoader(loader, DomUtil.srcToDocument(D1X));
+		assertThat(xmlLoader.getSqlInsert(loader), is(SQL));
+		loader = ObjectFactoryUtil.getLoadTypeBySrcXml(L2X).getXml();
+		xmlLoader = new XmlLoader(loader, DomUtil.srcToDocument(D2X));
+		assertThat(xmlLoader.getSqlInsert(loader), is(SQL));
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/xml/DomParserTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/xml/DomParserTest.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/xml/DomParserTest.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/xml/DomParserTest.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,35 @@
+package org.apache.ctakes.jdl.data.xml;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.apache.ctakes.jdl.common.FileUtil;
+import org.apache.ctakes.jdl.data.xml.DomParser;
+import org.apache.ctakes.jdl.test.Resources;
+import org.junit.experimental.theories.DataPoint;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
+
+@RunWith(Theories.class)
+public class DomParserTest {
+	private static final String CX = FileUtil.getFile(Resources.CONN_X).toString();
+	@DataPoint
+	public static String L1C = Resources.LOAD1C;
+	@DataPoint
+	public static String L1X = Resources.LOAD1X;
+	@DataPoint
+	public static String L2C = Resources.LOAD2C;
+	@DataPoint
+	public static String L2X = Resources.LOAD2X;
+
+	@Theory
+	public void getRoot(String xml) {
+		xml = FileUtil.getFile(xml).toString();
+		DomParser dom;
+		dom = new DomParser(CX);
+		assertThat(dom.getRoot().getTagName(), is(Resources.ROOT_CONN));
+		dom = new DomParser(xml);
+		assertThat(dom.getRoot().getTagName(), is(Resources.ROOT_LOAD));
+	}
+}

Added: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/xml/DomUtilTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/xml/DomUtilTest.java?rev=1551254&view=auto
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/xml/DomUtilTest.java (added)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/jdl/data/xml/DomUtilTest.java Mon Dec 16 16:30:30 2013
@@ -0,0 +1,61 @@
+package org.apache.ctakes.jdl.data.xml;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.ctakes.jdl.common.FileUtil;
+import org.apache.ctakes.jdl.data.xml.DomUtil;
+import org.apache.ctakes.jdl.test.Resources;
+import org.junit.Test;
+import org.junit.experimental.theories.DataPoint;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+@RunWith(Theories.class)
+public final class DomUtilTest {
+	@DataPoint
+	public static String L1C = Resources.LOAD1C;
+	@DataPoint
+	public static String L1X = Resources.LOAD1X;
+	@DataPoint
+	public static String L2C = Resources.LOAD2C;
+	@DataPoint
+	public static String L2X = Resources.LOAD2X;
+
+	@Test
+	public void getEmptyDocument() throws ParserConfigurationException {
+		assertThat(DomUtil.getEmptyDocument().getDocumentElement(), nullValue());
+	}
+
+	@Test
+	public void strToDocument() {
+		Document document = DomUtil.strToDocument("<root />");
+		Element element = document.getDocumentElement();
+		assertThat(element.getTagName(), is("root"));
+	}
+
+	@Theory
+	public void srcToDocument(String xml) {
+		xml = FileUtil.getFile(xml).toString();
+		Document document = DomUtil.srcToDocument(xml);
+		Element element = document.getDocumentElement();
+		assertThat(element.getTagName(), is(Resources.ROOT_LOAD));
+	}
+
+	@Theory
+	public void nodeToStr(String xml) {
+		xml = FileUtil.getFile(xml).toString();
+		Document document = DomUtil.srcToDocument(xml);
+		Element element = document.getDocumentElement();
+		assertThat(StringUtils.startsWith(DomUtil.nodeToStr(element), "<" + Resources.ROOT_LOAD), is(true));
+		assertThat(StringUtils.endsWith(DomUtil.nodeToStr(element).trim(), "</" + Resources.ROOT_LOAD + ">"), is(true));
+	}
+}



Mime
View raw message