package de.tudresden.inf.lat.born.owlapi.multiprocessor;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLOntology;

import de.tudresden.inf.lat.born.owlapi.processor.ProcessorConfiguration;
import de.tudresden.inf.lat.born.owlapi.processor.ProcessorCore;

/**
 * An object of this class processed several ontologies with their respective
 * Bayesian networks, using pseudorandomly generated queries.
 * 
 * @author Julian Mendez
 *
 */
public class MultiProcessorCore {
	public static final char TAB_CHAR = '\t';
	public static final char NEW_LINE_CHAR = '\n';
	public static final char SLASH_CHAR = '/';

	/**
	 * Constructs a new multi processor core.
	 */
	public MultiProcessorCore() {
	}

	List<OWLClass> getClasses(OWLOntology ontology) {
		List<OWLClass> listOfClasses = new ArrayList<OWLClass>();
		Set<OWLClass> treeSet = new TreeSet<OWLClass>();
		treeSet.addAll(ontology.getClassesInSignature());
		listOfClasses.addAll(treeSet);
		return listOfClasses;
	}

	SubsumptionQuery getNextQuery(List<OWLClass> listOfClasses, PseudorandomNumberGenerator random) {
		int n = listOfClasses.size();
		int a = random.nextInt(n);
		int b = random.nextInt(n);
		return new SubsumptionQuery(listOfClasses.get(a), listOfClasses.get(b));
	}

	List<SubsumptionQuery> getQueries(OWLOntology ontology, int numberOfQueries, PseudorandomNumberGenerator random) {
		List<OWLClass> listOfClasses = getClasses(ontology);
		List<SubsumptionQuery> listOfQueries = new ArrayList<SubsumptionQuery>();
		for (int i = 0; i < numberOfQueries; i++) {
			listOfQueries.add(getNextQuery(listOfClasses, random));
		}
		return listOfQueries;
	}

	public List<String> run(MultiProcessorConfiguration conf, long start) {
		List<String> ret = new ArrayList<String>();
		PseudorandomNumberGenerator random = new PseudorandomNumberGenerator(conf.getSeed());
		ProcessorCore core = new ProcessorCore();

		for (OntologyAndNetwork ontPair : conf.getOntologyList()) {

			ProcessorConfiguration configuration = new ProcessorConfiguration();
			configuration.setOntology(ontPair.getOntology());
			configuration.setBayesianNetwork(ontPair.getBayesianNetwork());
			configuration.setOutputFileName(conf.getOutputDirectory() + SLASH_CHAR + ontPair.getOntologyName());
			List<SubsumptionQuery> queries = getQueries(ontPair.getOntology(), conf.getNumberOfQueries(), random);
			StringBuffer sbuf = new StringBuffer();

			for (SubsumptionQuery query : queries) {

				configuration.setQuery(query.asProblogString());
				String result = core.run(configuration, start);
				sbuf.append(query.getSubClass().getIRI());
				sbuf.append(TAB_CHAR);
				sbuf.append(query.getSuperClass().getIRI());
				sbuf.append(TAB_CHAR);
				sbuf.append(result);
				sbuf.append(NEW_LINE_CHAR);
			}
			ret.add(sbuf.toString());
		}
		return ret;
	}

}

@@ -735,16 +735,71 @@
 R = '/';
+%0A%09public static final String TEMP_FILE_SUFFIX = %22.tmp%22;
 %0A%0A%09/**%0A%09
@@ -2349,16 +2349,22 @@
 ileName(
+%0A%09%09%09%09%09
 conf.get
@@ -2421,16 +2421,35 @@
 gyName()
+ + TEMP_FILE_SUFFIX
 );%0A%09%09%09Li

Make minor change in temporary file name