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.
Merge pull request #267 from Arquisoft/feat/questionAddChanges
More questions
- Loading branch information
Showing
15 changed files
with
489 additions
and
69 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 | ||
CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE | ||
} | ||
|
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 | ||
CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE | ||
} | ||
|
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
77 changes: 77 additions & 0 deletions
77
questiongenerator/src/main/java/templates/BasketballVenueQuestion.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.*; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class BasketballVenueQuestion extends QuestionTemplate { | ||
|
||
private List<String> teamLabels; | ||
|
||
private static final String[] spanishStringsIni = {"¿Cómo se llama el estadio de ", "¿Dónde juega el equipo ", "¿Cuál es el estadio del equipo ", "¿Dónde se juegan los partidos del equipo "}; | ||
private static final String[] englishStringsIni= {"What is the venue of ", "What is the stadium of ", "Which name receives the venue of ", "Where does "}; | ||
|
||
private static final String[] spanishStringsFin = {"?", "?", "?", "?"}; | ||
private static final String[] englishStringsFin = {"?", "?", "?", " play?"}; | ||
|
||
public BasketballVenueQuestion(String langCode) { | ||
super(langCode); | ||
} | ||
|
||
@Override | ||
public void setQuery() { | ||
this.sparqlQuery = "SELECT ?teamLabel ?venueLabel " + | ||
"WHERE { " + | ||
" ?team wdt:P31 wd:Q13393265; " + | ||
" wdt:P118 ?league; " + | ||
" wdt:P115 ?venue. " + | ||
" VALUES ?league {wd:Q1126104 wd:Q155223} " + | ||
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"" + langCode + "\". } " + | ||
"} "; | ||
} | ||
|
||
@Override | ||
public void processResults() { | ||
teamLabels = 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 teamLabel = result.getJSONObject("teamLabel").getString("value"); | ||
String venueLabel = result.getJSONObject("venueLabel").getString("value"); | ||
|
||
if (needToSkip(teamLabel, venueLabel)) { | ||
continue; | ||
} | ||
|
||
Answer a = new Answer(venueLabel, AnswerCategory.BASKETBALL_VENUE, langCode); | ||
answers.add(a); | ||
|
||
String questionString = ""; | ||
|
||
if (langCode.equals("es")) | ||
questionString = spanishStringsIni[i%4] + teamLabel + spanishStringsFin[i%4]; | ||
else | ||
questionString = englishStringsIni[i%4] + teamLabel + englishStringsFin[i%4]; | ||
|
||
questions.add(new Question(a, questionString, QuestionCategory.SPORTS, QuestionType.TEXT)); | ||
} | ||
repository.saveAll(new ArrayList<>(answers)); | ||
repository.saveAll(new ArrayList<>(questions)); | ||
} | ||
|
||
private boolean needToSkip(String teamLabel, String venueLabel){ | ||
if (teamLabels.contains(teamLabel)) { | ||
return true; | ||
} | ||
teamLabels.add(teamLabel); | ||
|
||
if (QGHelper.isEntityName(teamLabel) || QGHelper.isEntityName(venueLabel)) | ||
return true; | ||
|
||
return false; | ||
} | ||
} |
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
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,33 @@ | ||
package templates; | ||
|
||
public class QGHelper { | ||
public final static String LINKCONCAT = "#* &%"; | ||
public final static String[] allowedExtensions = {"png", "jpg", "jpeg", "gif", "svg"}; | ||
|
||
private QGHelper() { | ||
} | ||
|
||
public static boolean isEntityName(String label){ | ||
boolean isEntityName = true; // Check if it is like Q232334 | ||
if (label.startsWith("Q") ){ | ||
for (int i=1; i<label.length(); i++){ | ||
if (!Character.isDigit(label.charAt(i))){ | ||
isEntityName = false; | ||
} | ||
} | ||
if (isEntityName){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static boolean notAllowedExtension(String link){ | ||
for (String s : allowedExtensions){ | ||
if (link.endsWith(s)){ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
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
Oops, something went wrong.