use of ai.elimu.model.content.LetterSoundCorrespondence in project webapp by elimu-ai.
the class LetterSoundCorrespondencesRestController method handleGetRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleGetRequest() {
logger.info("handleGetRequest");
JSONArray letterSoundCorrespondencesJsonArray = new JSONArray();
for (LetterSoundCorrespondence letterSoundCorrespondence : letterSoundCorrespondenceDao.readAllOrderedByUsage()) {
LetterSoundCorrespondenceGson letterSoundCorrespondenceGson = JpaToGsonConverter.getLetterSoundCorrespondenceGson(letterSoundCorrespondence);
String json = new Gson().toJson(letterSoundCorrespondenceGson);
letterSoundCorrespondencesJsonArray.put(new JSONObject(json));
}
String jsonResponse = letterSoundCorrespondencesJsonArray.toString();
logger.info("jsonResponse: " + jsonResponse);
return jsonResponse;
}
use of ai.elimu.model.content.LetterSoundCorrespondence in project webapp by elimu-ai.
the class WordContributionRestController method getLetterSoundCorrespondences.
/**
* Returns a list of {@link LetterSoundCorrespondence}s that will be used to construct a {@link Word}.
*/
@RequestMapping(value = "/letter-sound-correspondences", method = RequestMethod.GET)
public String getLetterSoundCorrespondences(HttpServletRequest request, HttpServletResponse response) {
logger.info("getLetterSoundCorrespondences");
JSONArray letterSoundCorrespondencesJsonArray = new JSONArray();
for (LetterSoundCorrespondence letterSoundCorrespondence : letterSoundCorrespondenceDao.readAllOrderedByUsage()) {
LetterSoundCorrespondenceGson letterSoundCorrespondenceGson = JpaToGsonConverter.getLetterSoundCorrespondenceGson(letterSoundCorrespondence);
String json = new Gson().toJson(letterSoundCorrespondenceGson);
letterSoundCorrespondencesJsonArray.put(new JSONObject(json));
}
String jsonResponse = letterSoundCorrespondencesJsonArray.toString();
logger.info("jsonResponse: " + jsonResponse);
return jsonResponse;
}
use of ai.elimu.model.content.LetterSoundCorrespondence in project webapp by elimu-ai.
the class JpaToGsonConverter method getWordGson.
public static WordGson getWordGson(Word word) {
if (word == null) {
return null;
} else {
WordGson wordGson = new WordGson();
// BaseEntity
wordGson.setId(word.getId());
// Content
wordGson.setRevisionNumber(word.getRevisionNumber());
wordGson.setUsageCount(word.getUsageCount());
// Word
wordGson.setText(word.getText());
List<LetterSoundCorrespondenceGson> letterSoundCorrespondences = new ArrayList<>();
for (LetterSoundCorrespondence letterSoundCorrespondence : word.getLetterSoundCorrespondences()) {
LetterSoundCorrespondenceGson letterSoundCorrespondenceGson = getLetterSoundCorrespondenceGson(letterSoundCorrespondence);
letterSoundCorrespondences.add(letterSoundCorrespondenceGson);
}
wordGson.setLetterSoundCorrespondences(letterSoundCorrespondences);
wordGson.setWordType(word.getWordType());
return wordGson;
}
}
use of ai.elimu.model.content.LetterSoundCorrespondence in project webapp by elimu-ai.
the class SoundUsageCountScheduler method execute.
// At 06:30 every day
@Scheduled(cron = "00 30 06 * * *")
public synchronized void execute() {
logger.info("execute");
logger.info("Calculating usage count of Sounds");
// Long = Sound ID
// Integer = Usage count
Map<Long, Integer> soundFrequencyMap = new HashMap<>();
// Summarize the usage count of each Word's Sounds based on the LetterSoundCorrespondence's
// usage count (see LetterSoundCorrespondenceUsageCountScheduler).
List<Word> words = wordDao.readAllOrdered();
logger.info("words.size(): " + words.size());
for (Word word : words) {
for (LetterSoundCorrespondence letterSoundCorrespondence : word.getLetterSoundCorrespondences()) {
for (Sound sound : letterSoundCorrespondence.getSounds()) {
soundFrequencyMap.put(sound.getId(), soundFrequencyMap.getOrDefault(sound.getId(), 0) + letterSoundCorrespondence.getUsageCount());
}
}
}
// Update each Sound's usage count in the database
for (Long soundId : soundFrequencyMap.keySet()) {
Sound sound = soundDao.read(soundId);
sound.setUsageCount(soundFrequencyMap.get(soundId));
soundDao.update(sound);
}
logger.info("execute complete");
}
use of ai.elimu.model.content.LetterSoundCorrespondence in project webapp by elimu-ai.
the class LetterSoundCorrespondenceCreateController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model) {
logger.info("handleRequest");
LetterSoundCorrespondence letterSoundCorrespondence = new LetterSoundCorrespondence();
model.addAttribute("letterSoundCorrespondence", letterSoundCorrespondence);
List<Letter> letters = letterDao.readAllOrdered();
model.addAttribute("letters", letters);
List<Sound> sounds = soundDao.readAllOrdered();
model.addAttribute("sounds", sounds);
model.addAttribute("timeStart", System.currentTimeMillis());
return "content/letter-sound-correspondence/create";
}
Aggregations