diff --git a/.gitignore b/.gitignore
index 4bd6c3981..5676083f4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,13 @@
-*.class
-*.cache
-.classpath
-.project
-target
-bin
-.settings
-gerbil_keys.properties
-gerbil_data
-*.log
-google*.html
-export
+*.class
+*.cache
+.classpath
+.project
+target
+bin
+.settings
+gerbil_keys.properties
+gerbil_data
+*.log
+google*.html
+export
+datadump.nt
\ No newline at end of file
diff --git a/exportData.sh b/exportData.sh
new file mode 100644
index 000000000..95f1a9286
--- /dev/null
+++ b/exportData.sh
@@ -0,0 +1 @@
+mvn clean compile exec:java -Dexec.mainClass=org.aksw.gerbil.tools.DataDumpTool
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index fa7d58a5b..f3c1516a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -368,7 +368,7 @@
org.codehaus.mojo
exec-maven-plugin
- 1.4.0
+ 1.5.0
diff --git a/src/main/java/org/aksw/gerbil/database/ExperimentDAO.java b/src/main/java/org/aksw/gerbil/database/ExperimentDAO.java
index 238498c66..4308cb768 100644
--- a/src/main/java/org/aksw/gerbil/database/ExperimentDAO.java
+++ b/src/main/java/org/aksw/gerbil/database/ExperimentDAO.java
@@ -85,6 +85,16 @@ public interface ExperimentDAO extends Closeable {
*/
public List getResultsOfExperiment(String experimentId);
+ /**
+ * Returns the result of the experiment task with the given ID or null if
+ * this task does not exist.
+ *
+ * @param experimentTaskId
+ * the id of the experiment task
+ * @return the experiment task or null if this task does not exist.
+ */
+ public ExperimentTaskResult getResultOfExperimentTask(int experimentTaskId);
+
/**
* This method is called with the description of an experiment task and an
* experiment id. The method checks whether there is already such an
diff --git a/src/main/java/org/aksw/gerbil/database/ExperimentDAOImpl.java b/src/main/java/org/aksw/gerbil/database/ExperimentDAOImpl.java
index eb626e715..4a51053ea 100644
--- a/src/main/java/org/aksw/gerbil/database/ExperimentDAOImpl.java
+++ b/src/main/java/org/aksw/gerbil/database/ExperimentDAOImpl.java
@@ -20,7 +20,6 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import javax.sql.DataSource;
@@ -54,6 +53,7 @@ public class ExperimentDAOImpl extends AbstractExperimentDAO {
private final static String CONNECT_TASK_EXPERIMENT = "INSERT INTO Experiments (id, taskId) VALUES(:id, :taskId)";
private final static String GET_TASK_STATE = "SELECT state FROM ExperimentTasks WHERE id=:id";
private final static String GET_EXPERIMENT_RESULTS = "SELECT annotatorName, datasetName, experimentType, matching, microF1, microPrecision, microRecall, macroF1, macroPrecision, macroRecall, state, errorCount, lastChanged, taskId FROM ExperimentTasks t, Experiments e WHERE e.id=:id AND e.taskId=t.id";
+ private final static String GET_EXPERIMENT_TASK_RESULT = "SELECT annotatorName, datasetName, experimentType, matching, microF1, microPrecision, microRecall, macroF1, macroPrecision, macroRecall, state, errorCount, lastChanged, id FROM ExperimentTasks t WHERE id=:id";
private final static String GET_CACHED_TASK = "SELECT id FROM ExperimentTasks WHERE annotatorName=:annotatorName AND datasetName=:datasetName AND experimentType=:experimentType AND matching=:matching AND lastChanged>:lastChanged AND state>:errorState ORDER BY lastChanged DESC LIMIT 1";
private final static String GET_HIGHEST_EXPERIMENT_ID = "SELECT id FROM Experiments ORDER BY id DESC LIMIT 1";
private final static String SET_UNFINISHED_TASK_STATE = "UPDATE ExperimentTasks SET state=:state, lastChanged=:lastChanged WHERE state=:unfinishedState";
@@ -67,7 +67,7 @@ public class ExperimentDAOImpl extends AbstractExperimentDAO {
private final static String GET_ADDITIONAL_RESULTS = "SELECT resultId, value FROM ExperimentTasks_AdditionalResults WHERE taskId=:taskId";
private final static String INSERT_ADDITIONAL_RESULT = "INSERT INTO ExperimentTasks_AdditionalResults(taskId, resultId, value) VALUES (:taskId, :resultId, :value)";
- private final static String GET_SUB_TASK_RESULTS = "SELECT annotatorName, datasetName, experimentType, matching, microF1, microPrecision, microRecall, macroF1, macroPrecision, macroRecall, state, errorCount, lastChanged, taskId FROM ExperimentTasks t, ExperimentTasks_SubTasks s WHERE s.taskId=:taskId AND s.subTaskId=t.id";
+ private final static String GET_SUB_TASK_RESULTS = "SELECT annotatorName, datasetName, experimentType, matching, microF1, microPrecision, microRecall, macroF1, macroPrecision, macroRecall, state, errorCount, lastChanged, subTaskId FROM ExperimentTasks t, ExperimentTasks_SubTasks s WHERE s.taskId=:taskId AND s.subTaskId=t.id";
private final static String INSERT_SUB_TASK_RELATION = "INSERT INTO ExperimentTasks_SubTasks(taskId, subTaskId) VALUES (:taskId, :subTaskId)";
// FIXME remove the following two statements by removing the experiment task
@@ -390,6 +390,24 @@ protected void addSubTasks(ExperimentTaskResult expTask) {
}
}
+ @Override
+ public ExperimentTaskResult getResultOfExperimentTask(int experimentTaskId) {
+ MapSqlParameterSource parameters = new MapSqlParameterSource();
+ parameters.addValue("id", experimentTaskId);
+ List results = this.template.query(GET_EXPERIMENT_TASK_RESULT, parameters,
+ new ExperimentTaskResultRowMapper());
+ if (results.size() == 0) {
+ return null;
+ }
+ ExperimentTaskResult result = results.get(0);
+ // FIXME remove this ugly workaround regarding the version of an
+ // experiment task
+ addVersion(result);
+ addAdditionalResults(result);
+ addSubTasks(result);
+ return result;
+ }
+
@Override
public void close() throws IOException {
this.template.execute(SHUTDOWN, new PreparedStatementCallback() {
diff --git a/src/main/java/org/aksw/gerbil/dataid/DataIDGenerator.java b/src/main/java/org/aksw/gerbil/dataid/DataIDGenerator.java
index 576573b1e..f3a90b53f 100644
--- a/src/main/java/org/aksw/gerbil/dataid/DataIDGenerator.java
+++ b/src/main/java/org/aksw/gerbil/dataid/DataIDGenerator.java
@@ -18,16 +18,19 @@
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
+import org.aksw.gerbil.database.ResultNameToIdMapping;
import org.aksw.gerbil.datatypes.ExperimentTaskResult;
import org.aksw.gerbil.semantic.vocabs.CUBE;
import org.aksw.gerbil.semantic.vocabs.GERBIL;
import org.aksw.gerbil.web.ExperimentTaskStateHelper;
import org.apache.jena.riot.RDFDataMgr;
+import com.carrotsearch.hppc.IntDoubleOpenHashMap;
import com.github.jsonldjava.jena.JenaJSONLD;
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.rdf.model.Model;
@@ -39,21 +42,19 @@
public class DataIDGenerator {
- private static final String EXPERIMENT_PREFIX = "#experiment_";
+ private static final String EXPERIMENT_PREFIX = "experiment?id=";
+ private static final String EXPERIMENT_TASK_PREFIX = "experimentTask_";
private static final String DATASET_DATAID = "dataId/corpora/";
private static final String ANNOTATOR_DATAID = "dataId/annotators/";
private static final String DATAID_EXTENSION = "";
private String gerbilURL;
- private String gerbilFullURL;
- public DataIDGenerator(String gerbilURL, String gerbilFullURL) {
+ public DataIDGenerator(String gerbilURL) {
this.gerbilURL = gerbilURL;
- this.gerbilFullURL = gerbilFullURL;
}
- public String createDataIDModel(List results, String eID) {
-
+ public Model generateDataIDModel() {
// create an empty JENA Model
Model model = ModelFactory.createDefaultModel();
@@ -64,15 +65,37 @@ public String createDataIDModel(List results, String eID)
model.setNsPrefix("xsd", XSD.getURI());
model.setNsPrefix("qb", CUBE.getURI());
+ return model;
+ }
+
+ public String createDataIDModel(List results, String eID) {
// If the experiment is not existing (== there are no results), return
// an empty String
if (results.size() == 0) {
return "";
}
+ Model model = generateDataIDModel();
+
+ addToModel(model, results, eID);
+
+ // writing dataid result to output
+ OutputStream o = new ByteArrayOutputStream();
+
+ // creating json-ld output format
+ RDFDataMgr.write(o, model, JenaJSONLD.JSONLD);
+
+ return o.toString();
+ }
+
+ public void addToModel(Model model, List results, String eID) {
+ if (results.size() == 0) {
+ return;
+ }
+
Resource experiment = createExperimentResource(model, eID);
- int experimentNumber = 0;
+ boolean first = true;
Iterator resultIterator = results.iterator();
ExperimentTaskResult result;
// iterating over the experiments
@@ -80,7 +103,7 @@ public String createDataIDModel(List results, String eID)
result = resultIterator.next();
// If this is the first experiment result, use it to get further
// properties of the experiment (matching, ...)
- if (experimentNumber == 0) {
+ if (first) {
Resource r = GERBIL.getExperimentTypeResource(result.type);
if (r != null) {
experiment.addProperty(GERBIL.experimentType, r);
@@ -89,27 +112,16 @@ public String createDataIDModel(List results, String eID)
if (r != null) {
experiment.addProperty(GERBIL.matching, r);
}
+ first = false;
}
// create experiment task
- addExperimentTask(model, result, experiment, experimentNumber);
-
- ++experimentNumber;
+ addExperimentTask(model, result, experiment);
}
-
- // writing dataid result to output (this should be removed)
- // RDFDataMgr.write(System.out, model, RDFFormat.TURTLE);
-
- OutputStream o = new ByteArrayOutputStream();
-
- // creating json-ld output format
- RDFDataMgr.write(o, model, JenaJSONLD.JSONLD);
-
- return o.toString();
}
- private Resource createExperimentResource(Model model, String eID) {
+ public Resource createExperimentResource(Model model, String eID) {
// create experiment resource
- Resource experiment = model.createResource(gerbilFullURL + EXPERIMENT_PREFIX + eID);
+ Resource experiment = model.createResource(gerbilURL + EXPERIMENT_PREFIX + eID);
experiment.addProperty(RDF.type, CUBE.Dataset);
experiment.addProperty(RDF.type, GERBIL.Experiment);
@@ -119,31 +131,83 @@ private Resource createExperimentResource(Model model, String eID) {
return experiment;
}
- private void addExperimentTask(Model model, ExperimentTaskResult result, Resource experiment, int experimentNumber) {
+ public void addExperimentTask(Model model, ExperimentTaskResult result, Resource experiment) {
+ addExperimentTask(model, result, experiment, null);
+ }
+
+ public void addExperimentTask(Model model, ExperimentTaskResult result, Resource experiment,
+ Resource superExpTask) {
+ List experimentTasks = new ArrayList();
+ createExperimentTask(model, result, superExpTask, experimentTasks);
+ linkTasksToExperiment(model, experiment, experimentTasks);
+ }
+
+ public void linkTasksToExperiment(Model model, Resource experiment, List experimentTasks) {
+ for (Resource experimentTask : experimentTasks) {
+ model.add(experimentTask, CUBE.dataset, experiment.getURI());
+ }
+ }
+
+ public void createExperimentTask(Model model, ExperimentTaskResult result, Resource superExpTask,
+ List experimentTasks) {
// create Resource
- Resource experimentTask = model.createResource(experiment.getURI() + "_task_" + experimentNumber);
+ Resource experimentTask = model.createResource(generateExperimentTaskUri(result.idInDb));
+ experimentTasks.add(experimentTask);
+ if (model.containsResource(experimentTask)) {
+ return;
+ }
experimentTask.addProperty(RDF.type, CUBE.Observation);
// add annotator and dataset
experimentTask.addProperty(GERBIL.annotator,
- gerbilURL + DATASET_DATAID + DataIDUtils.treatsNames(result.annotator) + DATAID_EXTENSION);
- experimentTask.addProperty(GERBIL.dataset,
gerbilURL + ANNOTATOR_DATAID + DataIDUtils.treatsNames(result.dataset) + DATAID_EXTENSION);
+ experimentTask.addProperty(GERBIL.dataset,
+ gerbilURL + DATASET_DATAID + DataIDUtils.treatsNames(result.annotator) + DATAID_EXTENSION);
// set the status of this task
model.add(experimentTask, GERBIL.statusCode, model.createTypedLiteral(result.state));
+ if (superExpTask != null) {
+ model.add(experimentTask, GERBIL.subExperimentOf, superExpTask);
+ }
+
// If this task has been finished
if (ExperimentTaskStateHelper.taskFinished(result)) {
- model.add(experimentTask, CUBE.dataset, model.createResource(experiment.getURI()));
// creating and setting literals for the current experiment
- model.add(experimentTask, GERBIL.microF1, model.createTypedLiteral(String.valueOf(result.getMicroF1Measure()),XSDDatatype.XSDdecimal));
- model.add(experimentTask, GERBIL.microPrecision, model.createTypedLiteral(String.valueOf(result.getMicroPrecision()),XSDDatatype.XSDdecimal));
- model.add(experimentTask, GERBIL.microRecall, model.createTypedLiteral(String.valueOf(result.getMicroRecall()),XSDDatatype.XSDdecimal));
- model.add(experimentTask, GERBIL.macroF1, model.createTypedLiteral(String.valueOf(result.getMacroF1Measure()),XSDDatatype.XSDdecimal));
- model.add(experimentTask, GERBIL.macroPrecision, model.createTypedLiteral(String.valueOf(result.getMacroPrecision()),XSDDatatype.XSDdecimal));
- model.add(experimentTask, GERBIL.macroRecall, model.createTypedLiteral(String.valueOf(result.getMacroRecall()), XSDDatatype.XSDdecimal));
+ model.add(experimentTask, GERBIL.microF1,
+ model.createTypedLiteral(String.valueOf(result.getMicroF1Measure()), XSDDatatype.XSDdecimal));
+ model.add(experimentTask, GERBIL.microPrecision,
+ model.createTypedLiteral(String.valueOf(result.getMicroPrecision()), XSDDatatype.XSDdecimal));
+ model.add(experimentTask, GERBIL.microRecall,
+ model.createTypedLiteral(String.valueOf(result.getMicroRecall()), XSDDatatype.XSDdecimal));
+ model.add(experimentTask, GERBIL.macroF1,
+ model.createTypedLiteral(String.valueOf(result.getMacroF1Measure()), XSDDatatype.XSDdecimal));
+ model.add(experimentTask, GERBIL.macroPrecision,
+ model.createTypedLiteral(String.valueOf(result.getMacroPrecision()), XSDDatatype.XSDdecimal));
+ model.add(experimentTask, GERBIL.macroRecall,
+ model.createTypedLiteral(String.valueOf(result.getMacroRecall()), XSDDatatype.XSDdecimal));
model.add(experimentTask, GERBIL.errorCount, model.createTypedLiteral(String.valueOf(result.errorCount)));
+
+ if (result.hasAdditionalResults()) {
+ IntDoubleOpenHashMap additionalResults = result.getAdditionalResults();
+ String propertyUri;
+ ResultNameToIdMapping mapping = ResultNameToIdMapping.getInstance();
+ for (int i = 0; i < additionalResults.allocated.length; ++i) {
+ if (additionalResults.allocated[i]) {
+ propertyUri = mapping.getResultName(additionalResults.keys[i]);
+ if (propertyUri != null) {
+ propertyUri = GERBIL.getURI() + propertyUri.replace(" ", "_");
+ model.add(experimentTask, model.createProperty(propertyUri), model.createTypedLiteral(
+ String.valueOf(additionalResults.values[i]), XSDDatatype.XSDdecimal));
+ }
+ }
+ }
+ }
+ if (result.hasSubTasks()) {
+ for (ExperimentTaskResult subResult : result.getSubTasks()) {
+ createExperimentTask(model, subResult, experimentTask, experimentTasks);
+ }
+ }
}
Calendar cal = Calendar.getInstance();
@@ -151,4 +215,8 @@ private void addExperimentTask(Model model, ExperimentTaskResult result, Resourc
model.add(experimentTask, GERBIL.timestamp, model.createTypedLiteral(cal));
}
+ public String generateExperimentTaskUri(int taskId) {
+ return gerbilURL + EXPERIMENT_TASK_PREFIX + taskId;
+ }
+
}
diff --git a/src/main/java/org/aksw/gerbil/dataset/SingletonDatasetConfigImpl.java b/src/main/java/org/aksw/gerbil/dataset/SingletonDatasetConfigImpl.java
index d25b2908f..07ad3d69c 100644
--- a/src/main/java/org/aksw/gerbil/dataset/SingletonDatasetConfigImpl.java
+++ b/src/main/java/org/aksw/gerbil/dataset/SingletonDatasetConfigImpl.java
@@ -43,11 +43,11 @@ public SingletonDatasetConfigImpl(String annotatorName, boolean couldBeCached,
}
@Override
- protected Dataset loadDataset() throws Exception {
+ protected Dataset getPreparedDataset() throws Exception {
instanceMutex.acquire();
try {
if (instance == null) {
- instance = super.loadDataset();
+ instance = super.getPreparedDataset();
instance.setClosePermitionGranter(this);
}
++instanceUsages;
diff --git a/src/main/java/org/aksw/gerbil/dataset/check/impl/HttpBasedEntityChecker.java b/src/main/java/org/aksw/gerbil/dataset/check/impl/HttpBasedEntityChecker.java
index 93f23ec58..8ebab0afc 100644
--- a/src/main/java/org/aksw/gerbil/dataset/check/impl/HttpBasedEntityChecker.java
+++ b/src/main/java/org/aksw/gerbil/dataset/check/impl/HttpBasedEntityChecker.java
@@ -50,7 +50,12 @@ public boolean entityExists(String uri) {
try {
request = createHeadRequest(uri);
} catch (IllegalArgumentException e) {
- LOGGER.error("Exception while creating HTTP request. Returning false.", e);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.error("Exception while creating HTTP request. Returning false.", e);
+ } else {
+ LOGGER.error("Exception while creating HTTP request. Returning false. Exception: "
+ + e.getLocalizedMessage());
+ }
return false;
}
CloseableHttpResponse response = null;
@@ -59,7 +64,12 @@ public boolean entityExists(String uri) {
StatusLine status = response.getStatusLine();
return (status.getStatusCode() >= 200) && (status.getStatusCode() < 300);
} catch (Exception e) {
- LOGGER.error("Exception while sending HTTP request. Returning false.", e);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.error("Exception while sending HTTP request. Returning false.", e);
+ } else {
+ LOGGER.error(
+ "Exception while sending HTTP request. Returning false. Exception: " + e.getLocalizedMessage());
+ }
return false;
} finally {
closeRequest(request);
diff --git a/src/main/java/org/aksw/gerbil/semantic/vocabs/GERBIL.java b/src/main/java/org/aksw/gerbil/semantic/vocabs/GERBIL.java
index 060a2f090..5be00ce4e 100644
--- a/src/main/java/org/aksw/gerbil/semantic/vocabs/GERBIL.java
+++ b/src/main/java/org/aksw/gerbil/semantic/vocabs/GERBIL.java
@@ -29,7 +29,7 @@ public class GERBIL {
private static final Logger LOGGER = LoggerFactory.getLogger(GERBIL.class);
- protected static final String uri = "http://gerbil.aksw.org/gerbil/vocab#";
+ protected static final String uri = "http://w3id.org/gerbil/vocab#";
/**
* returns the URI for this schema
@@ -80,6 +80,7 @@ protected static final Property property(String local) {
public static final Property microPrecision = property("microPrecision");
public static final Property microRecall = property("microRecall");
public static final Property statusCode = property("statusCode");
+ public static final Property subExperimentOf = property("subExperimentOf");
public static final Property timestamp = property("timestamp");
public static final Property topic = property("topic");
@@ -121,11 +122,9 @@ public static Resource getExperimentTypeResource(ExperimentType type) {
return ERec;
case ETyping:
return ETyping;
- // FIXME add missing experiment types
- default:
- ;
}
LOGGER.error("Got an unknown experiment type: " + type.name());
return null;
}
+
}
diff --git a/src/main/java/org/aksw/gerbil/tools/DataDumpTool.java b/src/main/java/org/aksw/gerbil/tools/DataDumpTool.java
new file mode 100644
index 000000000..dce8bc4f6
--- /dev/null
+++ b/src/main/java/org/aksw/gerbil/tools/DataDumpTool.java
@@ -0,0 +1,160 @@
+package org.aksw.gerbil.tools;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.aksw.gerbil.database.ExperimentDAO;
+import org.aksw.gerbil.database.ExperimentDAOImpl;
+import org.aksw.gerbil.dataid.DataIDGenerator;
+import org.aksw.gerbil.datatypes.ExperimentTaskResult;
+import org.apache.commons.io.IOUtils;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFDataMgr;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Resource;
+
+public class DataDumpTool implements Closeable {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(DataDumpTool.class);
+
+ private static final String OUTPUT_FILE_NAME = "datadump.nt";
+ private static final Lang OUTPUT_LANG = Lang.NT;
+
+ private static final String GERBIL_BASE_URL = "http://gerbil.aksw.org/gerbil/";
+
+ private static final String EXPERIMENT_IDS_QUERY = "SELECT id, taskId FROM Experiments";
+
+ public static void main(String[] args) {
+ ClassPathXmlApplicationContext context = null;
+ DataDumpTool tool = null;
+ try {
+ context = new ClassPathXmlApplicationContext("/spring/database/database-context.xml");
+ DriverManagerDataSource database = context.getBean("databaseDataSource", DriverManagerDataSource.class);
+ tool = new DataDumpTool(GERBIL_BASE_URL, database);
+ tool.run(OUTPUT_FILE_NAME, OUTPUT_LANG);
+ } finally {
+ IOUtils.closeQuietly(tool);
+ IOUtils.closeQuietly(context);
+ }
+ }
+
+ private String gerbilBaseUrl;
+ private DataSource dataSource;
+ private ExperimentDAO dao;
+
+ public DataDumpTool(String gerbilBaseUrl, DataSource dataSource) {
+ this.gerbilBaseUrl = gerbilBaseUrl;
+ this.dataSource = dataSource;
+ this.dao = new ExperimentDAOImpl(dataSource);
+ }
+
+ public void run(String outputFileName, Lang language) {
+ List experiments = loadExperiments();
+ LOGGER.info("Loaded {} experiment to experiment task links from the database.", experiments.size());
+
+ DataIDGenerator generator = new DataIDGenerator(gerbilBaseUrl);
+
+ Model model = generator.generateDataIDModel();
+
+ Resource experimentResource;
+ String taskUri;
+ List listOfTasks;
+ Map experimentInstances = new HashMap();
+ Map> taskResources = new HashMap>();
+ int count = 0;
+ for (ExperimentToTaskLink link : experiments) {
+ // Get the experiment resource
+ if (experimentInstances.containsKey(link.experimentId)) {
+ experimentResource = experimentInstances.get(link.experimentId);
+ } else {
+ experimentResource = generator.createExperimentResource(model, link.experimentId);
+ experimentInstances.put(link.experimentId, experimentResource);
+ }
+ // Get the experiment task resource
+ taskUri = generator.generateExperimentTaskUri(link.experimentTaskId);
+ if (taskResources.containsKey(taskUri)) {
+ listOfTasks = taskResources.get(taskUri);
+ } else {
+ listOfTasks = new ArrayList();
+ ExperimentTaskResult result = dao.getResultOfExperimentTask(link.experimentTaskId);
+ if (result == null) {
+ LOGGER.error("Couldn't find an experiment task with the id {}. It will be ignored.",
+ link.experimentTaskId);
+ listOfTasks = null;
+ } else {
+ generator.createExperimentTask(model, result, null, listOfTasks);
+ taskResources.put(taskUri, listOfTasks);
+ }
+ }
+ // Link both resources
+ if (listOfTasks != null) {
+ generator.linkTasksToExperiment(model, experimentResource, listOfTasks);
+ }
+ ++count;
+ if ((count % 1000) == 0) {
+ LOGGER.info("Processed {} experiment task links.", count);
+ }
+ }
+
+ File outputFile = new File(outputFileName);
+ if ((outputFile.getParentFile() != null) && (!outputFile.getParentFile().exists())) {
+ outputFile.getParentFile().mkdirs();
+ }
+ FileOutputStream fout = null;
+ try {
+ fout = new FileOutputStream(outputFile);
+ RDFDataMgr.write(fout, model, language);
+ } catch (FileNotFoundException e) {
+ LOGGER.error("Exception while writing model.", e);
+ } finally {
+ IOUtils.closeQuietly(fout);
+ }
+ }
+
+ private List loadExperiments() {
+ NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource);
+ return template.query(EXPERIMENT_IDS_QUERY, new ExperimentToTaskLinkRowMapper());
+ }
+
+ @Override
+ public void close() throws IOException {
+ IOUtils.closeQuietly(dao);
+ }
+
+ protected static class ExperimentToTaskLink {
+ public String experimentId;
+ public int experimentTaskId;
+
+ public ExperimentToTaskLink(String experimentId, int experimentTaskId) {
+ this.experimentId = experimentId;
+ this.experimentTaskId = experimentTaskId;
+ }
+ }
+
+ protected static class ExperimentToTaskLinkRowMapper implements RowMapper {
+
+ @Override
+ public ExperimentToTaskLink mapRow(ResultSet arg0, int arg1) throws SQLException {
+ return new ExperimentToTaskLink(arg0.getString(1), arg0.getInt(2));
+ }
+
+ }
+}
diff --git a/src/main/java/org/aksw/gerbil/web/MainController.java b/src/main/java/org/aksw/gerbil/web/MainController.java
index 53c264a52..9fb6021ab 100644
--- a/src/main/java/org/aksw/gerbil/web/MainController.java
+++ b/src/main/java/org/aksw/gerbil/web/MainController.java
@@ -104,9 +104,6 @@ public void init() {
private ExperimentType[] availableExperimentTypes = RootConfig.getAvailableExperimentTypes();
- @Autowired
- protected HttpServletRequest request;
-
private AnnotatorOutputWriter annotatorOutputWriter = RootConfig.getAnnotatorOutputWriter();
@RequestMapping("/config")
@@ -186,9 +183,9 @@ public ModelAndView index() {
}
@RequestMapping("/experiment")
- public ModelAndView experiment(@RequestParam(value = "id") String id) {
+ public ModelAndView experiment(@RequestParam(value = "id") String id, HttpServletRequest request) {
LOGGER.debug("Got request on /experiment with id={}", id);
- dataIdGenerator = new DataIDGenerator(getURLBase(), getFullURL());
+ dataIdGenerator = new DataIDGenerator(getURLBase(request));
List results = dao.getResultsOfExperiment(id);
ExperimentTaskStateHelper.setStatusLines(results);
ModelAndView model = new ModelAndView();
@@ -293,7 +290,7 @@ public ModelAndView experiment(@RequestParam(value = "id") String id) {
return "";
}
- private String getURLBase() {
+ private String getURLBase(HttpServletRequest request) {
String scheme = request.getScheme();
String serverName = request.getServerName();
int serverPort = request.getServerPort();
@@ -306,7 +303,9 @@ private String getURLBase() {
return url.toString();
}
- private String getFullURL() {
+ @SuppressWarnings("unused")
+ @Deprecated
+ private String getFullURL(HttpServletRequest request) {
StringBuffer requestURL = request.getRequestURL();
String queryString = request.getQueryString();
diff --git a/src/main/java/org/aksw/gerbil/web/VocabularyController.java b/src/main/java/org/aksw/gerbil/web/VocabularyController.java
index a71477519..0fac443cc 100644
--- a/src/main/java/org/aksw/gerbil/web/VocabularyController.java
+++ b/src/main/java/org/aksw/gerbil/web/VocabularyController.java
@@ -27,7 +27,6 @@
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
-@RequestMapping("/vocab")
public class VocabularyController {
private static final Logger LOGGER = LoggerFactory.getLogger(VocabularyController.class);
@@ -36,19 +35,19 @@ public class VocabularyController {
private static final String GERBIL_VOCABULARY_RDF_FILE = "vocab/gerbil.rdf";
private static final String GERBIL_VOCABULARY_TTL_FILE = "vocab/gerbil.ttl";
- @RequestMapping(value = "/gerbil*", produces = { "text/turtle", "text/plain" })
+ @RequestMapping(value = "/vocab*", produces = { "text/turtle", "text/plain" })
public @ResponseBody
String vocabularyAsTTL() {
return getResourceAsString(GERBIL_VOCABULARY_TTL_FILE);
}
-
- @RequestMapping(value = "/gerbil*", produces = { "application/json+ld", "application/json" })
+
+ @RequestMapping(value = "/vocab*", produces = { "application/json+ld", "application/json" })
public @ResponseBody
String vocabularyAsJSON() {
return getResourceAsString(GERBIL_VOCABULARY_JSON_FILE);
}
- @RequestMapping(value = "/gerbil*", produces = "application/rdf+xml")
+ @RequestMapping(value = "/vocab*", produces = "application/rdf+xml")
public @ResponseBody
String vocabularyAsRDFXML() {
return getResourceAsString(GERBIL_VOCABULARY_RDF_FILE);
diff --git a/src/test/java/org/aksw/gerbil/database/SimpleLoggingDAO4Debugging.java b/src/test/java/org/aksw/gerbil/database/SimpleLoggingDAO4Debugging.java
index 42568f313..706a1835b 100644
--- a/src/test/java/org/aksw/gerbil/database/SimpleLoggingDAO4Debugging.java
+++ b/src/test/java/org/aksw/gerbil/database/SimpleLoggingDAO4Debugging.java
@@ -18,7 +18,6 @@
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import org.aksw.gerbil.datatypes.ExperimentTaskResult;
@@ -123,4 +122,9 @@ public List getLatestResultsOfExperiments(String experimen
return null;
}
+ @Override
+ public ExperimentTaskResult getResultOfExperimentTask(int experimentTaskId) {
+ return null;
+ }
+
}