import java.io.IOException;
import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import ubiware.integration.soprano.Node;
import ubiware.integration.soprano.QueryLanguage;
import ubiware.integration.soprano.SopranoException;
import ubiware.integration.soprano.SopranoStatementIterator;
import ubiware.integration.soprano.Statement;
import ubiware.integration.soprano.TCPClientModel;
public class Testing {
public static void main(String[] args) {
try {
InetAddress address = InetAddress.getByName("192.168.179.141");
// for (int i = 0; i < 5; i++) {
// debug classloading
// TCPClientModel.class.getClass();
// Node.class.getClass();
List<Statement> statementList = new ArrayList<Statement>(1000);
// add statements
for (int s = 0; s < 10; s++) {
Node subject = new Node(new URI("http://S" + s));
for (int p = 0; p < 10; p++) {
Node predicate = new Node(new URI("http://P" + p));
for (int o = 0; o < 10; o++) {
Node object = new Node(new URI("http://O" + o));
for (int c = 0; c < 1; c++) {
Node context = new Node(new URI("http://C" + c));
Statement statement = new Statement(subject,
predicate, object, context);
statementList.add(statement);
}
}
}
}
TCPClientModel model = new TCPClientModel(address, 5000, "test2");
System.out.println("adding " + statementList.size()+ " statements");
long startTime = System.currentTimeMillis();
int counter = 0;
for (Statement statement : statementList) {
model.addStatement(statement);
//counter++;
//if (counter % 100 == 0)
// System.out.print(".");
}
long endTime = System.currentTimeMillis();
double durationinseconds = (endTime - startTime) / 1000.0;
System.out.println("done adding "+ statementList.size()+ " statements in " +durationinseconds+ " seconds");
startTime = System.currentTimeMillis();
for (Statement statement : statementList){
SopranoStatementIterator it = model.listStatements(statement);
while (it.hasNext()){
it.next();
}
}
endTime = System.currentTimeMillis();
durationinseconds = (endTime - startTime) / 1000.0;
System.out.println("done querying "+ statementList.size()+ " statements in " +durationinseconds+ " seconds");
System.exit(0);
Node subject = new Node(new URI("http://S2"));
Node predicate = new Node(new URI("http://P3"));
Node object = new Node(new URI("http://O2"));
Node context = new Node(new URI("http://C6"));
Statement partial = new Statement(subject, predicate, object,
context);
System.out.println("querying 1 specific");
SopranoStatementIterator iterator = model.listStatements(partial);
counter = 0;
while (iterator.hasNext()) {
Statement st = iterator.next();
counter++;
System.out.println(st);
}
System.out.println("Done querying " + counter);
//System.out.println("querying 100 with only object set.");
//subject = new Node();
//predicate = new Node();
//object = new Node(new URI("http://O2"));
//context = new Node();
//partial = new Statement(subject, predicate, object, context);
//iterator = model.listStatements(partial);
//counter = 0;
//while (iterator.hasNext()) {
// Statement st = iterator.next();
// counter++;
// System.out.print(".");
//}
//System.out.println("Done querying " + counter);
System.out.println("querying all with nothing set.");
subject = new Node();
predicate = new Node();
object = new Node();
context = new Node();
partial = new Statement(subject, predicate, object, context);
startTime = System.currentTimeMillis();
iterator = model.listStatements(partial);
counter = 0;
while (iterator.hasNext()) {
Statement st = iterator.next();
// counter++;
// if (counter % 100 == 0) {
// System.out.print(".");
// }
}
endTime = System.currentTimeMillis();
durationinseconds = (endTime - startTime) / 1000.0;
System.out.println("Done querying all " + counter + "in " + durationinseconds + "seconds");
// iterator.close();
String query = "SELECT *";
//model.executeQuery(query, QueryLanguage.QueryLanguageSparql);
model.closeConnection();
// }
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SopranoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}