From bab32606d7bbfa222baf883482e3752020d73c3d Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Sun, 28 Apr 2024 18:43:06 +0200 Subject: [PATCH 1/4] Feat: Added new question --- .../java/lab/en2b/quizapi/questions/answer/AnswerCategory.java | 2 +- questiongenerator/src/main/java/model/AnswerCategory.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerCategory.java b/api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerCategory.java index f74bd1b0..3e0f25b4 100644 --- a/api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerCategory.java +++ b/api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerCategory.java @@ -1,6 +1,6 @@ package lab.en2b.quizapi.questions.answer; public enum AnswerCategory { - CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE, COUNTRY_FLAG + CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE, COUNTRY_FLAG, GAMES_RELEASE } diff --git a/questiongenerator/src/main/java/model/AnswerCategory.java b/questiongenerator/src/main/java/model/AnswerCategory.java index c4b0f5a1..dae58ced 100644 --- a/questiongenerator/src/main/java/model/AnswerCategory.java +++ b/questiongenerator/src/main/java/model/AnswerCategory.java @@ -1,6 +1,6 @@ package model; public enum AnswerCategory { - CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE, COUNTRY_FLAG + CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE, COUNTRY_FLAG, GAMES_RELEASE } From 1d7617a0057a36e8005fe9de461947370345dbd0 Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Sun, 28 Apr 2024 18:43:30 +0200 Subject: [PATCH 2/4] Feat: Added new question (with the calls) --- questiongenerator/src/main/java/Main.java | 7 ++ .../java/templates/VideogamesReleaseDate.java | 90 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 questiongenerator/src/main/java/templates/VideogamesReleaseDate.java diff --git a/questiongenerator/src/main/java/Main.java b/questiongenerator/src/main/java/Main.java index d89a60bb..6ef99cb1 100644 --- a/questiongenerator/src/main/java/Main.java +++ b/questiongenerator/src/main/java/Main.java @@ -43,6 +43,11 @@ public static void main(String[] args) { new MusicAuthorQuestion("es"); } + if (GeneralRepositoryStorer.doesntExist(AnswerCategory.GAMES_RELEASE)) { + new VideogamesReleaseDate("en"); + new VideogamesReleaseDate("es"); + } + // IMAGES if(GeneralRepositoryStorer.doesntExist(AnswerCategory.STADIUM)) { @@ -65,6 +70,8 @@ public static void main(String[] args) { new CountryFlagQuestion("es"); } + + /* // VIDEOS not yet supported if(GeneralRepositoryStorer.doesntExist(AnswerCategory.SONG.toString())) { diff --git a/questiongenerator/src/main/java/templates/VideogamesReleaseDate.java b/questiongenerator/src/main/java/templates/VideogamesReleaseDate.java new file mode 100644 index 00000000..6599fbd8 --- /dev/null +++ b/questiongenerator/src/main/java/templates/VideogamesReleaseDate.java @@ -0,0 +1,90 @@ +package templates; + +import model.*; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class VideogamesReleaseDate extends QuestionTemplate { + List videoGameLabels; + + private static final String[] spanishStringsIni = {"¿Cuándo fue publicado ", "¿En qué fecha fue lanzado ", "¿Cuándo fue lanzado ", "¿En qué fecha fue publicado "}; + private static final String[] englishStringsIni= {"When was ", "On what date was ", "When was ", "On what date was "}; + + private static final String[] spanishStringsFin = {"?", "?", "?", "?"}; + private static final String[] englishStringsFin = {" released?", " released?", " launched?", " launched?"}; + + public VideogamesReleaseDate(String langCode) { + super(langCode); + } + + @Override + public void setQuery() { + this.sparqlQuery = "SELECT ?gameLabel (MAX(?unitsSoldValue) as ?maxUnitsSold) (MIN(?publicationDate) as ?oldestPublicationDate)\n" + + "WHERE { " + + " ?game wdt:P31 wd:Q7889; " + + " wdt:P2664 ?unitsSoldValue. " + + " ?game wdt:P577 ?publicationDate. " + + " SERVICE wikibase:label { bd:serviceParam wikibase:language \"" + langCode + "\". } " + + "} " + + "GROUP BY ?game ?gameLabel " + + "ORDER BY DESC(?maxUnitsSold) " + + "LIMIT 150 "; + } + + @Override + public void processResults() { + videoGameLabels = new ArrayList<>(); + List questions = new ArrayList<>(); + List answers = new ArrayList<>(); + + for (int i = 0; i < results.length()-10; i++) { + + JSONObject result = results.getJSONObject(i); + + String videoGameLabel = ""; + String publishDateLabel = ""; + + try { + JSONObject videoGameLabelObject = result.getJSONObject("gameLabel"); + videoGameLabel = videoGameLabelObject.getString("value"); + + JSONObject publishDateLabelObject = result.getJSONObject("oldestPublicationDate"); + publishDateLabel = publishDateLabelObject.getString("value"); + + publishDateLabel = publishDateLabel.substring(0, 4); + + } catch (Exception e) { + continue; + } + + if (needToSkip(videoGameLabel, publishDateLabel)) + continue; + + Answer a = new Answer(publishDateLabel, AnswerCategory.GAMES_RELEASE, langCode); + answers.add(a); + + if (langCode.equals("es")) + questions.add(new Question(a, "¿Qué compañía publicó " + videoGameLabel + "?", QuestionCategory.VIDEOGAMES, QuestionType.TEXT)); + else + questions.add(new Question(a, "Who published " + videoGameLabel + "?", QuestionCategory.VIDEOGAMES, QuestionType.TEXT)); + } + + repository.saveAll(new ArrayList<>(answers)); + repository.saveAll(new ArrayList<>(questions)); + } + + private boolean needToSkip(String videoGameLabel, String countryLabel) { + if (videoGameLabels.contains(videoGameLabel)) { + return true; + } + videoGameLabels.add(videoGameLabel); + + if (QGHelper.isEntityName(videoGameLabel) || QGHelper.isEntityName(countryLabel)) + return true; + + return false; + } +} + From fe374431bccd8bae32efd41e0e79dfc01a88371b Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Sun, 28 Apr 2024 19:04:54 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Fix:=20Solved=20the=20string=20of=20the=20q?= =?UTF-8?q?uestions=20(copypaste=20bad=20=E2=98=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/templates/VideogamesReleaseDate.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/questiongenerator/src/main/java/templates/VideogamesReleaseDate.java b/questiongenerator/src/main/java/templates/VideogamesReleaseDate.java index 6599fbd8..e817f066 100644 --- a/questiongenerator/src/main/java/templates/VideogamesReleaseDate.java +++ b/questiongenerator/src/main/java/templates/VideogamesReleaseDate.java @@ -65,10 +65,14 @@ public void processResults() { Answer a = new Answer(publishDateLabel, AnswerCategory.GAMES_RELEASE, langCode); answers.add(a); + String questionString = ""; + if (langCode.equals("es")) - questions.add(new Question(a, "¿Qué compañía publicó " + videoGameLabel + "?", QuestionCategory.VIDEOGAMES, QuestionType.TEXT)); + questionString = spanishStringsIni[i%4] + videoGameLabel + spanishStringsFin[i%4]; else - questions.add(new Question(a, "Who published " + videoGameLabel + "?", QuestionCategory.VIDEOGAMES, QuestionType.TEXT)); + questionString = englishStringsIni[i%4] + videoGameLabel + englishStringsFin[i%4]; + + questions.add(new Question(a, questionString, QuestionCategory.VIDEOGAMES, QuestionType.TEXT)); } repository.saveAll(new ArrayList<>(answers)); From 5d001805a006bd92a431d17a536a9c194a2fc59f Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Sun, 28 Apr 2024 19:05:58 +0200 Subject: [PATCH 4/4] Fix: Added diversity to the question --- .../src/main/java/templates/VideogamesReleaseDate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/questiongenerator/src/main/java/templates/VideogamesReleaseDate.java b/questiongenerator/src/main/java/templates/VideogamesReleaseDate.java index e817f066..76741c90 100644 --- a/questiongenerator/src/main/java/templates/VideogamesReleaseDate.java +++ b/questiongenerator/src/main/java/templates/VideogamesReleaseDate.java @@ -9,7 +9,7 @@ public class VideogamesReleaseDate extends QuestionTemplate { List videoGameLabels; - private static final String[] spanishStringsIni = {"¿Cuándo fue publicado ", "¿En qué fecha fue lanzado ", "¿Cuándo fue lanzado ", "¿En qué fecha fue publicado "}; + private static final String[] spanishStringsIni = {"¿Cuándo se publicó ", "¿En qué fecha fue lanzado ", "¿Cuándo fue lanzado ", "¿En qué fecha fue publicado "}; private static final String[] englishStringsIni= {"When was ", "On what date was ", "When was ", "On what date was "}; private static final String[] spanishStringsFin = {"?", "?", "?", "?"};