// Path: src/fr/lip6/reden/ldextractor/QuerySource.java
// public class QuerySource implements QuerySourceInterface {
// 
// 	/**
// 	 * Prepare the SPARQL statement. Children must implement their own queries.
// 	 * 
// 	 * @param domain
// 	 *            configuration
// 	 * @param firstleter,
// 	 *            optional filtering for queries
// 	 * @return
// 	 */
// 	public Query formulateSPARQLQuery(List<TopicExtent> domainParams, String firstleter, String outDictionnaireDir) {
// 		return null;
// 	}
// 
// 	/**
// 	 * Execute query in SPARQL endpoint. 
// 	 * Same methods for all children.
// 	 * @param query, query to execute
// 	 * @param sparqlendpoint, URL of the SPARQL endpoint
// 	 * @param timeout, query timeout
// 	 * @return the result
// 	 */
// 	public ResultSet executeQuery(Query query, String sparqlendpoint,
// 			String timeout, String outDictionnaireDir, String letter) {
// 		
// 		try {
// 			// wait 20 seconds for every query
// 			Thread.sleep(10000); 
// 			try {
// 				QueryExecution qexec = QueryExecutionFactory.sparqlService(sparqlendpoint, query);
// 				ResultSet results = qexec.execSelect() ;
// 			      results = ResultSetFactory.copyResults(results) ;
// 			      qexec.close();
// 			      return results ;    // Passes the result set out of the try-resources			     
// 			} catch (Exception e){
// 				System.err.println("error in sparql query execution");
// 			}
// 		} catch (InterruptedException e) {
// 			e.printStackTrace();
// 		}
// 		return null;
// 	}
// 
// 	/**
// 	 * Process and write results. Children must implement their own result
// 	 * processing.
// 	 * 
// 	 * @param res,
// 	 *            query results
// 	 * @param outDictionnaireDir,
// 	 *            name of the folder where to write the dictionary file
// 	 * @param prefixDictionnaireFile,
// 	 *            prefix of the dico files
// 	 * @param letter,
// 	 *            optional parameter for large repos
// 	 */
// 
// 	public void processResults(ResultSet res, String outDictionnaireDir, String letter,
// 			List<TopicExtent> domainParams) {
// 	}
// 
// }
// 
// Path: src/fr/lip6/reden/ldextractor/QuerySourceInterface.java
// public interface QuerySourceInterface {
// 		
// 	/**
// 	 * Prepare the SPARQL query.
// 	 * @param domain configuration
// 	 * @param firstleter, optional filtering for queries
// 	 * @return the query
// 	 */
// 	Query formulateSPARQLQuery(List<TopicExtent> domainParams, String firstleter, 
// 			String outDictionnaireDir);
// 		
// 	/**
// 	 * Execute query in SPARQL endpoint.
// 	 * @param query, query to execute
// 	 * @param sparqlendpoint, URL of the SPARQL endpoint
// 	 * @param timeout, query timeout
// 	 * @return the result
// 	 */
// 	ResultSet executeQuery(Query query, String sparqlendpoint, String timeout, 
// 			String outDictionnaireDir, String letter);
// 	
// 	/**
// 	 * Process and write results.
// 	 * @param res, query results
// 	 * @param outDictionnaireDir, name of the folder where to write the dictionary file
// 	 * @param prefixDictionnaireFile, prefix of the dico files
// 	 * @param optional parameter in the presence of large repos
// 	 */
// 	void processResults(ResultSet res, String outDictionnaireDir, String letter, List<TopicExtent> domainParams);
// 	
// }
// 
// Path: src/fr/lip6/reden/ldextractor/TopicExtent.java
// public class TopicExtent {
// 
// }


import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
import com.opencsv.CSVWriter;
import fr.lip6.reden.ldextractor.QuerySource;
import fr.lip6.reden.ldextractor.QuerySourceInterface;
import fr.lip6.reden.ldextractor.TopicExtent;
					+ "OPTIONAL {?author ns2:P5012 ?rejectedForm } . "
					+ "OPTIONAL {?author owl:sameAs ?ref } . "					
					+ "OPTIONAL { ?author ns2:P5002 ?period } "
					+ "} ";
			
			Query query = QueryFactory.create(queryString);
			logger.info("query: " + query.toString());
			logger.info("exiting BNF: formulateSPARQLQuery");
			return query;
		}		
	}
	
	public ResultSet executeQuery(Query query, String timeout, String sparqlendpoint, 
			String outDictionnaireDir, String letter) {
		File fexists = new File(outDictionnaireDir+"/"+prefixDictionnaireFile+letter+".tsv");
		if (fexists.exists() && fexists.length() > 0) {
			System.out.println("entering BNF: skip, file exists - "+outDictionnaireDir+"/"+prefixDictionnaireFile+letter+".tsv");
			return null; //file exists, skip processing
		} else {
			logger.info("entering BNF: executeQuery");
			logger.info("exiting BNF: executeQuery");
			return super.executeQuery(query, SPARQL_END_POINT, timeout, 
					outDictionnaireDir, letter);
		}
	}
	
	/**
	 * Handling of the results specific to the BnF model.
	 */
	@Override
// Path: src/fr/lip6/reden/ldextractor/QuerySource.java
// public class QuerySource implements QuerySourceInterface {
// 
// 	/**
// 	 * Prepare the SPARQL statement. Children must implement their own queries.
// 	 * 
// 	 * @param domain
// 	 *            configuration
// 	 * @param firstleter,
// 	 *            optional filtering for queries
// 	 * @return
// 	 */
// 	public Query formulateSPARQLQuery(List<TopicExtent> domainParams, String firstleter, String outDictionnaireDir) {
// 		return null;
// 	}
// 
// 	/**
// 	 * Execute query in SPARQL endpoint. 
// 	 * Same methods for all children.
// 	 * @param query, query to execute
// 	 * @param sparqlendpoint, URL of the SPARQL endpoint
// 	 * @param timeout, query timeout
// 	 * @return the result
// 	 */
// 	public ResultSet executeQuery(Query query, String sparqlendpoint,
// 			String timeout, String outDictionnaireDir, String letter) {
// 		
// 		try {
// 			// wait 20 seconds for every query
// 			Thread.sleep(10000); 
// 			try {
// 				QueryExecution qexec = QueryExecutionFactory.sparqlService(sparqlendpoint, query);
// 				ResultSet results = qexec.execSelect() ;
// 			      results = ResultSetFactory.copyResults(results) ;
// 			      qexec.close();
// 			      return results ;    // Passes the result set out of the try-resources			     
// 			} catch (Exception e){
// 				System.err.println("error in sparql query execution");
// 			}
// 		} catch (InterruptedException e) {
// 			e.printStackTrace();
// 		}
// 		return null;
// 	}
// 
// 	/**
// 	 * Process and write results. Children must implement their own result
// 	 * processing.
// 	 * 
// 	 * @param res,
// 	 *            query results
// 	 * @param outDictionnaireDir,
// 	 *            name of the folder where to write the dictionary file
// 	 * @param prefixDictionnaireFile,
// 	 *            prefix of the dico files
// 	 * @param letter,
// 	 *            optional parameter for large repos
// 	 */
// 
// 	public void processResults(ResultSet res, String outDictionnaireDir, String letter,
// 			List<TopicExtent> domainParams) {
// 	}
// 
// }
// 
// Path: src/fr/lip6/reden/ldextractor/QuerySourceInterface.java
// public interface QuerySourceInterface {
// 		
// 	/**
// 	 * Prepare the SPARQL query.
// 	 * @param domain configuration
// 	 * @param firstleter, optional filtering for queries
// 	 * @return the query
// 	 */
// 	Query formulateSPARQLQuery(List<TopicExtent> domainParams, String firstleter, 
// 			String outDictionnaireDir);
// 		
// 	/**
// 	 * Execute query in SPARQL endpoint.
// 	 * @param query, query to execute
// 	 * @param sparqlendpoint, URL of the SPARQL endpoint
// 	 * @param timeout, query timeout
// 	 * @return the result
// 	 */
// 	ResultSet executeQuery(Query query, String sparqlendpoint, String timeout, 
// 			String outDictionnaireDir, String letter);
// 	
// 	/**
// 	 * Process and write results.
// 	 * @param res, query results
// 	 * @param outDictionnaireDir, name of the folder where to write the dictionary file
// 	 * @param prefixDictionnaireFile, prefix of the dico files
// 	 * @param optional parameter in the presence of large repos
// 	 */
// 	void processResults(ResultSet res, String outDictionnaireDir, String letter, List<TopicExtent> domainParams);
// 	
// }
// 
// Path: src/fr/lip6/reden/ldextractor/TopicExtent.java
// public class TopicExtent {
// 
// }


// Path: src/fr/lip6/reden/ldextractor/per/QueryAuthorBNEAll.java
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
import com.opencsv.CSVWriter;
import fr.lip6.reden.ldextractor.QuerySource;
import fr.lip6.reden.ldextractor.QuerySourceInterface;
import fr.lip6.reden.ldextractor.TopicExtent;

					+ "OPTIONAL {?author ns2:P5012 ?rejectedForm } . "
					+ "OPTIONAL {?author owl:sameAs ?ref } . "					
					+ "OPTIONAL { ?author ns2:P5002 ?period } "
					+ "} ";
			
			Query query = QueryFactory.create(queryString);
			logger.info("query: " + query.toString());
			logger.info("exiting BNF: formulateSPARQLQuery");
			return query;
		}		
	}
	
	public ResultSet executeQuery(Query query, String timeout, String sparqlendpoint, 
			String outDictionnaireDir, String letter) {
		File fexists = new File(outDictionnaireDir+"/"+prefixDictionnaireFile+letter+".tsv");
		if (fexists.exists() && fexists.length() > 0) {
			System.out.println("entering BNF: skip, file exists - "+outDictionnaireDir+"/"+prefixDictionnaireFile+letter+".tsv");
			return null; //file exists, skip processing
		} else {
			logger.info("entering BNF: executeQuery");
			logger.info("exiting BNF: executeQuery");
			return super.executeQuery(query, SPARQL_END_POINT, timeout, 
					outDictionnaireDir, letter);
		}
	}
	
	/**
	 * Handling of the results specific to the BnF model.
	 */
	@Override
	public void processResults(ResultSet res, String outDictionnaireDir, String letter, List<TopicExtent> domainParams) {