<commit_before>package org.aksw.kbox.kibe;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.aksw.kbox.kibe.KBox;
import org.aksw.kbox.kibe.tdb.TDBTest;
import org.junit.Test;

import com.hp.hpl.jena.query.ResultSet;

public class KBoxTest {
	
	@Test
	public void testPrintKBs() throws Exception {
		URL serverURL = KBoxTest.class.getResource("/org/aksw/kbox/kibe/");
		KBox.printKB(serverURL);
	}
	
	@Test
	public void testResolveURLWithKBoxKNSService() throws Exception {
		URL db = KBox.resolveURL(new URL("http://dbpedia.org/en/full"));
		assertEquals(db.toString(), "http://vmdbpedia.informatik.uni-leipzig.de:3030/kbox.kb");
	}
	
	@Test
	public void testInstallProcess() throws Exception {
		File indexFile = new File("knowledgebase.idx");
		URL[] filesToIndex = new URL[1];
		URL url = TDBTest.class.getResource("/org/aksw/kbox/kibe/dbpedia_3.9.xml");
		filesToIndex[0] = url;
		KBox.createIndex(indexFile, filesToIndex);
		KBox.installKB(new URL("http://my.knowledgebox"), 
									indexFile.toURI().toURL());
		ResultSet rs = KBox.query(new URL("http://my.knowledgebox"), 
									"Select ?p where {<http://dbpedia.org/ontology/Place> ?p ?o}");
		int i = 0;
		while (rs != null && rs.hasNext()) {
			rs.next();
			i++;
		}
		assertEquals(19, i);
	}
	
	@Test
	public void testQueryInstalledKB() throws Exception {
		ResultSet rs = KBox.query(new URL("http://my.knowledgebox"), 
									"Select ?p where {<http://dbpedia.org/ontology/Place> ?p ?o}");
		int i = 0;
		while (rs != null && rs.hasNext()) {
			rs.next();
			i++;
		}
		assertEquals(19, i);
		
		rs = KBox.query(new URL("http://my.knowledgebox"), 
				"Select ?p where {<http://dbpedia.org/ontology/Place> ?p ?o}");
		i = 0;
		while (rs != null && rs.hasNext()) {
		rs.next();
		i++;
		}
		assertEquals(19, i);
	}
	
	@Test
	public void testQueryNotInstalledKB() throws Exception {
		try {
			@SuppressWarnings("unused")
			ResultSet rs = KBox.query(new URL("http://my.knowledgebox.com"), 
					"Select ?p where {<http://dbpedia.org/ontology/Place> ?p ?o}");
			throw new Exception("The query should have returned an Exception.");
		} catch (Exception e) {			
		}	
	}
	
	@Test
	public void testResolveKNS() throws MalformedURLException, Exception {
		URL serverURL = TDBTest.class.getResource("/org/aksw/kbox/kibe/");
		URL fileURL = KBox.resolveURL(new URL("http://test.org"), serverURL);
		assertEquals(fileURL.toString(), "http://target.org");
	}
	
	@Test
	public void listKNSServers() throws MalformedURLException, Exception {
		Iterable<String> knsList = KBox.listAvailableKNS();
		int i = 0;
		for(@SuppressWarnings("unused") String knsServer : knsList) {
			i++;
		}
		assertEquals(0, i);
	}
	
	@Test
	public void listKNSServers2() throws MalformedURLException, Exception {
		URL serverURL = TDBTest.class.getResource("/org/aksw/kbox/kibe/");
		KBox.installKNS(serverURL);
		Iterable<String> knsList = KBox.listAvailableKNS();
		int i = 0;
		for(String knsServer : knsList) {
			assertEquals(knsServer, serverURL.toString());
			i++;
		}
		assertEquals(1, i);
		KBox.removeKNS(serverURL);
		knsList = KBox.listAvailableKNS();
		i=0;
		for(String knsServer : knsList) {
			assertEquals(knsServer, serverURL.toString());
			i++;
		}
		assertEquals(0, i);
	}
	
	@Test
	public void installKNSServers() throws MalformedURLException, Exception {
		Iterable<String> knsList = KBox.listAvailableKNS();
		int i = 0;
		for(@SuppressWarnings("unused") String knsServer : knsList) {
			i++;
		}
		assertEquals(0, i);
	}
	
}
<commit_msg>- adding function to test new directory<commit_after>package org.aksw.kbox.kibe;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.aksw.kbox.kibe.tdb.TDBTest;
import org.junit.Test;

import com.hp.hpl.jena.query.ResultSet;

public class KBoxTest {
	
	@Test
	public void testPrintKBs() throws Exception {
		URL serverURL = KBoxTest.class.getResource("/org/aksw/kbox/kibe/");
		KBox.printKB(serverURL);
	}
	
	@Test
	public void testResolveURLWithKBoxKNSService() throws Exception {
		URL db = KBox.resolveURL(new URL("http://dbpedia.org/3.9/en/full"));
		assertEquals(db.toString(), "http://vmdbpedia.informatik.uni-leipzig.de:3030/kbox.kb");
	}
	
	@Test
	public void testNewDir() throws Exception {
		File f = KBox.newDir(new URL("http://dbpedia.org/en/full"));
		assertTrue(f.getAbsolutePath().endsWith("en\\full"));
	}
	
	@Test
	public void testInstallProcess() throws Exception {
		File indexFile = new File("knowledgebase.idx");
		URL[] filesToIndex = new URL[1];
		URL url = TDBTest.class.getResource("/org/aksw/kbox/kibe/dbpedia_3.9.xml");
		filesToIndex[0] = url;
		KBox.createIndex(indexFile, filesToIndex);
		KBox.installKB(new URL("http://my.knowledgebox"), 
									indexFile.toURI().toURL());
		ResultSet rs = KBox.query(new URL("http://my.knowledgebox"), 
									"Select ?p where {<http://dbpedia.org/ontology/Place> ?p ?o}");
		int i = 0;
		while (rs != null && rs.hasNext()) {
			rs.next();
			i++;
		}
		assertEquals(19, i);
	}
	
	@Test
	public void testQueryInstalledKB() throws Exception {
		ResultSet rs = KBox.query(new URL("http://my.knowledgebox"), 
									"Select ?p where {<http://dbpedia.org/ontology/Place> ?p ?o}");
		int i = 0;
		while (rs != null && rs.hasNext()) {
			rs.next();
			i++;
		}
		assertEquals(19, i);
		
		rs = KBox.query(new URL("http://my.knowledgebox"), 
				"Select ?p where {<http://dbpedia.org/ontology/Place> ?p ?o}");
		i = 0;
		while (rs != null && rs.hasNext()) {
		rs.next();
		i++;
		}
		assertEquals(19, i);
	}
	
	@Test
	public void testQueryNotInstalledKB() throws Exception {
		try {
			@SuppressWarnings("unused")
			ResultSet rs = KBox.query(new URL("http://my.knowledgebox.com"), 
					"Select ?p where {<http://dbpedia.org/ontology/Place> ?p ?o}");
			throw new Exception("The query should have returned an Exception.");
		} catch (Exception e) {			
		}	
	}
	
	@Test
	public void testResolveKNS() throws MalformedURLException, Exception {
		URL serverURL = TDBTest.class.getResource("/org/aksw/kbox/kibe/");
		URL fileURL = KBox.resolveURL(new URL("http://test.org"), serverURL);
		assertEquals(fileURL.toString(), "http://target.org");
	}
	
	@Test
	public void listKNSServers() throws MalformedURLException, Exception {
		Iterable<String> knsList = KBox.listAvailableKNS();
		int i = 0;
		for(@SuppressWarnings("unused") String knsServer : knsList) {
			i++;
		}
		assertEquals(0, i);
	}
	
	@Test
	public void listKNSServers2() throws MalformedURLException, Exception {
		URL serverURL = TDBTest.class.getResource("/org/aksw/kbox/kibe/");
		KBox.installKNS(serverURL);
		Iterable<String> knsList = KBox.listAvailableKNS();
		int i = 0;
		for(String knsServer : knsList) {
			assertEquals(knsServer, serverURL.toString());
			i++;
		}
		assertEquals(1, i);
		KBox.removeKNS(serverURL);
		knsList = KBox.listAvailableKNS();
		i=0;
		for(String knsServer : knsList) {
			assertEquals(knsServer, serverURL.toString());
			i++;
		}
		assertEquals(0, i);
	}
	
	@Test
	public void installKNSServers() throws MalformedURLException, Exception {
		Iterable<String> knsList = KBox.listAvailableKNS();
		int i = 0;
		for(@SuppressWarnings("unused") String knsServer : knsList) {
			i++;
		}
		assertEquals(0, i);
	}
	
}

{'fraction_non_alphanumeric': 0.15907555075010135, 'fraction_numerical': 0.007298283551831329, 'mean_word_length': 3.969778374748153, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2274615', 'n_tokens_mistral': 2975, 'n_tokens_neox': 2663, 'n_words': 536}