Add: add a test example using Java API

This commit is contained in:
suxunbin 2017-11-26 16:22:32 +08:00
parent 93fb9f6fa6
commit ef599f1ba0
3 changed files with 220 additions and 0 deletions

View File

@ -0,0 +1,7 @@
CC=g++ -std=c++11
test: test.o
$(CC) -o test test.o
test.o: test.cpp
$(CC) -c test.cpp -o test.o
clean:
rm -rf *.o test

View File

@ -0,0 +1,69 @@
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
string encode(string& s)
{
string ret;
unsigned char *ptr = (unsigned char *)s.c_str();
ret.reserve(s.length());
for(int i=0;i<s.length();++i)
{
if((int(ptr[i])==58) || (int(ptr[i])==47) ||(int(ptr[i])==42) || (int(ptr[i])==45) || (int(ptr[i])==46) || (int(ptr[i])==95))
ret += ptr[i];
else if((int(ptr[i])>=48) && (int(ptr[i])<=57))
ret += ptr[i];
else if((int(ptr[i])>=65) && (int(ptr[i])<=90))
ret += ptr[i];
else if((int(ptr[i])>=97) && (int(ptr[i])<=122))
ret += ptr[i];
else if(int(ptr[i])==32)
ret += '+';
else
{
char buf[5];
memset(buf,0,5);
snprintf(buf,5,"%%%X",ptr[i]);
ret.append(buf);
}
}
return ret;
}
string decode(string& s)
{
string ret;
char ch;
int ii;
for(size_t i = 0; i < s.length(); ++i)
{
if(int(s[i]) == 37)
{
sscanf(s.substr(i+1,2).c_str(), "%x", &ii);
ch = static_cast<char>(ii);
ret += ch;
i = i + 2;
}
else if(s[i] == '+')
{
ret += ' ';
}
else
{
ret += s[i];
}
}
return (ret);
}
int main()
{
string a;
cin >> a;
string b=encode(a);
cout<<b<<endl;
string c=decode(b);
if(a==c)
cout<<"OK"<<endl;
return 0;
}

View File

@ -0,0 +1,144 @@
import java.io.*;
import java.util.*;
import jgsc.GstoreConnector;
class MyThread extends Thread {
public static boolean correctness = true;
//public static int cnum = 0;
private int num = 0;
private GstoreConnector gc;
private String sparql;
private int rnum = 0;
public MyThread(int _num, GstoreConnector _gc, String _sparql, int _rnum) {
num = _num;
gc = _gc;
sparql = _sparql;
rnum = _rnum;
}
public void run() {
Thread t = Thread.currentThread();
//try {
// File f = new File("result/"+num+".txt");
// DataOutputStream of = new DataOutputStream(new FileOutputStream(f));
// of.writeBytes(t.getName()+" "+t.getId()+"\n");
// of.writeBytes("Thread: "+num+"\n");
String answer = gc.query(sparql);
// of.writeBytes(answer);
int m = 0;
for(int i = 0; i<sparql.length(); ++i)
{
if(sparql.charAt(i) == '?')
++m;
if(sparql.charAt(i) == '{')
break;
}
int n = 0;
for(int i = 0; i<answer.length(); ++i)
{
if(answer.charAt(i) == '{')
++n;
}
int Num = (n-3)/(m+1);
// of.writeBytes("The number of the results: "+Num+"\n");
// of.writeBytes("Thread "+t.getName()+" ends!");
// of.close();
if (rnum != Num)
correctness = false;
// if (rnum == Num)
// {
// synchronized (this){
// cnum++;
// }
// }
//}
//catch(IOException e) {
// e.printStackTrace();
//}
}
}
public class Benchmark
{
public static void main(String[] args)
{
GstoreConnector gc = new GstoreConnector("172.31.222.94", 9000);
//gc.load("dbpedia");
String[] spq = new String[6];
spq[0] = "select ?v0 where"
+"{"
+"?v0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/LanguagesOfBotswana> ."
+"?v0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/LanguagesOfNamibia> ."
+"?v0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Language> ."
+"}";
spq[1] = "select ?v0 where"
+"{"
+"?v0 <http://dbpedia.org/ontology/associatedBand> <http://dbpedia.org/resource/LCD_Soundsystem> ."
+"}";
spq[2] = "select ?v2 where"
+"{"
+"<http://dbpedia.org/resource/!!Destroy-Oh-Boy!!> <http://dbpedia.org/property/title> ?v2 ."
+"}";
spq[3] = "select ?v0 ?v2 where"
+"{"
+"?v0 <http://dbpedia.org/ontology/activeYearsStartYear> ?v2 ."
+"}";
spq[4] = "select ?v0 ?v1 ?v2 where"
+"{"
+"?v0 <http://dbpedia.org/property/dateOfBirth> ?v2 ."
+"?v1 <http://dbpedia.org/property/genre> ?v2 ."
+"}";
spq[5] = "select ?v0 ?v1 ?v2 ?v3 where"
+"{"
+"?v0 <http://dbpedia.org/property/familycolor> ?v1 ."
+"?v0 <http://dbpedia.org/property/glotto> ?v2 ."
+"?v0 <http://dbpedia.org/property/lc> ?v3 ."
+"}";
//spq[6] = "select ?v0 ?v1 ?v2 ?v3 ?v4 ?v5 ?v6 ?v7 ?v8 ?v9 where"
// +"{"
// +"?v0 <http://dbpedia.org/property/dateOfBirth> ?v1 ."
// +"?v0 <http://dbpedia.org/property/genre> ?v2 ."
// +"?v0 <http://dbpedia.org/property/instrument> ?v3 ."
// +"?v0 <http://dbpedia.org/property/label> ?v4 ."
// +"?v0 <http://dbpedia.org/property/placeOfBirth> ?v5 ."
// +"?v6 <http://dbpedia.org/property/name> ?v7 ."
// +"?v6 <http://dbpedia.org/property/occupation> ?v8 ."
// +"?v6 <http://dbpedia.org/property/placeOfBirth> ?v5 ."
// +"?v6 <http://dbpedia.org/property/instrument> ?v3 ."
// +"?v6 <http://dbpedia.org/property/notableInstruments> ?v9 ."
// +"}";
int[] result = {10, 14, 14, 199424, 33910, 1039};
int tnum = 6;
tnum = 100;
MyThread[] qt = new MyThread[tnum];
for(int i = 0; i < tnum; ++i)
{
qt[i] = new MyThread(i, gc, spq[i%6], result[i%6]);
qt[i].start();
}
for(int i = 0; i < tnum; ++i)
{
try {
qt[i].join();
}
catch(InterruptedException e) {
e.printStackTrace();
}
}
//gc.unload("dbpedia");
//double accuracy = MyThread.cnum / tnum;
try{
File f = new File("result/correctness.txt");
DataOutputStream of = new DataOutputStream(new FileOutputStream(f));
if (MyThread.correctness == true)
of.writeBytes("The results are correct!");
else
of.writeBytes("The results exist errors!");
of.close();
}
catch(IOException e) {
e.printStackTrace();
}
}
}