Commit d392ad5c authored by akucera's avatar akucera
Browse files

gitignore update

parent da0d88db
package cz.muni.fi.lasaris.sbms.semantics.logic;
import java.util.LinkedList;
import java.util.List;
import org.apache.jena.graph.NodeFactory;
......@@ -25,6 +26,21 @@ import cz.muni.fi.lasaris.sbms.semantics.api.request.GroupableRequest;
import cz.muni.fi.lasaris.sbms.semantics.api.request.TrendsRequest;
public class BodyBuilders {
private static class TypeClauseContainer {
public String f1;
public String f2;
public String f3;
public String f4;
public TypeClauseContainer(String f1, String f2, String f3, String f4) {
this.f1 = f1;
this.f2 = f2;
this.f3 = f3;
this.f4 = f4;
}
}
public static ElementGroup getQueryBody(DataPointsRequest request) {
return getQueryBody(request.getDataPoint(), request);
}
......@@ -32,6 +48,9 @@ public class BodyBuilders {
private static ElementGroup getQueryBody(DataPoint dp, GroupableRequest request) {
ElementGroup body = new ElementGroup();
// type clauses moved to the end of the query as it significantly decreases performance
//List<TypeClauseContainer> tcc = new LinkedList<TypeClauseContainer>();
List<String> fields = request.getResponseFields();
body.addTriplePattern(Triple.create(Var.alloc("datapoint"),
......@@ -48,18 +67,7 @@ public class BodyBuilders {
NodeFactory.createLiteral(dp.getBmsId()))
);
}
// type clauses should not be first in the query as it significantly decreases performance
if(fields.contains("type")) {
setTypeClause(body, "datapoint", gsv("type"), NS.sbms + "DataPoint", NS.sbms + "DataPoint");
}
if(dp.getType() != null) {
body.addTriplePattern(Triple.create(Var.alloc("datapoint"),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(NS.sbms + dp.getType())));
}
if(fields.contains("source.bimId")
|| fields.contains("source.type")
|| fields.contains("source.location")
......@@ -83,13 +91,17 @@ public class BodyBuilders {
if(dp.getSource() != null && dp.getSource().getType() != null) {
body.addTriplePattern(Triple.create(Var.alloc("source"),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(NS.sbim + dp.getSource().getType())));
//tcc.add(new TypeClauseContainer(null, null, "source", NS.sbim + dp.getSource().getType()));
}
if(fields.contains("source.type")) {
setTypeClause(body, "source", gsv("source.type"), NS.sbim + "Device", NS.sbms + "Source");
//tcc.add(new TypeClauseContainer("source", gsv("source.type"), NS.sbim + "Device", NS.sbms + "Source"));
}
if((dp.getSource() != null && dp.getSource().getLocation() != null)) {
......@@ -142,21 +154,23 @@ public class BodyBuilders {
if(dp.getScope() != null && dp.getScope().getType() != null) {
body.addTriplePattern(Triple.create(Var.alloc("scope"),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(NS.sbim + dp.getScope().getType())));
//tcc.add(new TypeClauseContainer(null, null, "scope", NS.sbim + dp.getScope().getType()));
}
if(fields.contains("scope.type")) {
//setTypeClause(body, "scope", gsv("scope.type"), NS.dul + "PhysicalObject", NS.sbms + "Scope");
setTypeClause(body, "scope", gsv("scope.type"), NS.sbim + "Facility", NS.sbms + "Scope");
//tcc.add(new TypeClauseContainer("scope", gsv("scope.type"), NS.sbim + "Facility", NS.sbms + "Scope"));
}
// scopeLoc
if((dp.getScope() != null && dp.getScope().getLocation() != null)) {
body.addTriplePattern(Triple.create(Var.alloc("scope"),
//NodeFactory.createURI(NS.sbim + "hasInstallationLocation"),
NodeFactory.createURI(NS.sbim + "isPartOf"),
Var.alloc("scopeLocR")
));
......@@ -183,9 +197,11 @@ public class BodyBuilders {
body.addTriplePattern(Triple.create(Var.alloc("sensing"),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(NS.sbms + dp.getSensing().getType())));
//tcc.add(new TypeClauseContainer(null, null, "sensing", NS.sbim + NS.sbms + dp.getSensing().getType()));
}
if(dp.getSensing() != null && dp.getSensing().getWindow() != null) {
body.addTriplePattern(Triple.create(Var.alloc("sensing"),
NodeFactory.createURI(NS.sbms + "hasAggregationTimeWindow"),
NodeFactory.createURI(NS.sbms + dp.getSensing().getWindow())));
......@@ -193,6 +209,7 @@ public class BodyBuilders {
if(fields.contains("sensing.type")) {
setTypeClause(body, "sensing", gsv("sensing.type"), NS.sbms + "Sensing", NS.sbms + "Sensing");
//tcc.add(new TypeClauseContainer("sensing", gsv("sensing.type"), NS.sbms + "Sensing", NS.sbms + "Sensing"));
}
if(fields.contains("sensing.window")) {
......@@ -286,7 +303,17 @@ public class BodyBuilders {
}
// optimization - placing type clauses at the end
/*for(TypeClauseContainer c : tcc) {
if(c.f1 == null) {
body.addTriplePattern(Triple.create(Var.alloc(c.f3),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(c.f4)));
} else {
setTypeClause(body, c.f1, c.f2, c.f3, c.f4);
}
}*/
// GROUPING
if(request.getGrouping() != null && Fields.GROUPINGS.contains(request.getGrouping())) {
switch(request.getGrouping()) {
......@@ -327,7 +354,21 @@ public class BodyBuilders {
}
}
// moved at the and, as it is the most expensive query part
if(fields.contains("type")) {
setTypeClause(body, "datapoint", gsv("type"), NS.sbms + "DataPoint", NS.sbms + "DataPoint");
//tcc.add(new TypeClauseContainer("datapoint", gsv("type"), NS.sbms + "DataPoint", NS.sbms + "DataPoint"));
}
if(dp.getType() != null) {
body.addTriplePattern(Triple.create(Var.alloc("datapoint"),
NodeFactory.createURI(NS.rdf + "type"),
NodeFactory.createURI(NS.sbms + dp.getType())));
//tcc.add(new TypeClauseContainer(null, null, "datapoint", NS.sbms + dp.getType()));
}
return body;
}
......
......@@ -23,6 +23,7 @@ import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.reasoner.Reasoner;
import org.apache.jena.reasoner.ReasonerRegistry;
import org.apache.jena.tdb.TDB;
import org.apache.jena.tdb.TDBFactory;
import org.apache.log4j.Logger;
......@@ -93,7 +94,7 @@ public class TdbConnector {
logger.debug("ontoModel created");
dataset.end();
//dataset.close();
/*
ValidityReport v = model.validate();
......@@ -131,15 +132,17 @@ public class TdbConnector {
open();
}
dataset.begin(ReadWrite.READ);
return model;
}
public static Model getWritableModel() {
if(dataPath == null || dataset == null) {
throw new IllegalStateException("Path not set");
}
logger.debug("Opening writable model...");
dataset.close();
dataset.begin(ReadWrite.WRITE);
return dataset.getDefaultModel();
}
......@@ -156,6 +159,7 @@ public class TdbConnector {
logger.debug("Ending writing");
if(commit) {
dataset.commit();
TDB.sync(dataset);
dirty.set(true);
logger.debug("Commiting changes - Readable model is dirty");
} else {
......@@ -167,6 +171,7 @@ public class TdbConnector {
public static void close() {
model.close();
dataset.end();
model = null;
}
/*
......@@ -188,8 +193,9 @@ public class TdbConnector {
{
l.add(results.next());
}
closeDs();
} catch (Exception e) {
logger.debug(e);
logger.debug("Unexpected error", e);
}
return l;
}
......@@ -212,12 +218,14 @@ public class TdbConnector {
logger.debug("query returned");
result = s.toString("UTF-8");
s.close();
} catch (Exception e) {
logger.debug(e);
result = "Unexpected error";
}
return result;
s.close();
} catch (Exception e) {
logger.debug("Unexpected error", e);
result = "Unexpected error";
}
closeDs();
return result;
}
public static List<RDFNode> executeSPARQLList(String queryString) {
......@@ -234,11 +242,17 @@ public class TdbConnector {
RDFNode r = results.next().get("member");
result.add(r);
}
closeDs();
} catch (Exception e) {
logger.debug(e);
logger.debug("Unexpected error", e);
} finally {
logger.debug("Query finished.");
}
return Collections.unmodifiableList(result);
}
public static void closeDs() {
dataset.end();
}
}
./NT-Data/tdb/
\ No newline at end of file
NT-Data/
CSV-Data/
test_runs.txt
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment