generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #70 from Arquisoft/Question_Generation_General
Updated question generator
- Loading branch information
Showing
14 changed files
with
472 additions
and
217 deletions.
There are no files selected for viewing
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,52 @@ | ||
package main.java; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import main.java.questionGenerator.QuestionGeneratorMock; | ||
import main.java.questionGenerator.question.Question; | ||
import main.java.questionGenerator.question.QuestionType; | ||
import main.java.questionGenerator.repository.QuestionRepository; | ||
|
||
public class MainMock { | ||
|
||
private static QuestionType[] types = {QuestionType.POPULATION, QuestionType.CAPITAL, QuestionType.SIZE, | ||
QuestionType.LANGUAGE}; | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Ahora en Espa�ol"); | ||
QuestionGeneratorMock qg = new QuestionGeneratorMock("es"); | ||
for(QuestionType t : types) { | ||
run(qg, t); | ||
System.out.println(); | ||
} | ||
System.out.println("Now English"); | ||
qg = new QuestionGeneratorMock("en"); | ||
for(QuestionType t : types) { | ||
run(qg, t); | ||
System.out.println(); | ||
} | ||
System.out.println("Now in english but with bad language code"); | ||
qg = new QuestionGeneratorMock("ep"); | ||
for(QuestionType t : types) { | ||
run(qg, t); | ||
System.out.println(); | ||
} | ||
|
||
} | ||
|
||
private static void run(QuestionGeneratorMock qg, QuestionType type) { | ||
List<String> questionJSONList = new ArrayList<>(); | ||
|
||
//Populate JSON list here | ||
for(int i=0; i<3; i++) { | ||
Question question = qg.generateQuestion(type); | ||
question.setNumber(i); | ||
questionJSONList.add(question.getJSON().toString()); | ||
System.out.println(question.getJSON().toString()); | ||
} | ||
|
||
QuestionRepository.getInstance().insert(questionJSONList); | ||
} | ||
|
||
} |
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
127 changes: 127 additions & 0 deletions
127
questionGenerator/src/main/java/questionGenerator/QuestionGeneratorMock.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,127 @@ | ||
package main.java.questionGenerator; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
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.LanguageGenerator; | ||
import main.java.questionGenerator.generator.specificGenerators.PopulationGenerator; | ||
import main.java.questionGenerator.generator.specificGenerators.SizeGenerator; | ||
import main.java.questionGenerator.question.Question; | ||
import main.java.questionGenerator.question.QuestionType; | ||
|
||
public class QuestionGeneratorMock { | ||
|
||
private AbstractGenerator generator; | ||
private String id; | ||
private String languageCode; | ||
|
||
private static String[] POP_ENTITIES = {"Q14317", "Q12273", "Q14649"}; | ||
private static String[] CAP_ENTITIES = {"Q3934", "Q29", "Q43"}; | ||
private static String[] SIZE_ENTITIES = {"Q29", "Q12273", "Q3934"}; | ||
private static String[] LANG_ENTITIES = {"Q29", "Q43", "Q3934"}; | ||
|
||
public QuestionGeneratorMock(String languageCode){ | ||
this.languageCode = languageCode; | ||
} | ||
|
||
public Question generateQuestion(QuestionType type) { | ||
generatorFactory(type); | ||
generator.setLocalization(languageCode); | ||
return generator.generate(id); | ||
} | ||
|
||
public List<Question> generateQuestions(QuestionType type, int amount){ | ||
setGenerator(type); | ||
generator.setLocalization(languageCode); | ||
List<Question> questions = new ArrayList<>(); | ||
List<String> entites = new ArrayList<>(); | ||
try { | ||
entites = EntityGenerator.getEntities(type, 100); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
Random rnd = new Random(); | ||
List<String> chosen = new ArrayList<>(); | ||
int size = entites.size(); | ||
int number = 0; | ||
while(number<amount) { | ||
int index = rnd.nextInt(size); | ||
String entity = entites.get(index); | ||
if(!chosen.contains(entity)) { | ||
chosen.add(entity); | ||
Question q = generator.generate(entity); | ||
questions.add(q); | ||
number++; | ||
} | ||
} | ||
return questions; | ||
} | ||
|
||
private void setGenerator(QuestionType type) { | ||
switch (type) { | ||
case POPULATION: { | ||
generator = new PopulationGenerator(); | ||
break; | ||
} | ||
case CAPITAL: { | ||
generator = new CapitalGenerator(); | ||
break; | ||
|
||
} | ||
case SIZE: { | ||
generator = new SizeGenerator(); | ||
break; | ||
} | ||
case LANGUAGE: { | ||
generator = new LanguageGenerator(); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private void generatorFactory(QuestionType type) { | ||
switch (type) { | ||
case POPULATION: { | ||
id = POP_ENTITIES[0]; | ||
generator = new PopulationGenerator(); | ||
moveUp(POP_ENTITIES); | ||
POP_ENTITIES[POP_ENTITIES.length-1] = id; | ||
break; | ||
} | ||
case CAPITAL: { | ||
id = CAP_ENTITIES[0]; | ||
generator = new CapitalGenerator(); | ||
moveUp(CAP_ENTITIES); | ||
CAP_ENTITIES[CAP_ENTITIES.length-1] = id; | ||
break; | ||
|
||
} | ||
case SIZE: { | ||
id = SIZE_ENTITIES[0]; | ||
generator = new SizeGenerator(); | ||
moveUp(SIZE_ENTITIES); | ||
SIZE_ENTITIES[SIZE_ENTITIES.length-1] = id; | ||
break; | ||
} | ||
case LANGUAGE: { | ||
id = LANG_ENTITIES[0]; | ||
generator = new LanguageGenerator(); | ||
moveUp(LANG_ENTITIES); | ||
LANG_ENTITIES[LANG_ENTITIES.length-1] = id; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private void moveUp(String[] list) { | ||
for(int i=0; i<list.length-1; i++) { | ||
list[i] = list[i+1]; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.