From a0b25b8dd1acbe078154dd2b36043d8411991cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Bl=C3=BCbaum?= Date: Wed, 10 Apr 2019 11:17:00 +0200 Subject: [PATCH] Some system and loading fixes + started to rework the READMEs --- .gitignore | 1 + README.md | 14 ++-- qa.annotation/README.md | 28 ++++++++ .../ExplorerProperties.java | 2 +- .../Field.java | 2 +- .../KnowledgeCardCreator.java | 2 +- .../qa/commons/load/LoaderController.java | 8 +-- .../org/aksw/qa/commons/load/tsv/LoadTsv.java | 3 +- .../measure/AnswerBasedEvaluation.java | 4 +- .../qa/commons/qald/IQuestionCsvParser.java | 2 +- .../aksw/qa/commons/qald/Qald8Creation.java | 6 +- .../KnowledgeCardCreatorTest.java | 4 +- .../org/aksw/qa/commons/load/LoadTest.java | 6 +- qa.datasets/pom.xml | 14 ++++ .../EntityDate.java | 2 +- .../EntityLocation.java | 2 +- .../EntityMoney.java | 2 +- .../EntityOrganization.java | 2 +- .../EntityPercent.java | 2 +- .../EntityPerson.java | 2 +- .../NumberOfToken.java | 2 +- .../aksw/mlqa/experiment/ArffFileFromRun.java | 8 +-- .../analyzer/comperative/ComperativeTest.java | 4 +- .../EntityTypeTest.java | 32 +++++---- .../NumberOfTokenTest.java | 3 +- .../analyzer/superlative/SuperlativeTest.java | 4 +- .../main/java/org/aksw/qa/systems/AskNow.java | 4 +- .../org/aksw/qa/systems/Gen_HTTP_QA_Sys.java | 11 +-- .../java/org/aksw/qa/systems/PLATYPUS.java | 4 +- .../main/java/org/aksw/qa/systems/QANARY.java | 68 ++++++++++++++++++- .../main/java/org/aksw/qa/systems/QUEPY.java | 8 +-- .../java/org/aksw/qa/systems/SorokinQA.java | 6 +- 32 files changed, 193 insertions(+), 69 deletions(-) create mode 100644 qa.annotation/README.md rename qa.commons/src/main/java/org/aksw/qa/commons/{knowledgeCard => knowledgecard}/ExplorerProperties.java (94%) rename qa.commons/src/main/java/org/aksw/qa/commons/{knowledgeCard => knowledgecard}/Field.java (96%) rename qa.commons/src/main/java/org/aksw/qa/commons/{knowledgeCard => knowledgecard}/KnowledgeCardCreator.java (99%) rename qa.commons/src/test/java/org/aksw/qa/commons/{knowledgeCard => knowledgecard}/KnowledgeCardCreatorTest.java (92%) rename qa.ml/src/main/java/org/aksw/mlqa/analyzer/{entityType => entitytype}/EntityDate.java (97%) rename qa.ml/src/main/java/org/aksw/mlqa/analyzer/{entityType => entitytype}/EntityLocation.java (97%) rename qa.ml/src/main/java/org/aksw/mlqa/analyzer/{entityType => entitytype}/EntityMoney.java (97%) rename qa.ml/src/main/java/org/aksw/mlqa/analyzer/{entityType => entitytype}/EntityOrganization.java (97%) rename qa.ml/src/main/java/org/aksw/mlqa/analyzer/{entityType => entitytype}/EntityPercent.java (97%) rename qa.ml/src/main/java/org/aksw/mlqa/analyzer/{entityType => entitytype}/EntityPerson.java (97%) rename qa.ml/src/main/java/org/aksw/mlqa/analyzer/{numberOfToken => numberoftoken}/NumberOfToken.java (94%) rename qa.ml/src/test/java/org/aksw/mlqa/analyzer/{entityType => entitytype}/EntityTypeTest.java (89%) rename qa.ml/src/test/java/org/aksw/mlqa/analyzer/{numberOfToken => numberoftoken}/NumberOfTokenTest.java (87%) diff --git a/.gitignore b/.gitignore index 61fb7a98..8ae823d4 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ log.out.* qa.datasets/src/main/resources/annotated_wd_data_valid_full.json qa.datasets/src/main/resources/lcquad_qaldformat.json qa.datasets/src/main/resources/qrels-v2.txt +qa.datasets/src/main/resources/queries-v2.txt qa.datasets/src/main/resources/webservice_25_06_2017.json qa.datasets/src/main/resources/QALD qa.datasets/src/main/resources/QALD-master diff --git a/README.md b/README.md index 9672bdf7..e384e4cf 100755 --- a/README.md +++ b/README.md @@ -8,13 +8,13 @@ Collection of tools, utilities, datasets and approaches towards realizing natural language interfaces for the Web of Data. Currently, we are focusing on Question Answering (QA) utilities. -Especially, this repository contains +Especially, this repository contains * QA Systems: A set of existing online webservices of QA systems all executable via a simple Java interface. * QA Datasets: A collection of existing Question Answering datasets * QA Machine Learning: This projects aims at learning a ML-based algorithm to combine multiple QA systems into one -* QA Commons: A collection to ease handling of QA datasets. It allows to load, store and evaluate datasets and systems. +* QA Commons: A collection to ease handling of QA datasets. It allows to load, store and evaluate datasets and systems. -We aim at providing a fast entrance to the field of natural language interfaces (search, question answering, ranking). Thus, we will offer here Maven dependencies and source code for using many available datasets, systems and techniques. +We aim at providing a fast entrance to the field of natural language interfaces (search, question answering, ranking). Thus, we will offer here Maven dependencies and source code for using many available datasets, systems and techniques. More interesting Question Answering and Natural Language Generation projects can be found here: * SemWeb2NL https://github.com/aksw/semweb2nl: This repository provides means to verbalize triples, entities, SPARQL queries and many more RDF dataset. This is especially useful to allow users understand Web of Data content. @@ -34,4 +34,10 @@ Add the following repository to your project: Artifacts are described in the sub-modules. -Look for more interesting libraries here: http://maven.aksw.org/archiva/#browse/org.aksw.qa +Look for more interesting libraries here: http://maven.aksw.org/archiva/#browse/org.aksw.qa + + +## Papers using NLIWOD +* https://doi.acm.org/10.1145/3178876.3186023 +* https://github.com/dice-group/goose +* https://arxiv.org/abs/1809.10044 diff --git a/qa.annotation/README.md b/qa.annotation/README.md new file mode 100644 index 00000000..5d8c7546 --- /dev/null +++ b/qa.annotation/README.md @@ -0,0 +1,28 @@ +# Question Answering (QA) annotation + + +## Maven Dependency +This library is available as a snapshot here: https://maven.aksw.org/archiva/#artifact~snapshots/org.aksw.qa/annotation + +``` + + org.aksw.qa + annotation + 0.3.4 + +``` +Add the following repository: +``` + + maven.aksw.internal + University Leipzig, AKSW Maven2 Repository + http://maven.aksw.org/archiva/repository/internal + + + maven.aksw.snapshots + University Leipzig, AKSW Maven2 Repository + http://maven.aksw.org/archiva/repository/snapshots + +``` + +Look for more interesting libraries here: http://maven.aksw.org/archiva/#browse/org.aksw.qa diff --git a/qa.commons/src/main/java/org/aksw/qa/commons/knowledgeCard/ExplorerProperties.java b/qa.commons/src/main/java/org/aksw/qa/commons/knowledgecard/ExplorerProperties.java similarity index 94% rename from qa.commons/src/main/java/org/aksw/qa/commons/knowledgeCard/ExplorerProperties.java rename to qa.commons/src/main/java/org/aksw/qa/commons/knowledgecard/ExplorerProperties.java index cc4349dd..07772acc 100644 --- a/qa.commons/src/main/java/org/aksw/qa/commons/knowledgeCard/ExplorerProperties.java +++ b/qa.commons/src/main/java/org/aksw/qa/commons/knowledgecard/ExplorerProperties.java @@ -1,4 +1,4 @@ -package org.aksw.qa.commons.knowledgeCard; +package org.aksw.qa.commons.knowledgecard; public class ExplorerProperties { private String className; diff --git a/qa.commons/src/main/java/org/aksw/qa/commons/knowledgeCard/Field.java b/qa.commons/src/main/java/org/aksw/qa/commons/knowledgecard/Field.java similarity index 96% rename from qa.commons/src/main/java/org/aksw/qa/commons/knowledgeCard/Field.java rename to qa.commons/src/main/java/org/aksw/qa/commons/knowledgecard/Field.java index 76d51f65..ef16bc34 100644 --- a/qa.commons/src/main/java/org/aksw/qa/commons/knowledgeCard/Field.java +++ b/qa.commons/src/main/java/org/aksw/qa/commons/knowledgecard/Field.java @@ -1,4 +1,4 @@ -package org.aksw.qa.commons.knowledgeCard; +package org.aksw.qa.commons.knowledgecard; import java.util.LinkedHashMap; diff --git a/qa.commons/src/main/java/org/aksw/qa/commons/knowledgeCard/KnowledgeCardCreator.java b/qa.commons/src/main/java/org/aksw/qa/commons/knowledgecard/KnowledgeCardCreator.java similarity index 99% rename from qa.commons/src/main/java/org/aksw/qa/commons/knowledgeCard/KnowledgeCardCreator.java rename to qa.commons/src/main/java/org/aksw/qa/commons/knowledgecard/KnowledgeCardCreator.java index cafdd721..afa1a178 100644 --- a/qa.commons/src/main/java/org/aksw/qa/commons/knowledgeCard/KnowledgeCardCreator.java +++ b/qa.commons/src/main/java/org/aksw/qa/commons/knowledgecard/KnowledgeCardCreator.java @@ -1,4 +1,4 @@ -package org.aksw.qa.commons.knowledgeCard; +package org.aksw.qa.commons.knowledgecard; import java.io.BufferedReader; import java.io.IOException; diff --git a/qa.commons/src/main/java/org/aksw/qa/commons/load/LoaderController.java b/qa.commons/src/main/java/org/aksw/qa/commons/load/LoaderController.java index ec2335d6..fcee5893 100644 --- a/qa.commons/src/main/java/org/aksw/qa/commons/load/LoaderController.java +++ b/qa.commons/src/main/java/org/aksw/qa/commons/load/LoaderController.java @@ -185,7 +185,7 @@ public static InputStream mapDatasetToPath(final Dataset set) { case INEX: case QALD2: case TREC_Entity: - return loadingAnchor.getResourceAsStream("/queries-v22.txt"); + return loadingAnchor.getResourceAsStream("/queries-v2.txt"); case Simple_Question_Wikidata: return loadingAnchor.getResourceAsStream("/annotated_wd_data_valid_full.json"); case Wdaqua_Core0_Logs: @@ -262,7 +262,7 @@ public static List load(final Dataset data, final String deriveUri, f // two files. case QALD3_Test_esdbpedia: is.close(); - out = qald3_test_esdbpedia_loader(deriveUri, questionLang); + out = qald3TestEsdbpediaLoader(deriveUri, questionLang); break; case QALD5_Test_Hybrid: @@ -368,7 +368,7 @@ public static List load(final Dataset data, final String deriveUri, f * Use this to load answers from server:{@link AnswerSyncer} */ @Deprecated //TODO refactor this so that answersyncing is no longer in this class - private static List qald3_test_esdbpedia_loader(final String deriveUri, final String questionLang) { + private static List qald3TestEsdbpediaLoader(final String deriveUri, final String questionLang) { List answerList = null; try { InputStream sparqlIs = null; @@ -686,7 +686,7 @@ public static void main(final String[] args) throws ParseException { public static List loadTSV(InputStream queries, String name) throws IOException { List out = new ArrayList<>(); - out = LoadTsv.readTSV(queries,getLoadingAnchor().getResourceAsStream("/qrels-v21.txt"),name); + out = LoadTsv.readTSV(queries,getLoadingAnchor().getResourceAsStream("/qrels-v2.txt"),name); return out; } diff --git a/qa.commons/src/main/java/org/aksw/qa/commons/load/tsv/LoadTsv.java b/qa.commons/src/main/java/org/aksw/qa/commons/load/tsv/LoadTsv.java index 45ad878a..4f2dbf56 100644 --- a/qa.commons/src/main/java/org/aksw/qa/commons/load/tsv/LoadTsv.java +++ b/qa.commons/src/main/java/org/aksw/qa/commons/load/tsv/LoadTsv.java @@ -37,7 +37,8 @@ public static List readTSV(InputStream queriesStream, InputStream qre String[] lineparts; if (line.startsWith(data)) { lineparts = line.split("\t"); - String result = lineparts[2].replaceAll(" new HashSet<>()).add(result); } diff --git a/qa.commons/src/main/java/org/aksw/qa/commons/measure/AnswerBasedEvaluation.java b/qa.commons/src/main/java/org/aksw/qa/commons/measure/AnswerBasedEvaluation.java index 7a05d1fc..4b77dc64 100644 --- a/qa.commons/src/main/java/org/aksw/qa/commons/measure/AnswerBasedEvaluation.java +++ b/qa.commons/src/main/java/org/aksw/qa/commons/measure/AnswerBasedEvaluation.java @@ -26,7 +26,7 @@ public static double precision(Set systemAnswer, IQuestion question) { if (systemAnswer.size() == 1) { String ans = systemAnswer.iterator().next(); String goldstandardAns = goldenStrings.iterator().next(); - if (ans.toString().equals(goldstandardAns.toString())) { + if (ans.equals(goldstandardAns.toString())) { precision = 1; } } @@ -43,7 +43,7 @@ public static double precision(Set systemAnswer, IQuestion question) { if (systemAnswer.size() == 1) { String ans = systemAnswer.iterator().next(); String goldstandardAns = goldenStrings.iterator().next(); - if (ans.toString().equals(goldstandardAns)) { + if (ans.equals(goldstandardAns)) { precision = 1; } } diff --git a/qa.commons/src/main/java/org/aksw/qa/commons/qald/IQuestionCsvParser.java b/qa.commons/src/main/java/org/aksw/qa/commons/qald/IQuestionCsvParser.java index 6626c431..43bcb9a6 100644 --- a/qa.commons/src/main/java/org/aksw/qa/commons/qald/IQuestionCsvParser.java +++ b/qa.commons/src/main/java/org/aksw/qa/commons/qald/IQuestionCsvParser.java @@ -308,7 +308,7 @@ protected static Column ignore() { return new Column(ColEnum.__IGNORE); } - protected static Column ID() { + protected static Column iD() { return new Column(ColEnum.ID); } diff --git a/qa.commons/src/main/java/org/aksw/qa/commons/qald/Qald8Creation.java b/qa.commons/src/main/java/org/aksw/qa/commons/qald/Qald8Creation.java index e8d31ab9..0821c1fa 100644 --- a/qa.commons/src/main/java/org/aksw/qa/commons/qald/Qald8Creation.java +++ b/qa.commons/src/main/java/org/aksw/qa/commons/qald/Qald8Creation.java @@ -148,7 +148,7 @@ public static void qald8train() throws Exception { CSVWriter wr = new CSVWriter(fw, ';', '"'); - IQuestionCsvParser.questionListToCsv(wr, true, questions, Column.ID(), Column.question("en"), Column.sparqlQuery(), Column.goldenAnswers()); + IQuestionCsvParser.questionListToCsv(wr, true, questions, Column.iD(), Column.question("en"), Column.sparqlQuery(), Column.goldenAnswers()); wr.flush(); fw.close(); @@ -161,7 +161,7 @@ public static void qald8train() throws Exception { CSVWriter wr2 = new CSVWriter(fw2, ';', '"'); - IQuestionCsvParser.questionListToCsv(wr2, true, failQuestions, Column.ID(), Column.question("en"), Column.sparqlQuery(), Column.goldenAnswers()); + IQuestionCsvParser.questionListToCsv(wr2, true, failQuestions, Column.iD(), Column.question("en"), Column.sparqlQuery(), Column.goldenAnswers()); wr2.flush(); fw2.close(); System.out.println("done qald8train"); @@ -239,7 +239,7 @@ public static void qald8test() throws Exception { CSVWriter wr2 = new CSVWriter(fw2, ';', '"'); - IQuestionCsvParser.questionListToCsv(wr2, true, que, Column.ID(), Column.question("en"), Column.sparqlQuery(), Column.goldenAnswers()); + IQuestionCsvParser.questionListToCsv(wr2, true, que, Column.iD(), Column.question("en"), Column.sparqlQuery(), Column.goldenAnswers()); wr2.close(); fw2.close(); diff --git a/qa.commons/src/test/java/org/aksw/qa/commons/knowledgeCard/KnowledgeCardCreatorTest.java b/qa.commons/src/test/java/org/aksw/qa/commons/knowledgecard/KnowledgeCardCreatorTest.java similarity index 92% rename from qa.commons/src/test/java/org/aksw/qa/commons/knowledgeCard/KnowledgeCardCreatorTest.java rename to qa.commons/src/test/java/org/aksw/qa/commons/knowledgecard/KnowledgeCardCreatorTest.java index 2b4e00fa..7dc294f7 100644 --- a/qa.commons/src/test/java/org/aksw/qa/commons/knowledgeCard/KnowledgeCardCreatorTest.java +++ b/qa.commons/src/test/java/org/aksw/qa/commons/knowledgecard/KnowledgeCardCreatorTest.java @@ -1,10 +1,12 @@ -package org.aksw.qa.commons.knowledgeCard; +package org.aksw.qa.commons.knowledgecard; import java.io.IOException; import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import org.aksw.qa.commons.knowledgecard.Field; +import org.aksw.qa.commons.knowledgecard.KnowledgeCardCreator; import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/qa.commons/src/test/java/org/aksw/qa/commons/load/LoadTest.java b/qa.commons/src/test/java/org/aksw/qa/commons/load/LoadTest.java index b62ef355..132c1201 100644 --- a/qa.commons/src/test/java/org/aksw/qa/commons/load/LoadTest.java +++ b/qa.commons/src/test/java/org/aksw/qa/commons/load/LoadTest.java @@ -95,7 +95,7 @@ public void loadQALD5Test() { } @Test - public void loadQALD6Train_Multilingual() throws IOException { + public void loadQALD6TrainMultilingual() throws IOException { List load = LoaderController.load(Dataset.QALD6_Train_Multilingual); List expectedIncompletes = Arrays.asList(100, 118, 136, 137, 147, 152, 94, 95, 96, 97, 98, 99, 249, 250, 312, 342); log.debug("Number of Loaded Questions:" + load.size()); @@ -123,10 +123,10 @@ public void loadQALD6Train_Multilingual() throws IOException { Assert.assertTrue((q.getPseudoSparqlQuery() != null) || (q.getSparqlQuery() != null)); // log.debug(q.getLanguageToQuestion().get("en") + "\t" + // "Answer:" + "\t" + q.getSparqlQuery()); - } else { + } // else { // log.debug(q.getLanguageToQuestion().get("en") + "\t" + // "No Answer, known incomplete question."); - } + // } } } diff --git a/qa.datasets/pom.xml b/qa.datasets/pom.xml index e80354b1..466ba187 100644 --- a/qa.datasets/pom.xml +++ b/qa.datasets/pom.xml @@ -167,6 +167,20 @@ src/main/resources/ + + Dbpedia-Entity-V2-Queries + package + + wget + + + https://raw.githubusercontent.com/iai-group/DBpedia-Entity/master/collection/v2/queries-v2.txt + true + true + queries-v2.txt + src/main/resources/ + + diff --git a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityDate.java b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityDate.java similarity index 97% rename from qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityDate.java rename to qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityDate.java index f4138307..1e41414b 100644 --- a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityDate.java +++ b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityDate.java @@ -1,4 +1,4 @@ -package org.aksw.mlqa.analyzer.entityType; +package org.aksw.mlqa.analyzer.entitytype; import java.util.ArrayList; import java.util.List; diff --git a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityLocation.java b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityLocation.java similarity index 97% rename from qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityLocation.java rename to qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityLocation.java index 717787d6..f51810fb 100644 --- a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityLocation.java +++ b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityLocation.java @@ -1,4 +1,4 @@ -package org.aksw.mlqa.analyzer.entityType; +package org.aksw.mlqa.analyzer.entitytype; import java.util.ArrayList; import java.util.List; diff --git a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityMoney.java b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityMoney.java similarity index 97% rename from qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityMoney.java rename to qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityMoney.java index 8a1f5f88..156482af 100644 --- a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityMoney.java +++ b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityMoney.java @@ -1,4 +1,4 @@ -package org.aksw.mlqa.analyzer.entityType; +package org.aksw.mlqa.analyzer.entitytype; import java.util.ArrayList; import java.util.List; diff --git a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityOrganization.java b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityOrganization.java similarity index 97% rename from qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityOrganization.java rename to qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityOrganization.java index fa18ef2b..d55c35e0 100644 --- a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityOrganization.java +++ b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityOrganization.java @@ -1,4 +1,4 @@ -package org.aksw.mlqa.analyzer.entityType; +package org.aksw.mlqa.analyzer.entitytype; import java.util.ArrayList; import java.util.List; diff --git a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityPercent.java b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityPercent.java similarity index 97% rename from qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityPercent.java rename to qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityPercent.java index c752feaa..172e2639 100644 --- a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityPercent.java +++ b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityPercent.java @@ -1,4 +1,4 @@ -package org.aksw.mlqa.analyzer.entityType; +package org.aksw.mlqa.analyzer.entitytype; import java.util.ArrayList; import java.util.List; diff --git a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityPerson.java b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityPerson.java similarity index 97% rename from qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityPerson.java rename to qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityPerson.java index 509eceba..6cce1dbd 100644 --- a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entityType/EntityPerson.java +++ b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/entitytype/EntityPerson.java @@ -1,4 +1,4 @@ -package org.aksw.mlqa.analyzer.entityType; +package org.aksw.mlqa.analyzer.entitytype; import java.util.ArrayList; import java.util.List; diff --git a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/numberOfToken/NumberOfToken.java b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/numberoftoken/NumberOfToken.java similarity index 94% rename from qa.ml/src/main/java/org/aksw/mlqa/analyzer/numberOfToken/NumberOfToken.java rename to qa.ml/src/main/java/org/aksw/mlqa/analyzer/numberoftoken/NumberOfToken.java index 9bac3180..79efcf46 100644 --- a/qa.ml/src/main/java/org/aksw/mlqa/analyzer/numberOfToken/NumberOfToken.java +++ b/qa.ml/src/main/java/org/aksw/mlqa/analyzer/numberoftoken/NumberOfToken.java @@ -1,4 +1,4 @@ -package org.aksw.mlqa.analyzer.numberOfToken; +package org.aksw.mlqa.analyzer.numberoftoken; import org.aksw.mlqa.analyzer.IAnalyzer; import org.slf4j.Logger; diff --git a/qa.ml/src/main/java/org/aksw/mlqa/experiment/ArffFileFromRun.java b/qa.ml/src/main/java/org/aksw/mlqa/experiment/ArffFileFromRun.java index d8cc3b27..be5eb088 100644 --- a/qa.ml/src/main/java/org/aksw/mlqa/experiment/ArffFileFromRun.java +++ b/qa.ml/src/main/java/org/aksw/mlqa/experiment/ArffFileFromRun.java @@ -101,10 +101,10 @@ public static void main(String[] args) throws Exception { JSONObject systemdata = (JSONObject) allsystemsdata.get(system.name()); if(new Double(systemdata.get("fmeasure").toString()) > 0) switch (system.name()){ - case "hawk": tmp.setValue(hawkatt, 1); - case "yoda": tmp.setValue(yodaatt, 1); - case "sina": tmp.setValue(sinaatt, 1); - case "qakis": tmp.setValue(qakisatt, 1); + case "hawk": tmp.setValue(hawkatt, 1); break; + case "yoda": tmp.setValue(yodaatt, 1); break; + case "sina": tmp.setValue(sinaatt, 1); break; + case "qakis": tmp.setValue(qakisatt, 1); break; } } diff --git a/qa.ml/src/test/java/org/aksw/mlqa/analyzer/comperative/ComperativeTest.java b/qa.ml/src/test/java/org/aksw/mlqa/analyzer/comperative/ComperativeTest.java index 6361cf8e..708ffae2 100644 --- a/qa.ml/src/test/java/org/aksw/mlqa/analyzer/comperative/ComperativeTest.java +++ b/qa.ml/src/test/java/org/aksw/mlqa/analyzer/comperative/ComperativeTest.java @@ -14,7 +14,7 @@ public class ComperativeTest { @Test - public void ThisContainsComperative() { + public void thisContainsComperative() { Comperative superlative = new Comperative(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(superlative.getAttribute()); @@ -25,7 +25,7 @@ public void ThisContainsComperative() { } @Test - public void ThisContainsNoComperative(){ + public void thisContainsNoComperative(){ Comperative superlative = new Comperative(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(superlative.getAttribute()); diff --git a/qa.ml/src/test/java/org/aksw/mlqa/analyzer/entityType/EntityTypeTest.java b/qa.ml/src/test/java/org/aksw/mlqa/analyzer/entitytype/EntityTypeTest.java similarity index 89% rename from qa.ml/src/test/java/org/aksw/mlqa/analyzer/entityType/EntityTypeTest.java rename to qa.ml/src/test/java/org/aksw/mlqa/analyzer/entitytype/EntityTypeTest.java index a923cc09..97c098d4 100644 --- a/qa.ml/src/test/java/org/aksw/mlqa/analyzer/entityType/EntityTypeTest.java +++ b/qa.ml/src/test/java/org/aksw/mlqa/analyzer/entitytype/EntityTypeTest.java @@ -1,9 +1,15 @@ -package org.aksw.mlqa.analyzer.entityType; +package org.aksw.mlqa.analyzer.entitytype; import static org.junit.Assert.assertTrue; import java.util.ArrayList; +import org.aksw.mlqa.analyzer.entitytype.EntityDate; +import org.aksw.mlqa.analyzer.entitytype.EntityLocation; +import org.aksw.mlqa.analyzer.entitytype.EntityMoney; +import org.aksw.mlqa.analyzer.entitytype.EntityOrganization; +import org.aksw.mlqa.analyzer.entitytype.EntityPercent; +import org.aksw.mlqa.analyzer.entitytype.EntityPerson; import org.junit.Test; import weka.core.Attribute; @@ -14,7 +20,7 @@ public class EntityTypeTest { @Test - public void PersonTest1() { + public void personTest1() { EntityPerson personana = new EntityPerson(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(personana.getAttribute()); @@ -25,7 +31,7 @@ public void PersonTest1() { } @Test - public void PersonTest2() { + public void personTest2() { EntityPerson personana = new EntityPerson(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(personana.getAttribute()); @@ -36,7 +42,7 @@ public void PersonTest2() { } @Test - public void LocationTest1() { + public void locationTest1() { EntityLocation locationana = new EntityLocation(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(locationana.getAttribute()); @@ -47,7 +53,7 @@ public void LocationTest1() { } @Test - public void LocationTest2() { + public void locationTest2() { EntityLocation locationana = new EntityLocation(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(locationana.getAttribute()); @@ -58,7 +64,7 @@ public void LocationTest2() { } @Test - public void OrganizationTest1() { + public void organizationTest1() { EntityOrganization organa = new EntityOrganization(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(organa.getAttribute()); @@ -69,7 +75,7 @@ public void OrganizationTest1() { } @Test - public void OrganizationTest2() { + public void organizationTest2() { EntityOrganization organa = new EntityOrganization(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(organa.getAttribute()); @@ -80,7 +86,7 @@ public void OrganizationTest2() { } @Test - public void MoneyTest1() { + public void moneyTest1() { EntityMoney monana = new EntityMoney(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(monana.getAttribute()); @@ -91,7 +97,7 @@ public void MoneyTest1() { } @Test - public void MoneyTest2() { + public void moneyTest2() { EntityMoney monana = new EntityMoney(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(monana.getAttribute()); @@ -102,7 +108,7 @@ public void MoneyTest2() { } @Test - public void PercentTest1() { + public void percentTest1() { EntityPercent percana = new EntityPercent(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(percana.getAttribute()); @@ -113,7 +119,7 @@ public void PercentTest1() { } @Test - public void PercentTest2() { + public void percentTest2() { EntityPercent percana = new EntityPercent(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(percana.getAttribute()); @@ -124,7 +130,7 @@ public void PercentTest2() { } @Test - public void DateTest1() { + public void dateTest1() { EntityDate dateana = new EntityDate(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(dateana.getAttribute()); @@ -135,7 +141,7 @@ public void DateTest1() { } @Test - public void DateTest2() { + public void dateTest2() { EntityDate dateana = new EntityDate(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(dateana.getAttribute()); diff --git a/qa.ml/src/test/java/org/aksw/mlqa/analyzer/numberOfToken/NumberOfTokenTest.java b/qa.ml/src/test/java/org/aksw/mlqa/analyzer/numberoftoken/NumberOfTokenTest.java similarity index 87% rename from qa.ml/src/test/java/org/aksw/mlqa/analyzer/numberOfToken/NumberOfTokenTest.java rename to qa.ml/src/test/java/org/aksw/mlqa/analyzer/numberoftoken/NumberOfTokenTest.java index e670fa8d..ee466c26 100644 --- a/qa.ml/src/test/java/org/aksw/mlqa/analyzer/numberOfToken/NumberOfTokenTest.java +++ b/qa.ml/src/test/java/org/aksw/mlqa/analyzer/numberoftoken/NumberOfTokenTest.java @@ -1,9 +1,10 @@ -package org.aksw.mlqa.analyzer.numberOfToken; +package org.aksw.mlqa.analyzer.numberoftoken; import static org.junit.Assert.assertTrue; import java.util.ArrayList; +import org.aksw.mlqa.analyzer.numberoftoken.NumberOfToken; import org.junit.Test; import weka.core.Attribute; diff --git a/qa.ml/src/test/java/org/aksw/mlqa/analyzer/superlative/SuperlativeTest.java b/qa.ml/src/test/java/org/aksw/mlqa/analyzer/superlative/SuperlativeTest.java index 5c82ad6c..2ba5713d 100644 --- a/qa.ml/src/test/java/org/aksw/mlqa/analyzer/superlative/SuperlativeTest.java +++ b/qa.ml/src/test/java/org/aksw/mlqa/analyzer/superlative/SuperlativeTest.java @@ -14,7 +14,7 @@ public class SuperlativeTest { @Test - public void ThisContainsSuperlative() { + public void thisContainsSuperlative() { Superlative superlative = new Superlative(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(superlative.getAttribute()); @@ -25,7 +25,7 @@ public void ThisContainsSuperlative() { } @Test - public void ThisContainsNoSuperlative() { + public void thisContainsNoSuperlative() { Superlative superlative = new Superlative(); ArrayList fvWekaAttributes = new ArrayList(); fvWekaAttributes.add(superlative.getAttribute()); diff --git a/qa.systems/src/main/java/org/aksw/qa/systems/AskNow.java b/qa.systems/src/main/java/org/aksw/qa/systems/AskNow.java index 4a7af844..09952df4 100644 --- a/qa.systems/src/main/java/org/aksw/qa/systems/AskNow.java +++ b/qa.systems/src/main/java/org/aksw/qa/systems/AskNow.java @@ -20,12 +20,12 @@ public class AskNow extends Gen_HTTP_QA_Sys { public AskNow() { super(URL, "asknow", true, false); - this.setQuery_key("question"); + this.setQueryKey("question"); } public AskNow(String url) { super(url, "asknow", true, false); - this.setQuery_key("question"); + this.setQueryKey("question"); } diff --git a/qa.systems/src/main/java/org/aksw/qa/systems/Gen_HTTP_QA_Sys.java b/qa.systems/src/main/java/org/aksw/qa/systems/Gen_HTTP_QA_Sys.java index 896259de..1e5f8d01 100644 --- a/qa.systems/src/main/java/org/aksw/qa/systems/Gen_HTTP_QA_Sys.java +++ b/qa.systems/src/main/java/org/aksw/qa/systems/Gen_HTTP_QA_Sys.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -21,6 +22,7 @@ import org.aksw.qa.commons.load.json.QaldJson; import org.aksw.qa.commons.load.json.QaldQuery; import org.aksw.qa.commons.load.json.QaldQuestionEntry; +import org.apache.commons.io.IOUtils; import org.apache.http.Consts; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; @@ -230,6 +232,7 @@ public void processQALDResp(HttpResponse response, IQuestion question) throws Js * @throws IOException */ public void processEQALDResponse(HttpResponse response, IQuestion question) throws JsonParseException, JsonMappingException, UnsupportedOperationException, IOException { + //System.out.println(IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8)); ExtendedJson json = (ExtendedJson) ExtendedQALDJSONLoader.readJson(response.getEntity().getContent(),ExtendedJson.class); for (EJQuestionEntry it : json.getQuestions()) { EJQuestion q = it.getQuestion(); @@ -291,19 +294,19 @@ public void setName(String name) { this.name = name; } - public String getQuery_key() { + public String getQueryKey() { return query_key; } - public void setQuery_key(String query_key) { + public void setQueryKey(String query_key) { this.query_key = query_key; } - public String getLang_key() { + public String getLangKey() { return lang_key; } - public void setLang_key(String lang_key) { + public void setLangKey(String lang_key) { this.lang_key = lang_key; } diff --git a/qa.systems/src/main/java/org/aksw/qa/systems/PLATYPUS.java b/qa.systems/src/main/java/org/aksw/qa/systems/PLATYPUS.java index e0d58b90..6ede6dc6 100644 --- a/qa.systems/src/main/java/org/aksw/qa/systems/PLATYPUS.java +++ b/qa.systems/src/main/java/org/aksw/qa/systems/PLATYPUS.java @@ -20,12 +20,12 @@ public class PLATYPUS extends Gen_HTTP_QA_Sys{ public PLATYPUS() { super(URL, "platypus", false, false); - this.setQuery_key("q"); + this.setQueryKey("q"); } public PLATYPUS(String url) { super(url, "platypus", false, false); - this.setQuery_key("q"); + this.setQueryKey("q"); } @Override diff --git a/qa.systems/src/main/java/org/aksw/qa/systems/QANARY.java b/qa.systems/src/main/java/org/aksw/qa/systems/QANARY.java index d899bdda..15691d52 100644 --- a/qa.systems/src/main/java/org/aksw/qa/systems/QANARY.java +++ b/qa.systems/src/main/java/org/aksw/qa/systems/QANARY.java @@ -1,19 +1,81 @@ package org.aksw.qa.systems; +import java.io.IOException; +import java.util.HashSet; + +import org.aksw.qa.commons.datastructure.IQuestion; +import org.aksw.qa.util.ResponseToStringParser; +import org.apache.http.HttpResponse; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; + public class QANARY extends Gen_HTTP_QA_Sys { - private static final String URL = "http://qanswer-core1.univ-st-etienne.fr/gerbil"; + private static final String URL = "http://qanswer-core1.univ-st-etienne.fr/api/gerbil"; //possible values: dbpedia, wikidata, dblp, freebase private static final String KB = "dbpedia"; public QANARY() { - super(URL, "qanary", false, true); + super(URL, "qanary", true, false); this.getParamMap().put("kb", KB); } public QANARY(String url, String kb) { - super(url, "qanary", false, true); + super(url, "qanary", true, false); this.getParamMap().put("kb", kb); } + + + @Override + public void processQALDResp(HttpResponse response, IQuestion question) throws JsonParseException, JsonMappingException, UnsupportedOperationException, IOException { + HashSet resultSet = new HashSet(); + + ResponseToStringParser responseparser = new ResponseToStringParser(); + JSONParser parser = new JSONParser(); + String responseString = responseparser.responseToString(response); + JSONObject answerjson = null; + + try { + answerjson = (JSONObject) parser.parse(responseString); + } catch (ParseException e) { + e.printStackTrace(); + return; + } + + JSONArray array = (JSONArray) answerjson.get("questions"); + JSONObject answer = (JSONObject) array.get(0); + JSONObject questionObject = (JSONObject) answer.get("question"); + String answerString = (String) questionObject.get("answers"); + + try { + answerjson = (JSONObject) parser.parse(answerString); + } catch (ParseException e) { + e.printStackTrace(); + return; + } + + JSONArray vars = (JSONArray) ((JSONObject) answerjson.get("head")).get("vars"); + + //no answers + if(vars == null) return; + + for(int var = 0; var < vars.size(); var++) { + JSONObject results = (JSONObject) answerjson.get("results"); + JSONArray bindings = (JSONArray) results.get("bindings"); + for(int result = 0; result