From 3d98d3fd7d758cf9a4e86a4b0f39085430dddaa6 Mon Sep 17 00:00:00 2001 From: jorge Date: Mon, 8 Apr 2024 16:41:10 +0200 Subject: [PATCH 01/78] Started the answers decoration --- .../generator/AbstractGenerator.java | 6 +++++- .../generator/AnswersAreEntities.java | 17 +++++++++++++++++ .../generator/AnswersAreNotEntites.java | 5 +++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java index 6b788927..c8d85f4f 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java @@ -77,8 +77,10 @@ public Question generate(String id) throws Exception { List answers = getWrongAnswers(rightAnswer); answers.add(0, rightAnswer); - //create and return the question + answers = decorateAnswers(answers); + + //create and return the question return new Question(question, answers, language, type); } @@ -90,6 +92,8 @@ protected String getName(Map names) { // protected abstract String getQuestion(String name); protected abstract String getRightAnswer(Map> claims) throws Exception; protected abstract List getWrongAnswers(String rightAnswer) throws Exception; + + protected abstract List decorateAnswers(List answers); protected String getQuestion(String name) { String q = getMessages().getString(message); diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java index f7bd6713..6fbb48d4 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java @@ -118,4 +118,21 @@ protected List getWrongAnswers(String rightAnswer) throws Exception { return result; } + @Override + protected List decorateAnswers(List answers) { + List result = new ArrayList<>(); + for(String s : answers) { + result.add(toUppercaseFirstCharacter(s)); + } + return result; + } + + + private String toUppercaseFirstCharacter(String string) { + char[] chars = string.toCharArray(); + chars[0] = Character.toUpperCase(chars[0]); + String result = String.copyValueOf(chars); + return result; + } + } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java index 9d5f0017..5c7f8ee9 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java @@ -72,4 +72,9 @@ protected List getWrongAnswers(String rightAnswer) { } return wrongAnswers; } + + @Override + protected List decorateAnswers(List answers) { + return answers; + } } From 0c789b8df63198ad55b82bd20c8102ca2fb67f08 Mon Sep 17 00:00:00 2001 From: jorge Date: Sun, 14 Apr 2024 17:22:18 +0200 Subject: [PATCH 02/78] Added the head of government question type --- questionGenerator/src/main/java/Main.java | 3 +++ .../questionGenerator/QuestionGenerator.java | 5 +++++ .../entityGenerator/EntityGenerator.java | 3 +++ .../HeadOfGovernmentGenerator.java | 16 ++++++++++++++++ .../questionGenerator/question/QuestionType.java | 2 +- .../src/main/resources/messages.properties | 3 ++- .../src/main/resources/messages_en.properties | 3 ++- .../src/main/resources/messages_es.properties | 9 +++++---- 8 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/HeadOfGovernmentGenerator.java diff --git a/questionGenerator/src/main/java/Main.java b/questionGenerator/src/main/java/Main.java index 44500083..ade8efe4 100644 --- a/questionGenerator/src/main/java/Main.java +++ b/questionGenerator/src/main/java/Main.java @@ -22,6 +22,9 @@ public static void main(String[] args) { System.out.println(); run(qg, QuestionType.SIZE, 3); + System.out.println(); + + run(qg, QuestionType.HEAD_OF_GOVERMENT, 3); } private static void run(QuestionGenerator qg, QuestionType type, int numberOfQuestions){ diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index 2c5f81b2..7a6a756f 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -8,6 +8,7 @@ import main.java.questionGenerator.entityGenerator.EntityGenerator; import main.java.questionGenerator.generator.AbstractGenerator; import main.java.questionGenerator.generator.specificGenerators.CapitalGenerator; +import main.java.questionGenerator.generator.specificGenerators.HeadOfGovernmentGenerator; import main.java.questionGenerator.generator.specificGenerators.LanguageGenerator; import main.java.questionGenerator.generator.specificGenerators.PopulationGenerator; import main.java.questionGenerator.generator.specificGenerators.SizeGenerator; @@ -71,6 +72,10 @@ private void setGenerator(QuestionType type) { generator = new LanguageGenerator(); break; } + case HEAD_OF_GOVERMENT:{ + generator = new HeadOfGovernmentGenerator(); + break; + } } } diff --git a/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java b/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java index 0f4a4335..56318fd1 100644 --- a/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java @@ -58,6 +58,9 @@ private static void propertyFactory(QuestionType type) { case SIZE: property = "2046"; break; + case HEAD_OF_GOVERMENT: + property = "6"; + break; } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/HeadOfGovernmentGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/HeadOfGovernmentGenerator.java new file mode 100644 index 00000000..c7c53ba2 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/HeadOfGovernmentGenerator.java @@ -0,0 +1,16 @@ +package main.java.questionGenerator.generator.specificGenerators; + +import main.java.questionGenerator.generator.AnswersAreEntities; +import main.java.questionGenerator.question.QuestionType; + +public class HeadOfGovernmentGenerator extends AnswersAreEntities { + + private final static String PROPERTY = "P6"; + private final static String PROPERTY_TO_CHECK = "P582"; + private final static String MESSAGE = "question.governmentHead"; + + public HeadOfGovernmentGenerator() { + super(PROPERTY, QuestionType.HEAD_OF_GOVERMENT, PROPERTY_TO_CHECK, MESSAGE); + } + +} diff --git a/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java b/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java index 8f1ec42c..b3e2be83 100644 --- a/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java +++ b/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java @@ -2,6 +2,6 @@ public enum QuestionType { - POPULATION, CAPITAL, SIZE, LANGUAGE; + POPULATION, CAPITAL, SIZE, LANGUAGE, HEAD_OF_GOVERMENT; } diff --git a/questionGenerator/src/main/resources/messages.properties b/questionGenerator/src/main/resources/messages.properties index 780a92bd..ff1a6b3a 100644 --- a/questionGenerator/src/main/resources/messages.properties +++ b/questionGenerator/src/main/resources/messages.properties @@ -1,4 +1,5 @@ question.population = What's the population of %s? question.language = What's the official language of %s? question.capital = What's the capital of %s? -question.size = What's the size of %s? \ No newline at end of file +question.size = What's the size of %s? +question.governmentHead = Who's the current head of the government of %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_en.properties b/questionGenerator/src/main/resources/messages_en.properties index 780a92bd..ff1a6b3a 100644 --- a/questionGenerator/src/main/resources/messages_en.properties +++ b/questionGenerator/src/main/resources/messages_en.properties @@ -1,4 +1,5 @@ question.population = What's the population of %s? question.language = What's the official language of %s? question.capital = What's the capital of %s? -question.size = What's the size of %s? \ No newline at end of file +question.size = What's the size of %s? +question.governmentHead = Who's the current head of the government of %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_es.properties b/questionGenerator/src/main/resources/messages_es.properties index 839ae10d..d7c1de0a 100644 --- a/questionGenerator/src/main/resources/messages_es.properties +++ b/questionGenerator/src/main/resources/messages_es.properties @@ -1,4 +1,5 @@ -question.population = ¿Cuál es la población de %s? -question.language = ¿Cuál es el idioma oficial de %s? -question.capital = ¿Cuál es la capital de %s? -question.size = ¿Cuál es el área (km cuadrados) de %s? \ No newline at end of file +question.population = ¿Cuál es la población de %s? +question.language = ¿Cuál es el idioma oficial de %s? +question.capital = ¿Cuál es la capital de %s? +question.size = ¿Cuál es el área (km cuadrados) de %s? +question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? \ No newline at end of file From 8672521b30295555fd2e981dbe00db85c334b14c Mon Sep 17 00:00:00 2001 From: jorge Date: Sun, 14 Apr 2024 20:56:10 +0200 Subject: [PATCH 03/78] Added the persistent main --- .../src/main/java/PersistentMain.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 questionGenerator/src/main/java/PersistentMain.java diff --git a/questionGenerator/src/main/java/PersistentMain.java b/questionGenerator/src/main/java/PersistentMain.java new file mode 100644 index 00000000..ab2dde8e --- /dev/null +++ b/questionGenerator/src/main/java/PersistentMain.java @@ -0,0 +1,51 @@ +package main.java; + +import java.util.List; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; +import main.java.questionGenerator.repository.QuestionRepository; + +public class PersistentMain { + + private static long timeSkip = 18000000; //5 hours +// private static long timeSkip = 43200000; //12 hours + + private static QuestionGenerator[] generators = {new QuestionGenerator("en"), new QuestionGenerator("es")}; + + public static void main(String[] args) { + while(true) { + generate(); + try { + Thread.sleep(timeSkip); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + } + + private static void generate() { + for(QuestionGenerator qg : generators) + generateQuestions(qg); + } + + private static void generateQuestions(QuestionGenerator qg) { + run(qg, QuestionType.CAPITAL, 50); + run(qg, QuestionType.LANGUAGE, 50); + run(qg, QuestionType.POPULATION, 50); + run(qg, QuestionType.SIZE, 50); + run(qg, QuestionType.HEAD_OF_GOVERMENT, 50); + } + + private static void run(QuestionGenerator qg, QuestionType type, int numberOfQuestions) { + List questions = qg.generateQuestions(type, numberOfQuestions); + for(int i=0; i q.getJSON().toString()).toList()); + } + +} \ No newline at end of file From 9a4b1d493acf55df7a786332371bd1a519af5653 Mon Sep 17 00:00:00 2001 From: jorge Date: Sun, 14 Apr 2024 21:00:11 +0200 Subject: [PATCH 04/78] Added the code to remove entites from the collection before adding the new ones --- .../src/main/java/PersistentMain.java | 1 + .../repository/QuestionRepository.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/questionGenerator/src/main/java/PersistentMain.java b/questionGenerator/src/main/java/PersistentMain.java index ab2dde8e..031c2a3b 100644 --- a/questionGenerator/src/main/java/PersistentMain.java +++ b/questionGenerator/src/main/java/PersistentMain.java @@ -16,6 +16,7 @@ public class PersistentMain { public static void main(String[] args) { while(true) { + QuestionRepository.getInstance().removeAll(); generate(); try { Thread.sleep(timeSkip); diff --git a/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java b/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java index b9ec14aa..c80bb8b3 100644 --- a/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java +++ b/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java @@ -61,5 +61,19 @@ public boolean insert(List questionJSONList){ return false; } } + + public boolean removeAll() { + try (MongoClient mongoClient = MongoClients.create(dbConnectionString)) { + MongoDatabase database = mongoClient.getDatabase("questions"); + + MongoCollection collection = database.getCollection("questions"); + + collection.deleteMany(Document.parse("{}")); + return true; + } catch (Exception e) { + System.out.println(e); + return false; + } + } } \ No newline at end of file From 289d78bae20f80cf3e769efa37580796c023063e Mon Sep 17 00:00:00 2001 From: jorge Date: Mon, 15 Apr 2024 15:01:47 +0200 Subject: [PATCH 05/78] Modified the main to comply with the new deisgn --- .../src/main/java/PersistentMain.java | 30 +++++++++++-------- .../repository/QuestionRepository.java | 8 +++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/questionGenerator/src/main/java/PersistentMain.java b/questionGenerator/src/main/java/PersistentMain.java index 031c2a3b..b2ba554a 100644 --- a/questionGenerator/src/main/java/PersistentMain.java +++ b/questionGenerator/src/main/java/PersistentMain.java @@ -1,5 +1,6 @@ package main.java; +import java.util.ArrayList; import java.util.List; import main.java.questionGenerator.QuestionGenerator; @@ -11,13 +12,14 @@ public class PersistentMain { private static long timeSkip = 18000000; //5 hours // private static long timeSkip = 43200000; //12 hours +// private static long timeSkip = 1000; //1 minute private static QuestionGenerator[] generators = {new QuestionGenerator("en"), new QuestionGenerator("es")}; public static void main(String[] args) { while(true) { - QuestionRepository.getInstance().removeAll(); - generate(); + List questions = generate(); + QuestionRepository.getInstance().populate(questions); try { Thread.sleep(timeSkip); } catch (InterruptedException e) { @@ -27,26 +29,30 @@ public static void main(String[] args) { } } - private static void generate() { + private static List generate() { + List questions = new ArrayList(); for(QuestionGenerator qg : generators) - generateQuestions(qg); + questions.addAll(generateQuestions(qg)); + return questions; } - private static void generateQuestions(QuestionGenerator qg) { - run(qg, QuestionType.CAPITAL, 50); - run(qg, QuestionType.LANGUAGE, 50); - run(qg, QuestionType.POPULATION, 50); - run(qg, QuestionType.SIZE, 50); - run(qg, QuestionType.HEAD_OF_GOVERMENT, 50); + private static List generateQuestions(QuestionGenerator qg) { + List questions = new ArrayList<>(); + questions.addAll(run(qg, QuestionType.CAPITAL, 50)); + questions.addAll(run(qg, QuestionType.LANGUAGE, 50)); + questions.addAll(run(qg, QuestionType.POPULATION, 50)); + questions.addAll(run(qg, QuestionType.SIZE, 50)); + questions.addAll(run(qg, QuestionType.HEAD_OF_GOVERMENT, 50)); + return questions; } - private static void run(QuestionGenerator qg, QuestionType type, int numberOfQuestions) { + private static List run(QuestionGenerator qg, QuestionType type, int numberOfQuestions) { List questions = qg.generateQuestions(type, numberOfQuestions); for(int i=0; i q.getJSON().toString()).toList()); + return questions; } } \ No newline at end of file diff --git a/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java b/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java index c80bb8b3..fa32dc03 100644 --- a/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java +++ b/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java @@ -12,6 +12,8 @@ import org.bson.Document; +import main.java.questionGenerator.question.Question; + public class QuestionRepository { private static QuestionRepository questionRepository; @@ -75,5 +77,11 @@ public boolean removeAll() { return false; } } + + public boolean populate(List questions) { + // TODO Auto-generated method stub + return false; + + } } \ No newline at end of file From 504648faea30f7fdcc48fe343655a0a0292ff4ec Mon Sep 17 00:00:00 2001 From: jorge Date: Mon, 15 Apr 2024 19:43:41 +0200 Subject: [PATCH 06/78] Included the decorator classes and interface --- .../question/answers/AnswerFormater.java | 9 +++ .../formatAnswers/CapitalLetersFormater.java | 27 +++++++++ .../EmbellishNumbersFormater.java | 56 +++++++++++++++++++ .../formatAnswers/RemoveEFromNumber.java | 45 +++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 questionGenerator/src/main/java/questionGenerator/question/answers/AnswerFormater.java create mode 100644 questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/CapitalLetersFormater.java create mode 100644 questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/EmbellishNumbersFormater.java create mode 100644 questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/RemoveEFromNumber.java diff --git a/questionGenerator/src/main/java/questionGenerator/question/answers/AnswerFormater.java b/questionGenerator/src/main/java/questionGenerator/question/answers/AnswerFormater.java new file mode 100644 index 00000000..4258f266 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/question/answers/AnswerFormater.java @@ -0,0 +1,9 @@ +package main.java.questionGenerator.question.answers; + +import java.util.List; + +public interface AnswerFormater { + + List format(List answers); + +} diff --git a/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/CapitalLetersFormater.java b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/CapitalLetersFormater.java new file mode 100644 index 00000000..edb5e384 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/CapitalLetersFormater.java @@ -0,0 +1,27 @@ +package main.java.questionGenerator.question.answers.formatAnswers; + +import java.util.ArrayList; +import java.util.List; + +import main.java.questionGenerator.question.answers.AnswerFormater; + +public class CapitalLetersFormater implements AnswerFormater { + + @Override + public List format(List answers) { + List result = new ArrayList<>(); + for(String s : answers) { + result.add(toUppercaseFirstCharacter(s)); + } + return result; + + } + + private String toUppercaseFirstCharacter(String string) { + char[] chars = string.toCharArray(); + chars[0] = Character.toUpperCase(chars[0]); + String result = String.copyValueOf(chars); + return result; + } + +} \ No newline at end of file diff --git a/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/EmbellishNumbersFormater.java b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/EmbellishNumbersFormater.java new file mode 100644 index 00000000..ca9c6d9c --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/EmbellishNumbersFormater.java @@ -0,0 +1,56 @@ +package main.java.questionGenerator.question.answers.formatAnswers; + +import java.util.ArrayList; +import java.util.List; + +import main.java.questionGenerator.question.answers.AnswerFormater; + +public class EmbellishNumbersFormater implements AnswerFormater { + + @Override + public List format(List answers) { + List result = new ArrayList<>(); + for(String s : answers) { + result.add(decorateAnswer(s)); + } + return result; + } + + private String decorateAnswer(String answer) { + char[] chars = answer.toCharArray(); + chars = invert(chars); + Character splitter = ','; + int splitPoint = getSplitPoint(chars); + String result = ""; + int j=0; + for(int i=0; isplitPoint) { + j++; + if(j%3==0 && i=0; i--) { + result[j++] = chars[i]; + } + return result; + } + +} \ No newline at end of file diff --git a/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/RemoveEFromNumber.java b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/RemoveEFromNumber.java new file mode 100644 index 00000000..32dd2346 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/RemoveEFromNumber.java @@ -0,0 +1,45 @@ +package main.java.questionGenerator.question.answers.formatAnswers; + +import java.util.ArrayList; +import java.util.List; + +import main.java.questionGenerator.question.answers.AnswerFormater; + +public class RemoveEFromNumber implements AnswerFormater { + + private AnswerFormater formater; + + public RemoveEFromNumber(AnswerFormater formater) { + this.formater = formater; + } + + @Override + public List format(List answers) { + List result = new ArrayList<>(); + for(String s : answers) { + result.add(removeE(s)); + } + return formater.format(result); + } + + private String removeE(String answer) { + String[] number = answer.split("E"); + if(number.length==1) + return answer; + String value = removeDecimalPoint(number[0]); + for(int i=value.length(); i Date: Mon, 15 Apr 2024 19:44:39 +0200 Subject: [PATCH 07/78] Removed use of previous decorator attempt --- .../generator/AnswersAreEntities.java | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java index 6fbb48d4..c2c19d0b 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java @@ -120,19 +120,7 @@ protected List getWrongAnswers(String rightAnswer) throws Exception { @Override protected List decorateAnswers(List answers) { - List result = new ArrayList<>(); - for(String s : answers) { - result.add(toUppercaseFirstCharacter(s)); - } - return result; - } - - - private String toUppercaseFirstCharacter(String string) { - char[] chars = string.toCharArray(); - chars[0] = Character.toUpperCase(chars[0]); - String result = String.copyValueOf(chars); - return result; + return answers; } } From 56cd284e7c25b45ee68cf8e2b80014b379c1d791 Mon Sep 17 00:00:00 2001 From: jorge Date: Mon, 15 Apr 2024 19:49:34 +0200 Subject: [PATCH 08/78] The generator now uses the correct decorator for the answers --- .../generator/AnswersAreNotEntites.java | 5 ----- .../specificGenerators/LanguageGenerator.java | 10 ++++++++++ .../specificGenerators/PopulationGenerator.java | 8 ++++++++ .../generator/specificGenerators/SizeGenerator.java | 9 +++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java index 5c7f8ee9..9d5f0017 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java @@ -72,9 +72,4 @@ protected List getWrongAnswers(String rightAnswer) { } return wrongAnswers; } - - @Override - protected List decorateAnswers(List answers) { - return answers; - } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java index 5e2b7781..4b77d571 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java @@ -1,7 +1,11 @@ package main.java.questionGenerator.generator.specificGenerators; +import java.util.List; + import main.java.questionGenerator.generator.AnswersAreEntities; import main.java.questionGenerator.question.QuestionType; +import main.java.questionGenerator.question.answers.AnswerFormater; +import main.java.questionGenerator.question.answers.formatAnswers.CapitalLetersFormater; public class LanguageGenerator extends AnswersAreEntities { @@ -12,5 +16,11 @@ public class LanguageGenerator extends AnswersAreEntities { public LanguageGenerator(){ super(PROPERTY, QuestionType.LANGUAGE, PROPERTY_TO_CHECK, MESSAGE); } + + @Override + protected List decorateAnswers(List answers) { + AnswerFormater formater = new CapitalLetersFormater(); + return formater.format(answers); + } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java index b1feb771..d58e1fe1 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java @@ -8,6 +8,8 @@ import main.java.questionGenerator.generator.AnswersAreNotEntites; import main.java.questionGenerator.question.QuestionType; +import main.java.questionGenerator.question.answers.AnswerFormater; +import main.java.questionGenerator.question.answers.formatAnswers.EmbellishNumbersFormater; public class PopulationGenerator extends AnswersAreNotEntites { @@ -24,4 +26,10 @@ protected String getRightAnswer(Map> claims) { Value v = statements.get(statements.size()-1).getValue(); return v.toString(); } + + @Override + protected List decorateAnswers(List answers) { + AnswerFormater formater = new EmbellishNumbersFormater(); + return formater.format(answers); + } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/SizeGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/SizeGenerator.java index 2259c13e..3c0714f0 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/SizeGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/SizeGenerator.java @@ -8,6 +8,9 @@ import main.java.questionGenerator.generator.AnswersAreNotEntites; import main.java.questionGenerator.question.QuestionType; +import main.java.questionGenerator.question.answers.AnswerFormater; +import main.java.questionGenerator.question.answers.formatAnswers.EmbellishNumbersFormater; +import main.java.questionGenerator.question.answers.formatAnswers.RemoveEFromNumber; public class SizeGenerator extends AnswersAreNotEntites { @@ -30,4 +33,10 @@ private String getRightAnswerEntity(String url) { return split2[split2.length-1]; } + @Override + protected List decorateAnswers(List answers) { + AnswerFormater formater = new RemoveEFromNumber(new EmbellishNumbersFormater()); + return formater.format(answers); + } + } From e7389dadede348a4be3ee440d3c0798bf13db133 Mon Sep 17 00:00:00 2001 From: jorge Date: Wed, 17 Apr 2024 20:42:31 +0200 Subject: [PATCH 09/78] Fixed the problems with the merges --- questionGenerator/src/main/java/Main.java | 8 ++++---- .../main/java/questionGenerator/question/Question.java | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/questionGenerator/src/main/java/Main.java b/questionGenerator/src/main/java/Main.java index 5275643b..c02cd21d 100644 --- a/questionGenerator/src/main/java/Main.java +++ b/questionGenerator/src/main/java/Main.java @@ -10,15 +10,15 @@ public class Main { public static void main(String[] args) { - QuestionGenerator qgEn = new QuestionGenerator("en"); + QuestionGenerator qg = new QuestionGenerator("en"); - run(qgEn, QuestionType.CAPITAL, 3); + run(qg, QuestionType.CAPITAL, 3); System.out.println(); - run(qgEn, QuestionType.LANGUAGE, 3); + run(qg, QuestionType.LANGUAGE, 3); System.out.println(); - run(qgEn, QuestionType.POPULATION, 3); + run(qg, QuestionType.POPULATION, 3); System.out.println(); run(qg, QuestionType.SIZE, 3); diff --git a/questionGenerator/src/main/java/questionGenerator/question/Question.java b/questionGenerator/src/main/java/questionGenerator/question/Question.java index 900e3b49..7068cbd6 100644 --- a/questionGenerator/src/main/java/questionGenerator/question/Question.java +++ b/questionGenerator/src/main/java/questionGenerator/question/Question.java @@ -9,6 +9,7 @@ public class Question { private String question; private List answers; + private int number = -1; private String language; private QuestionType type; @@ -43,12 +44,16 @@ public void addRightAnswer(String answer) { answers.add(0, answer); } + public void setNumber(int number){ + this.number = number; + } public JSONObject getJSON() { JSONObject json = new JSONObject(); json.accumulate("question", question); for(String s : answers) json.accumulate("answers", s); + if(number != -1) json.accumulate("number", number); //Para que los tests pasen json.accumulate("language", language); json.accumulate("type", type); return json; From b112212ca09ca6695cfe43a2d0dd65dcfdd2507b Mon Sep 17 00:00:00 2001 From: jorge Date: Wed, 17 Apr 2024 20:58:19 +0200 Subject: [PATCH 10/78] Fixed the duplicate code for generating number distractors --- .../generator/AnswersAreNotEntites.java | 57 ++++++------------- .../PopulationGenerator.java | 11 ++++ 2 files changed, 28 insertions(+), 40 deletions(-) diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java index 9d5f0017..a7fc72a4 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java @@ -15,17 +15,11 @@ public AnswersAreNotEntites(String propertyId, QuestionType type, String message @Override protected List getWrongAnswers(String rightAnswer) { - int inumber = 0; - float fnumber = 0; + float fnumber = 0; // Check if it is a float try { - inumber = Integer.parseInt(rightAnswer); + fnumber = Float.parseFloat(rightAnswer); } catch(NumberFormatException e1) { - try { - fnumber = Float.parseFloat(rightAnswer); - } catch (NumberFormatException e2) { - //throw some exception or return null. - } } List wrongAnswers = new ArrayList<>(); @@ -36,40 +30,23 @@ protected List getWrongAnswers(String rightAnswer) { int parameter = 50; - if(inumber != 0){ - //for integer values - for(int i = 0; i < 3; i++){ - long wrong = (inumber * (100 + rnd.nextInt(parameter * 2 + 1) - parameter) / 100); - // An extra check for the wrong answer to be same sign. - if((inumber > 0 && wrong < 0) || (inumber < 0 && wrong > 0)) - { - i--; - continue; - } - // Checking if it creates the same answer as any other. - if(wrong == inumber || wrongAnswers.contains(String.valueOf(wrong))) - i--; - else - wrongAnswers.add(String.valueOf(wrong)); - } - } - else{ - //for float values - for(int i = 0; i < 3; i++){ - float wrong = (fnumber * (100 + rnd.nextInt(parameter * 2 + 1) - parameter) / 100); - // An extra check for the wrong answer to be same sign. - if((fnumber > 0 && wrong < 0) || (fnumber < 0 && wrong > 0)) - { - i--; - continue; - } - // Checking if it creates the same answer as any other - if(wrong == fnumber || wrongAnswers.contains(String.valueOf(wrong))) - i--; - else - wrongAnswers.add(String.valueOf(wrong)); + + //for float values + for(int i = 0; i < 3; i++){ + float wrong = (fnumber * (100 + rnd.nextInt(parameter * 2 + 1) - parameter) / 100); + // An extra check for the wrong answer to be same sign. + if((fnumber > 0 && wrong < 0) || (fnumber < 0 && wrong > 0)) + { + i--; + continue; } + // Checking if it creates the same answer as any other + if(wrong == fnumber || wrongAnswers.contains(String.valueOf(wrong))) + i--; + else + wrongAnswers.add(String.valueOf(wrong)); } + return wrongAnswers; } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java index d58e1fe1..99bf79e9 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java @@ -1,5 +1,6 @@ package main.java.questionGenerator.generator.specificGenerators; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -32,4 +33,14 @@ protected List decorateAnswers(List answers) { AnswerFormater formater = new EmbellishNumbersFormater(); return formater.format(answers); } + + @Override + protected List getWrongAnswers(String rightAnswer) { + List original = super.getWrongAnswers(rightAnswer); + List result = new ArrayList<>(); + for(String s : original) { + result.add(String.valueOf((int) Float.parseFloat(s))); + } + return result; + } } From 25435dda5fffc052779d32d13dc3f8222d9e53aa Mon Sep 17 00:00:00 2001 From: jorge Date: Wed, 17 Apr 2024 22:26:51 +0200 Subject: [PATCH 11/78] Added the movie director generator --- questionGenerator/src/main/java/Main.java | 3 ++ .../questionGenerator/QuestionGenerator.java | 5 ++++ .../entityGenerator/EntityGenerator.java | 3 ++ .../generator/AnswersAreEntities.java | 2 +- .../specificGenerators/DirectorGenerator.java | 30 +++++++++++++++++++ .../question/QuestionType.java | 2 +- .../src/main/resources/messages.properties | 3 +- .../src/main/resources/messages_en.properties | 3 +- .../src/main/resources/messages_es.properties | 3 +- 9 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java diff --git a/questionGenerator/src/main/java/Main.java b/questionGenerator/src/main/java/Main.java index c02cd21d..bc0c03d1 100644 --- a/questionGenerator/src/main/java/Main.java +++ b/questionGenerator/src/main/java/Main.java @@ -25,6 +25,9 @@ public static void main(String[] args) { System.out.println(); run(qg, QuestionType.HEAD_OF_GOVERMENT, 3); + System.out.println(); + + run(qg, QuestionType.DIRECTOR, 3); } private static void run(QuestionGenerator qg, QuestionType type, int numberOfQuestions){ diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index 7a6a756f..c653acee 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -8,6 +8,7 @@ import main.java.questionGenerator.entityGenerator.EntityGenerator; import main.java.questionGenerator.generator.AbstractGenerator; import main.java.questionGenerator.generator.specificGenerators.CapitalGenerator; +import main.java.questionGenerator.generator.specificGenerators.DirectorGenerator; import main.java.questionGenerator.generator.specificGenerators.HeadOfGovernmentGenerator; import main.java.questionGenerator.generator.specificGenerators.LanguageGenerator; import main.java.questionGenerator.generator.specificGenerators.PopulationGenerator; @@ -76,6 +77,10 @@ private void setGenerator(QuestionType type) { generator = new HeadOfGovernmentGenerator(); break; } + case DIRECTOR: { + generator = new DirectorGenerator(); + break; + } } } diff --git a/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java b/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java index 56318fd1..608dfeb2 100644 --- a/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java @@ -61,6 +61,9 @@ private static void propertyFactory(QuestionType type) { case HEAD_OF_GOVERMENT: property = "6"; break; + case DIRECTOR: + property = "57"; + break; } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java index c2c19d0b..f6e635e1 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java @@ -52,7 +52,7 @@ protected String getRightAnswer(Map> claims) throws Exce return null; } - private String processRightAnswer(Statement st) { + protected String processRightAnswer(Statement st) { String entity = getIdFromLink(st.getValue().toString()); String answer = ""; try { diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java new file mode 100644 index 00000000..50bd9146 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java @@ -0,0 +1,30 @@ +package main.java.questionGenerator.generator.specificGenerators; + +import java.util.List; +import java.util.Map; + +import org.wikidata.wdtk.datamodel.interfaces.Statement; + +import main.java.questionGenerator.generator.AnswersAreEntities; +import main.java.questionGenerator.question.QuestionType; + +public class DirectorGenerator extends AnswersAreEntities{ + + private final static String PROPERTY = "P57"; + private final static String MESSAGE = "question.director"; + + public DirectorGenerator() { + super(PROPERTY, QuestionType.DIRECTOR, null, MESSAGE); + } + + @Override + protected String getRightAnswer(Map> claims) throws Exception { + if(claims.get(super.getPropertyId())==null) { + throw new Exception("Claims does not have the property " + super.getPropertyId()); + } + List stms = claims.get(getPropertyId()); + Statement stm = claims.get(getPropertyId()).get(stms.size()-1); + return processRightAnswer(stm); + } + +} diff --git a/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java b/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java index b3e2be83..226e6e32 100644 --- a/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java +++ b/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java @@ -2,6 +2,6 @@ public enum QuestionType { - POPULATION, CAPITAL, SIZE, LANGUAGE, HEAD_OF_GOVERMENT; + POPULATION, CAPITAL, SIZE, LANGUAGE, HEAD_OF_GOVERMENT, DIRECTOR; } diff --git a/questionGenerator/src/main/resources/messages.properties b/questionGenerator/src/main/resources/messages.properties index ff1a6b3a..01743131 100644 --- a/questionGenerator/src/main/resources/messages.properties +++ b/questionGenerator/src/main/resources/messages.properties @@ -2,4 +2,5 @@ question.population = What's the population of %s? question.language = What's the official language of %s? question.capital = What's the capital of %s? question.size = What's the size of %s? -question.governmentHead = Who's the current head of the government of %s? \ No newline at end of file +question.governmentHead = Who's the current head of the government of %s? +question.director = %s \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_en.properties b/questionGenerator/src/main/resources/messages_en.properties index ff1a6b3a..01743131 100644 --- a/questionGenerator/src/main/resources/messages_en.properties +++ b/questionGenerator/src/main/resources/messages_en.properties @@ -2,4 +2,5 @@ question.population = What's the population of %s? question.language = What's the official language of %s? question.capital = What's the capital of %s? question.size = What's the size of %s? -question.governmentHead = Who's the current head of the government of %s? \ No newline at end of file +question.governmentHead = Who's the current head of the government of %s? +question.director = %s \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_es.properties b/questionGenerator/src/main/resources/messages_es.properties index d7c1de0a..33d74f2d 100644 --- a/questionGenerator/src/main/resources/messages_es.properties +++ b/questionGenerator/src/main/resources/messages_es.properties @@ -2,4 +2,5 @@ question.population = ¿Cuál es la población de %s? question.language = ¿Cuál es el idioma oficial de %s? question.capital = ¿Cuál es la capital de %s? question.size = ¿Cuál es el área (km cuadrados) de %s? -question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? \ No newline at end of file +question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? +question.director = %s \ No newline at end of file From fbb89a258bde6fb0bc24b751b190b3e48ca04b69 Mon Sep 17 00:00:00 2001 From: jorge Date: Wed, 17 Apr 2024 22:28:08 +0200 Subject: [PATCH 12/78] Improved the messages for the director questions --- questionGenerator/src/main/resources/messages.properties | 2 +- questionGenerator/src/main/resources/messages_en.properties | 2 +- questionGenerator/src/main/resources/messages_es.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/questionGenerator/src/main/resources/messages.properties b/questionGenerator/src/main/resources/messages.properties index 01743131..812c2f9d 100644 --- a/questionGenerator/src/main/resources/messages.properties +++ b/questionGenerator/src/main/resources/messages.properties @@ -3,4 +3,4 @@ question.language = What's the official language of %s? question.capital = What's the capital of %s? question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? -question.director = %s \ No newline at end of file +question.director = Who's the director of %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_en.properties b/questionGenerator/src/main/resources/messages_en.properties index 01743131..812c2f9d 100644 --- a/questionGenerator/src/main/resources/messages_en.properties +++ b/questionGenerator/src/main/resources/messages_en.properties @@ -3,4 +3,4 @@ question.language = What's the official language of %s? question.capital = What's the capital of %s? question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? -question.director = %s \ No newline at end of file +question.director = Who's the director of %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_es.properties b/questionGenerator/src/main/resources/messages_es.properties index 33d74f2d..2566e077 100644 --- a/questionGenerator/src/main/resources/messages_es.properties +++ b/questionGenerator/src/main/resources/messages_es.properties @@ -3,4 +3,4 @@ question.language = ¿Cuál es el idioma oficial de %s? question.capital = ¿Cuál es la capital de %s? question.size = ¿Cuál es el área (km cuadrados) de %s? question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? -question.director = %s \ No newline at end of file +question.director = ¿Quién es el director de %s? \ No newline at end of file From d338c8470b3fcf01f87fe147f04a482522ae932b Mon Sep 17 00:00:00 2001 From: jorge Date: Wed, 17 Apr 2024 22:56:51 +0200 Subject: [PATCH 13/78] Modified the answers are entites hierarchy --- ...es.java => AbstractAnswersAreEntites.java} | 104 +++++++----------- .../AnswersAreEntitiesWithSubProperties.java | 47 ++++++++ ...nswersAreEntitiesWithoutSubProperties.java | 26 +++++ .../specificGenerators/CapitalGenerator.java | 4 +- .../specificGenerators/DirectorGenerator.java | 6 +- .../HeadOfGovernmentGenerator.java | 4 +- .../specificGenerators/LanguageGenerator.java | 4 +- 7 files changed, 121 insertions(+), 74 deletions(-) rename questionGenerator/src/main/java/questionGenerator/generator/{AnswersAreEntities.java => AbstractAnswersAreEntites.java} (66%) create mode 100644 questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithSubProperties.java create mode 100644 questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java b/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java similarity index 66% rename from questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java rename to questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java index f6e635e1..442e6fb1 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntities.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java @@ -3,74 +3,26 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Random; import org.wikidata.wdtk.datamodel.implementation.ItemDocumentImpl; -import org.wikidata.wdtk.datamodel.interfaces.Snak; -import org.wikidata.wdtk.datamodel.interfaces.SnakGroup; import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException; import main.java.questionGenerator.entityGenerator.EntityGenerator; import main.java.questionGenerator.question.QuestionType; -public abstract class AnswersAreEntities extends AbstractGenerator { - - private final String PROPERTY_TO_CHECK; - private QuestionType type; - public AnswersAreEntities(String propertyId, QuestionType type, String propertyToCheck, String message) { - super(propertyId, type, message); - this.PROPERTY_TO_CHECK = propertyToCheck; - this.type = type; - } +public abstract class AbstractAnswersAreEntites extends AbstractGenerator{ - @Override - protected String getRightAnswer(Map> claims) throws Exception { - if(claims.get(super.getPropertyId())==null) { - throw new Exception("Claims does not have the property " + super.getPropertyId()); - } - - for(Statement st : claims.get(super.getPropertyId())) { - boolean valid = true; - for(SnakGroup sg : st.getQualifiers()) { - for(Snak s : sg.getSnaks()) { - String value = getIdFromLink(s.getPropertyId().toString()); - if(value.equals(PROPERTY_TO_CHECK)) { - valid = false; - break; - } - } - if(!valid) - break; - } - if(valid) { - return processRightAnswer(st); - } - } - return null; - } - - protected String processRightAnswer(Statement st) { - String entity = getIdFromLink(st.getValue().toString()); - String answer = ""; - try { - ItemDocumentImpl idi = getAlreadyProcessedEntity(entity); - if(idi==null) { - idi = (ItemDocumentImpl) wbdf.getEntityDocument(entity); - answer = getName(idi.getLabels()); - addProcessedEntity(entity, idi); - } - else - answer = getName(idi.getLabels()); - } catch (MediaWikiApiErrorException | IOException e) { - - } - return answer; - } - - private String getAnswer(String id) throws Exception{ + private QuestionType type; + + public AbstractAnswersAreEntites(String propertyId, QuestionType type, String message) { + super(propertyId, type, message); + this.type = type; + } + + private String getAnswer(String id) throws Exception{ ItemDocumentImpl idi = getAlreadyProcessedEntity(id); if(idi==null) { @@ -89,13 +41,7 @@ private String getAnswer(String id) throws Exception{ } return getRightAnswer(idi.getJsonClaims()); } - - protected String getIdFromLink(String url) { - String[] split1 = url.split(" "); - String[] split2 = split1[0].split("/"); - return split2[split2.length-1]; - } - + @Override protected List getWrongAnswers(String rightAnswer) throws Exception { List entites = new ArrayList<>(); @@ -117,10 +63,38 @@ protected List getWrongAnswers(String rightAnswer) throws Exception { } return result; } - + + /** + * Since most of the implementations do not require to decorate the answer, this general one + * simply returns the value passed to it as a parameter + */ @Override protected List decorateAnswers(List answers) { return answers; } + + protected String getIdFromLink(String url) { + String[] split1 = url.split(" "); + String[] split2 = split1[0].split("/"); + return split2[split2.length-1]; + } + + protected String processRightAnswer(Statement st) { + String entity = getIdFromLink(st.getValue().toString()); + String answer = ""; + try { + ItemDocumentImpl idi = getAlreadyProcessedEntity(entity); + if(idi==null) { + idi = (ItemDocumentImpl) wbdf.getEntityDocument(entity); + answer = getName(idi.getLabels()); + addProcessedEntity(entity, idi); + } + else + answer = getName(idi.getLabels()); + } catch (MediaWikiApiErrorException | IOException e) { + + } + return answer; + } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithSubProperties.java new file mode 100644 index 00000000..a6082f99 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithSubProperties.java @@ -0,0 +1,47 @@ +package main.java.questionGenerator.generator; + +import java.util.List; +import java.util.Map; + +import org.wikidata.wdtk.datamodel.interfaces.Snak; +import org.wikidata.wdtk.datamodel.interfaces.SnakGroup; +import org.wikidata.wdtk.datamodel.interfaces.Statement; + +import main.java.questionGenerator.question.QuestionType; + +public abstract class AnswersAreEntitiesWithSubProperties extends AbstractAnswersAreEntites { + + private final String PROPERTY_TO_CHECK; + + public AnswersAreEntitiesWithSubProperties(String propertyId, QuestionType type, String propertyToCheck, String message) { + super(propertyId, type, message); + this.PROPERTY_TO_CHECK = propertyToCheck; + } + + @Override + protected String getRightAnswer(Map> claims) throws Exception { + if(claims.get(super.getPropertyId())==null) { + throw new Exception("Claims does not have the property " + super.getPropertyId()); + } + + for(Statement st : claims.get(super.getPropertyId())) { + boolean valid = true; + for(SnakGroup sg : st.getQualifiers()) { + for(Snak s : sg.getSnaks()) { + String value = getIdFromLink(s.getPropertyId().toString()); + if(value.equals(PROPERTY_TO_CHECK)) { + valid = false; + break; + } + } + if(!valid) + break; + } + if(valid) { + return processRightAnswer(st); + } + } + return null; + } + +} diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java new file mode 100644 index 00000000..49264b38 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java @@ -0,0 +1,26 @@ +package main.java.questionGenerator.generator; + +import java.util.List; +import java.util.Map; + +import org.wikidata.wdtk.datamodel.interfaces.Statement; + +import main.java.questionGenerator.question.QuestionType; + +public abstract class AnswersAreEntitiesWithoutSubProperties extends AbstractAnswersAreEntites { + + public AnswersAreEntitiesWithoutSubProperties(String propertyId, QuestionType type, String message) { + super(propertyId, type, message); + } + + @Override + protected String getRightAnswer(Map> claims) throws Exception { + if(claims.get(super.getPropertyId())==null) { + throw new Exception("Claims does not have the property " + super.getPropertyId()); + } + List stms = claims.get(getPropertyId()); + Statement stm = claims.get(getPropertyId()).get(stms.size()-1); + return processRightAnswer(stm); + } + +} diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/CapitalGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/CapitalGenerator.java index 64444133..8ae71ccc 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/CapitalGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/CapitalGenerator.java @@ -1,9 +1,9 @@ package main.java.questionGenerator.generator.specificGenerators; -import main.java.questionGenerator.generator.AnswersAreEntities; +import main.java.questionGenerator.generator.AnswersAreEntitiesWithSubProperties; import main.java.questionGenerator.question.QuestionType; -public class CapitalGenerator extends AnswersAreEntities { +public class CapitalGenerator extends AnswersAreEntitiesWithSubProperties { private final static String PROPERTY = "P36"; private final static String PROPERTY_TO_CHECK = "P582"; diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java index 50bd9146..6e64fd24 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java @@ -5,16 +5,16 @@ import org.wikidata.wdtk.datamodel.interfaces.Statement; -import main.java.questionGenerator.generator.AnswersAreEntities; +import main.java.questionGenerator.generator.AnswersAreEntitiesWithoutSubProperties; import main.java.questionGenerator.question.QuestionType; -public class DirectorGenerator extends AnswersAreEntities{ +public class DirectorGenerator extends AnswersAreEntitiesWithoutSubProperties{ private final static String PROPERTY = "P57"; private final static String MESSAGE = "question.director"; public DirectorGenerator() { - super(PROPERTY, QuestionType.DIRECTOR, null, MESSAGE); + super(PROPERTY, QuestionType.DIRECTOR, MESSAGE); } @Override diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/HeadOfGovernmentGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/HeadOfGovernmentGenerator.java index c7c53ba2..62839247 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/HeadOfGovernmentGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/HeadOfGovernmentGenerator.java @@ -1,9 +1,9 @@ package main.java.questionGenerator.generator.specificGenerators; -import main.java.questionGenerator.generator.AnswersAreEntities; +import main.java.questionGenerator.generator.AnswersAreEntitiesWithSubProperties; import main.java.questionGenerator.question.QuestionType; -public class HeadOfGovernmentGenerator extends AnswersAreEntities { +public class HeadOfGovernmentGenerator extends AnswersAreEntitiesWithSubProperties { private final static String PROPERTY = "P6"; private final static String PROPERTY_TO_CHECK = "P582"; diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java index 4b77d571..8b025b3d 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java @@ -2,12 +2,12 @@ import java.util.List; -import main.java.questionGenerator.generator.AnswersAreEntities; +import main.java.questionGenerator.generator.AnswersAreEntitiesWithSubProperties; import main.java.questionGenerator.question.QuestionType; import main.java.questionGenerator.question.answers.AnswerFormater; import main.java.questionGenerator.question.answers.formatAnswers.CapitalLetersFormater; -public class LanguageGenerator extends AnswersAreEntities { +public class LanguageGenerator extends AnswersAreEntitiesWithSubProperties { private final static String PROPERTY = "P37"; private final static String PROPERTY_TO_CHECK = "P518"; From 9ed97194f2bd8f1e848006848b87a17b12722328 Mon Sep 17 00:00:00 2001 From: jorge Date: Wed, 17 Apr 2024 23:00:30 +0200 Subject: [PATCH 14/78] Fixed small code repetition --- .../generator/AnswersAreEntitiesWithoutSubProperties.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java index 49264b38..caa3157c 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java @@ -19,7 +19,7 @@ protected String getRightAnswer(Map> claims) throws Exce throw new Exception("Claims does not have the property " + super.getPropertyId()); } List stms = claims.get(getPropertyId()); - Statement stm = claims.get(getPropertyId()).get(stms.size()-1); + Statement stm = stms.get(stms.size()-1); return processRightAnswer(stm); } From 6229686fe0e979a780f7fb20b16a57c6d27c2ea1 Mon Sep 17 00:00:00 2001 From: jorge Date: Wed, 17 Apr 2024 23:18:26 +0200 Subject: [PATCH 15/78] Ensured that the director generator only generated film directors quesitons --- questionGenerator/src/main/java/Main.java | 5 ++++ .../questionGenerator/QuestionGenerator.java | 11 +++++-- ...nswersAreEntitiesWithoutSubProperties.java | 13 +++++++- .../specificGenerators/DirectorGenerator.java | 30 ------------------- .../FilmDirectorGenerator.java | 16 ++++++++++ 5 files changed, 42 insertions(+), 33 deletions(-) delete mode 100644 questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java create mode 100644 questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/FilmDirectorGenerator.java diff --git a/questionGenerator/src/main/java/Main.java b/questionGenerator/src/main/java/Main.java index bc0c03d1..22b2635d 100644 --- a/questionGenerator/src/main/java/Main.java +++ b/questionGenerator/src/main/java/Main.java @@ -32,6 +32,11 @@ public static void main(String[] args) { private static void run(QuestionGenerator qg, QuestionType type, int numberOfQuestions){ List questions = qg.generateQuestions(type, numberOfQuestions); + for(int i=0; i q.getJSON().toString()).toList()); } } diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index c653acee..0e58d9ba 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -8,7 +8,7 @@ import main.java.questionGenerator.entityGenerator.EntityGenerator; import main.java.questionGenerator.generator.AbstractGenerator; import main.java.questionGenerator.generator.specificGenerators.CapitalGenerator; -import main.java.questionGenerator.generator.specificGenerators.DirectorGenerator; +import main.java.questionGenerator.generator.specificGenerators.FilmDirectorGenerator; import main.java.questionGenerator.generator.specificGenerators.HeadOfGovernmentGenerator; import main.java.questionGenerator.generator.specificGenerators.LanguageGenerator; import main.java.questionGenerator.generator.specificGenerators.PopulationGenerator; @@ -45,6 +45,13 @@ public List generateQuestions(QuestionType type, int amount){ try { q = generator.generate(entity); questions.add(q); + } catch(RuntimeException e) { + /* + * Sometimes not all the parameters for generating can be passed in the query, so this + * acts as failsave to avoid generating undesired questions, while not overloading the + * screen with error messages if not wanted + */ + //System.err.println(e.getMessage()); } catch (Exception e) { //If there's any problem generating the question we jump to the next one System.err.println(e.getMessage()); @@ -78,7 +85,7 @@ private void setGenerator(QuestionType type) { break; } case DIRECTOR: { - generator = new DirectorGenerator(); + generator = new FilmDirectorGenerator(); break; } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java index caa3157c..3dbc0bb0 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java @@ -9,8 +9,13 @@ public abstract class AnswersAreEntitiesWithoutSubProperties extends AbstractAnswersAreEntites { - public AnswersAreEntitiesWithoutSubProperties(String propertyId, QuestionType type, String message) { + private static final String INSTANCE_OF_PROPERTY = "P31"; + private String instanceOf; + + public AnswersAreEntitiesWithoutSubProperties(String propertyId, QuestionType type, String message, + String instanceOfPropertyValue) { super(propertyId, type, message); + this.instanceOf = instanceOfPropertyValue; } @Override @@ -18,6 +23,12 @@ protected String getRightAnswer(Map> claims) throws Exce if(claims.get(super.getPropertyId())==null) { throw new Exception("Claims does not have the property " + super.getPropertyId()); } + + String value = processRightAnswer(claims.get(INSTANCE_OF_PROPERTY).get(0)); + if(!value.equals(instanceOf)) { + throw new RuntimeException("The entity is not a " + instanceOf); + } + List stms = claims.get(getPropertyId()); Statement stm = stms.get(stms.size()-1); return processRightAnswer(stm); diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java deleted file mode 100644 index 6e64fd24..00000000 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java +++ /dev/null @@ -1,30 +0,0 @@ -package main.java.questionGenerator.generator.specificGenerators; - -import java.util.List; -import java.util.Map; - -import org.wikidata.wdtk.datamodel.interfaces.Statement; - -import main.java.questionGenerator.generator.AnswersAreEntitiesWithoutSubProperties; -import main.java.questionGenerator.question.QuestionType; - -public class DirectorGenerator extends AnswersAreEntitiesWithoutSubProperties{ - - private final static String PROPERTY = "P57"; - private final static String MESSAGE = "question.director"; - - public DirectorGenerator() { - super(PROPERTY, QuestionType.DIRECTOR, MESSAGE); - } - - @Override - protected String getRightAnswer(Map> claims) throws Exception { - if(claims.get(super.getPropertyId())==null) { - throw new Exception("Claims does not have the property " + super.getPropertyId()); - } - List stms = claims.get(getPropertyId()); - Statement stm = claims.get(getPropertyId()).get(stms.size()-1); - return processRightAnswer(stm); - } - -} diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/FilmDirectorGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/FilmDirectorGenerator.java new file mode 100644 index 00000000..c8bc285a --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/FilmDirectorGenerator.java @@ -0,0 +1,16 @@ +package main.java.questionGenerator.generator.specificGenerators; + +import main.java.questionGenerator.generator.AnswersAreEntitiesWithoutSubProperties; +import main.java.questionGenerator.question.QuestionType; + +public class FilmDirectorGenerator extends AnswersAreEntitiesWithoutSubProperties{ + + private final static String PROPERTY = "P57"; + private final static String MESSAGE = "question.director"; + private final static String INSTANCE_OF = "film"; + + public FilmDirectorGenerator() { + super(PROPERTY, QuestionType.DIRECTOR, MESSAGE, INSTANCE_OF); + } + +} From fa035a9440a45fc5cf5faba701117bfa05ac4506 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 10:01:28 +0200 Subject: [PATCH 16/78] Added an interface to the generator hierarchy --- .../generator/AbstractAnswersAreEntites.java | 4 ++-- .../generator/AbstractGenerator.java | 11 ++------- .../AnswersAreEntitiesWithSubProperties.java | 2 +- ...nswersAreEntitiesWithoutSubProperties.java | 2 +- .../generator/AnswersAreNotEntites.java | 2 +- .../generator/Generator.java | 24 +++++++++++++++++++ .../specificGenerators/LanguageGenerator.java | 2 +- .../PopulationGenerator.java | 6 ++--- .../specificGenerators/SizeGenerator.java | 4 ++-- 9 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 questionGenerator/src/main/java/questionGenerator/generator/Generator.java diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java b/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java index 442e6fb1..bf749266 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java @@ -43,7 +43,7 @@ private String getAnswer(String id) throws Exception{ } @Override - protected List getWrongAnswers(String rightAnswer) throws Exception { + public List getWrongAnswers(String rightAnswer) throws Exception { List entites = new ArrayList<>(); try { entites = EntityGenerator.getEntities(type, 100); @@ -69,7 +69,7 @@ protected List getWrongAnswers(String rightAnswer) throws Exception { * simply returns the value passed to it as a parameter */ @Override - protected List decorateAnswers(List answers) { + public List decorateAnswers(List answers) { return answers; } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java index c8d85f4f..98f3f37e 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java @@ -9,14 +9,13 @@ import org.wikidata.wdtk.datamodel.implementation.ItemDocumentImpl; import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue; -import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher; import org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException; import main.java.questionGenerator.question.Question; import main.java.questionGenerator.question.QuestionType; -public abstract class AbstractGenerator { +public abstract class AbstractGenerator implements Generator { protected static final WikibaseDataFetcher wbdf = WikibaseDataFetcher.getWikidataDataFetcher(); private String language = "en"; @@ -89,13 +88,7 @@ protected String getName(Map names) { return mtv.getText(); } -// protected abstract String getQuestion(String name); - protected abstract String getRightAnswer(Map> claims) throws Exception; - protected abstract List getWrongAnswers(String rightAnswer) throws Exception; - - protected abstract List decorateAnswers(List answers); - - protected String getQuestion(String name) { + public String getQuestion(String name) { String q = getMessages().getString(message); return String.format(q, name); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithSubProperties.java index a6082f99..66bb47af 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithSubProperties.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithSubProperties.java @@ -19,7 +19,7 @@ public AnswersAreEntitiesWithSubProperties(String propertyId, QuestionType type, } @Override - protected String getRightAnswer(Map> claims) throws Exception { + public String getRightAnswer(Map> claims) throws Exception { if(claims.get(super.getPropertyId())==null) { throw new Exception("Claims does not have the property " + super.getPropertyId()); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java index 3dbc0bb0..6cc51551 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java @@ -19,7 +19,7 @@ public AnswersAreEntitiesWithoutSubProperties(String propertyId, QuestionType ty } @Override - protected String getRightAnswer(Map> claims) throws Exception { + public String getRightAnswer(Map> claims) throws Exception { if(claims.get(super.getPropertyId())==null) { throw new Exception("Claims does not have the property " + super.getPropertyId()); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java index a7fc72a4..7b14459b 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java @@ -14,7 +14,7 @@ public AnswersAreNotEntites(String propertyId, QuestionType type, String message } @Override - protected List getWrongAnswers(String rightAnswer) { + public List getWrongAnswers(String rightAnswer) { float fnumber = 0; // Check if it is a float try { diff --git a/questionGenerator/src/main/java/questionGenerator/generator/Generator.java b/questionGenerator/src/main/java/questionGenerator/generator/Generator.java new file mode 100644 index 00000000..08228f05 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/generator/Generator.java @@ -0,0 +1,24 @@ +package main.java.questionGenerator.generator; + +import java.util.List; +import java.util.Map; + +import org.wikidata.wdtk.datamodel.interfaces.Statement; + +import main.java.questionGenerator.question.Question; + +public interface Generator { + + Question generate(String id) throws Exception; + + String getQuestion(String name); + + String getRightAnswer(Map> claims) throws Exception; + + List getWrongAnswers(String rightAnswer) throws Exception; + + List decorateAnswers(List answers); + + String getPropertyId(); + +} diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java index 8b025b3d..e4e31bf1 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java @@ -18,7 +18,7 @@ public LanguageGenerator(){ } @Override - protected List decorateAnswers(List answers) { + public List decorateAnswers(List answers) { AnswerFormater formater = new CapitalLetersFormater(); return formater.format(answers); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java index 99bf79e9..187a8617 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java @@ -22,20 +22,20 @@ public PopulationGenerator(){ } @Override - protected String getRightAnswer(Map> claims) { + public String getRightAnswer(Map> claims) { List statements = claims.get(PROPERTY); Value v = statements.get(statements.size()-1).getValue(); return v.toString(); } @Override - protected List decorateAnswers(List answers) { + public List decorateAnswers(List answers) { AnswerFormater formater = new EmbellishNumbersFormater(); return formater.format(answers); } @Override - protected List getWrongAnswers(String rightAnswer) { + public List getWrongAnswers(String rightAnswer) { List original = super.getWrongAnswers(rightAnswer); List result = new ArrayList<>(); for(String s : original) { diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/SizeGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/SizeGenerator.java index 3c0714f0..aa391d8c 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/SizeGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/SizeGenerator.java @@ -22,7 +22,7 @@ public SizeGenerator() { } @Override - protected String getRightAnswer(Map> claims) { + public String getRightAnswer(Map> claims) { Value v = claims.get(PROPERTY).get(0).getValue(); return getRightAnswerEntity(v.toString()); } @@ -34,7 +34,7 @@ private String getRightAnswerEntity(String url) { } @Override - protected List decorateAnswers(List answers) { + public List decorateAnswers(List answers) { AnswerFormater formater = new RemoveEFromNumber(new EmbellishNumbersFormater()); return formater.format(answers); } From 9238de6acd50e483c0d400dc545ec192de5deb03 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 10:06:19 +0200 Subject: [PATCH 17/78] Improved the generator hierarchy usage --- .../src/main/java/questionGenerator/QuestionGenerator.java | 4 ++-- .../src/main/java/questionGenerator/generator/Generator.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index 0e58d9ba..1593d182 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -6,7 +6,7 @@ import java.util.Random; import main.java.questionGenerator.entityGenerator.EntityGenerator; -import main.java.questionGenerator.generator.AbstractGenerator; +import main.java.questionGenerator.generator.Generator; import main.java.questionGenerator.generator.specificGenerators.CapitalGenerator; import main.java.questionGenerator.generator.specificGenerators.FilmDirectorGenerator; import main.java.questionGenerator.generator.specificGenerators.HeadOfGovernmentGenerator; @@ -18,7 +18,7 @@ public class QuestionGenerator { - private AbstractGenerator generator; + private Generator generator; private String languageCode; public QuestionGenerator(String languageCode){ diff --git a/questionGenerator/src/main/java/questionGenerator/generator/Generator.java b/questionGenerator/src/main/java/questionGenerator/generator/Generator.java index 08228f05..157e29d2 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/Generator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/Generator.java @@ -20,5 +20,7 @@ public interface Generator { List decorateAnswers(List answers); String getPropertyId(); + + void setLocalization(String languageCode); } From 2aef92a3c1436ca98890c576654e85455fa79619 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 11:02:51 +0200 Subject: [PATCH 18/78] Fixed the problem with the director generator --- .../generator/AbstractGenerator.java | 15 +++++++++++---- .../questionGenerator/generator/Generator.java | 2 +- .../src/main/resources/messages.properties | 2 +- .../src/main/resources/messages_en.properties | 2 +- .../src/main/resources/messages_es.properties | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java index 98f3f37e..bdf7dbd2 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java @@ -9,6 +9,7 @@ import org.wikidata.wdtk.datamodel.implementation.ItemDocumentImpl; import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue; +import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher; import org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException; @@ -63,14 +64,16 @@ public Question generate(String id) throws Exception { } } + Map labels = idi.getLabels(); + Map> claims = idi.getJsonClaims(); - String name = getName(idi.getLabels()); + String name = getName(labels); //get the question - String question = getQuestion(name); + String question = getQuestion(name, claims); //get the right answer - String rightAnswer = getRightAnswer(idi.getJsonClaims()); + String rightAnswer = getRightAnswer(claims); //get the wrong answers List answers = getWrongAnswers(rightAnswer); @@ -88,7 +91,7 @@ protected String getName(Map names) { return mtv.getText(); } - public String getQuestion(String name) { + public String getQuestion(String name, Map> claims) { String q = getMessages().getString(message); return String.format(q, name); } @@ -136,4 +139,8 @@ private void localize(String languageCode) { this.messages = ResourceBundle.getBundle(MESSAGES_PATH, localization); } + public String getMessage(){ + return message; + } + } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/Generator.java b/questionGenerator/src/main/java/questionGenerator/generator/Generator.java index 157e29d2..294566a6 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/Generator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/Generator.java @@ -11,7 +11,7 @@ public interface Generator { Question generate(String id) throws Exception; - String getQuestion(String name); + String getQuestion(String name, Map> claims); String getRightAnswer(Map> claims) throws Exception; diff --git a/questionGenerator/src/main/resources/messages.properties b/questionGenerator/src/main/resources/messages.properties index 812c2f9d..fc9a5dcf 100644 --- a/questionGenerator/src/main/resources/messages.properties +++ b/questionGenerator/src/main/resources/messages.properties @@ -3,4 +3,4 @@ question.language = What's the official language of %s? question.capital = What's the capital of %s? question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? -question.director = Who's the director of %s? \ No newline at end of file +question.director = Who's the director of the %s %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_en.properties b/questionGenerator/src/main/resources/messages_en.properties index 812c2f9d..fc9a5dcf 100644 --- a/questionGenerator/src/main/resources/messages_en.properties +++ b/questionGenerator/src/main/resources/messages_en.properties @@ -3,4 +3,4 @@ question.language = What's the official language of %s? question.capital = What's the capital of %s? question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? -question.director = Who's the director of %s? \ No newline at end of file +question.director = Who's the director of the %s %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_es.properties b/questionGenerator/src/main/resources/messages_es.properties index 2566e077..8824c670 100644 --- a/questionGenerator/src/main/resources/messages_es.properties +++ b/questionGenerator/src/main/resources/messages_es.properties @@ -3,4 +3,4 @@ question.language = ¿Cuál es el idioma oficial de %s? question.capital = ¿Cuál es la capital de %s? question.size = ¿Cuál es el área (km cuadrados) de %s? question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? -question.director = ¿Quién es el director de %s? \ No newline at end of file +question.director = ¿Quién es el director de la %s %s? \ No newline at end of file From e807bf144b238ae92617ebc920fb24aa1afda0b9 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 11:03:53 +0200 Subject: [PATCH 19/78] Removed old code remaining of the film director --- .../questionGenerator/QuestionGenerator.java | 4 ++-- .../AnswersAreEntitiesWithoutSubProperties.java | 17 ++++++++--------- ...torGenerator.java => DirectorGenerator.java} | 7 +++---- 3 files changed, 13 insertions(+), 15 deletions(-) rename questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/{FilmDirectorGenerator.java => DirectorGenerator.java} (58%) diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index 1593d182..b4093677 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -8,7 +8,7 @@ import main.java.questionGenerator.entityGenerator.EntityGenerator; import main.java.questionGenerator.generator.Generator; import main.java.questionGenerator.generator.specificGenerators.CapitalGenerator; -import main.java.questionGenerator.generator.specificGenerators.FilmDirectorGenerator; +import main.java.questionGenerator.generator.specificGenerators.DirectorGenerator; import main.java.questionGenerator.generator.specificGenerators.HeadOfGovernmentGenerator; import main.java.questionGenerator.generator.specificGenerators.LanguageGenerator; import main.java.questionGenerator.generator.specificGenerators.PopulationGenerator; @@ -85,7 +85,7 @@ private void setGenerator(QuestionType type) { break; } case DIRECTOR: { - generator = new FilmDirectorGenerator(); + generator = new DirectorGenerator(); break; } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java index 6cc51551..39cb32fc 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java @@ -10,12 +10,9 @@ public abstract class AnswersAreEntitiesWithoutSubProperties extends AbstractAnswersAreEntites { private static final String INSTANCE_OF_PROPERTY = "P31"; - private String instanceOf; - public AnswersAreEntitiesWithoutSubProperties(String propertyId, QuestionType type, String message, - String instanceOfPropertyValue) { + public AnswersAreEntitiesWithoutSubProperties(String propertyId, QuestionType type, String message) { super(propertyId, type, message); - this.instanceOf = instanceOfPropertyValue; } @Override @@ -23,15 +20,17 @@ public String getRightAnswer(Map> claims) throws Excepti if(claims.get(super.getPropertyId())==null) { throw new Exception("Claims does not have the property " + super.getPropertyId()); } - - String value = processRightAnswer(claims.get(INSTANCE_OF_PROPERTY).get(0)); - if(!value.equals(instanceOf)) { - throw new RuntimeException("The entity is not a " + instanceOf); - } List stms = claims.get(getPropertyId()); Statement stm = stms.get(stms.size()-1); return processRightAnswer(stm); } + @Override + public String getQuestion(String name, Map> claims) { + String value = processRightAnswer(claims.get(INSTANCE_OF_PROPERTY).get(0)); + String q = getMessages().getString(getMessage()); + return String.format(q, value, name); + } + } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/FilmDirectorGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java similarity index 58% rename from questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/FilmDirectorGenerator.java rename to questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java index c8bc285a..04609671 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/FilmDirectorGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java @@ -3,14 +3,13 @@ import main.java.questionGenerator.generator.AnswersAreEntitiesWithoutSubProperties; import main.java.questionGenerator.question.QuestionType; -public class FilmDirectorGenerator extends AnswersAreEntitiesWithoutSubProperties{ +public class DirectorGenerator extends AnswersAreEntitiesWithoutSubProperties{ private final static String PROPERTY = "P57"; private final static String MESSAGE = "question.director"; - private final static String INSTANCE_OF = "film"; - public FilmDirectorGenerator() { - super(PROPERTY, QuestionType.DIRECTOR, MESSAGE, INSTANCE_OF); + public DirectorGenerator() { + super(PROPERTY, QuestionType.DIRECTOR, MESSAGE); } } From 5281b9c570c748922b4d51272f7b3d3105bc2252 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 14:49:00 +0200 Subject: [PATCH 20/78] Improved the way of collecting the properties for generating entites --- .../questionGenerator/QuestionGenerator.java | 2 +- .../entityGenerator/EntityGenerator.java | 29 ++----------------- .../generator/AbstractAnswersAreEntites.java | 2 +- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index b4093677..01f92f15 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -31,7 +31,7 @@ public List generateQuestions(QuestionType type, int amount){ List questions = new ArrayList<>(); List entites = new ArrayList<>(); try { - entites = EntityGenerator.getEntities(type, 100); + entites = EntityGenerator.getEntities(type, 100, generator.getPropertyId()); } catch (IOException e) { e.printStackTrace(); } diff --git a/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java b/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java index 608dfeb2..0c6541c0 100644 --- a/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java @@ -15,15 +15,13 @@ public class EntityGenerator { private static final String PRE_URL = "https://www.wikidata.org/w/api.php?action=query&format=json&" + "list=backlinks&formatversion=2&"; - private static String property = ""; - private static final String PROPERTY_URL = "bltitle=Property%3AP"; + private static final String PROPERTY_URL = "bltitle=Property%3A"; private static final String POST_URL = "&blnamespace=0&"; private static final String LIMIT = "bllimit="; - public static List getEntities(QuestionType type, int size) throws IOException{ - propertyFactory(type); + public static List getEntities(QuestionType type, int size, String property) throws IOException{ URL url = new URL(PRE_URL+PROPERTY_URL+property+POST_URL+LIMIT+size); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); @@ -44,29 +42,6 @@ public static List getEntities(QuestionType type, int size) throws IOExc return result; } - private static void propertyFactory(QuestionType type) { - switch (type) { - case CAPITAL: - property = "36"; - break; - case LANGUAGE: - property = "37"; - break; - case POPULATION: - property = "1082"; - break; - case SIZE: - property = "2046"; - break; - case HEAD_OF_GOVERMENT: - property = "6"; - break; - case DIRECTOR: - property = "57"; - break; - } - } - private static List extractEntities(String json){ List result = new ArrayList<>(); String[] entities = json.split("\"title\":"); diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java b/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java index bf749266..5f68ed44 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java @@ -46,7 +46,7 @@ private String getAnswer(String id) throws Exception{ public List getWrongAnswers(String rightAnswer) throws Exception { List entites = new ArrayList<>(); try { - entites = EntityGenerator.getEntities(type, 100); + entites = EntityGenerator.getEntities(type, 100, getPropertyId()); } catch (IOException e) { e.printStackTrace(); } From b59fe087c991867c0a430bb0b8e39e7d2a213748 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 14:50:11 +0200 Subject: [PATCH 21/78] Aumented the number of entites generated to reduce the number of errors --- .../src/main/java/questionGenerator/QuestionGenerator.java | 2 +- .../questionGenerator/generator/AbstractAnswersAreEntites.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index 01f92f15..66791f58 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -31,7 +31,7 @@ public List generateQuestions(QuestionType type, int amount){ List questions = new ArrayList<>(); List entites = new ArrayList<>(); try { - entites = EntityGenerator.getEntities(type, 100, generator.getPropertyId()); + entites = EntityGenerator.getEntities(type, 1000, generator.getPropertyId()); } catch (IOException e) { e.printStackTrace(); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java b/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java index 5f68ed44..87cdebcb 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java @@ -46,7 +46,7 @@ private String getAnswer(String id) throws Exception{ public List getWrongAnswers(String rightAnswer) throws Exception { List entites = new ArrayList<>(); try { - entites = EntityGenerator.getEntities(type, 100, getPropertyId()); + entites = EntityGenerator.getEntities(type, 1000, getPropertyId()); } catch (IOException e) { e.printStackTrace(); } From d65ca3183638b68759d95096103597a7ea06cacf Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 15:08:12 +0200 Subject: [PATCH 22/78] Restructured the generator package hierarchy --- .../java/questionGenerator/QuestionGenerator.java | 12 ++++++------ .../AbstractAnswersAreEntites.java | 3 ++- .../AnswersAreEntitiesWithSubProperties.java | 3 ++- .../withSubProperties}/CapitalGenerator.java | 3 +-- .../HeadOfGovernmentGenerator.java | 3 +-- .../withSubProperties}/LanguageGenerator.java | 3 +-- .../AnswersAreEntitiesWithoutSubProperties.java | 3 ++- .../withoutSubProperties}/DirectorGenerator.java | 3 +-- .../AnswersAreNotEntites.java | 4 ++-- .../PopulationGenerator.java | 3 +-- .../SizeGenerator.java | 3 +-- 11 files changed, 20 insertions(+), 23 deletions(-) rename questionGenerator/src/main/java/questionGenerator/generator/{ => answersAreEntites}/AbstractAnswersAreEntites.java (95%) rename questionGenerator/src/main/java/questionGenerator/generator/{ => answersAreEntites/withSubProperties}/AnswersAreEntitiesWithSubProperties.java (88%) rename questionGenerator/src/main/java/questionGenerator/generator/{specificGenerators => answersAreEntites/withSubProperties}/CapitalGenerator.java (73%) rename questionGenerator/src/main/java/questionGenerator/generator/{specificGenerators => answersAreEntites/withSubProperties}/HeadOfGovernmentGenerator.java (74%) rename questionGenerator/src/main/java/questionGenerator/generator/{specificGenerators => answersAreEntites/withSubProperties}/LanguageGenerator.java (83%) rename questionGenerator/src/main/java/questionGenerator/generator/{ => answersAreEntites/withoutSubProperties}/AnswersAreEntitiesWithoutSubProperties.java (86%) rename questionGenerator/src/main/java/questionGenerator/generator/{specificGenerators => answersAreEntites/withoutSubProperties}/DirectorGenerator.java (69%) rename questionGenerator/src/main/java/questionGenerator/generator/{ => answersAreNotEntites}/AnswersAreNotEntites.java (91%) rename questionGenerator/src/main/java/questionGenerator/generator/{specificGenerators => answersAreNotEntites}/PopulationGenerator.java (91%) rename questionGenerator/src/main/java/questionGenerator/generator/{specificGenerators => answersAreNotEntites}/SizeGenerator.java (90%) diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index 66791f58..aaa4981b 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -7,12 +7,12 @@ import main.java.questionGenerator.entityGenerator.EntityGenerator; import main.java.questionGenerator.generator.Generator; -import main.java.questionGenerator.generator.specificGenerators.CapitalGenerator; -import main.java.questionGenerator.generator.specificGenerators.DirectorGenerator; -import main.java.questionGenerator.generator.specificGenerators.HeadOfGovernmentGenerator; -import main.java.questionGenerator.generator.specificGenerators.LanguageGenerator; -import main.java.questionGenerator.generator.specificGenerators.PopulationGenerator; -import main.java.questionGenerator.generator.specificGenerators.SizeGenerator; +import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.CapitalGenerator; +import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.HeadOfGovernmentGenerator; +import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.LanguageGenerator; +import main.java.questionGenerator.generator.answersAreEntites.withoutSubProperties.DirectorGenerator; +import main.java.questionGenerator.generator.answersAreNotEntites.PopulationGenerator; +import main.java.questionGenerator.generator.answersAreNotEntites.SizeGenerator; import main.java.questionGenerator.question.Question; import main.java.questionGenerator.question.QuestionType; diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/AbstractAnswersAreEntites.java similarity index 95% rename from questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java rename to questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/AbstractAnswersAreEntites.java index 87cdebcb..33f20339 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AbstractAnswersAreEntites.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/AbstractAnswersAreEntites.java @@ -1,4 +1,4 @@ -package main.java.questionGenerator.generator; +package main.java.questionGenerator.generator.answersAreEntites; import java.io.IOException; import java.util.ArrayList; @@ -10,6 +10,7 @@ import org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException; import main.java.questionGenerator.entityGenerator.EntityGenerator; +import main.java.questionGenerator.generator.AbstractGenerator; import main.java.questionGenerator.question.QuestionType; diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/AnswersAreEntitiesWithSubProperties.java similarity index 88% rename from questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithSubProperties.java rename to questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/AnswersAreEntitiesWithSubProperties.java index 66bb47af..b78db818 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithSubProperties.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/AnswersAreEntitiesWithSubProperties.java @@ -1,4 +1,4 @@ -package main.java.questionGenerator.generator; +package main.java.questionGenerator.generator.answersAreEntites.withSubProperties; import java.util.List; import java.util.Map; @@ -7,6 +7,7 @@ import org.wikidata.wdtk.datamodel.interfaces.SnakGroup; import org.wikidata.wdtk.datamodel.interfaces.Statement; +import main.java.questionGenerator.generator.answersAreEntites.AbstractAnswersAreEntites; import main.java.questionGenerator.question.QuestionType; public abstract class AnswersAreEntitiesWithSubProperties extends AbstractAnswersAreEntites { diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/CapitalGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/CapitalGenerator.java similarity index 73% rename from questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/CapitalGenerator.java rename to questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/CapitalGenerator.java index 8ae71ccc..b1ecdf67 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/CapitalGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/CapitalGenerator.java @@ -1,6 +1,5 @@ -package main.java.questionGenerator.generator.specificGenerators; +package main.java.questionGenerator.generator.answersAreEntites.withSubProperties; -import main.java.questionGenerator.generator.AnswersAreEntitiesWithSubProperties; import main.java.questionGenerator.question.QuestionType; public class CapitalGenerator extends AnswersAreEntitiesWithSubProperties { diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/HeadOfGovernmentGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/HeadOfGovernmentGenerator.java similarity index 74% rename from questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/HeadOfGovernmentGenerator.java rename to questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/HeadOfGovernmentGenerator.java index 62839247..33818e4e 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/HeadOfGovernmentGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/HeadOfGovernmentGenerator.java @@ -1,6 +1,5 @@ -package main.java.questionGenerator.generator.specificGenerators; +package main.java.questionGenerator.generator.answersAreEntites.withSubProperties; -import main.java.questionGenerator.generator.AnswersAreEntitiesWithSubProperties; import main.java.questionGenerator.question.QuestionType; public class HeadOfGovernmentGenerator extends AnswersAreEntitiesWithSubProperties { diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/LanguageGenerator.java similarity index 83% rename from questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java rename to questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/LanguageGenerator.java index e4e31bf1..b43ad0b7 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/LanguageGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/LanguageGenerator.java @@ -1,8 +1,7 @@ -package main.java.questionGenerator.generator.specificGenerators; +package main.java.questionGenerator.generator.answersAreEntites.withSubProperties; import java.util.List; -import main.java.questionGenerator.generator.AnswersAreEntitiesWithSubProperties; import main.java.questionGenerator.question.QuestionType; import main.java.questionGenerator.question.answers.AnswerFormater; import main.java.questionGenerator.question.answers.formatAnswers.CapitalLetersFormater; diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/AnswersAreEntitiesWithoutSubProperties.java similarity index 86% rename from questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java rename to questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/AnswersAreEntitiesWithoutSubProperties.java index 39cb32fc..8eff8ff8 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreEntitiesWithoutSubProperties.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/AnswersAreEntitiesWithoutSubProperties.java @@ -1,10 +1,11 @@ -package main.java.questionGenerator.generator; +package main.java.questionGenerator.generator.answersAreEntites.withoutSubProperties; import java.util.List; import java.util.Map; import org.wikidata.wdtk.datamodel.interfaces.Statement; +import main.java.questionGenerator.generator.answersAreEntites.AbstractAnswersAreEntites; import main.java.questionGenerator.question.QuestionType; public abstract class AnswersAreEntitiesWithoutSubProperties extends AbstractAnswersAreEntites { diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/DirectorGenerator.java similarity index 69% rename from questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java rename to questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/DirectorGenerator.java index 04609671..4ca7a794 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/DirectorGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/DirectorGenerator.java @@ -1,6 +1,5 @@ -package main.java.questionGenerator.generator.specificGenerators; +package main.java.questionGenerator.generator.answersAreEntites.withoutSubProperties; -import main.java.questionGenerator.generator.AnswersAreEntitiesWithoutSubProperties; import main.java.questionGenerator.question.QuestionType; public class DirectorGenerator extends AnswersAreEntitiesWithoutSubProperties{ diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/AnswersAreNotEntites.java similarity index 91% rename from questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java rename to questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/AnswersAreNotEntites.java index 7b14459b..70d16c01 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AnswersAreNotEntites.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/AnswersAreNotEntites.java @@ -1,14 +1,14 @@ -package main.java.questionGenerator.generator; +package main.java.questionGenerator.generator.answersAreNotEntites; import java.util.ArrayList; import java.util.List; import java.util.Random; +import main.java.questionGenerator.generator.AbstractGenerator; import main.java.questionGenerator.question.QuestionType; public abstract class AnswersAreNotEntites extends AbstractGenerator{ - //Open to changes if needed. public AnswersAreNotEntites(String propertyId, QuestionType type, String message) { super(propertyId, type, message); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java similarity index 91% rename from questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java rename to questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java index 187a8617..2cf74a79 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/PopulationGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java @@ -1,4 +1,4 @@ -package main.java.questionGenerator.generator.specificGenerators; +package main.java.questionGenerator.generator.answersAreNotEntites; import java.util.ArrayList; import java.util.List; @@ -7,7 +7,6 @@ import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.Value; -import main.java.questionGenerator.generator.AnswersAreNotEntites; import main.java.questionGenerator.question.QuestionType; import main.java.questionGenerator.question.answers.AnswerFormater; import main.java.questionGenerator.question.answers.formatAnswers.EmbellishNumbersFormater; diff --git a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/SizeGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java similarity index 90% rename from questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/SizeGenerator.java rename to questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java index aa391d8c..24a40c44 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/specificGenerators/SizeGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java @@ -1,4 +1,4 @@ -package main.java.questionGenerator.generator.specificGenerators; +package main.java.questionGenerator.generator.answersAreNotEntites; import java.util.List; import java.util.Map; @@ -6,7 +6,6 @@ import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.Value; -import main.java.questionGenerator.generator.AnswersAreNotEntites; import main.java.questionGenerator.question.QuestionType; import main.java.questionGenerator.question.answers.AnswerFormater; import main.java.questionGenerator.question.answers.formatAnswers.EmbellishNumbersFormater; From bc4df3bd9e52f2f32a1eb3f6781940ebf48c2f74 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 15:11:14 +0200 Subject: [PATCH 23/78] Added the Director question type to the persistent main --- questionGenerator/src/main/java/PersistentMain.java | 1 + 1 file changed, 1 insertion(+) diff --git a/questionGenerator/src/main/java/PersistentMain.java b/questionGenerator/src/main/java/PersistentMain.java index b2ba554a..1d2525fd 100644 --- a/questionGenerator/src/main/java/PersistentMain.java +++ b/questionGenerator/src/main/java/PersistentMain.java @@ -43,6 +43,7 @@ private static List generateQuestions(QuestionGenerator qg) { questions.addAll(run(qg, QuestionType.POPULATION, 50)); questions.addAll(run(qg, QuestionType.SIZE, 50)); questions.addAll(run(qg, QuestionType.HEAD_OF_GOVERMENT, 50)); + questions.addAll(run(qg, QuestionType.DIRECTOR, 50)); return questions; } From 2f4e5d860938b18cfe56a9512fde96609b07f3ff Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 15:41:27 +0200 Subject: [PATCH 24/78] Added extra parameter to the getRightAnswer method --- .../java/questionGenerator/generator/AbstractGenerator.java | 2 +- .../src/main/java/questionGenerator/generator/Generator.java | 2 +- .../generator/answersAreEntites/AbstractAnswersAreEntites.java | 2 +- .../withSubProperties/AnswersAreEntitiesWithSubProperties.java | 2 +- .../AnswersAreEntitiesWithoutSubProperties.java | 2 +- .../generator/answersAreNotEntites/PopulationGenerator.java | 2 +- .../generator/answersAreNotEntites/SizeGenerator.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java index bdf7dbd2..a825165b 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java @@ -73,7 +73,7 @@ public Question generate(String id) throws Exception { String question = getQuestion(name, claims); //get the right answer - String rightAnswer = getRightAnswer(claims); + String rightAnswer = getRightAnswer(claims, propertyId); //get the wrong answers List answers = getWrongAnswers(rightAnswer); diff --git a/questionGenerator/src/main/java/questionGenerator/generator/Generator.java b/questionGenerator/src/main/java/questionGenerator/generator/Generator.java index 294566a6..2740d900 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/Generator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/Generator.java @@ -13,7 +13,7 @@ public interface Generator { String getQuestion(String name, Map> claims); - String getRightAnswer(Map> claims) throws Exception; + String getRightAnswer(Map> claims, String propertyId) throws Exception; List getWrongAnswers(String rightAnswer) throws Exception; diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/AbstractAnswersAreEntites.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/AbstractAnswersAreEntites.java index 33f20339..33c4032b 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/AbstractAnswersAreEntites.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/AbstractAnswersAreEntites.java @@ -40,7 +40,7 @@ private String getAnswer(String id) throws Exception{ return null; } } - return getRightAnswer(idi.getJsonClaims()); + return getRightAnswer(idi.getJsonClaims(), getPropertyId()); } @Override diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/AnswersAreEntitiesWithSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/AnswersAreEntitiesWithSubProperties.java index b78db818..adab4700 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/AnswersAreEntitiesWithSubProperties.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/AnswersAreEntitiesWithSubProperties.java @@ -20,7 +20,7 @@ public AnswersAreEntitiesWithSubProperties(String propertyId, QuestionType type, } @Override - public String getRightAnswer(Map> claims) throws Exception { + public String getRightAnswer(Map> claims, String propertyId) throws Exception { if(claims.get(super.getPropertyId())==null) { throw new Exception("Claims does not have the property " + super.getPropertyId()); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/AnswersAreEntitiesWithoutSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/AnswersAreEntitiesWithoutSubProperties.java index 8eff8ff8..e8b94049 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/AnswersAreEntitiesWithoutSubProperties.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/AnswersAreEntitiesWithoutSubProperties.java @@ -17,7 +17,7 @@ public AnswersAreEntitiesWithoutSubProperties(String propertyId, QuestionType ty } @Override - public String getRightAnswer(Map> claims) throws Exception { + public String getRightAnswer(Map> claims, String propertyId) throws Exception { if(claims.get(super.getPropertyId())==null) { throw new Exception("Claims does not have the property " + super.getPropertyId()); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java index 2cf74a79..39a848d2 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java @@ -21,7 +21,7 @@ public PopulationGenerator(){ } @Override - public String getRightAnswer(Map> claims) { + public String getRightAnswer(Map> claims, String propertyId) { List statements = claims.get(PROPERTY); Value v = statements.get(statements.size()-1).getValue(); return v.toString(); diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java index 24a40c44..28b6e112 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java @@ -21,7 +21,7 @@ public SizeGenerator() { } @Override - public String getRightAnswer(Map> claims) { + public String getRightAnswer(Map> claims, String propertyId) { Value v = claims.get(PROPERTY).get(0).getValue(); return getRightAnswerEntity(v.toString()); } From b5f6596b8b27cbd4c78132a43fb7e614c123550b Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 15:45:01 +0200 Subject: [PATCH 25/78] The new parameter is now properly used --- .../AnswersAreEntitiesWithSubProperties.java | 6 +++--- .../AnswersAreEntitiesWithoutSubProperties.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/AnswersAreEntitiesWithSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/AnswersAreEntitiesWithSubProperties.java index adab4700..e1a2badc 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/AnswersAreEntitiesWithSubProperties.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/AnswersAreEntitiesWithSubProperties.java @@ -21,11 +21,11 @@ public AnswersAreEntitiesWithSubProperties(String propertyId, QuestionType type, @Override public String getRightAnswer(Map> claims, String propertyId) throws Exception { - if(claims.get(super.getPropertyId())==null) { - throw new Exception("Claims does not have the property " + super.getPropertyId()); + if(claims.get(propertyId)==null) { + throw new Exception("Claims does not have the property " + propertyId); } - for(Statement st : claims.get(super.getPropertyId())) { + for(Statement st : claims.get(propertyId)) { boolean valid = true; for(SnakGroup sg : st.getQualifiers()) { for(Snak s : sg.getSnaks()) { diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/AnswersAreEntitiesWithoutSubProperties.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/AnswersAreEntitiesWithoutSubProperties.java index e8b94049..732befe4 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/AnswersAreEntitiesWithoutSubProperties.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/AnswersAreEntitiesWithoutSubProperties.java @@ -18,11 +18,11 @@ public AnswersAreEntitiesWithoutSubProperties(String propertyId, QuestionType ty @Override public String getRightAnswer(Map> claims, String propertyId) throws Exception { - if(claims.get(super.getPropertyId())==null) { - throw new Exception("Claims does not have the property " + super.getPropertyId()); + if(claims.get(propertyId)==null) { + throw new Exception("Claims does not have the property " + propertyId); } - List stms = claims.get(getPropertyId()); + List stms = claims.get(propertyId); Statement stm = stms.get(stms.size()-1); return processRightAnswer(stm); } From 31ec0e32ca4bb2e84bdb45af2af7ea7c8ae4ab86 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 15:55:26 +0200 Subject: [PATCH 26/78] Added the videogame developer generator --- questionGenerator/src/main/java/Main.java | 27 ++++++++++--------- .../questionGenerator/QuestionGenerator.java | 5 ++++ .../AbstractVideogameGenerator.java | 26 ++++++++++++++++++ .../VideogameDeveloperGenerator.java | 16 +++++++++++ .../question/QuestionType.java | 2 +- .../src/main/resources/messages.properties | 3 ++- .../src/main/resources/messages_en.properties | 3 ++- .../src/main/resources/messages_es.properties | 3 ++- 8 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/AbstractVideogameGenerator.java create mode 100644 questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameDeveloperGenerator.java diff --git a/questionGenerator/src/main/java/Main.java b/questionGenerator/src/main/java/Main.java index 22b2635d..a6a7a6c9 100644 --- a/questionGenerator/src/main/java/Main.java +++ b/questionGenerator/src/main/java/Main.java @@ -12,22 +12,25 @@ public class Main { public static void main(String[] args) { QuestionGenerator qg = new QuestionGenerator("en"); - run(qg, QuestionType.CAPITAL, 3); - System.out.println(); + // run(qg, QuestionType.CAPITAL, 3); + // System.out.println(); - run(qg, QuestionType.LANGUAGE, 3); - System.out.println(); + // run(qg, QuestionType.LANGUAGE, 3); + // System.out.println(); - run(qg, QuestionType.POPULATION, 3); - System.out.println(); + // run(qg, QuestionType.POPULATION, 3); + // System.out.println(); - run(qg, QuestionType.SIZE, 3); - System.out.println(); + // run(qg, QuestionType.SIZE, 3); + // System.out.println(); - run(qg, QuestionType.HEAD_OF_GOVERMENT, 3); - System.out.println(); + // run(qg, QuestionType.HEAD_OF_GOVERMENT, 3); + // System.out.println(); - run(qg, QuestionType.DIRECTOR, 3); + // run(qg, QuestionType.DIRECTOR, 3); + // System.out.println(); + + run(qg, QuestionType.VIDEOGAME_DEVELOPER, 3); } private static void run(QuestionGenerator qg, QuestionType type, int numberOfQuestions){ @@ -37,6 +40,6 @@ private static void run(QuestionGenerator qg, QuestionType type, int numberOfQue question.setNumber(i); System.out.println(question.getJSON().toString()); } - QuestionRepository.getInstance().insert(questions.stream().map(q -> q.getJSON().toString()).toList()); + // QuestionRepository.getInstance().insert(questions.stream().map(q -> q.getJSON().toString()).toList()); } } diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index aaa4981b..6616d252 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -10,6 +10,7 @@ import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.CapitalGenerator; import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.HeadOfGovernmentGenerator; import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.LanguageGenerator; +import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames.VideogameDeveloperGenerator; import main.java.questionGenerator.generator.answersAreEntites.withoutSubProperties.DirectorGenerator; import main.java.questionGenerator.generator.answersAreNotEntites.PopulationGenerator; import main.java.questionGenerator.generator.answersAreNotEntites.SizeGenerator; @@ -88,6 +89,10 @@ private void setGenerator(QuestionType type) { generator = new DirectorGenerator(); break; } + case VIDEOGAME_DEVELOPER: { + generator = new VideogameDeveloperGenerator(); + break; + } } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/AbstractVideogameGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/AbstractVideogameGenerator.java new file mode 100644 index 00000000..cfd8cf83 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/AbstractVideogameGenerator.java @@ -0,0 +1,26 @@ +package main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames; + +import java.util.List; +import java.util.Map; + +import org.wikidata.wdtk.datamodel.interfaces.Statement; + +import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.AnswersAreEntitiesWithSubProperties; +import main.java.questionGenerator.question.QuestionType; + +public abstract class AbstractVideogameGenerator extends AnswersAreEntitiesWithSubProperties{ + + private String realProperty; + + public AbstractVideogameGenerator(String propertyId, QuestionType type, String propertyToCheck, + String message, String realProperty) { + super(propertyId, type, propertyToCheck, message); + this.realProperty = realProperty; + } + + @Override + public String getRightAnswer(Map> claims, String propertyId) throws Exception { + return super.getRightAnswer(claims, realProperty); + } + +} diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameDeveloperGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameDeveloperGenerator.java new file mode 100644 index 00000000..9dbdd251 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameDeveloperGenerator.java @@ -0,0 +1,16 @@ +package main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames; + +import main.java.questionGenerator.question.QuestionType; + +public class VideogameDeveloperGenerator extends AbstractVideogameGenerator { + + private static final String PROPERTY = "P404"; + private static final String PROPERTY_TO_CHECK = "P2868"; + private static final String MESSAGE = "question.videogame.developer"; + private static final String REAL_PROPERTY = "P178"; + + public VideogameDeveloperGenerator() { + super(PROPERTY, QuestionType.VIDEOGAME_DEVELOPER, PROPERTY_TO_CHECK, MESSAGE, REAL_PROPERTY); + } + +} diff --git a/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java b/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java index 226e6e32..062eaa33 100644 --- a/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java +++ b/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java @@ -2,6 +2,6 @@ public enum QuestionType { - POPULATION, CAPITAL, SIZE, LANGUAGE, HEAD_OF_GOVERMENT, DIRECTOR; + POPULATION, CAPITAL, SIZE, LANGUAGE, HEAD_OF_GOVERMENT, DIRECTOR, VIDEOGAME_DEVELOPER; } diff --git a/questionGenerator/src/main/resources/messages.properties b/questionGenerator/src/main/resources/messages.properties index fc9a5dcf..4a18833c 100644 --- a/questionGenerator/src/main/resources/messages.properties +++ b/questionGenerator/src/main/resources/messages.properties @@ -3,4 +3,5 @@ question.language = What's the official language of %s? question.capital = What's the capital of %s? question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? -question.director = Who's the director of the %s %s? \ No newline at end of file +question.director = Who's the director of the %s %s? +question.videogame.developer = %s \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_en.properties b/questionGenerator/src/main/resources/messages_en.properties index fc9a5dcf..4a18833c 100644 --- a/questionGenerator/src/main/resources/messages_en.properties +++ b/questionGenerator/src/main/resources/messages_en.properties @@ -3,4 +3,5 @@ question.language = What's the official language of %s? question.capital = What's the capital of %s? question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? -question.director = Who's the director of the %s %s? \ No newline at end of file +question.director = Who's the director of the %s %s? +question.videogame.developer = %s \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_es.properties b/questionGenerator/src/main/resources/messages_es.properties index 8824c670..1fd174a6 100644 --- a/questionGenerator/src/main/resources/messages_es.properties +++ b/questionGenerator/src/main/resources/messages_es.properties @@ -3,4 +3,5 @@ question.language = ¿Cuál es el idioma oficial de %s? question.capital = ¿Cuál es la capital de %s? question.size = ¿Cuál es el área (km cuadrados) de %s? question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? -question.director = ¿Quién es el director de la %s %s? \ No newline at end of file +question.director = ¿Quién es el director de la %s %s? +question.videogame.developer = %s \ No newline at end of file From 55f709ed0a1ec197834d3da7945fcb60610b9ce1 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 15:55:47 +0200 Subject: [PATCH 27/78] Removed commented code --- questionGenerator/src/main/java/Main.java | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/questionGenerator/src/main/java/Main.java b/questionGenerator/src/main/java/Main.java index a6a7a6c9..0758c9b2 100644 --- a/questionGenerator/src/main/java/Main.java +++ b/questionGenerator/src/main/java/Main.java @@ -12,23 +12,23 @@ public class Main { public static void main(String[] args) { QuestionGenerator qg = new QuestionGenerator("en"); - // run(qg, QuestionType.CAPITAL, 3); - // System.out.println(); + run(qg, QuestionType.CAPITAL, 3); + System.out.println(); - // run(qg, QuestionType.LANGUAGE, 3); - // System.out.println(); + run(qg, QuestionType.LANGUAGE, 3); + System.out.println(); - // run(qg, QuestionType.POPULATION, 3); - // System.out.println(); + run(qg, QuestionType.POPULATION, 3); + System.out.println(); - // run(qg, QuestionType.SIZE, 3); - // System.out.println(); + run(qg, QuestionType.SIZE, 3); + System.out.println(); - // run(qg, QuestionType.HEAD_OF_GOVERMENT, 3); - // System.out.println(); + run(qg, QuestionType.HEAD_OF_GOVERMENT, 3); + System.out.println(); - // run(qg, QuestionType.DIRECTOR, 3); - // System.out.println(); + run(qg, QuestionType.DIRECTOR, 3); + System.out.println(); run(qg, QuestionType.VIDEOGAME_DEVELOPER, 3); } @@ -40,6 +40,6 @@ private static void run(QuestionGenerator qg, QuestionType type, int numberOfQue question.setNumber(i); System.out.println(question.getJSON().toString()); } - // QuestionRepository.getInstance().insert(questions.stream().map(q -> q.getJSON().toString()).toList()); + QuestionRepository.getInstance().insert(questions.stream().map(q -> q.getJSON().toString()).toList()); } } From a1985fa028ada6cfb285990b567ff9490a7cd7c9 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 15:57:06 +0200 Subject: [PATCH 28/78] Improved the questions for the videogame developer --- questionGenerator/src/main/resources/messages.properties | 2 +- questionGenerator/src/main/resources/messages_en.properties | 2 +- questionGenerator/src/main/resources/messages_es.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/questionGenerator/src/main/resources/messages.properties b/questionGenerator/src/main/resources/messages.properties index 4a18833c..296fcd6c 100644 --- a/questionGenerator/src/main/resources/messages.properties +++ b/questionGenerator/src/main/resources/messages.properties @@ -4,4 +4,4 @@ question.capital = What's the capital of %s? question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? question.director = Who's the director of the %s %s? -question.videogame.developer = %s \ No newline at end of file +question.videogame.developer = Who were the developers of %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_en.properties b/questionGenerator/src/main/resources/messages_en.properties index 4a18833c..296fcd6c 100644 --- a/questionGenerator/src/main/resources/messages_en.properties +++ b/questionGenerator/src/main/resources/messages_en.properties @@ -4,4 +4,4 @@ question.capital = What's the capital of %s? question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? question.director = Who's the director of the %s %s? -question.videogame.developer = %s \ No newline at end of file +question.videogame.developer = Who were the developers of %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_es.properties b/questionGenerator/src/main/resources/messages_es.properties index 1fd174a6..06decd6b 100644 --- a/questionGenerator/src/main/resources/messages_es.properties +++ b/questionGenerator/src/main/resources/messages_es.properties @@ -4,4 +4,4 @@ question.capital = ¿Cuál es la capital de %s? question.size = ¿Cuál es el área (km cuadrados) de %s? question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? question.director = ¿Quién es el director de la %s %s? -question.videogame.developer = %s \ No newline at end of file +question.videogame.developer = ¿Quién desarolló %s? \ No newline at end of file From f9418a158f1cfb25a34265e72d247c6af7560009 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 17:04:14 +0200 Subject: [PATCH 29/78] Added the videogame publisher generator --- questionGenerator/src/main/java/Main.java | 9 +++------ .../java/questionGenerator/QuestionGenerator.java | 5 +++++ .../videogames/VideogamePublisherGenerator.java | 15 +++++++++++++++ .../questionGenerator/question/QuestionType.java | 3 ++- .../src/main/resources/messages.properties | 3 ++- .../src/main/resources/messages_en.properties | 3 ++- .../src/main/resources/messages_es.properties | 3 ++- 7 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogamePublisherGenerator.java diff --git a/questionGenerator/src/main/java/Main.java b/questionGenerator/src/main/java/Main.java index 0758c9b2..56335a82 100644 --- a/questionGenerator/src/main/java/Main.java +++ b/questionGenerator/src/main/java/Main.java @@ -13,24 +13,20 @@ public static void main(String[] args) { QuestionGenerator qg = new QuestionGenerator("en"); run(qg, QuestionType.CAPITAL, 3); - System.out.println(); run(qg, QuestionType.LANGUAGE, 3); - System.out.println(); run(qg, QuestionType.POPULATION, 3); - System.out.println(); run(qg, QuestionType.SIZE, 3); - System.out.println(); run(qg, QuestionType.HEAD_OF_GOVERMENT, 3); - System.out.println(); run(qg, QuestionType.DIRECTOR, 3); - System.out.println(); run(qg, QuestionType.VIDEOGAME_DEVELOPER, 3); + + run(qg, QuestionType.VIDEOGAME_PUBLISHER, 3); } private static void run(QuestionGenerator qg, QuestionType type, int numberOfQuestions){ @@ -40,6 +36,7 @@ private static void run(QuestionGenerator qg, QuestionType type, int numberOfQue question.setNumber(i); System.out.println(question.getJSON().toString()); } + System.out.println(); QuestionRepository.getInstance().insert(questions.stream().map(q -> q.getJSON().toString()).toList()); } } diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index 6616d252..56270d19 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -11,6 +11,7 @@ import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.HeadOfGovernmentGenerator; import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.LanguageGenerator; import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames.VideogameDeveloperGenerator; +import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames.VideogamePublisherGenerator; import main.java.questionGenerator.generator.answersAreEntites.withoutSubProperties.DirectorGenerator; import main.java.questionGenerator.generator.answersAreNotEntites.PopulationGenerator; import main.java.questionGenerator.generator.answersAreNotEntites.SizeGenerator; @@ -93,6 +94,10 @@ private void setGenerator(QuestionType type) { generator = new VideogameDeveloperGenerator(); break; } + case VIDEOGAME_PUBLISHER: { + generator = new VideogamePublisherGenerator(); + break; + } } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogamePublisherGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogamePublisherGenerator.java new file mode 100644 index 00000000..fc95f166 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogamePublisherGenerator.java @@ -0,0 +1,15 @@ +package main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames; + +import main.java.questionGenerator.question.QuestionType; + +public class VideogamePublisherGenerator extends AbstractVideogameGenerator { + + private static final String PROPERTY = "P404"; + private static final String PROPERTY_TO_CHECK = "P2868"; + private static final String MESSAGE = "question.videogame.publisher"; + private static final String REAL_PROPERTY = "P123"; + + public VideogamePublisherGenerator() { + super(PROPERTY, QuestionType.VIDEOGAME_DEVELOPER, PROPERTY_TO_CHECK, MESSAGE, REAL_PROPERTY); + } +} diff --git a/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java b/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java index 062eaa33..845bab52 100644 --- a/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java +++ b/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java @@ -2,6 +2,7 @@ public enum QuestionType { - POPULATION, CAPITAL, SIZE, LANGUAGE, HEAD_OF_GOVERMENT, DIRECTOR, VIDEOGAME_DEVELOPER; + POPULATION, CAPITAL, SIZE, LANGUAGE, HEAD_OF_GOVERMENT, DIRECTOR, VIDEOGAME_DEVELOPER, + VIDEOGAME_PUBLISHER; } diff --git a/questionGenerator/src/main/resources/messages.properties b/questionGenerator/src/main/resources/messages.properties index 296fcd6c..8fbf4590 100644 --- a/questionGenerator/src/main/resources/messages.properties +++ b/questionGenerator/src/main/resources/messages.properties @@ -4,4 +4,5 @@ question.capital = What's the capital of %s? question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? question.director = Who's the director of the %s %s? -question.videogame.developer = Who were the developers of %s? \ No newline at end of file +question.videogame.developer = Who were the developers of %s? +question.videogame.publisher = Who was the publisher of %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_en.properties b/questionGenerator/src/main/resources/messages_en.properties index 296fcd6c..8fbf4590 100644 --- a/questionGenerator/src/main/resources/messages_en.properties +++ b/questionGenerator/src/main/resources/messages_en.properties @@ -4,4 +4,5 @@ question.capital = What's the capital of %s? question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? question.director = Who's the director of the %s %s? -question.videogame.developer = Who were the developers of %s? \ No newline at end of file +question.videogame.developer = Who were the developers of %s? +question.videogame.publisher = Who was the publisher of %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_es.properties b/questionGenerator/src/main/resources/messages_es.properties index 06decd6b..4ce90dae 100644 --- a/questionGenerator/src/main/resources/messages_es.properties +++ b/questionGenerator/src/main/resources/messages_es.properties @@ -4,4 +4,5 @@ question.capital = ¿Cuál es la capital de %s? question.size = ¿Cuál es el área (km cuadrados) de %s? question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? question.director = ¿Quién es el director de la %s %s? -question.videogame.developer = ¿Quién desarolló %s? \ No newline at end of file +question.videogame.developer = ¿Quién desarolló %s? +question.videogame.publisher = ¿Cuál fue la distribuidora del videojuego %s? \ No newline at end of file From c414f65acfe61d0c0f7f7501ed15290cf19b8dc2 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 17:05:20 +0200 Subject: [PATCH 30/78] Improved the questions of the videogames generators --- questionGenerator/src/main/resources/messages.properties | 4 ++-- questionGenerator/src/main/resources/messages_en.properties | 4 ++-- questionGenerator/src/main/resources/messages_es.properties | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/questionGenerator/src/main/resources/messages.properties b/questionGenerator/src/main/resources/messages.properties index 8fbf4590..cea3fa0a 100644 --- a/questionGenerator/src/main/resources/messages.properties +++ b/questionGenerator/src/main/resources/messages.properties @@ -4,5 +4,5 @@ question.capital = What's the capital of %s? question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? question.director = Who's the director of the %s %s? -question.videogame.developer = Who were the developers of %s? -question.videogame.publisher = Who was the publisher of %s? \ No newline at end of file +question.videogame.developer = Who were the developers of the videogame %s? +question.videogame.publisher = Who was the publisher of the videogame %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_en.properties b/questionGenerator/src/main/resources/messages_en.properties index 8fbf4590..cea3fa0a 100644 --- a/questionGenerator/src/main/resources/messages_en.properties +++ b/questionGenerator/src/main/resources/messages_en.properties @@ -4,5 +4,5 @@ question.capital = What's the capital of %s? question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? question.director = Who's the director of the %s %s? -question.videogame.developer = Who were the developers of %s? -question.videogame.publisher = Who was the publisher of %s? \ No newline at end of file +question.videogame.developer = Who were the developers of the videogame %s? +question.videogame.publisher = Who was the publisher of the videogame %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_es.properties b/questionGenerator/src/main/resources/messages_es.properties index 4ce90dae..bca648f4 100644 --- a/questionGenerator/src/main/resources/messages_es.properties +++ b/questionGenerator/src/main/resources/messages_es.properties @@ -4,5 +4,5 @@ question.capital = ¿Cuál es la capital de %s? question.size = ¿Cuál es el área (km cuadrados) de %s? question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? question.director = ¿Quién es el director de la %s %s? -question.videogame.developer = ¿Quién desarolló %s? +question.videogame.developer = ¿Quién desarolló el videojuego %s? question.videogame.publisher = ¿Cuál fue la distribuidora del videojuego %s? \ No newline at end of file From 463ec802f36dc0a98cf9a4951d17de9022ff3ba6 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 17:22:04 +0200 Subject: [PATCH 31/78] Added the videogame genre generator --- questionGenerator/src/main/java/Main.java | 9 ++----- .../questionGenerator/QuestionGenerator.java | 5 ++++ .../videogames/VideogameGenreGenerator.java | 25 +++++++++++++++++++ .../question/QuestionType.java | 2 +- .../src/main/resources/messages.properties | 3 ++- .../src/main/resources/messages_en.properties | 3 ++- .../src/main/resources/messages_es.properties | 3 ++- 7 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameGenreGenerator.java diff --git a/questionGenerator/src/main/java/Main.java b/questionGenerator/src/main/java/Main.java index 56335a82..04a6c1a8 100644 --- a/questionGenerator/src/main/java/Main.java +++ b/questionGenerator/src/main/java/Main.java @@ -13,20 +13,15 @@ public static void main(String[] args) { QuestionGenerator qg = new QuestionGenerator("en"); run(qg, QuestionType.CAPITAL, 3); - run(qg, QuestionType.LANGUAGE, 3); - run(qg, QuestionType.POPULATION, 3); - run(qg, QuestionType.SIZE, 3); - run(qg, QuestionType.HEAD_OF_GOVERMENT, 3); - run(qg, QuestionType.DIRECTOR, 3); - run(qg, QuestionType.VIDEOGAME_DEVELOPER, 3); - run(qg, QuestionType.VIDEOGAME_PUBLISHER, 3); + run(qg, QuestionType.VIDEOGAME_GENRE, 3); + } private static void run(QuestionGenerator qg, QuestionType type, int numberOfQuestions){ diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index 56270d19..7a3a8a0d 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -11,6 +11,7 @@ import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.HeadOfGovernmentGenerator; import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.LanguageGenerator; import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames.VideogameDeveloperGenerator; +import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames.VideogameGenreGenerator; import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames.VideogamePublisherGenerator; import main.java.questionGenerator.generator.answersAreEntites.withoutSubProperties.DirectorGenerator; import main.java.questionGenerator.generator.answersAreNotEntites.PopulationGenerator; @@ -98,6 +99,10 @@ private void setGenerator(QuestionType type) { generator = new VideogamePublisherGenerator(); break; } + case VIDEOGAME_GENRE: { + generator = new VideogameGenreGenerator(); + break; + } } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameGenreGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameGenreGenerator.java new file mode 100644 index 00000000..1fe18ed0 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameGenreGenerator.java @@ -0,0 +1,25 @@ +package main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames; + +import java.util.List; + +import main.java.questionGenerator.question.QuestionType; +import main.java.questionGenerator.question.answers.AnswerFormater; +import main.java.questionGenerator.question.answers.formatAnswers.CapitalLetersFormater; + +public class VideogameGenreGenerator extends AbstractVideogameGenerator { + + private static final String PROPERTY = "P404"; + private static final String PROPERTY_TO_CHECK = "P2868"; + private static final String MESSAGE = "question.videogame.genre"; + private static final String REAL_PROPERTY = "P136"; + + public VideogameGenreGenerator() { + super(PROPERTY, QuestionType.VIDEOGAME_DEVELOPER, PROPERTY_TO_CHECK, MESSAGE, REAL_PROPERTY); + } + + @Override + public List decorateAnswers(List answers) { + AnswerFormater formater = new CapitalLetersFormater(); + return formater.format(answers); + } +} diff --git a/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java b/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java index 845bab52..0dd59db0 100644 --- a/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java +++ b/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java @@ -3,6 +3,6 @@ public enum QuestionType { POPULATION, CAPITAL, SIZE, LANGUAGE, HEAD_OF_GOVERMENT, DIRECTOR, VIDEOGAME_DEVELOPER, - VIDEOGAME_PUBLISHER; + VIDEOGAME_PUBLISHER, VIDEOGAME_GENRE; } diff --git a/questionGenerator/src/main/resources/messages.properties b/questionGenerator/src/main/resources/messages.properties index cea3fa0a..a385eb59 100644 --- a/questionGenerator/src/main/resources/messages.properties +++ b/questionGenerator/src/main/resources/messages.properties @@ -5,4 +5,5 @@ question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? question.director = Who's the director of the %s %s? question.videogame.developer = Who were the developers of the videogame %s? -question.videogame.publisher = Who was the publisher of the videogame %s? \ No newline at end of file +question.videogame.publisher = Who was the publisher of the videogame %s? +question.videogame.genre = What's the genre of the videogame %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_en.properties b/questionGenerator/src/main/resources/messages_en.properties index cea3fa0a..a385eb59 100644 --- a/questionGenerator/src/main/resources/messages_en.properties +++ b/questionGenerator/src/main/resources/messages_en.properties @@ -5,4 +5,5 @@ question.size = What's the size of %s? question.governmentHead = Who's the current head of the government of %s? question.director = Who's the director of the %s %s? question.videogame.developer = Who were the developers of the videogame %s? -question.videogame.publisher = Who was the publisher of the videogame %s? \ No newline at end of file +question.videogame.publisher = Who was the publisher of the videogame %s? +question.videogame.genre = What's the genre of the videogame %s? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_es.properties b/questionGenerator/src/main/resources/messages_es.properties index bca648f4..f20f9bd7 100644 --- a/questionGenerator/src/main/resources/messages_es.properties +++ b/questionGenerator/src/main/resources/messages_es.properties @@ -5,4 +5,5 @@ question.size = ¿Cuál es el área (km cuadrados) de %s? question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? question.director = ¿Quién es el director de la %s %s? question.videogame.developer = ¿Quién desarolló el videojuego %s? -question.videogame.publisher = ¿Cuál fue la distribuidora del videojuego %s? \ No newline at end of file +question.videogame.publisher = ¿Cuál fue la distribuidora del videojuego %s? +question.videogame.genre = ¿Cuál es el género del videojuego %s? \ No newline at end of file From 636661bed394cd57ba6644745d8000cd679dc09e Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 17:26:52 +0200 Subject: [PATCH 32/78] The persistent main now can generate questions for the videogames types --- questionGenerator/src/main/java/PersistentMain.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/questionGenerator/src/main/java/PersistentMain.java b/questionGenerator/src/main/java/PersistentMain.java index 1d2525fd..a8d4605d 100644 --- a/questionGenerator/src/main/java/PersistentMain.java +++ b/questionGenerator/src/main/java/PersistentMain.java @@ -44,6 +44,9 @@ private static List generateQuestions(QuestionGenerator qg) { questions.addAll(run(qg, QuestionType.SIZE, 50)); questions.addAll(run(qg, QuestionType.HEAD_OF_GOVERMENT, 50)); questions.addAll(run(qg, QuestionType.DIRECTOR, 50)); + questions.addAll(run(qg, QuestionType.VIDEOGAME_DEVELOPER, 50)); + questions.addAll(run(qg, QuestionType.VIDEOGAME_PUBLISHER, 50)); + questions.addAll(run(qg, QuestionType.VIDEOGAME_GENRE, 50)); return questions; } From 75f697770b51ab73a2684024873a8f711b5fa493 Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 17:32:55 +0200 Subject: [PATCH 33/78] Improved the persistent main --- .../src/main/java/PersistentMain.java | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/questionGenerator/src/main/java/PersistentMain.java b/questionGenerator/src/main/java/PersistentMain.java index a8d4605d..75e46329 100644 --- a/questionGenerator/src/main/java/PersistentMain.java +++ b/questionGenerator/src/main/java/PersistentMain.java @@ -16,6 +16,15 @@ public class PersistentMain { private static QuestionGenerator[] generators = {new QuestionGenerator("en"), new QuestionGenerator("es")}; + private static QuestionType[] types = {QuestionType.CAPITAL, QuestionType.LANGUAGE, QuestionType.POPULATION, + QuestionType.SIZE, QuestionType.HEAD_OF_GOVERMENT, QuestionType.VIDEOGAME_DEVELOPER, + QuestionType.VIDEOGAME_PUBLISHER, QuestionType.VIDEOGAME_GENRE}; + + private static final int numberOfQuestions = 50; + // private static final int numberOfQuestions = 100; + // private static final int numberOfQuestions = 3; + // private static final int numberOfQuestions = 1; + public static void main(String[] args) { while(true) { List questions = generate(); @@ -25,28 +34,14 @@ public static void main(String[] args) { } catch (InterruptedException e) { e.printStackTrace(); } - } } private static List generate() { List questions = new ArrayList(); for(QuestionGenerator qg : generators) - questions.addAll(generateQuestions(qg)); - return questions; - } - - private static List generateQuestions(QuestionGenerator qg) { - List questions = new ArrayList<>(); - questions.addAll(run(qg, QuestionType.CAPITAL, 50)); - questions.addAll(run(qg, QuestionType.LANGUAGE, 50)); - questions.addAll(run(qg, QuestionType.POPULATION, 50)); - questions.addAll(run(qg, QuestionType.SIZE, 50)); - questions.addAll(run(qg, QuestionType.HEAD_OF_GOVERMENT, 50)); - questions.addAll(run(qg, QuestionType.DIRECTOR, 50)); - questions.addAll(run(qg, QuestionType.VIDEOGAME_DEVELOPER, 50)); - questions.addAll(run(qg, QuestionType.VIDEOGAME_PUBLISHER, 50)); - questions.addAll(run(qg, QuestionType.VIDEOGAME_GENRE, 50)); + for(QuestionType type: types) + questions.addAll(run(qg, type, numberOfQuestions)); return questions; } From e412d513e1359d18c953b4f996ee08627ea4e70a Mon Sep 17 00:00:00 2001 From: jorge Date: Thu, 18 Apr 2024 18:57:18 +0200 Subject: [PATCH 34/78] Introduced the transaction logic in the persistent main and repository --- .../src/main/java/PersistentMain.java | 2 +- .../repository/QuestionRepository.java | 33 ++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/questionGenerator/src/main/java/PersistentMain.java b/questionGenerator/src/main/java/PersistentMain.java index 75e46329..1244536a 100644 --- a/questionGenerator/src/main/java/PersistentMain.java +++ b/questionGenerator/src/main/java/PersistentMain.java @@ -27,7 +27,7 @@ public class PersistentMain { public static void main(String[] args) { while(true) { - List questions = generate(); + List questions = generate().stream().map(q -> q.getJSON().toString()).toList(); QuestionRepository.getInstance().populate(questions); try { Thread.sleep(timeSkip); diff --git a/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java b/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java index fa32dc03..bc6546c7 100644 --- a/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java +++ b/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java @@ -1,5 +1,6 @@ package main.java.questionGenerator.repository; +import com.mongodb.client.ClientSession; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoCollection; @@ -12,8 +13,6 @@ import org.bson.Document; -import main.java.questionGenerator.question.Question; - public class QuestionRepository { private static QuestionRepository questionRepository; @@ -78,9 +77,33 @@ public boolean removeAll() { } } - public boolean populate(List questions) { - // TODO Auto-generated method stub - return false; + public boolean populate(List questions) { + try (MongoClient mongoClient = MongoClients.create(dbConnectionString)) { + MongoDatabase database = mongoClient.getDatabase("questions"); + + ClientSession session = mongoClient.startSession(); + session.startTransaction(); + + MongoCollection collection = database.getCollection("questions"); + + collection.deleteMany(Document.parse("{}")); + + List documents = new ArrayList<>(); + for (String questionJSON : questions) { + documents.add(Document.parse(questionJSON)); + } + + collection.insertMany(session, documents); + + session.commitTransaction(); + session.close(); + + return true; + + } catch (Exception e) { + System.out.println(e); + return false; + } } From fa5d1e7bb4d5c6a62355246abb05d81937394548 Mon Sep 17 00:00:00 2001 From: jorge Date: Fri, 19 Apr 2024 11:48:28 +0200 Subject: [PATCH 35/78] Added the new Videogame country generator --- questionGenerator/src/main/java/Main.java | 1 + .../questionGenerator/QuestionGenerator.java | 5 +++++ .../videogames/VideogameCountryGenerator.java | 16 ++++++++++++++++ .../questionGenerator/question/QuestionType.java | 2 +- .../src/main/resources/messages.properties | 3 ++- .../src/main/resources/messages_en.properties | 3 ++- .../src/main/resources/messages_es.properties | 3 ++- 7 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameCountryGenerator.java diff --git a/questionGenerator/src/main/java/Main.java b/questionGenerator/src/main/java/Main.java index 04a6c1a8..1ecfa9a2 100644 --- a/questionGenerator/src/main/java/Main.java +++ b/questionGenerator/src/main/java/Main.java @@ -21,6 +21,7 @@ public static void main(String[] args) { run(qg, QuestionType.VIDEOGAME_DEVELOPER, 3); run(qg, QuestionType.VIDEOGAME_PUBLISHER, 3); run(qg, QuestionType.VIDEOGAME_GENRE, 3); + run(qg, QuestionType.VIDEOGAME_COUNTRY, 3); } diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index 7a3a8a0d..8d4b62d8 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -10,6 +10,7 @@ import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.CapitalGenerator; import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.HeadOfGovernmentGenerator; import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.LanguageGenerator; +import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames.VideogameCountryGenerator; import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames.VideogameDeveloperGenerator; import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames.VideogameGenreGenerator; import main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames.VideogamePublisherGenerator; @@ -103,6 +104,10 @@ private void setGenerator(QuestionType type) { generator = new VideogameGenreGenerator(); break; } + case VIDEOGAME_COUNTRY:{ + generator = new VideogameCountryGenerator(); + break; + } } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameCountryGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameCountryGenerator.java new file mode 100644 index 00000000..09f70c65 --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameCountryGenerator.java @@ -0,0 +1,16 @@ +package main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames; + +import main.java.questionGenerator.question.QuestionType; + +public class VideogameCountryGenerator extends AbstractVideogameGenerator { + + private static final String PROPERTY = "P404"; + private static final String PROPERTY_TO_CHECK = "P2868"; + private static final String MESSAGE = "question.videogame.country"; + private static final String REAL_PROPERTY = "P495"; + + public VideogameCountryGenerator() { + super(PROPERTY, QuestionType.VIDEOGAME_COUNTRY, PROPERTY_TO_CHECK, MESSAGE, REAL_PROPERTY); + } + +} \ No newline at end of file diff --git a/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java b/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java index 0dd59db0..28bb63f0 100644 --- a/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java +++ b/questionGenerator/src/main/java/questionGenerator/question/QuestionType.java @@ -3,6 +3,6 @@ public enum QuestionType { POPULATION, CAPITAL, SIZE, LANGUAGE, HEAD_OF_GOVERMENT, DIRECTOR, VIDEOGAME_DEVELOPER, - VIDEOGAME_PUBLISHER, VIDEOGAME_GENRE; + VIDEOGAME_PUBLISHER, VIDEOGAME_GENRE, VIDEOGAME_COUNTRY; } diff --git a/questionGenerator/src/main/resources/messages.properties b/questionGenerator/src/main/resources/messages.properties index a385eb59..07672d0f 100644 --- a/questionGenerator/src/main/resources/messages.properties +++ b/questionGenerator/src/main/resources/messages.properties @@ -6,4 +6,5 @@ question.governmentHead = Who's the current head of the government of %s? question.director = Who's the director of the %s %s? question.videogame.developer = Who were the developers of the videogame %s? question.videogame.publisher = Who was the publisher of the videogame %s? -question.videogame.genre = What's the genre of the videogame %s? \ No newline at end of file +question.videogame.genre = What's the genre of the videogame %s? +question.videogame.country = Which country is the videogame %s from? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_en.properties b/questionGenerator/src/main/resources/messages_en.properties index a385eb59..07672d0f 100644 --- a/questionGenerator/src/main/resources/messages_en.properties +++ b/questionGenerator/src/main/resources/messages_en.properties @@ -6,4 +6,5 @@ question.governmentHead = Who's the current head of the government of %s? question.director = Who's the director of the %s %s? question.videogame.developer = Who were the developers of the videogame %s? question.videogame.publisher = Who was the publisher of the videogame %s? -question.videogame.genre = What's the genre of the videogame %s? \ No newline at end of file +question.videogame.genre = What's the genre of the videogame %s? +question.videogame.country = Which country is the videogame %s from? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_es.properties b/questionGenerator/src/main/resources/messages_es.properties index f20f9bd7..7df0338f 100644 --- a/questionGenerator/src/main/resources/messages_es.properties +++ b/questionGenerator/src/main/resources/messages_es.properties @@ -6,4 +6,5 @@ question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? question.director = ¿Quién es el director de la %s %s? question.videogame.developer = ¿Quién desarolló el videojuego %s? question.videogame.publisher = ¿Cuál fue la distribuidora del videojuego %s? -question.videogame.genre = ¿Cuál es el género del videojuego %s? \ No newline at end of file +question.videogame.genre = ¿Cuál es el género del videojuego %s? +question.videogame.country = ¿De que país viene el videojuego %s? \ No newline at end of file From bcd23c5943ecc2ee56b9abfe17f48cccb6c137a0 Mon Sep 17 00:00:00 2001 From: jorge Date: Fri, 19 Apr 2024 16:15:20 +0200 Subject: [PATCH 36/78] Added the videogame country to the persistent main --- questionGenerator/src/main/java/PersistentMain.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/questionGenerator/src/main/java/PersistentMain.java b/questionGenerator/src/main/java/PersistentMain.java index 1244536a..b8678902 100644 --- a/questionGenerator/src/main/java/PersistentMain.java +++ b/questionGenerator/src/main/java/PersistentMain.java @@ -18,7 +18,7 @@ public class PersistentMain { private static QuestionType[] types = {QuestionType.CAPITAL, QuestionType.LANGUAGE, QuestionType.POPULATION, QuestionType.SIZE, QuestionType.HEAD_OF_GOVERMENT, QuestionType.VIDEOGAME_DEVELOPER, - QuestionType.VIDEOGAME_PUBLISHER, QuestionType.VIDEOGAME_GENRE}; + QuestionType.VIDEOGAME_PUBLISHER, QuestionType.VIDEOGAME_GENRE, QuestionType.VIDEOGAME_COUNTRY}; private static final int numberOfQuestions = 50; // private static final int numberOfQuestions = 100; From 97edb71c8bafc3c749a176153a6dbf3fcd74ee3d Mon Sep 17 00:00:00 2001 From: jorge Date: Fri, 19 Apr 2024 17:08:48 +0200 Subject: [PATCH 37/78] The Question Generator is now a singleton --- questionGenerator/src/main/java/Main.java | 2 +- .../src/main/java/PersistentMain.java | 10 ++++++++-- .../questionGenerator/QuestionGenerator.java | 20 +++++++++++++++++-- .../QuestionGeneratorTests.java | 18 +++++++---------- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/questionGenerator/src/main/java/Main.java b/questionGenerator/src/main/java/Main.java index 1ecfa9a2..62b4f474 100644 --- a/questionGenerator/src/main/java/Main.java +++ b/questionGenerator/src/main/java/Main.java @@ -10,7 +10,7 @@ public class Main { public static void main(String[] args) { - QuestionGenerator qg = new QuestionGenerator("en"); + QuestionGenerator qg = QuestionGenerator.getInstance(); run(qg, QuestionType.CAPITAL, 3); run(qg, QuestionType.LANGUAGE, 3); diff --git a/questionGenerator/src/main/java/PersistentMain.java b/questionGenerator/src/main/java/PersistentMain.java index b8678902..e93b67a5 100644 --- a/questionGenerator/src/main/java/PersistentMain.java +++ b/questionGenerator/src/main/java/PersistentMain.java @@ -10,11 +10,15 @@ public class PersistentMain { + private static QuestionGenerator qg = QuestionGenerator.getInstance(); + private static long timeSkip = 18000000; //5 hours // private static long timeSkip = 43200000; //12 hours // private static long timeSkip = 1000; //1 minute - private static QuestionGenerator[] generators = {new QuestionGenerator("en"), new QuestionGenerator("es")}; + // private static QuestionGenerator[] generators = {new QuestionGenerator("en"), new QuestionGenerator("es")}; + + private static String[] languages = {"en", "es"}; private static QuestionType[] types = {QuestionType.CAPITAL, QuestionType.LANGUAGE, QuestionType.POPULATION, QuestionType.SIZE, QuestionType.HEAD_OF_GOVERMENT, QuestionType.VIDEOGAME_DEVELOPER, @@ -39,9 +43,11 @@ public static void main(String[] args) { private static List generate() { List questions = new ArrayList(); - for(QuestionGenerator qg : generators) + for(String lang : languages) { + qg.setLanguageCode(lang); for(QuestionType type: types) questions.addAll(run(qg, type, numberOfQuestions)); + } return questions; } diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index 8d4b62d8..bf28df85 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -25,8 +25,16 @@ public class QuestionGenerator { private Generator generator; private String languageCode; - public QuestionGenerator(String languageCode){ - this.languageCode = languageCode; + private static QuestionGenerator questionGenerator; + + public static QuestionGenerator getInstance() { + if(questionGenerator==null) + questionGenerator = new QuestionGenerator(); + return questionGenerator; + } + + private QuestionGenerator() { + } public List generateQuestions(QuestionType type, int amount){ @@ -111,4 +119,12 @@ private void setGenerator(QuestionType type) { } } + public String getLanguageCode() { + return languageCode; + } + + public void setLanguageCode(String languageCode) { + this.languageCode = languageCode; + } + } diff --git a/questionGenerator/src/test/java/questionGenerator/QuestionGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/QuestionGeneratorTests.java index 67a6aa97..fcceef44 100644 --- a/questionGenerator/src/test/java/questionGenerator/QuestionGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/QuestionGeneratorTests.java @@ -13,7 +13,6 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import main.java.questionGenerator.QuestionGenerator; @@ -21,25 +20,20 @@ public class QuestionGeneratorTests { - private QuestionGenerator qgEN; - private QuestionGenerator qgES; + private QuestionGenerator qg = QuestionGenerator.getInstance(); private static QuestionType[] types = {QuestionType.POPULATION, QuestionType.CAPITAL, QuestionType.SIZE, QuestionType.LANGUAGE}; - @BeforeEach - void setUp(){ - qgEN = new QuestionGenerator("en"); - qgES = new QuestionGenerator("es"); - } - @Test void testGenerateQuestionsEnglish() { String question; + qg.setLanguageCode("en"); + for(QuestionType t : types) { for(int i=0; i<3; i++) { - question = qgEN.generateQuestions(t, 1).get(0).getJSON().toString(); + question = qg.generateQuestions(t, 1).get(0).getJSON().toString(); JSONObject json = null; //Check correct format @@ -96,9 +90,11 @@ void testGenerateQuestionsSpanish() { String question; + qg.setLanguageCode("es"); + for(QuestionType t : types) { for(int i=0; i<3; i++) { - question = qgES.generateQuestions(t, 1).get(0).getJSON().toString(); + question = qg.generateQuestions(t, 1).get(0).getJSON().toString(); JSONObject json = null; //Check correct format From b646455abf77bff0690ddc9378b39ee48f04875d Mon Sep 17 00:00:00 2001 From: jorge Date: Fri, 19 Apr 2024 17:20:53 +0200 Subject: [PATCH 38/78] Parametrized the number of entites generated --- .../java/questionGenerator/QuestionGenerator.java | 11 ++++++++++- .../entityGenerator/EntityGenerator.java | 2 +- .../generator/AbstractGenerator.java | 12 ++++++++++++ .../java/questionGenerator/generator/Generator.java | 4 ++++ .../answersAreEntites/AbstractAnswersAreEntites.java | 2 +- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index bf28df85..c4b692e5 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -40,10 +40,12 @@ private QuestionGenerator() { public List generateQuestions(QuestionType type, int amount){ setGenerator(type); generator.setLocalization(languageCode); + long sampleSize = getSampleSize(amount); + generator.setSampleSize(sampleSize); List questions = new ArrayList<>(); List entites = new ArrayList<>(); try { - entites = EntityGenerator.getEntities(type, 1000, generator.getPropertyId()); + entites = EntityGenerator.getEntities(type, sampleSize, generator.getPropertyId()); } catch (IOException e) { e.printStackTrace(); } @@ -127,4 +129,11 @@ public void setLanguageCode(String languageCode) { this.languageCode = languageCode; } + private long getSampleSize(int amount) { + long value = amount * 10; + if(value<1000) + return 1000; + return value; + } + } diff --git a/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java b/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java index 0c6541c0..9e43a4a4 100644 --- a/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/entityGenerator/EntityGenerator.java @@ -21,7 +21,7 @@ public class EntityGenerator { private static final String LIMIT = "bllimit="; - public static List getEntities(QuestionType type, int size, String property) throws IOException{ + public static List getEntities(QuestionType type, long size, String property) throws IOException{ URL url = new URL(PRE_URL+PROPERTY_URL+property+POST_URL+LIMIT+size); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java index a825165b..f667d176 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java @@ -33,6 +33,8 @@ public abstract class AbstractGenerator implements Generator { private String message; + private long sampleSize = 0L; + public AbstractGenerator(String propertyId, QuestionType type, String message) { this.propertyId = propertyId; this.type = type; @@ -142,5 +144,15 @@ private void localize(String languageCode) { public String getMessage(){ return message; } + + @Override + public void setSampleSize(long sampleSize) { + this.sampleSize = sampleSize; + } + + @Override + public long getSampleSize() { + return sampleSize; + } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/Generator.java b/questionGenerator/src/main/java/questionGenerator/generator/Generator.java index 2740d900..e4bce495 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/Generator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/Generator.java @@ -23,4 +23,8 @@ public interface Generator { void setLocalization(String languageCode); + void setSampleSize(long sampleSize); + + long getSampleSize(); + } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/AbstractAnswersAreEntites.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/AbstractAnswersAreEntites.java index 33c4032b..963104e7 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/AbstractAnswersAreEntites.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/AbstractAnswersAreEntites.java @@ -47,7 +47,7 @@ private String getAnswer(String id) throws Exception{ public List getWrongAnswers(String rightAnswer) throws Exception { List entites = new ArrayList<>(); try { - entites = EntityGenerator.getEntities(type, 1000, getPropertyId()); + entites = EntityGenerator.getEntities(type, getSampleSize(), getPropertyId()); } catch (IOException e) { e.printStackTrace(); } From 16146c0b47799abc997643fc9d22ef738df3a948 Mon Sep 17 00:00:00 2001 From: jorge Date: Fri, 19 Apr 2024 17:23:30 +0200 Subject: [PATCH 39/78] Improved the question message in the videogame genre question --- questionGenerator/src/main/resources/messages.properties | 2 +- questionGenerator/src/main/resources/messages_en.properties | 2 +- questionGenerator/src/main/resources/messages_es.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/questionGenerator/src/main/resources/messages.properties b/questionGenerator/src/main/resources/messages.properties index 07672d0f..d9837ebb 100644 --- a/questionGenerator/src/main/resources/messages.properties +++ b/questionGenerator/src/main/resources/messages.properties @@ -6,5 +6,5 @@ question.governmentHead = Who's the current head of the government of %s? question.director = Who's the director of the %s %s? question.videogame.developer = Who were the developers of the videogame %s? question.videogame.publisher = Who was the publisher of the videogame %s? -question.videogame.genre = What's the genre of the videogame %s? +question.videogame.genre = What's the main genre of the videogame %s? question.videogame.country = Which country is the videogame %s from? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_en.properties b/questionGenerator/src/main/resources/messages_en.properties index 07672d0f..d9837ebb 100644 --- a/questionGenerator/src/main/resources/messages_en.properties +++ b/questionGenerator/src/main/resources/messages_en.properties @@ -6,5 +6,5 @@ question.governmentHead = Who's the current head of the government of %s? question.director = Who's the director of the %s %s? question.videogame.developer = Who were the developers of the videogame %s? question.videogame.publisher = Who was the publisher of the videogame %s? -question.videogame.genre = What's the genre of the videogame %s? +question.videogame.genre = What's the main genre of the videogame %s? question.videogame.country = Which country is the videogame %s from? \ No newline at end of file diff --git a/questionGenerator/src/main/resources/messages_es.properties b/questionGenerator/src/main/resources/messages_es.properties index 7df0338f..9648fc81 100644 --- a/questionGenerator/src/main/resources/messages_es.properties +++ b/questionGenerator/src/main/resources/messages_es.properties @@ -6,5 +6,5 @@ question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? question.director = ¿Quién es el director de la %s %s? question.videogame.developer = ¿Quién desarolló el videojuego %s? question.videogame.publisher = ¿Cuál fue la distribuidora del videojuego %s? -question.videogame.genre = ¿Cuál es el género del videojuego %s? +question.videogame.genre = ¿Cuál es el género principal del videojuego %s? question.videogame.country = ¿De que país viene el videojuego %s? \ No newline at end of file From 248b0294e6b7cf67b39f4902de742e1f7db4a326 Mon Sep 17 00:00:00 2001 From: jorge Date: Fri, 19 Apr 2024 18:26:40 +0200 Subject: [PATCH 40/78] Improved the usage of the decorator pattern --- .../withSubProperties/LanguageGenerator.java | 2 +- .../videogames/VideogameGenreGenerator.java | 2 +- .../PopulationGenerator.java | 2 +- .../answersAreNotEntites/SizeGenerator.java | 4 ++- .../question/answers/AbstractFormater.java | 19 ++++++++++++++ .../question/answers/AnswerFormater.java | 2 ++ .../formatAnswers/AddUnitsFormater.java | 26 +++++++++++++++++++ .../formatAnswers/CapitalLetersFormater.java | 9 +++++-- .../EmbellishNumbersFormater.java | 9 +++++-- .../formatAnswers/RemoveEFromNumber.java | 9 +++---- 10 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 questionGenerator/src/main/java/questionGenerator/question/answers/AbstractFormater.java create mode 100644 questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/AddUnitsFormater.java diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/LanguageGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/LanguageGenerator.java index b43ad0b7..b5e5282e 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/LanguageGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/LanguageGenerator.java @@ -18,7 +18,7 @@ public LanguageGenerator(){ @Override public List decorateAnswers(List answers) { - AnswerFormater formater = new CapitalLetersFormater(); + AnswerFormater formater = new CapitalLetersFormater(null); return formater.format(answers); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameGenreGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameGenreGenerator.java index 1fe18ed0..fd3871e5 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameGenreGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameGenreGenerator.java @@ -19,7 +19,7 @@ public VideogameGenreGenerator() { @Override public List decorateAnswers(List answers) { - AnswerFormater formater = new CapitalLetersFormater(); + AnswerFormater formater = new CapitalLetersFormater(null); return formater.format(answers); } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java index 39a848d2..e08b4cf6 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java @@ -29,7 +29,7 @@ public String getRightAnswer(Map> claims, String propert @Override public List decorateAnswers(List answers) { - AnswerFormater formater = new EmbellishNumbersFormater(); + AnswerFormater formater = new EmbellishNumbersFormater(null); return formater.format(answers); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java index 28b6e112..4b186112 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java @@ -8,6 +8,7 @@ import main.java.questionGenerator.question.QuestionType; import main.java.questionGenerator.question.answers.AnswerFormater; +import main.java.questionGenerator.question.answers.formatAnswers.AddUnitsFormater; import main.java.questionGenerator.question.answers.formatAnswers.EmbellishNumbersFormater; import main.java.questionGenerator.question.answers.formatAnswers.RemoveEFromNumber; @@ -34,7 +35,8 @@ private String getRightAnswerEntity(String url) { @Override public List decorateAnswers(List answers) { - AnswerFormater formater = new RemoveEFromNumber(new EmbellishNumbersFormater()); + AnswerFormater formater = new RemoveEFromNumber(new EmbellishNumbersFormater( + new AddUnitsFormater(null, "km^2"))); return formater.format(answers); } diff --git a/questionGenerator/src/main/java/questionGenerator/question/answers/AbstractFormater.java b/questionGenerator/src/main/java/questionGenerator/question/answers/AbstractFormater.java new file mode 100644 index 00000000..a977174b --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/question/answers/AbstractFormater.java @@ -0,0 +1,19 @@ +package main.java.questionGenerator.question.answers; + +import java.util.List; + +public abstract class AbstractFormater implements AnswerFormater{ + + private AnswerFormater formater; + + public AbstractFormater(AnswerFormater formater){ + this.formater = formater; + } + + public List end(List answers){ + if(formater!=null) + return formater.format(answers); + return answers; + } + +} diff --git a/questionGenerator/src/main/java/questionGenerator/question/answers/AnswerFormater.java b/questionGenerator/src/main/java/questionGenerator/question/answers/AnswerFormater.java index 4258f266..f320907d 100644 --- a/questionGenerator/src/main/java/questionGenerator/question/answers/AnswerFormater.java +++ b/questionGenerator/src/main/java/questionGenerator/question/answers/AnswerFormater.java @@ -6,4 +6,6 @@ public interface AnswerFormater { List format(List answers); + List end(List answers); + } diff --git a/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/AddUnitsFormater.java b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/AddUnitsFormater.java new file mode 100644 index 00000000..899fe9ae --- /dev/null +++ b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/AddUnitsFormater.java @@ -0,0 +1,26 @@ +package main.java.questionGenerator.question.answers.formatAnswers; + +import java.util.ArrayList; +import java.util.List; + +import main.java.questionGenerator.question.answers.AbstractFormater; +import main.java.questionGenerator.question.answers.AnswerFormater; + +public class AddUnitsFormater extends AbstractFormater { + + private String unit; + + public AddUnitsFormater(AnswerFormater formater, String unit) { + super(formater); + this.unit = unit; + } + + @Override + public List format(List answers) { + List result = new ArrayList(); + for(String s : answers) + result.add(s +" " + unit); + return end(result); + } + +} diff --git a/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/CapitalLetersFormater.java b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/CapitalLetersFormater.java index edb5e384..156c867b 100644 --- a/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/CapitalLetersFormater.java +++ b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/CapitalLetersFormater.java @@ -3,9 +3,14 @@ import java.util.ArrayList; import java.util.List; +import main.java.questionGenerator.question.answers.AbstractFormater; import main.java.questionGenerator.question.answers.AnswerFormater; -public class CapitalLetersFormater implements AnswerFormater { +public class CapitalLetersFormater extends AbstractFormater { + + public CapitalLetersFormater(AnswerFormater formater) { + super(formater); + } @Override public List format(List answers) { @@ -13,7 +18,7 @@ public List format(List answers) { for(String s : answers) { result.add(toUppercaseFirstCharacter(s)); } - return result; + return end(result); } diff --git a/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/EmbellishNumbersFormater.java b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/EmbellishNumbersFormater.java index ca9c6d9c..d07e30e2 100644 --- a/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/EmbellishNumbersFormater.java +++ b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/EmbellishNumbersFormater.java @@ -4,8 +4,13 @@ import java.util.List; import main.java.questionGenerator.question.answers.AnswerFormater; +import main.java.questionGenerator.question.answers.AbstractFormater; -public class EmbellishNumbersFormater implements AnswerFormater { +public class EmbellishNumbersFormater extends AbstractFormater { + + public EmbellishNumbersFormater(AnswerFormater formater) { + super(formater); + } @Override public List format(List answers) { @@ -13,7 +18,7 @@ public List format(List answers) { for(String s : answers) { result.add(decorateAnswer(s)); } - return result; + return end(result); } private String decorateAnswer(String answer) { diff --git a/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/RemoveEFromNumber.java b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/RemoveEFromNumber.java index 32dd2346..70f932f3 100644 --- a/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/RemoveEFromNumber.java +++ b/questionGenerator/src/main/java/questionGenerator/question/answers/formatAnswers/RemoveEFromNumber.java @@ -4,13 +4,12 @@ import java.util.List; import main.java.questionGenerator.question.answers.AnswerFormater; +import main.java.questionGenerator.question.answers.AbstractFormater; -public class RemoveEFromNumber implements AnswerFormater { - - private AnswerFormater formater; +public class RemoveEFromNumber extends AbstractFormater { public RemoveEFromNumber(AnswerFormater formater) { - this.formater = formater; + super(formater); } @Override @@ -19,7 +18,7 @@ public List format(List answers) { for(String s : answers) { result.add(removeE(s)); } - return formater.format(result); + return end(result); } private String removeE(String answer) { From 3dbe449a9e8311fc5e8c76db87a7aa127c39ff23 Mon Sep 17 00:00:00 2001 From: jorge Date: Fri, 19 Apr 2024 18:38:06 +0200 Subject: [PATCH 41/78] Removed redundancies in the messages --- questionGenerator/src/main/resources/messages_es.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/questionGenerator/src/main/resources/messages_es.properties b/questionGenerator/src/main/resources/messages_es.properties index 9648fc81..d48a4b96 100644 --- a/questionGenerator/src/main/resources/messages_es.properties +++ b/questionGenerator/src/main/resources/messages_es.properties @@ -1,7 +1,7 @@ question.population = ¿Cuál es la población de %s? question.language = ¿Cuál es el idioma oficial de %s? question.capital = ¿Cuál es la capital de %s? -question.size = ¿Cuál es el área (km cuadrados) de %s? +question.size = ¿Cuál es el área de %s? question.governmentHead = ¿Quién es el actual jefe de gobierno de %s? question.director = ¿Quién es el director de la %s %s? question.videogame.developer = ¿Quién desarolló el videojuego %s? From f5f8a0eb70daefa8bf862293e33b7cd36e60222d Mon Sep 17 00:00:00 2001 From: jorge Date: Fri, 19 Apr 2024 18:47:29 +0200 Subject: [PATCH 42/78] The specific generators now work as singletons --- .../questionGenerator/QuestionGenerator.java | 25 +++++++++---------- .../withSubProperties/CapitalGenerator.java | 11 +++++++- .../HeadOfGovernmentGenerator.java | 11 +++++++- .../withSubProperties/LanguageGenerator.java | 11 +++++++- .../videogames/VideogameCountryGenerator.java | 11 +++++++- .../VideogameDeveloperGenerator.java | 12 ++++++++- .../videogames/VideogameGenreGenerator.java | 13 ++++++++-- .../VideogamePublisherGenerator.java | 13 ++++++++-- .../DirectorGenerator.java | 17 ++++++++++--- .../PopulationGenerator.java | 11 +++++++- .../answersAreNotEntites/SizeGenerator.java | 11 +++++++- 11 files changed, 118 insertions(+), 28 deletions(-) diff --git a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java index c4b692e5..1fd27702 100644 --- a/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/QuestionGenerator.java @@ -78,44 +78,43 @@ public List generateQuestions(QuestionType type, int amount){ private void setGenerator(QuestionType type) { switch (type) { case POPULATION: { - generator = new PopulationGenerator(); + generator = PopulationGenerator.getInstance(); break; } case CAPITAL: { - generator = new CapitalGenerator(); + generator = CapitalGenerator.getInstance(); break; - } case SIZE: { - generator = new SizeGenerator(); + generator = SizeGenerator.getInstance(); break; } case LANGUAGE: { - generator = new LanguageGenerator(); + generator = LanguageGenerator.getInstance(); break; } - case HEAD_OF_GOVERMENT:{ - generator = new HeadOfGovernmentGenerator(); + case HEAD_OF_GOVERMENT: { + generator = HeadOfGovernmentGenerator.getInstance(); break; } case DIRECTOR: { - generator = new DirectorGenerator(); + generator = DirectorGenerator.getInstance(); break; } case VIDEOGAME_DEVELOPER: { - generator = new VideogameDeveloperGenerator(); + generator = VideogameDeveloperGenerator.getInstance(); break; } case VIDEOGAME_PUBLISHER: { - generator = new VideogamePublisherGenerator(); + generator = VideogamePublisherGenerator.getInstance(); break; } case VIDEOGAME_GENRE: { - generator = new VideogameGenreGenerator(); + generator = VideogameGenreGenerator.getInstance(); break; } - case VIDEOGAME_COUNTRY:{ - generator = new VideogameCountryGenerator(); + case VIDEOGAME_COUNTRY: { + generator = VideogameCountryGenerator.getInstance(); break; } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/CapitalGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/CapitalGenerator.java index b1ecdf67..c50a19f8 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/CapitalGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/CapitalGenerator.java @@ -1,5 +1,6 @@ package main.java.questionGenerator.generator.answersAreEntites.withSubProperties; +import main.java.questionGenerator.generator.Generator; import main.java.questionGenerator.question.QuestionType; public class CapitalGenerator extends AnswersAreEntitiesWithSubProperties { @@ -7,8 +8,16 @@ public class CapitalGenerator extends AnswersAreEntitiesWithSubProperties { private final static String PROPERTY = "P36"; private final static String PROPERTY_TO_CHECK = "P582"; private final static String MESSAGE = "question.capital"; + + private static Generator generator; + + public static Generator getInstance() { + if(generator==null) + generator = new CapitalGenerator(); + return generator; + } - public CapitalGenerator(){ + private CapitalGenerator(){ super(PROPERTY, QuestionType.CAPITAL, PROPERTY_TO_CHECK, MESSAGE); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/HeadOfGovernmentGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/HeadOfGovernmentGenerator.java index 33818e4e..e0f96b7e 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/HeadOfGovernmentGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/HeadOfGovernmentGenerator.java @@ -1,5 +1,6 @@ package main.java.questionGenerator.generator.answersAreEntites.withSubProperties; +import main.java.questionGenerator.generator.Generator; import main.java.questionGenerator.question.QuestionType; public class HeadOfGovernmentGenerator extends AnswersAreEntitiesWithSubProperties { @@ -7,8 +8,16 @@ public class HeadOfGovernmentGenerator extends AnswersAreEntitiesWithSubProperti private final static String PROPERTY = "P6"; private final static String PROPERTY_TO_CHECK = "P582"; private final static String MESSAGE = "question.governmentHead"; + + private static Generator generator; + + public static Generator getInstance() { + if(generator==null) + generator = new HeadOfGovernmentGenerator(); + return generator; + } - public HeadOfGovernmentGenerator() { + private HeadOfGovernmentGenerator() { super(PROPERTY, QuestionType.HEAD_OF_GOVERMENT, PROPERTY_TO_CHECK, MESSAGE); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/LanguageGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/LanguageGenerator.java index b5e5282e..8d1df7ef 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/LanguageGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/LanguageGenerator.java @@ -2,6 +2,7 @@ import java.util.List; +import main.java.questionGenerator.generator.Generator; import main.java.questionGenerator.question.QuestionType; import main.java.questionGenerator.question.answers.AnswerFormater; import main.java.questionGenerator.question.answers.formatAnswers.CapitalLetersFormater; @@ -11,8 +12,16 @@ public class LanguageGenerator extends AnswersAreEntitiesWithSubProperties { private final static String PROPERTY = "P37"; private final static String PROPERTY_TO_CHECK = "P518"; private final static String MESSAGE = "question.language"; + + private static Generator generator; + + public static Generator getInstance() { + if(generator==null) + generator = new LanguageGenerator(); + return generator; + } - public LanguageGenerator(){ + private LanguageGenerator(){ super(PROPERTY, QuestionType.LANGUAGE, PROPERTY_TO_CHECK, MESSAGE); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameCountryGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameCountryGenerator.java index 09f70c65..beca47d7 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameCountryGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameCountryGenerator.java @@ -1,5 +1,6 @@ package main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames; +import main.java.questionGenerator.generator.Generator; import main.java.questionGenerator.question.QuestionType; public class VideogameCountryGenerator extends AbstractVideogameGenerator { @@ -9,7 +10,15 @@ public class VideogameCountryGenerator extends AbstractVideogameGenerator { private static final String MESSAGE = "question.videogame.country"; private static final String REAL_PROPERTY = "P495"; - public VideogameCountryGenerator() { + private static Generator generator; + + public static Generator getInstance() { + if(generator==null) + generator = new VideogameCountryGenerator(); + return generator; + } + + private VideogameCountryGenerator() { super(PROPERTY, QuestionType.VIDEOGAME_COUNTRY, PROPERTY_TO_CHECK, MESSAGE, REAL_PROPERTY); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameDeveloperGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameDeveloperGenerator.java index 9dbdd251..4c541ee5 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameDeveloperGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameDeveloperGenerator.java @@ -1,5 +1,6 @@ package main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames; +import main.java.questionGenerator.generator.Generator; import main.java.questionGenerator.question.QuestionType; public class VideogameDeveloperGenerator extends AbstractVideogameGenerator { @@ -8,9 +9,18 @@ public class VideogameDeveloperGenerator extends AbstractVideogameGenerator { private static final String PROPERTY_TO_CHECK = "P2868"; private static final String MESSAGE = "question.videogame.developer"; private static final String REAL_PROPERTY = "P178"; + + private static Generator generator; + + public static Generator getInstance() { + if(generator==null) + generator = new VideogameDeveloperGenerator(); + return generator; + } - public VideogameDeveloperGenerator() { + private VideogameDeveloperGenerator() { super(PROPERTY, QuestionType.VIDEOGAME_DEVELOPER, PROPERTY_TO_CHECK, MESSAGE, REAL_PROPERTY); } + } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameGenreGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameGenreGenerator.java index fd3871e5..b9a34210 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameGenreGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogameGenreGenerator.java @@ -2,9 +2,10 @@ import java.util.List; +import main.java.questionGenerator.generator.Generator; import main.java.questionGenerator.question.QuestionType; import main.java.questionGenerator.question.answers.AnswerFormater; -import main.java.questionGenerator.question.answers.formatAnswers.CapitalLetersFormater; +import main.java.questionGenerator.question.answers.formatAnswers.CapitalLetersFormater;; public class VideogameGenreGenerator extends AbstractVideogameGenerator { @@ -12,8 +13,16 @@ public class VideogameGenreGenerator extends AbstractVideogameGenerator { private static final String PROPERTY_TO_CHECK = "P2868"; private static final String MESSAGE = "question.videogame.genre"; private static final String REAL_PROPERTY = "P136"; + + private static Generator generator; + + public static Generator getInstance() { + if(generator==null) + generator = new VideogameGenreGenerator(); + return generator; + } - public VideogameGenreGenerator() { + private VideogameGenreGenerator() { super(PROPERTY, QuestionType.VIDEOGAME_DEVELOPER, PROPERTY_TO_CHECK, MESSAGE, REAL_PROPERTY); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogamePublisherGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogamePublisherGenerator.java index fc95f166..68689608 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogamePublisherGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withSubProperties/videogames/VideogamePublisherGenerator.java @@ -1,5 +1,6 @@ package main.java.questionGenerator.generator.answersAreEntites.withSubProperties.videogames; +import main.java.questionGenerator.generator.Generator; import main.java.questionGenerator.question.QuestionType; public class VideogamePublisherGenerator extends AbstractVideogameGenerator { @@ -8,8 +9,16 @@ public class VideogamePublisherGenerator extends AbstractVideogameGenerator { private static final String PROPERTY_TO_CHECK = "P2868"; private static final String MESSAGE = "question.videogame.publisher"; private static final String REAL_PROPERTY = "P123"; + + private static Generator generator; + + public static Generator getInstance() { + if(generator==null) + generator = new VideogamePublisherGenerator(); + return generator; + } - public VideogamePublisherGenerator() { - super(PROPERTY, QuestionType.VIDEOGAME_DEVELOPER, PROPERTY_TO_CHECK, MESSAGE, REAL_PROPERTY); + private VideogamePublisherGenerator() { + super(PROPERTY, QuestionType.VIDEOGAME_PUBLISHER, PROPERTY_TO_CHECK, MESSAGE, REAL_PROPERTY); } } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/DirectorGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/DirectorGenerator.java index 4ca7a794..65977fab 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/DirectorGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreEntites/withoutSubProperties/DirectorGenerator.java @@ -1,13 +1,22 @@ package main.java.questionGenerator.generator.answersAreEntites.withoutSubProperties; +import main.java.questionGenerator.generator.Generator; import main.java.questionGenerator.question.QuestionType; -public class DirectorGenerator extends AnswersAreEntitiesWithoutSubProperties{ - - private final static String PROPERTY = "P57"; +public class DirectorGenerator extends AnswersAreEntitiesWithoutSubProperties { + + private final static String PROPERTY = "P57"; private final static String MESSAGE = "question.director"; + + private static Generator generator; + + public static Generator getInstance() { + if(generator==null) + generator = new DirectorGenerator(); + return generator; + } - public DirectorGenerator() { + private DirectorGenerator() { super(PROPERTY, QuestionType.DIRECTOR, MESSAGE); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java index e08b4cf6..889aee7f 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/PopulationGenerator.java @@ -7,6 +7,7 @@ import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.Value; +import main.java.questionGenerator.generator.Generator; import main.java.questionGenerator.question.QuestionType; import main.java.questionGenerator.question.answers.AnswerFormater; import main.java.questionGenerator.question.answers.formatAnswers.EmbellishNumbersFormater; @@ -15,8 +16,16 @@ public class PopulationGenerator extends AnswersAreNotEntites { private final static String PROPERTY = "P1082"; private final static String MESSAGE = "question.population"; + + private static Generator generator; + + public static Generator getInstance() { + if(generator==null) + generator = new PopulationGenerator(); + return generator; + } - public PopulationGenerator(){ + private PopulationGenerator(){ super(PROPERTY, QuestionType.POPULATION, MESSAGE); } diff --git a/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java index 4b186112..3e321036 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/answersAreNotEntites/SizeGenerator.java @@ -6,6 +6,7 @@ import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.Value; +import main.java.questionGenerator.generator.Generator; import main.java.questionGenerator.question.QuestionType; import main.java.questionGenerator.question.answers.AnswerFormater; import main.java.questionGenerator.question.answers.formatAnswers.AddUnitsFormater; @@ -16,8 +17,16 @@ public class SizeGenerator extends AnswersAreNotEntites { private final static String PROPERTY = "P2046"; private final static String MESSAGE = "question.size"; + + private static Generator generator; + + public static Generator getInstance() { + if(generator==null) + generator = new SizeGenerator(); + return generator; + } - public SizeGenerator() { + private SizeGenerator() { super(PROPERTY, QuestionType.SIZE, MESSAGE); } From 859cc6fe4a6da802bdd961e1c8004db2ba5030f1 Mon Sep 17 00:00:00 2001 From: jorge Date: Fri, 19 Apr 2024 22:17:48 +0200 Subject: [PATCH 43/78] Created the head of state test file and added a few test cases --- .../generator/HeadOfStateGeneratorTest.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java new file mode 100644 index 00000000..f95a61a8 --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java @@ -0,0 +1,56 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +public class HeadOfStateGeneratorTest { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.HEAD_OF_GOVERMENT, 3); + + @Test + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + +} From e4f9e2031c67a9fbee01e071790c5fcc3477ed1c Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:10:38 +0200 Subject: [PATCH 44/78] Improved the tests for the head of state generator --- .../generator/HeadOfStateGeneratorTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java index f95a61a8..ebff864c 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.List; @@ -19,6 +20,11 @@ public class HeadOfStateGeneratorTest { private QuestionGenerator qg = QuestionGenerator.getInstance(); private List questions = qg.generateQuestions(QuestionType.HEAD_OF_GOVERMENT, 3); + @Test + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + @Test public void QuestionsAreGeneratedTest() { assertNotNull(questions); @@ -53,4 +59,13 @@ public void AllAnswersInAQuestionAreDifferent() { } } + @Test + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("Who's the current head of the government of ")); + assertTrue(q.getQuestion().endsWith("?")); + } + + } + } From 1795b9ae2e3bfa716666c3581c18e61bb26adfb9 Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:15:11 +0200 Subject: [PATCH 45/78] The test now run in order --- .../generator/HeadOfStateGeneratorTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java index ebff864c..e33d130c 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java @@ -9,23 +9,29 @@ import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import main.java.questionGenerator.QuestionGenerator; import main.java.questionGenerator.question.Question; import main.java.questionGenerator.question.QuestionType; +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class HeadOfStateGeneratorTest { private QuestionGenerator qg = QuestionGenerator.getInstance(); private List questions = qg.generateQuestions(QuestionType.HEAD_OF_GOVERMENT, 3); @Test + @Order(1) public void AmountOfQuestions() { assertTrue(questions.size()<=3); } @Test + @Order(2) public void QuestionsAreGeneratedTest() { assertNotNull(questions); assertNotEquals(List.of(questions), questions); @@ -35,6 +41,7 @@ public void QuestionsAreGeneratedTest() { } @Test + @Order(3) public void AllQuestionsAreDifferentTest() { List messages = new ArrayList(); for(Question q : questions) { @@ -47,6 +54,7 @@ public void AllQuestionsAreDifferentTest() { } @Test + @Order(4) public void AllAnswersInAQuestionAreDifferent() { for(Question q : questions) { assertFalse(q.getAnswers().isEmpty()); @@ -60,6 +68,7 @@ public void AllAnswersInAQuestionAreDifferent() { } @Test + @Order(5) public void TheQuestionFollowsTheExpectedMessage() { for(Question q : questions) { assertTrue(q.getQuestion().contains("Who's the current head of the government of ")); From 5e58811554076307a93c5f7b7aeb4a3c778f5009 Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:17:47 +0200 Subject: [PATCH 46/78] Added tests for the director generator --- .../generator/DirectorGeneratorTests.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java new file mode 100644 index 00000000..6dd1cf2f --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java @@ -0,0 +1,76 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +public class DirectorGeneratorTests { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.DIRECTOR, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("Who's the director of the ")); + assertTrue(q.getQuestion().endsWith("?")); + } + } + +} \ No newline at end of file From 4763bf7e29abc564e1ab5ba506620b770e3b36a3 Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:19:56 +0200 Subject: [PATCH 47/78] The order of the tests of the director generator now works as intended --- .../questionGenerator/generator/DirectorGeneratorTests.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java index 6dd1cf2f..049dfd56 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java @@ -9,13 +9,16 @@ import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import main.java.questionGenerator.QuestionGenerator; import main.java.questionGenerator.question.Question; import main.java.questionGenerator.question.QuestionType; +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class DirectorGeneratorTests { private QuestionGenerator qg = QuestionGenerator.getInstance(); From 637459ac061df70b7812279ce635dba5e604dd91 Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:32:41 +0200 Subject: [PATCH 48/78] Added the test of the videogame developer generator --- .../VideogameDeveloperGenerator.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java new file mode 100644 index 00000000..05fdb9ab --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java @@ -0,0 +1,103 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class VideogameDeveloperGenerator { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.VIDEOGAME_DEVELOPER, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("Who were the developers of the videogame ")); + assertTrue(q.getQuestion().endsWith("?")); + } + + } + + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 10:33:53 +0200 Subject: [PATCH 49/78] Added new test cases for the director and head of government tests --- .../generator/DirectorGeneratorTests.java | 23 +++++++++++++++++++ .../generator/HeadOfStateGeneratorTest.java | 23 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java index 049dfd56..6a6f35a6 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.List; +import org.json.JSONArray; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -76,4 +77,26 @@ public void TheQuestionFollowsTheExpectedMessage() { } } + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 10:34:36 +0200 Subject: [PATCH 50/78] Fixed the name of the head of government test --- ...ateGeneratorTest.java => HeadOfGovernmentGeneratorTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename questionGenerator/src/test/java/questionGenerator/generator/{HeadOfStateGeneratorTest.java => HeadOfGovernmentGeneratorTest.java} (98%) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfGovernmentGeneratorTest.java similarity index 98% rename from questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java rename to questionGenerator/src/test/java/questionGenerator/generator/HeadOfGovernmentGeneratorTest.java index 54a9a773..d2ad302d 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfGovernmentGeneratorTest.java @@ -20,7 +20,7 @@ import main.java.questionGenerator.question.QuestionType; @TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class HeadOfStateGeneratorTest { +public class HeadOfGovernmentGeneratorTest { private QuestionGenerator qg = QuestionGenerator.getInstance(); private List questions = qg.generateQuestions(QuestionType.HEAD_OF_GOVERMENT, 3); From 235e3b8e5afd1ab1edddc066a7824ead748912bd Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:36:44 +0200 Subject: [PATCH 51/78] Fixed the problem in the videogame developer generator test name --- ...operGenerator.java => VideogameDeveloperGeneratorTests.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename questionGenerator/src/test/java/questionGenerator/generator/{VideogameDeveloperGenerator.java => VideogameDeveloperGeneratorTests.java} (98%) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGeneratorTests.java similarity index 98% rename from questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java rename to questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGeneratorTests.java index 05fdb9ab..ffb357f0 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGeneratorTests.java @@ -20,7 +20,7 @@ import main.java.questionGenerator.question.QuestionType; @TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class VideogameDeveloperGenerator { +public class VideogameDeveloperGeneratorTests { private QuestionGenerator qg = QuestionGenerator.getInstance(); private List questions = qg.generateQuestions(QuestionType.VIDEOGAME_DEVELOPER, 3); From 549c267171ff3be35f84c552b7db5db6fd172e6f Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:39:13 +0200 Subject: [PATCH 52/78] Added test for the videogame publisher generator --- .../VideogamePublisherGeneratorTests.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/VideogamePublisherGeneratorTests.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogamePublisherGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogamePublisherGeneratorTests.java new file mode 100644 index 00000000..8132bf77 --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogamePublisherGeneratorTests.java @@ -0,0 +1,103 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class VideogamePublisherGeneratorTests { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.VIDEOGAME_PUBLISHER, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("Who was the publisher of the videogame ")); + assertTrue(q.getQuestion().endsWith("?")); + } + + } + + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 10:41:12 +0200 Subject: [PATCH 53/78] Added tests for the videogame genre generator --- .../VideogameGenreGeneratorTests.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/VideogameGenreGeneratorTests.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogameGenreGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogameGenreGeneratorTests.java new file mode 100644 index 00000000..fb3e8e35 --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogameGenreGeneratorTests.java @@ -0,0 +1,103 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class VideogameGenreGeneratorTests { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.VIDEOGAME_GENRE, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("What's the main genre of the videogame ")); + assertTrue(q.getQuestion().endsWith("?")); + } + + } + + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 10:44:03 +0200 Subject: [PATCH 54/78] Added test for the videogame country generator --- .../VideogameCountryGeneratorTests.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java new file mode 100644 index 00000000..328ab630 --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java @@ -0,0 +1,103 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class VideogameCountryGeneratorTests { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.VIDEOGAME_COUNTRY, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("Which country is the videogame ")); + assertTrue(q.getQuestion().endsWith(" from?")); + } + + } + + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 12:32:53 +0200 Subject: [PATCH 55/78] new file before translation --- .../src/main/resources/messages_tk.properties | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 questionGenerator/src/main/resources/messages_tk.properties diff --git a/questionGenerator/src/main/resources/messages_tk.properties b/questionGenerator/src/main/resources/messages_tk.properties new file mode 100644 index 00000000..d9837ebb --- /dev/null +++ b/questionGenerator/src/main/resources/messages_tk.properties @@ -0,0 +1,10 @@ +question.population = What's the population of %s? +question.language = What's the official language of %s? +question.capital = What's the capital of %s? +question.size = What's the size of %s? +question.governmentHead = Who's the current head of the government of %s? +question.director = Who's the director of the %s %s? +question.videogame.developer = Who were the developers of the videogame %s? +question.videogame.publisher = Who was the publisher of the videogame %s? +question.videogame.genre = What's the main genre of the videogame %s? +question.videogame.country = Which country is the videogame %s from? \ No newline at end of file From 3a78d925d2b04d90274aa54221b063a087faeb1c Mon Sep 17 00:00:00 2001 From: ErdemYabaci Date: Sat, 20 Apr 2024 12:46:12 +0200 Subject: [PATCH 56/78] turkish translation for the questions --- .../src/main/resources/messages_tk.properties | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/questionGenerator/src/main/resources/messages_tk.properties b/questionGenerator/src/main/resources/messages_tk.properties index d9837ebb..bb70bf31 100644 --- a/questionGenerator/src/main/resources/messages_tk.properties +++ b/questionGenerator/src/main/resources/messages_tk.properties @@ -1,10 +1,10 @@ -question.population = What's the population of %s? -question.language = What's the official language of %s? -question.capital = What's the capital of %s? -question.size = What's the size of %s? -question.governmentHead = Who's the current head of the government of %s? -question.director = Who's the director of the %s %s? -question.videogame.developer = Who were the developers of the videogame %s? -question.videogame.publisher = Who was the publisher of the videogame %s? -question.videogame.genre = What's the main genre of the videogame %s? -question.videogame.country = Which country is the videogame %s from? \ No newline at end of file +question.population = %s nüfusu ne kadardır? +question.language = %s resmi dili nedir? +question.capital = %s baÅŸkenti neresidir? +question.size = %s büyüklüğü ne kadardır? +question.governmentHead = %s kralı kimdir? +question.director = %s %s filminin direktörü kimdir? +question.videogame.developer = %s video oyunun yapımcıları kimdir? +question.videogame.publisher = %s video oyunun yayımcıları kimdir? +question.videogame.genre = %s video oyunun türü nedir? +question.videogame.country = %s video oyunu hangi ülkeden çıkmıştır? \ No newline at end of file From 029327e74e629e24a9639a3d75f0cc34066028ba Mon Sep 17 00:00:00 2001 From: ErdemYabaci Date: Sat, 20 Apr 2024 12:50:49 +0200 Subject: [PATCH 57/78] better translation for: king->president, makers->developers --- questionGenerator/src/main/resources/messages_tk.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/questionGenerator/src/main/resources/messages_tk.properties b/questionGenerator/src/main/resources/messages_tk.properties index bb70bf31..73a72af5 100644 --- a/questionGenerator/src/main/resources/messages_tk.properties +++ b/questionGenerator/src/main/resources/messages_tk.properties @@ -2,9 +2,9 @@ question.population = %s nüfusu ne kadardır? question.language = %s resmi dili nedir? question.capital = %s baÅŸkenti neresidir? question.size = %s büyüklüğü ne kadardır? -question.governmentHead = %s kralı kimdir? +question.governmentHead = %s baÅŸkanı kimdir? question.director = %s %s filminin direktörü kimdir? -question.videogame.developer = %s video oyunun yapımcıları kimdir? +question.videogame.developer = %s video oyunun geliÅŸtiricileri kimdir? question.videogame.publisher = %s video oyunun yayımcıları kimdir? question.videogame.genre = %s video oyunun türü nedir? question.videogame.country = %s video oyunu hangi ülkeden çıkmıştır? \ No newline at end of file From 6cdfaafa2f3a123a2c35bd9d282131860cedb074 Mon Sep 17 00:00:00 2001 From: ErdemYabaci Date: Sat, 20 Apr 2024 13:44:45 +0200 Subject: [PATCH 58/78] added turkish to the abstractgenerator --- .../java/questionGenerator/generator/AbstractGenerator.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java b/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java index f667d176..ceeff146 100644 --- a/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java +++ b/questionGenerator/src/main/java/questionGenerator/generator/AbstractGenerator.java @@ -128,6 +128,10 @@ public void setLocalization(String languageCode) { localize(languageCode); break; } + case "tr":{ + localize(languageCode); + break; + } default:{ localize("en"); break; From 0a813d1e7054087b8d36118cab09a1278e0b0930 Mon Sep 17 00:00:00 2001 From: ErdemYabaci Date: Sat, 20 Apr 2024 13:50:00 +0200 Subject: [PATCH 59/78] renaming of turkish messages file --- .../resources/{messages_tk.properties => messages_tr.properties} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename questionGenerator/src/main/resources/{messages_tk.properties => messages_tr.properties} (100%) diff --git a/questionGenerator/src/main/resources/messages_tk.properties b/questionGenerator/src/main/resources/messages_tr.properties similarity index 100% rename from questionGenerator/src/main/resources/messages_tk.properties rename to questionGenerator/src/main/resources/messages_tr.properties From 81634ed34124cb103d5148ebd44601229f3e5439 Mon Sep 17 00:00:00 2001 From: ErdemYabaci Date: Sat, 20 Apr 2024 14:00:56 +0200 Subject: [PATCH 60/78] removal of special characters --- .../src/main/resources/messages_tr.properties | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/questionGenerator/src/main/resources/messages_tr.properties b/questionGenerator/src/main/resources/messages_tr.properties index 73a72af5..7fe7762d 100644 --- a/questionGenerator/src/main/resources/messages_tr.properties +++ b/questionGenerator/src/main/resources/messages_tr.properties @@ -1,10 +1,10 @@ -question.population = %s nüfusu ne kadardır? +question.population = %s nufusu ne kadardir? question.language = %s resmi dili nedir? -question.capital = %s baÅŸkenti neresidir? -question.size = %s büyüklüğü ne kadardır? -question.governmentHead = %s baÅŸkanı kimdir? -question.director = %s %s filminin direktörü kimdir? -question.videogame.developer = %s video oyunun geliÅŸtiricileri kimdir? -question.videogame.publisher = %s video oyunun yayımcıları kimdir? -question.videogame.genre = %s video oyunun türü nedir? -question.videogame.country = %s video oyunu hangi ülkeden çıkmıştır? \ No newline at end of file +question.capital = %s baskenti neresidir? +question.size = %s buyuklugu ne kadardir? +question.governmentHead = %s baskani kimdir? +question.director = %s %s filminin direktoru kimdir? +question.videogame.developer = %s video oyunun gelistiricileri kimdir? +question.videogame.publisher = %s video oyunun yayimcilari kimdir? +question.videogame.genre = %s video oyunun turu nedir? +question.videogame.country = %s video oyunu hangi ulkeden cikmistir? \ No newline at end of file From 2cb63ebdb09cb22a555a801fb0af9f000cab75da Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 17:06:56 +0200 Subject: [PATCH 61/78] Added tests for the capital generator --- .../generator/CapitalGeneratorTests.java | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/CapitalGeneratorTests.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/CapitalGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/CapitalGeneratorTests.java new file mode 100644 index 00000000..fa14324f --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/CapitalGeneratorTests.java @@ -0,0 +1,102 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class CapitalGeneratorTests { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.CAPITAL, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("What's the capital of ")); + assertTrue(q.getQuestion().endsWith("?")); + } + } + + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 17:12:33 +0200 Subject: [PATCH 62/78] Added tests for the population generator --- .../generator/PopulationGeneratorTests.java | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/PopulationGeneratorTests.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/PopulationGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/PopulationGeneratorTests.java new file mode 100644 index 00000000..b7117332 --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/PopulationGeneratorTests.java @@ -0,0 +1,102 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class PopulationGeneratorTests { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.POPULATION, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("What's the population of ")); + assertTrue(q.getQuestion().endsWith("?")); + } + } + + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 17:15:50 +0200 Subject: [PATCH 63/78] Added tests for the language generator --- .../generator/LanguageGeneratorTests.java | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/LanguageGeneratorTests.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/LanguageGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/LanguageGeneratorTests.java new file mode 100644 index 00000000..f0c88fb6 --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/LanguageGeneratorTests.java @@ -0,0 +1,102 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class LanguageGeneratorTests { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.LANGUAGE, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("What's the official language of ")); + assertTrue(q.getQuestion().endsWith("?")); + } + } + + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 17:18:36 +0200 Subject: [PATCH 64/78] Added tests for the size generator --- .../generator/SizeGeneratorTests.java | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/SizeGeneratorTests.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/SizeGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/SizeGeneratorTests.java new file mode 100644 index 00000000..d9cd6621 --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/SizeGeneratorTests.java @@ -0,0 +1,102 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class SizeGeneratorTests { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.SIZE, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("What's the size of ")); + assertTrue(q.getQuestion().endsWith("?")); + } + } + + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 17:21:42 +0200 Subject: [PATCH 65/78] Improved the test case that checked that the question was as expected --- .../java/questionGenerator/generator/CapitalGeneratorTests.java | 2 +- .../questionGenerator/generator/DirectorGeneratorTests.java | 2 +- .../generator/HeadOfGovernmentGeneratorTest.java | 2 +- .../questionGenerator/generator/LanguageGeneratorTests.java | 2 +- .../questionGenerator/generator/PopulationGeneratorTests.java | 2 +- .../java/questionGenerator/generator/SizeGeneratorTests.java | 2 +- .../generator/VideogameCountryGeneratorTests.java | 2 +- .../generator/VideogameDeveloperGeneratorTests.java | 2 +- .../generator/VideogameGenreGeneratorTests.java | 2 +- .../generator/VideogamePublisherGeneratorTests.java | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/CapitalGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/CapitalGeneratorTests.java index fa14324f..9403bed4 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/CapitalGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/CapitalGeneratorTests.java @@ -72,7 +72,7 @@ public void AllAnswersInAQuestionAreDifferent() { @Order(5) public void TheQuestionFollowsTheExpectedMessage() { for(Question q : questions) { - assertTrue(q.getQuestion().contains("What's the capital of ")); + assertTrue(q.getQuestion().startsWith("What's the capital of ")); assertTrue(q.getQuestion().endsWith("?")); } } diff --git a/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java index 6a6f35a6..0fe21eff 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java @@ -72,7 +72,7 @@ public void AllAnswersInAQuestionAreDifferent() { @Order(5) public void TheQuestionFollowsTheExpectedMessage() { for(Question q : questions) { - assertTrue(q.getQuestion().contains("Who's the director of the ")); + assertTrue(q.getQuestion().startsWith("Who's the director of the ")); assertTrue(q.getQuestion().endsWith("?")); } } diff --git a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfGovernmentGeneratorTest.java b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfGovernmentGeneratorTest.java index d2ad302d..e432648a 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfGovernmentGeneratorTest.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfGovernmentGeneratorTest.java @@ -72,7 +72,7 @@ public void AllAnswersInAQuestionAreDifferent() { @Order(5) public void TheQuestionFollowsTheExpectedMessage() { for(Question q : questions) { - assertTrue(q.getQuestion().contains("Who's the current head of the government of ")); + assertTrue(q.getQuestion().startsWith("Who's the current head of the government of ")); assertTrue(q.getQuestion().endsWith("?")); } diff --git a/questionGenerator/src/test/java/questionGenerator/generator/LanguageGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/LanguageGeneratorTests.java index f0c88fb6..ecc7f620 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/LanguageGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/LanguageGeneratorTests.java @@ -72,7 +72,7 @@ public void AllAnswersInAQuestionAreDifferent() { @Order(5) public void TheQuestionFollowsTheExpectedMessage() { for(Question q : questions) { - assertTrue(q.getQuestion().contains("What's the official language of ")); + assertTrue(q.getQuestion().startsWith("What's the official language of ")); assertTrue(q.getQuestion().endsWith("?")); } } diff --git a/questionGenerator/src/test/java/questionGenerator/generator/PopulationGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/PopulationGeneratorTests.java index b7117332..7084ea0e 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/PopulationGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/PopulationGeneratorTests.java @@ -72,7 +72,7 @@ public void AllAnswersInAQuestionAreDifferent() { @Order(5) public void TheQuestionFollowsTheExpectedMessage() { for(Question q : questions) { - assertTrue(q.getQuestion().contains("What's the population of ")); + assertTrue(q.getQuestion().startsWith("What's the population of ")); assertTrue(q.getQuestion().endsWith("?")); } } diff --git a/questionGenerator/src/test/java/questionGenerator/generator/SizeGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/SizeGeneratorTests.java index d9cd6621..824dc59b 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/SizeGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/SizeGeneratorTests.java @@ -72,7 +72,7 @@ public void AllAnswersInAQuestionAreDifferent() { @Order(5) public void TheQuestionFollowsTheExpectedMessage() { for(Question q : questions) { - assertTrue(q.getQuestion().contains("What's the size of ")); + assertTrue(q.getQuestion().startsWith("What's the size of ")); assertTrue(q.getQuestion().endsWith("?")); } } diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java index 328ab630..aae764bd 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java @@ -72,7 +72,7 @@ public void AllAnswersInAQuestionAreDifferent() { @Order(5) public void TheQuestionFollowsTheExpectedMessage() { for(Question q : questions) { - assertTrue(q.getQuestion().contains("Which country is the videogame ")); + assertTrue(q.getQuestion().startsWith("Which country is the videogame ")); assertTrue(q.getQuestion().endsWith(" from?")); } diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGeneratorTests.java index ffb357f0..99ac8c8b 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGeneratorTests.java @@ -72,7 +72,7 @@ public void AllAnswersInAQuestionAreDifferent() { @Order(5) public void TheQuestionFollowsTheExpectedMessage() { for(Question q : questions) { - assertTrue(q.getQuestion().contains("Who were the developers of the videogame ")); + assertTrue(q.getQuestion().startsWith("Who were the developers of the videogame ")); assertTrue(q.getQuestion().endsWith("?")); } diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogameGenreGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogameGenreGeneratorTests.java index fb3e8e35..b3701fde 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/VideogameGenreGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogameGenreGeneratorTests.java @@ -72,7 +72,7 @@ public void AllAnswersInAQuestionAreDifferent() { @Order(5) public void TheQuestionFollowsTheExpectedMessage() { for(Question q : questions) { - assertTrue(q.getQuestion().contains("What's the main genre of the videogame ")); + assertTrue(q.getQuestion().startsWith("What's the main genre of the videogame ")); assertTrue(q.getQuestion().endsWith("?")); } diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogamePublisherGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogamePublisherGeneratorTests.java index 8132bf77..8531651d 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/VideogamePublisherGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogamePublisherGeneratorTests.java @@ -72,7 +72,7 @@ public void AllAnswersInAQuestionAreDifferent() { @Order(5) public void TheQuestionFollowsTheExpectedMessage() { for(Question q : questions) { - assertTrue(q.getQuestion().contains("Who was the publisher of the videogame ")); + assertTrue(q.getQuestion().startsWith("Who was the publisher of the videogame ")); assertTrue(q.getQuestion().endsWith("?")); } From 6b16f91043cc6db237d1f9d4804a8d3c4ea378d7 Mon Sep 17 00:00:00 2001 From: ErdemYabaci Date: Sun, 21 Apr 2024 13:06:55 +0200 Subject: [PATCH 66/78] adding turkish to persistentmain.java --- questionGenerator/src/main/java/PersistentMain.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/questionGenerator/src/main/java/PersistentMain.java b/questionGenerator/src/main/java/PersistentMain.java index e93b67a5..b4588d8c 100644 --- a/questionGenerator/src/main/java/PersistentMain.java +++ b/questionGenerator/src/main/java/PersistentMain.java @@ -18,7 +18,7 @@ public class PersistentMain { // private static QuestionGenerator[] generators = {new QuestionGenerator("en"), new QuestionGenerator("es")}; - private static String[] languages = {"en", "es"}; + private static String[] languages = {"en", "es", "tr"}; private static QuestionType[] types = {QuestionType.CAPITAL, QuestionType.LANGUAGE, QuestionType.POPULATION, QuestionType.SIZE, QuestionType.HEAD_OF_GOVERMENT, QuestionType.VIDEOGAME_DEVELOPER, From bad36e277c1360e6243f57345fb7ef33dd46cbef Mon Sep 17 00:00:00 2001 From: ErdemYabaci Date: Sun, 21 Apr 2024 14:25:37 +0200 Subject: [PATCH 67/78] removal of unused commented code --- questionGenerator/src/main/java/PersistentMain.java | 1 - 1 file changed, 1 deletion(-) diff --git a/questionGenerator/src/main/java/PersistentMain.java b/questionGenerator/src/main/java/PersistentMain.java index b4588d8c..95e8ddfe 100644 --- a/questionGenerator/src/main/java/PersistentMain.java +++ b/questionGenerator/src/main/java/PersistentMain.java @@ -16,7 +16,6 @@ public class PersistentMain { // private static long timeSkip = 43200000; //12 hours // private static long timeSkip = 1000; //1 minute - // private static QuestionGenerator[] generators = {new QuestionGenerator("en"), new QuestionGenerator("es")}; private static String[] languages = {"en", "es", "tr"}; From 30f56e97df71968bc69d238651c668497029b3e0 Mon Sep 17 00:00:00 2001 From: jorge Date: Mon, 22 Apr 2024 17:31:46 +0200 Subject: [PATCH 68/78] Updated the main naming nomenclature --- questionGenerator/src/main/java/Main.java | 70 +++++++++++++------ .../src/main/java/PersistentMain.java | 62 ---------------- .../src/main/java/StaticMain.java | 38 ++++++++++ 3 files changed, 85 insertions(+), 85 deletions(-) delete mode 100644 questionGenerator/src/main/java/PersistentMain.java create mode 100644 questionGenerator/src/main/java/StaticMain.java diff --git a/questionGenerator/src/main/java/Main.java b/questionGenerator/src/main/java/Main.java index 62b4f474..a810d5ba 100644 --- a/questionGenerator/src/main/java/Main.java +++ b/questionGenerator/src/main/java/Main.java @@ -1,5 +1,6 @@ package main.java; +import java.util.ArrayList; import java.util.List; import main.java.questionGenerator.QuestionGenerator; @@ -8,31 +9,54 @@ import main.java.questionGenerator.repository.QuestionRepository; public class Main { + + private static QuestionGenerator qg = QuestionGenerator.getInstance(); + + // private static final long TIME_SKIP = 18000000; //5 hours + // private static final long TIME_SKIP = 43200000; //12 hours + private static final long TIME_SKIP = 1000; //1 minute + + + private static String[] languages = {"en", "es", "tr"}; + + private static QuestionType[] types = {QuestionType.CAPITAL, QuestionType.LANGUAGE, QuestionType.POPULATION, + QuestionType.SIZE, QuestionType.HEAD_OF_GOVERMENT, QuestionType.VIDEOGAME_DEVELOPER, + QuestionType.VIDEOGAME_PUBLISHER, QuestionType.VIDEOGAME_GENRE, QuestionType.VIDEOGAME_COUNTRY}; - public static void main(String[] args) { - QuestionGenerator qg = QuestionGenerator.getInstance(); - - run(qg, QuestionType.CAPITAL, 3); - run(qg, QuestionType.LANGUAGE, 3); - run(qg, QuestionType.POPULATION, 3); - run(qg, QuestionType.SIZE, 3); - run(qg, QuestionType.HEAD_OF_GOVERMENT, 3); - run(qg, QuestionType.DIRECTOR, 3); - run(qg, QuestionType.VIDEOGAME_DEVELOPER, 3); - run(qg, QuestionType.VIDEOGAME_PUBLISHER, 3); - run(qg, QuestionType.VIDEOGAME_GENRE, 3); - run(qg, QuestionType.VIDEOGAME_COUNTRY, 3); + // private static final int NUMBER_OF_QUESTIONS = 50; + // private static final int NUMBER_OF_QUESTIONS = 100; + // private static final int NUMBER_OF_QUESTIONS = 3; + private static final int NUMBER_OF_QUESTIONS = 1; + public static void main(String[] args) { + while(true) { + List questions = generate().stream().map(q -> q.getJSON().toString()).toList(); + QuestionRepository.getInstance().populate(questions); + try { + Thread.sleep(TIME_SKIP); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } } - private static void run(QuestionGenerator qg, QuestionType type, int numberOfQuestions){ - List questions = qg.generateQuestions(type, numberOfQuestions); - for(int i=0; i q.getJSON().toString()).toList()); + private static List generate() { + List questions = new ArrayList(); + for(String lang : languages) { + qg.setLanguageCode(lang); + for(QuestionType type: types) + questions.addAll(run(qg, type, NUMBER_OF_QUESTIONS)); + } + return questions; } -} + + private static List run(QuestionGenerator qg, QuestionType type, int numberOfQuestions) { + List questions = qg.generateQuestions(type, numberOfQuestions); + for(int i=0; i questions = generate().stream().map(q -> q.getJSON().toString()).toList(); - QuestionRepository.getInstance().populate(questions); - try { - Thread.sleep(timeSkip); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - - private static List generate() { - List questions = new ArrayList(); - for(String lang : languages) { - qg.setLanguageCode(lang); - for(QuestionType type: types) - questions.addAll(run(qg, type, numberOfQuestions)); - } - return questions; - } - - private static List run(QuestionGenerator qg, QuestionType type, int numberOfQuestions) { - List questions = qg.generateQuestions(type, numberOfQuestions); - for(int i=0; i questions = qg.generateQuestions(type, numberOfQuestions); + for(int i=0; i q.getJSON().toString()).toList()); + } +} From 4625dd620c28a4b9fe07e0fc728409e83f07e37a Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Wed, 24 Apr 2024 20:16:46 +0200 Subject: [PATCH 69/78] Opened questions endpoint so some dont need token --- gatewayservice/gateway-service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index c08d0e37..34ce5eaa 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -48,7 +48,7 @@ app.post('/adduser', async (req, res) => { } }); -app.get('/questions', verifyToken, async (req, res) => { +app.get('/questions', async (req, res) => { try { // Forward the question request to the quetion service @@ -101,7 +101,7 @@ app.get('/questions/:lang/:amount', verifyToken, async (req, res) => { } }); -app.get('/questions/:lang', verifyToken, async (req, res) => { +app.get('/questions/:lang', async (req, res) => { try { if(!validateLang(req.params.lang.toString())) res.status(400).json({ error: 'Wrong values given' }); From 59a2b4a4975f482adddeb79888825a119e447eaf Mon Sep 17 00:00:00 2001 From: uo289267 Date: Wed, 24 Apr 2024 20:33:51 +0200 Subject: [PATCH 70/78] Added Play as a Guest Functionality --- webapp/public/game.png | Bin 0 -> 22717 bytes webapp/src/App.js | 2 +- webapp/src/components/Home/Home.js | 4 ++-- .../src/components/questionView/QuestionView.js | 11 ++++++++--- webapp/src/translations/en/global.json | 3 ++- webapp/src/translations/es/global.json | 3 ++- 6 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 webapp/public/game.png diff --git a/webapp/public/game.png b/webapp/public/game.png new file mode 100644 index 0000000000000000000000000000000000000000..a547de5b7918184bff9d4dd67b59f87a0eaf0a41 GIT binary patch literal 22717 zcmeFZXIE2U(*_D52nbRY1nC42=^(vJ4OLLOH0ix}2u(x<1BBjHnn-U6Jwa4@@4bVR z(0hO!e4g{ZYn`8P)_Onf{o&qoUo(4V?YU>J*&knOt3J3-cOM4_=K)wvNe>4HaCZy9 zA-s2YISClMy1U?d>#4rLsTiQ&!ogw20V^rI4!}jX5;X8AH^Oh|sqV=OetC-`e9x9H zz-$S4$ae4b!DB(o35%B$qq=>}s>(`n>3He_Z=sJVNYe4_fDe^PEH7>$aG6;vv~g{d z{Z)CzcH2&qWqf*N@^4v-lKmrx!D@PD`eXNUiDg8%;ngXK%0D9pzg zY?xTrSfIsjX7iG_K#)8fbq^@rg@E~Rg5%SCz7$0L=w2Ff5(;Q7K!AfP3&_A%1qD=~ zoTppIFj<~0GnhH&7CCq@r7o`^6f}<|ST4nYqIp?%HJ!i<&QAGG@tw{SL?S;EOlPz3gS0aID^7k`N&`*mNF8!rzV{rDSpSN^S^t2=ZiBoPpzH>M+O?5(dx z+^KkvYB}CGPS z>0ngsO+9Gda75$&o87EF5lDapJm^DUB#4Ou#*7nzPxz+3X;b2K);lRe?45Hij8n#RcW;fnMwi%$xv&zT>Rc^|AZ)VNV^N$o;;!jV%xx?}?Q-ec~G-zYna?%~)@d zAF0fEPRGTY%d!=EDw_Z3frS6A**jIk2yV5eyn@NGoZjp0%F7z@+D;Av zKqmlAS$&8cNB1W$McTR0x(;{K{mTA_?gklBL7dUR2tFbs&(nnzz)tD2=+=D!bE%BV zTZ1fCi^^UoD?j0y_7ZfQ_8gI}B$=UPC*xrxd>H_SCobR?b2g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q8-M1?b5;UbZL`+R29@+5X?J@ zwk3-17j;=~4=cQICS)W3svvBU6CI{{=~gkx@jvUxvtd<7wH+)gQK1B^?1#X$X-Q!o zuX5kQgv4}bt@gYFSZWcHSLz-f{eV3y);Yk7($ch6bhC@0l>&1aDMY-Vx;`?<{sk46 zvn2v|PJ3WC5_l9b2qfYyBX6apIWegnE=G{|=}kNtt?WDZO~$TF4YY^*wX~b+Tki(9 z)j7)hdwjv$-#P3j7kW>xx^AqNuV6LokN^C8oSU`8ICb}`*!N|HInkg7k)!2(2GS}M zVE>)HMZO$As{4HK(2PF3y*Rp{V7Vg%-*tWHtk-0YK;c$0I&zO4>0Od>tht#Dk8t5| zJ^6ag1?`+ar$%K1UK)Me(rlL$ye6(p) z6|R~QYPTT|4|>~95S;s5y)NE>?Q}zPvG;w8EQTpB0Zpk1%5)@Gt80=>(BU%w z3V-Ketg%EuMomx%U|#WceQOl@uF27;zx89U!z8o%&G`9s(@Z@{k0gCeJgoAU`r>o8 zhXM7Oo8=}`t?aaZjpd2arqaDysGno3`H1%l$BCJ^8=_mGLo#=cx=a-Mv;JxbPxDQC z=djSa(88dtpFL``r^dKVYn-cKaL#3vYxcEvyO$M<7#17e-$+Ob7yUmy5}4or>SzD` t{ErOz-;n&P5C1m~|8L`P@ha#bP8^_P!} /> : } /> : } /> - : } /> + } /> : } /> : }/> : } /> diff --git a/webapp/src/components/Home/Home.js b/webapp/src/components/Home/Home.js index d2da0752..4af21adb 100644 --- a/webapp/src/components/Home/Home.js +++ b/webapp/src/components/Home/Home.js @@ -30,8 +30,8 @@ function Home() { W - - Instructions + + Game diff --git a/webapp/src/components/questionView/QuestionView.js b/webapp/src/components/questionView/QuestionView.js index 7b757576..61047729 100644 --- a/webapp/src/components/questionView/QuestionView.js +++ b/webapp/src/components/questionView/QuestionView.js @@ -25,8 +25,12 @@ function QuestionView({type= "COMPETITIVE", amount=5}){ const generateQuestions = async (numQuestion) => { if (numQuestion < 0) { try { - - var generatedQuestions = await questionGenerator.generateQuestions(i18n.language, type, amount, cookie.token); + var generatedQuestions; + if(cookie){ + generatedQuestions = await questionGenerator.generateQuestions(i18n.language, type, amount, cookie.token); + }else{ + generateQuestions = await questionGenerator.generateQuestions(i18n.language, type, amount, null);//playing as guest + } setQuestions(generatedQuestions); setnumQuestion(0); } catch (error) { @@ -110,7 +114,8 @@ function QuestionView({type= "COMPETITIVE", amount=5}){ creationHistoricalRecord.setCompetitive(type === 'COMPETITIVE'); creationHistoricalRecord.setDate(Date.now()); creationHistoricalRecord.setPoints(points); - creationHistoricalRecord.sendRecord(cookie.username, cookie.token); + if(cookie) + creationHistoricalRecord.sendRecord(cookie.username, cookie.token); } }, 1000); diff --git a/webapp/src/translations/en/global.json b/webapp/src/translations/en/global.json index 54f087cf..1bcf3aa0 100644 --- a/webapp/src/translations/en/global.json +++ b/webapp/src/translations/en/global.json @@ -8,7 +8,8 @@ "msg1": "Welcome to the knowledge challenge! Get ready to test your mind and demonstrate your skills. In this exciting game, you will face a series of questions that will test your knowledge on a variety of topics.", "msg2": "So go ahead, prove that you are the master of questions! Are you ready to accept the challenge?", "clickOpen": "Click to continue", - "clickClose": "Click to close" + "clickClose": "Click to close", + "game":"Play as a guest" }, "navBar": { diff --git a/webapp/src/translations/es/global.json b/webapp/src/translations/es/global.json index 092ecc74..8906341c 100644 --- a/webapp/src/translations/es/global.json +++ b/webapp/src/translations/es/global.json @@ -8,7 +8,8 @@ "msg1": "Bienvenido al desafío de conocimientos! Prepárate para poner a prueba tu mente y demostrar tus habilidades. En este emocionante juego, te enfrentarás a una serie de preguntas que pondrán a prueba tu conocimiento en una variedad de temas.", "msg2": "¡Así que adelante, demuestra que eres el maestro de las preguntas! ¿Estás listo para aceptar el desafío?", "clickOpen": "Haz click para continuar", - "clickClose": "Haz click para cerrar" + "clickClose": "Haz click para cerrar", + "game":"Juega como invitado" }, From eecfb76a5b58d0f995c11640020e1ee3e1d23450 Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Wed, 24 Apr 2024 20:49:18 +0200 Subject: [PATCH 71/78] Tested and fixed --- webapp/src/components/questionView/QuestionView.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/webapp/src/components/questionView/QuestionView.js b/webapp/src/components/questionView/QuestionView.js index 61047729..4a90bc4c 100644 --- a/webapp/src/components/questionView/QuestionView.js +++ b/webapp/src/components/questionView/QuestionView.js @@ -14,23 +14,20 @@ import BackButtonToGameMenu from '../fragments/BackButtonToGameMenu'; const creationHistoricalRecord = new CreationHistoricalRecord(); const questionGenerator = new QuestionGenerator(); var points = 0; +var playAsGuestUsername = "Play as Guest" //Wont be ever used as it has spaces +var playAsGuestToken = " " function QuestionView({type= "COMPETITIVE", amount=5}){ const [numQuestion, setnumQuestion] = useState(-1); const [questions, setQuestions] = useState(null); const[t, i18n] = useTranslation("global"); - const cookie = JSON.parse(Cookies.get('user')) + const cookie = JSON.parse(Cookies.get('user')??JSON.stringify({username : playAsGuestUsername, token : playAsGuestToken})) const [audio] = useState(new Audio('/tictac.mp3')); const generateQuestions = async (numQuestion) => { if (numQuestion < 0) { try { - var generatedQuestions; - if(cookie){ - generatedQuestions = await questionGenerator.generateQuestions(i18n.language, type, amount, cookie.token); - }else{ - generateQuestions = await questionGenerator.generateQuestions(i18n.language, type, amount, null);//playing as guest - } + var generatedQuestions = await questionGenerator.generateQuestions(i18n.language, type, amount, cookie.token); setQuestions(generatedQuestions); setnumQuestion(0); } catch (error) { @@ -114,7 +111,7 @@ function QuestionView({type= "COMPETITIVE", amount=5}){ creationHistoricalRecord.setCompetitive(type === 'COMPETITIVE'); creationHistoricalRecord.setDate(Date.now()); creationHistoricalRecord.setPoints(points); - if(cookie) + if(cookie.username !== playAsGuestUsername) creationHistoricalRecord.sendRecord(cookie.username, cookie.token); } }, 1000); From 8479e47853f00ea187848265c1c019fefe8ec98c Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Wed, 24 Apr 2024 20:57:18 +0200 Subject: [PATCH 72/78] Fixed tests to test with new home --- webapp/src/components/Home/Home.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/Home/Home.test.js b/webapp/src/components/Home/Home.test.js index 0d16902b..78b36338 100644 --- a/webapp/src/components/Home/Home.test.js +++ b/webapp/src/components/Home/Home.test.js @@ -22,8 +22,8 @@ describe('Home component', () => { // Click toggle open button fireEvent.click(screen.getByTitle("home.clickOpen")); - // Icons of instructions, login and signup must be shown - expect(screen.getByAltText('Instructions')).toBeVisible(); + // Icons of play as guest, login and signup must be shown + expect(screen.getByAltText('Game')).toBeVisible(); expect(screen.getByAltText('Login')).toBeVisible(); expect(screen.getByAltText('Add user')).toBeVisible(); From d184f3436877f828ef51ecbab79e1549ab12472d Mon Sep 17 00:00:00 2001 From: uo289267 Date: Thu, 25 Apr 2024 16:07:50 +0200 Subject: [PATCH 73/78] fixed flaky --- webapp/e2e/features/competitiveGame.feature | 4 ++++ webapp/e2e/steps/competitiveGame.steps.js | 17 +++++++++++++++-- .../GameConfigurator/GameConfigurator.js | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/webapp/e2e/features/competitiveGame.feature b/webapp/e2e/features/competitiveGame.feature index 073860be..30620078 100644 --- a/webapp/e2e/features/competitiveGame.feature +++ b/webapp/e2e/features/competitiveGame.feature @@ -2,4 +2,8 @@ Feature: Game Configurator and Competitive Game functionality Scenario: Create Competitive Game should go to /questions Given I am on the game configurator When I click on new competitive game + Then I am in /questions + Scenario: Create Customized Game should go to /questions + Given I am on the game configurator + When I click on new customized game Then I am in /questions \ No newline at end of file diff --git a/webapp/e2e/steps/competitiveGame.steps.js b/webapp/e2e/steps/competitiveGame.steps.js index 95f41dad..8bd7682d 100644 --- a/webapp/e2e/steps/competitiveGame.steps.js +++ b/webapp/e2e/steps/competitiveGame.steps.js @@ -9,8 +9,8 @@ const { register, login, logout } = require("../utils"); let page; let browser; -const email = "testUser@example.com"; -const username = "testUser" +const email = "testUser1@example.com"; +const username = "testUser1" const password = "testUserPassword" defineFeature(feature, test => { @@ -46,5 +46,18 @@ defineFeature(feature, test => { await expect(page).toMatchElement('.questionContainer'); }); }); + + test('Create Customized Game should go to /questions', ({ given,when, then }) => { + given('I am on the game configurator', async () => { + await page.goto('http://localhost:3000/configurator'); + await page.waitForSelector('.GameConfiguratorDiv'); + }); + when('I click on new customized game', async () => { + await page.click('.linkButton'); + }); + then('I am in /questions', async () => { + await expect(page).toMatchElement('.questionContainer'); + }); + }); }); diff --git a/webapp/src/components/GameConfigurator/GameConfigurator.js b/webapp/src/components/GameConfigurator/GameConfigurator.js index 5ab12b27..899a8528 100644 --- a/webapp/src/components/GameConfigurator/GameConfigurator.js +++ b/webapp/src/components/GameConfigurator/GameConfigurator.js @@ -71,7 +71,7 @@ function ButtonRandomizeCustom({t,handleClick}){ function ButtonCustomized({t,handleClick}) { return ( - + ); } From 867fc5801186df59588b57f8a2bd9dd86223a1f8 Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Thu, 25 Apr 2024 19:49:53 +0200 Subject: [PATCH 74/78] Removed transaction idea --- questionGenerator/src/main/java/Main.java | 16 ++++++++-------- .../repository/QuestionRepository.java | 9 +-------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/questionGenerator/src/main/java/Main.java b/questionGenerator/src/main/java/Main.java index a810d5ba..e5c144aa 100644 --- a/questionGenerator/src/main/java/Main.java +++ b/questionGenerator/src/main/java/Main.java @@ -12,21 +12,21 @@ public class Main { private static QuestionGenerator qg = QuestionGenerator.getInstance(); - // private static final long TIME_SKIP = 18000000; //5 hours + private static final long TIME_SKIP = 18000000; //5 hours // private static final long TIME_SKIP = 43200000; //12 hours - private static final long TIME_SKIP = 1000; //1 minute + //private static final long TIME_SKIP = 1000; //1 minute private static String[] languages = {"en", "es", "tr"}; private static QuestionType[] types = {QuestionType.CAPITAL, QuestionType.LANGUAGE, QuestionType.POPULATION, - QuestionType.SIZE, QuestionType.HEAD_OF_GOVERMENT, QuestionType.VIDEOGAME_DEVELOPER, - QuestionType.VIDEOGAME_PUBLISHER, QuestionType.VIDEOGAME_GENRE, QuestionType.VIDEOGAME_COUNTRY}; + QuestionType.SIZE, QuestionType.HEAD_OF_GOVERMENT}; + //, QuestionType.VIDEOGAME_DEVELOPER, QuestionType.VIDEOGAME_PUBLISHER, QuestionType.VIDEOGAME_GENRE, QuestionType.VIDEOGAME_COUNTRY}; - // private static final int NUMBER_OF_QUESTIONS = 50; - // private static final int NUMBER_OF_QUESTIONS = 100; - // private static final int NUMBER_OF_QUESTIONS = 3; - private static final int NUMBER_OF_QUESTIONS = 1; + //private static final int NUMBER_OF_QUESTIONS = 50; + private static final int NUMBER_OF_QUESTIONS = 100; + //private static final int NUMBER_OF_QUESTIONS = 3; + //private static final int NUMBER_OF_QUESTIONS = 1; public static void main(String[] args) { while(true) { diff --git a/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java b/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java index bc6546c7..d79636d0 100644 --- a/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java +++ b/questionGenerator/src/main/java/questionGenerator/repository/QuestionRepository.java @@ -1,6 +1,5 @@ package main.java.questionGenerator.repository; -import com.mongodb.client.ClientSession; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoCollection; @@ -81,9 +80,6 @@ public boolean populate(List questions) { try (MongoClient mongoClient = MongoClients.create(dbConnectionString)) { MongoDatabase database = mongoClient.getDatabase("questions"); - ClientSession session = mongoClient.startSession(); - session.startTransaction(); - MongoCollection collection = database.getCollection("questions"); collection.deleteMany(Document.parse("{}")); @@ -93,10 +89,7 @@ public boolean populate(List questions) { documents.add(Document.parse(questionJSON)); } - collection.insertMany(session, documents); - - session.commitTransaction(); - session.close(); + collection.insertMany(documents); return true; From d5d5059d38c55a7f29d66c808c0265e620da600e Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Thu, 25 Apr 2024 20:08:58 +0200 Subject: [PATCH 75/78] Small changes for the new question type --- gatewayservice/gateway-service.js | 2 +- webapp/src/components/GameConfigurator/GameConfigurator.js | 3 ++- webapp/src/translations/en/global.json | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index c4a1134c..9fe898b3 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -220,7 +220,7 @@ function validateAmount(amount) { } function validateType(type){ - return ['POPULATION', 'CAPITAL', 'LANGUAGE', 'SIZE'].includes(type); + return ['POPULATION', 'CAPITAL', 'LANGUAGE', 'SIZE', 'HEAD_OF_GOVERMENT'].includes(type); } function validateUser(user){ diff --git a/webapp/src/components/GameConfigurator/GameConfigurator.js b/webapp/src/components/GameConfigurator/GameConfigurator.js index 899a8528..d76a865a 100644 --- a/webapp/src/components/GameConfigurator/GameConfigurator.js +++ b/webapp/src/components/GameConfigurator/GameConfigurator.js @@ -16,7 +16,7 @@ function GameConfigurator(){ } function handleClickRandomize() { - const options = ['ALL', 'POPULATION', 'CAPITAL', 'LANGUAGE', 'SIZE']; + const options = ['ALL', 'POPULATION', 'CAPITAL', 'LANGUAGE', 'SIZE', 'HEAD_OF_GOVERMENT']; const randomOptionIndex = Math.floor(Math.random() * options.length); setTipoPregunta(options[randomOptionIndex]); @@ -37,6 +37,7 @@ function GameConfigurator(){ +

diff --git a/webapp/src/translations/en/global.json b/webapp/src/translations/en/global.json index 1bcf3aa0..ac6e6bf3 100644 --- a/webapp/src/translations/en/global.json +++ b/webapp/src/translations/en/global.json @@ -98,6 +98,7 @@ "option_capital":"Capital", "option_language":"Language", "option_size":"Size", + "option_head_of_goverment":"Head of Goverment", "custo_game":"Create custom game", "competi_game":"Play Competitive", "randomize":"Randomize Parameters" From 2fdd1e2dc28d17691e6186f30a64b53cf67b35f3 Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Thu, 25 Apr 2024 20:59:00 +0200 Subject: [PATCH 76/78] New tests added --- gatewayservice/gateway-service.js | 2 +- gatewayservice/gateway-service.test.js | 47 +++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 9fe898b3..9e2e9353 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -231,7 +231,7 @@ function manageError(res, error){ if(error.response) //Some microservice responded with an error res.status(error.response.status).json({ error: error.response.data.error }); else //Some other error - res.status(500).json({error : "Interanl server error"}) + res.status(500).json({error : "Internal server error"}) } module.exports = server diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index 550c4024..ecb355a4 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -2,6 +2,7 @@ const request = require('supertest'); const axios = require('axios'); const jwt = require('jsonwebtoken'); const app = require('./gateway-service'); +const { cat } = require('asciidoctor-emoji/dist/node/twemoji-map'); afterAll(async () => { app.close(); @@ -13,8 +14,8 @@ jest.mock('jsonwebtoken'); jest.mock('axios'); - -describe('Gateway Service with token mock', () => { +/* +describe('Gateway Service with mocked micro services', () => { // Mock responses from external services axios.post.mockImplementation((url, data) => { @@ -146,7 +147,7 @@ describe('Gateway Service with token mock', () => { }); -}); +});*/ function checkRecord(response){ expect(response.statusCode).toBe(200); @@ -156,4 +157,42 @@ function checkRecord(response){ function checkQuestion(response){ expect(response.statusCode).toBe(200); expect(response.body[0]).toHaveProperty('question', "¿Cuál es la población de Oviedo?"); -} \ No newline at end of file +} + +describe('Gateway Service without mocked micro services', () => { + + it('should not forward login request and give 500', async () => { + try{ + await request(app) + .post('/login') + .send({ username: 'testuser', password: 'testpassword' }); + + } catch(error){ + expect(error.response.status).toBe(500); + expect(error.response.data.error).toBe('Internal server error'); + } + }); + + axios.post.mockImplementation((url, data) => { + if (url.endsWith('/login')) { + throw new Error("Important information"); + } + }); + + it('should not forward login request and give 500', async () => { + axios.post.mockImplementation((url, data) => { + if (url.endsWith('/login')) { + throw new Error("Important information"); + } + }); + try{ + await request(app) + .post('/login') + .send({ username: 'testuser', password: 'testpassword' }); + + } catch(error){ + expect(error.response.status).toBe(500); + expect(error.response.data.error).toBe('Internal server error'); + } + }); +}); From ada02ec53a22b0190a70aae143b08e1f41d87fe6 Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Thu, 25 Apr 2024 21:02:27 +0200 Subject: [PATCH 77/78] Removed some comments --- gatewayservice/gateway-service.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index ecb355a4..9629a443 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -14,7 +14,7 @@ jest.mock('jsonwebtoken'); jest.mock('axios'); -/* + describe('Gateway Service with mocked micro services', () => { // Mock responses from external services @@ -147,7 +147,7 @@ describe('Gateway Service with mocked micro services', () => { }); -});*/ +}); function checkRecord(response){ expect(response.statusCode).toBe(200); From 2b4fc3e23cdbe10f06d13483a67d0ee56fc440ab Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Thu, 25 Apr 2024 21:23:39 +0200 Subject: [PATCH 78/78] Removed an extra mock --- gatewayservice/gateway-service.js | 1 + gatewayservice/gateway-service.test.js | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 9e2e9353..49b59c0f 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -41,6 +41,7 @@ app.post('/adduser', async (req, res) => { try { // Forward the add user request to the user service const userResponse = await axios.post(userServiceUrl+'/adduser', req.body); + console.log(userResponse) res.json(userResponse.data); } catch (error) { manageError(res, error); diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index 9629a443..a51f5f18 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -2,7 +2,6 @@ const request = require('supertest'); const axios = require('axios'); const jwt = require('jsonwebtoken'); const app = require('./gateway-service'); -const { cat } = require('asciidoctor-emoji/dist/node/twemoji-map'); afterAll(async () => { app.close(); @@ -173,12 +172,6 @@ describe('Gateway Service without mocked micro services', () => { } }); - axios.post.mockImplementation((url, data) => { - if (url.endsWith('/login')) { - throw new Error("Important information"); - } - }); - it('should not forward login request and give 500', async () => { axios.post.mockImplementation((url, data) => { if (url.endsWith('/login')) {