From 3d98d3fd7d758cf9a4e86a4b0f39085430dddaa6 Mon Sep 17 00:00:00 2001 From: jorge Date: Mon, 8 Apr 2024 16:41:10 +0200 Subject: [PATCH 01/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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/69] 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 867fc5801186df59588b57f8a2bd9dd86223a1f8 Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Thu, 25 Apr 2024 19:49:53 +0200 Subject: [PATCH 69/69] 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;