generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE, COUNTRY_FLAG | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE, COUNTRY_FLAG | ||
} | ||
|
77 changes: 77 additions & 0 deletions
77
questiongenerator/src/main/java/templates/CountryFlagQuestion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package templates; | ||
|
||
import model.QuestionCategory; | ||
import model.QuestionType; | ||
import model.Answer; | ||
import model.AnswerCategory; | ||
import model.Question; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CountryFlagQuestion extends QuestionTemplate { | ||
|
||
private static final String[] spanishStringsIni = {"¿Que país tiene esta bandera? ", "¿A qué país pertenece esta bandera? ", "¿De qué país es esta bandera? ", "¿Cuál es el país de esta bandera? "}; | ||
private static final String[] englishStringsIni= {"Which country has this flag? ", "To which country belongs this flag? ", "From which country is this flag? ", "What is the country represented by this flag? "}; | ||
|
||
List<String> countryLabels; | ||
|
||
public CountryFlagQuestion(String langCode) { | ||
super(langCode); | ||
} | ||
|
||
@Override | ||
public void setQuery() { | ||
this.sparqlQuery = "SELECT ?countryLabel ?flagLabel\n" + | ||
"WHERE " + | ||
"{ " + | ||
" ?country wdt:P31 wd:Q6256; " + | ||
" wdt:P41 ?flag. " + | ||
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"" + langCode + "\". } " + | ||
"}"; | ||
} | ||
|
||
@Override | ||
public void processResults() { | ||
countryLabels = new ArrayList<>(); | ||
List<Question> questions = new ArrayList<>(); | ||
List<Answer> answers = new ArrayList<>(); | ||
|
||
for (int i = 0; i < results.length(); i++) { | ||
JSONObject result = results.getJSONObject(i); | ||
String countryLabel = result.getJSONObject("countryLabel").getString("value"); | ||
String flagLabel = result.getJSONObject("flagLabel").getString("value"); | ||
|
||
if (needToSkip(countryLabel, flagLabel)) { | ||
continue; | ||
} | ||
|
||
Answer a = new Answer(countryLabel, AnswerCategory.COUNTRY_FLAG, langCode); | ||
answers.add(a); | ||
|
||
if (langCode.equals("es")){ | ||
String questionString = spanishStringsIni[i%4] + QGHelper.LINKCONCAT + flagLabel; | ||
questions.add(new Question(a, questionString, QuestionCategory.GEOGRAPHY, QuestionType.IMAGE)); | ||
} else { | ||
String questionString = englishStringsIni[i%4] + QGHelper.LINKCONCAT + flagLabel; | ||
questions.add(new Question(a, questionString, QuestionCategory.GEOGRAPHY, QuestionType.IMAGE)); | ||
} | ||
} | ||
repository.saveAll(new ArrayList<>(answers)); | ||
repository.saveAll(new ArrayList<>(questions)); | ||
} | ||
|
||
private boolean needToSkip(String countryLabel, String venueLabel){ | ||
if (countryLabels.contains(countryLabel)) { | ||
return true; | ||
} | ||
countryLabels.add(countryLabel); | ||
|
||
if (QGHelper.isEntityName(countryLabel) || QGHelper.isEntityName(venueLabel)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |