Skip to content

Commit d526c11

Browse files
author
TortugaAttack
committed
#250, #344 - added option to upload dataset and answer file
1 parent 0b4b28c commit d526c11

File tree

10 files changed

+179
-110
lines changed

10 files changed

+179
-110
lines changed

src/main/java/org/aksw/gerbil/annotator/InstanceListBasedConfigurationImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public Annotator getAnnotator(ExperimentType experimentType) throws GerbilExcept
6565
}
6666

6767
protected Annotator loadAnnotator(ExperimentType experimentType) throws Exception {
68+
datasetConfig.setQuestionLanguage(this.questionLang);
6869
Dataset dataset = datasetConfig.getDataset(experimentType);
6970
if (dataset == null) {
7071
return null;

src/main/java/org/aksw/gerbil/dataset/AbstractDatasetConfiguration.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,38 @@ public abstract class AbstractDatasetConfiguration extends AbstractAdapterConfig
3333
protected EntityCheckerManager entityCheckerManager;
3434
protected SameAsRetriever globalRetriever;
3535
protected String questionLang;
36+
protected String questionLabel;
3637

37-
public AbstractDatasetConfiguration(String datasetName, boolean couldBeCached,
38+
public AbstractDatasetConfiguration(String datasetName,boolean couldBeCached,
3839
ExperimentType applicableForExperiment, EntityCheckerManager entityCheckerManager,
3940
SameAsRetriever globalRetriever) {
4041
super(datasetName, couldBeCached, applicableForExperiment);
42+
this.questionLabel=datasetName;
4143
this.entityCheckerManager = entityCheckerManager;
4244
this.globalRetriever = globalRetriever;
4345
}
44-
46+
47+
public AbstractDatasetConfiguration(String datasetName, String questionLabel, boolean couldBeCached,
48+
ExperimentType applicableForExperiment, EntityCheckerManager entityCheckerManager,
49+
SameAsRetriever globalRetriever) {
50+
super(datasetName, couldBeCached, applicableForExperiment);
51+
this.questionLabel=questionLabel;
52+
this.entityCheckerManager = entityCheckerManager;
53+
this.globalRetriever = globalRetriever;
54+
}
55+
4556
public void setQuestionLang(String questionLang){
4657
this.questionLang = questionLang;
4758
}
4859

60+
public String getQuestionLabel() {
61+
return questionLabel;
62+
}
63+
64+
public void setQuestionLabel(String questionLabel) {
65+
this.questionLabel = questionLabel;
66+
}
67+
4968
@Override
5069
public Dataset getDataset(ExperimentType experimentType) throws GerbilException {
5170
// for (int i = 0; i < applicableForExperiments.length; ++i) {

src/main/java/org/aksw/gerbil/dataset/Dataset.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ public interface Dataset extends Closeable {
3737
public void setQuestionLanguage(String qLang);
3838

3939
public String getQuestionLanguage();
40+
41+
public String getQuestionLabel();
42+
43+
public void setQuestionLabel(String questionLabel);
4044
}

src/main/java/org/aksw/gerbil/dataset/impl/AbstractDataset.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
public abstract class AbstractDataset implements Dataset {
2525

2626
protected String name;
27+
protected String questionLabel;
2728
protected ClosePermitionGranter granter;
2829
protected String qLang;
2930

@@ -33,6 +34,23 @@ public AbstractDataset() {
3334

3435
public AbstractDataset(String name) {
3536
this.name = name;
37+
this.questionLabel=name;
38+
}
39+
40+
41+
public AbstractDataset(String name, String questionLabel) {
42+
this.name = name;
43+
this.questionLabel=questionLabel;
44+
}
45+
46+
@Override
47+
public String getQuestionLabel() {
48+
return questionLabel;
49+
}
50+
51+
@Override
52+
public void setQuestionLabel(String questionLabel) {
53+
this.questionLabel = questionLabel;
3654
}
3755

3856
@Override

src/main/java/org/aksw/gerbil/dataset/impl/qald/FileBasedQALDDataset.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.aksw.gerbil.qa.QALDStreamUtils;
1818
import org.aksw.gerbil.qa.QAUtils;
1919
import org.aksw.gerbil.transfer.nif.Document;
20+
import org.aksw.gerbil.web.config.AdapterManager;
2021
import org.aksw.qa.commons.datastructure.IQuestion;
2122
import org.aksw.qa.commons.load.LoaderController;
2223
import org.aksw.qa.commons.load.json.EJQuestionFactory;
@@ -40,8 +41,8 @@ public FileBasedQALDDataset(String file){
4041
this.file=file;
4142
initLanguage();
4243
}
43-
public FileBasedQALDDataset(String name, String file){
44-
super(name);
44+
public FileBasedQALDDataset(String name, String questionLabel, String file){
45+
super(name, questionLabel);
4546
this.file=file;
4647
initLanguage();
4748
}
@@ -52,14 +53,14 @@ public FileBasedQALDDataset(String file, QALDStreamType fileType) {
5253
initLanguage();
5354
}
5455

55-
public FileBasedQALDDataset(String name, String file, QALDStreamType fileType) {
56-
super(name);
56+
public FileBasedQALDDataset(String name, String questionLabel, String file, QALDStreamType fileType) {
57+
super(name, questionLabel);
5758
this.file = file;
5859
this.fileType = fileType;
5960
initLanguage();
6061
}
61-
public FileBasedQALDDataset(String name, String file, String questionLanguage) {
62-
super(name);
62+
public FileBasedQALDDataset(String name, String questionLabel, String file, String questionLanguage) {
63+
super(name, questionLabel);
6364
this.file = file;
6465
this.fileType = fileType;
6566
this.qLang=questionLanguage;
@@ -86,7 +87,7 @@ public void init() throws GerbilException {
8687
try {
8788
fin = new FileInputStream(file);
8889
if(fileType!=null){
89-
instances = QALDStreamUtils.parseDocument(fin, fileType, getName());
90+
instances = QALDStreamUtils.parseDocument(fin, fileType, getQuestionLabel());
9091
}
9192
else{
9293
List<IQuestion> questions;
@@ -96,7 +97,7 @@ public void init() throws GerbilException {
9697
//XML
9798
questions = LoaderController.loadXML(fin, null, qLang);
9899
}
99-
instances = generateInstancesFromQuestions(getName(), questions, qLang);
100+
instances = generateInstancesFromQuestions(getQuestionLabel(), questions, qLang);
100101
}
101102
} catch (Exception e) {
102103
IOUtils.closeQuietly(fin);

src/main/java/org/aksw/gerbil/dataset/impl/qald/QALDFileDatasetConfig.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ public QALDFileDatasetConfig(String name, String file, boolean couldBeCached, Ex
3434
this.file = file;
3535
}
3636

37+
38+
public QALDFileDatasetConfig(String name, String questionLabel, String file, boolean couldBeCached, ExperimentType applicableForExperiment,
39+
EntityCheckerManager entityCheckerManager, SameAsRetriever globalRetriever) {
40+
super(name, questionLabel, couldBeCached, applicableForExperiment, entityCheckerManager, globalRetriever);
41+
this.file = file;
42+
}
43+
3744
@Override
3845
protected Dataset loadDataset() throws Exception {
39-
FileBasedQALDDataset dataset = new FileBasedQALDDataset(getName(), file);
46+
FileBasedQALDDataset dataset = new FileBasedQALDDataset(getName(), getQuestionLabel(), file, questionLang);
4047
dataset.setQuestionLanguage(questionLang);
4148
dataset.init();
4249
return dataset;

src/main/java/org/aksw/gerbil/execute/ExperimentTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ protected void prepareAnnotatorResults(List<? extends List<? extends Meaning>> r
248248
case Sc2KB:
249249
case OKE_Task1: // falls through
250250
case OKE_Task2:
251-
case QA:
251+
252252
case ETyping: {
253253
if (annotatorSameAsRetriever != null) {
254254
for (List<? extends Meaning> result : results) {
@@ -257,6 +257,7 @@ protected void prepareAnnotatorResults(List<? extends List<? extends Meaning>> r
257257
}
258258
return;
259259
}
260+
case QA:
260261
case ERec:// falls through
261262
default:
262263
// nothing to do

src/main/java/org/aksw/gerbil/web/MainController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public ModelAndView index() {
190190
for (String answerFile : answerFiles) {
191191
configs[count] = new ExperimentTaskConfiguration(adapterManager.getAnnotatorConfig(answerFile, type, qLang),
192192
adapterManager.getDatasetConfig(answerFile, type, qLang), type, getMatching(matching), qLang);
193+
193194
LOGGER.debug("Created config: {}", configs[count]);
194195
++count;
195196
}

src/main/java/org/aksw/gerbil/web/config/AdapterManager.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public class AdapterManager {
4848
private static final String NIF_WS_PREFIX = "NIFWS_";
4949
private static final String NIF_WS_SUFFIX = " (WS)";
5050
private static final String AF_PREFIX = "AF_";
51-
private static final String UPLOADED_AF_SUFFIX = " (uploaded)";
51+
private static final String AFDS_PREFIX = "AFDS_";
52+
public static final String UPLOADED_AF_SUFFIX = " (uploaded)";
5253
private static final String UPLOADED_FILES_PATH_PROPERTY_KEY = "org.aksw.gerbil.UploadPath";
5354
private static final String UPLOADED_DATASET_SUFFIX = " (uploaded)";
5455
private static final String UPLOADED_DATASET_PREFIX = "NIFDS_";
@@ -164,8 +165,8 @@ public AnnotatorConfiguration getAnnotatorConfig(String name, ExperimentType typ
164165
try {
165166
return new InstanceListBasedConfigurationImpl(name, false,
166167
new DatasetConfigurationImpl(datasetName, false,
167-
FileBasedQALDDataset.class.getConstructor(String.class, String.class, String.class),
168-
new Object[] { datasetName, uploadedFilesPath + fileName, questionLanguage},
168+
FileBasedQALDDataset.class.getConstructor(String.class, String.class, String.class, String.class),
169+
new Object[] { datasetName, datasetName.replace(AFDS_PREFIX, ""), uploadedFilesPath + fileName, questionLanguage},
169170
ExperimentType.QA, null, null),
170171
type, questionLanguage);
171172
} catch (Exception e) {
@@ -207,8 +208,9 @@ public DatasetConfiguration getDatasetConfig(String name, ExperimentType type, S
207208
}
208209
String uri = uploadedFilesPath + name.substring(brackets[0] + 1, brackets[1]);
209210
// remove dataset prefix from the name
210-
name = name.substring(UPLOADED_DATASET_PREFIX.length(), brackets[0]) + UPLOADED_DATASET_SUFFIX;
211-
return new QALDFileDatasetConfig(name, uri, false, type, entityCheckerManager, globalRetriever);
211+
String questionLabel = name.substring(UPLOADED_DATASET_PREFIX.length(), brackets[0]);
212+
name = questionLabel + UPLOADED_DATASET_SUFFIX;
213+
return new QALDFileDatasetConfig(name, questionLabel, uri, false, type, entityCheckerManager, globalRetriever);
212214
}
213215
if (name.startsWith(AF_PREFIX)) {
214216
// This describes a QA answer file
@@ -223,6 +225,11 @@ public DatasetConfiguration getDatasetConfig(String name, ExperimentType type, S
223225
String datasetName = name.substring(brackets[0] + 1, brackets[1]);
224226
return getDatasetConfig(datasetName, type, questionLanguage);
225227
}
228+
if(name.startsWith(AFDS_PREFIX)){
229+
String formatted= name.replace(AFDS_PREFIX, "");
230+
return getDatasetConfig("NIFDS_"+formatted+"("+formatted+")", type, questionLanguage);
231+
232+
}
226233
}
227234
LOGGER.error("Got an unknown annotator name\"" + name + "\". Returning null.");
228235
return null;

0 commit comments

Comments
 (0)