// Path: kbox.kibe/src/main/java/org/aksw/kbox/kibe/utils/FileUtils.java
// public class FileUtils {
// 	public static String[] files2AbsolutePath(File... files) {
// 		String[] paths = new String[files.length];
// 		for(int i = 0; i < files.length; i++) {
// 			paths[i]  = files[i].getAbsolutePath();
// 		}
// 		return paths;
// 	}
// }
// 
// Path: kbox.kns/src/main/java/org/aksw/kbox/kns/ServerAddress.java
// public class ServerAddress {
// 	
// 	private String url = null;
// 	
// 	public ServerAddress(String url) {
// 		this.url = url;
// 	}
// 	
// 	public String getURL() {
// 		return url;
// 	}
// 	
// 	public String getQueryURL() {
// 		return url;
// 	}
// }


import java.io.File;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.naming.OperationNotSupportedException;
import org.aksw.kbox.kibe.utils.FileUtils;
import org.aksw.kbox.kns.ServerAddress;
import org.apache.jena.graph.Triple;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.tdb.TDBFactory;
import org.apache.jena.tdb.TDBLoader;
import org.apache.jena.tdb.transaction.DatasetGraphTransaction;
package org.aksw.kbox.kibe.tdb;




public class TDB {

	public static ResultSet queryGraph(String sparql, String graph, String dbDir) throws Exception {
		Query query = QueryFactory.create(sparql, graph);
		return query(query, dbDir);
	}

	public static Model createModel(String... dbDirs) {
		Model mainModel = null; 
		Dataset dataset = null;
		for(String dbDir : dbDirs) {
			dataset = TDBFactory.createDataset(dbDir);
			if(mainModel == null) {
				mainModel = dataset.getDefaultModel();
			} else {
				Model secondaryModel = dataset.getDefaultModel();
				mainModel = ModelFactory.createUnion(mainModel, secondaryModel);
			}
		}
		mainModel = ModelFactory.createRDFSModel(mainModel);
		return mainModel;
	}
	
	public static Model createModel(File... dirs) {
// Path: kbox.kibe/src/main/java/org/aksw/kbox/kibe/utils/FileUtils.java
// public class FileUtils {
// 	public static String[] files2AbsolutePath(File... files) {
// 		String[] paths = new String[files.length];
// 		for(int i = 0; i < files.length; i++) {
// 			paths[i]  = files[i].getAbsolutePath();
// 		}
// 		return paths;
// 	}
// }
// 
// Path: kbox.kns/src/main/java/org/aksw/kbox/kns/ServerAddress.java
// public class ServerAddress {
// 	
// 	private String url = null;
// 	
// 	public ServerAddress(String url) {
// 		this.url = url;
// 	}
// 	
// 	public String getURL() {
// 		return url;
// 	}
// 	
// 	public String getQueryURL() {
// 		return url;
// 	}
// }


// Path: kbox.kibe/src/main/java/org/aksw/kbox/kibe/tdb/TDB.java
import java.io.File;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.naming.OperationNotSupportedException;
import org.aksw.kbox.kibe.utils.FileUtils;
import org.aksw.kbox.kns.ServerAddress;
import org.apache.jena.graph.Triple;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.tdb.TDBFactory;
import org.apache.jena.tdb.TDBLoader;
import org.apache.jena.tdb.transaction.DatasetGraphTransaction;

package org.aksw.kbox.kibe.tdb;




public class TDB {

	public static ResultSet queryGraph(String sparql, String graph, String dbDir) throws Exception {
		Query query = QueryFactory.create(sparql, graph);
		return query(query, dbDir);
	}

	public static Model createModel(String... dbDirs) {
		Model mainModel = null; 
		Dataset dataset = null;
		for(String dbDir : dbDirs) {
			dataset = TDBFactory.createDataset(dbDir);
			if(mainModel == null) {
				mainModel = dataset.getDefaultModel();
			} else {
				Model secondaryModel = dataset.getDefaultModel();
				mainModel = ModelFactory.createUnion(mainModel, secondaryModel);
			}
		}
		mainModel = ModelFactory.createRDFSModel(mainModel);
		return mainModel;
	}
	
	public static Model createModel(File... dirs) {
		return createModel(FileUtils.files2AbsolutePath(dirs));