Search in sources :

Example 1 with LetterSoundCorrespondence

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;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) LetterSoundCorrespondenceGson(ai.elimu.model.v2.gson.content.LetterSoundCorrespondenceGson) Gson(com.google.gson.Gson) LetterSoundCorrespondence(ai.elimu.model.content.LetterSoundCorrespondence) LetterSoundCorrespondenceGson(ai.elimu.model.v2.gson.content.LetterSoundCorrespondenceGson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with LetterSoundCorrespondence

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;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) LetterSoundCorrespondenceGson(ai.elimu.model.v2.gson.content.LetterSoundCorrespondenceGson) Gson(com.google.gson.Gson) WordGson(ai.elimu.model.v2.gson.content.WordGson) WordContributionEventGson(ai.elimu.model.v2.gson.crowdsource.WordContributionEventGson) LetterSoundCorrespondence(ai.elimu.model.content.LetterSoundCorrespondence) LetterSoundCorrespondenceGson(ai.elimu.model.v2.gson.content.LetterSoundCorrespondenceGson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with LetterSoundCorrespondence

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;
    }
}
Also used : WordGson(ai.elimu.model.v2.gson.content.WordGson) ArrayList(java.util.ArrayList) LetterSoundCorrespondence(ai.elimu.model.content.LetterSoundCorrespondence) LetterSoundCorrespondenceGson(ai.elimu.model.v2.gson.content.LetterSoundCorrespondenceGson)

Example 4 with LetterSoundCorrespondence

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");
}
Also used : Word(ai.elimu.model.content.Word) HashMap(java.util.HashMap) Sound(ai.elimu.model.content.Sound) LetterSoundCorrespondence(ai.elimu.model.content.LetterSoundCorrespondence) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 5 with LetterSoundCorrespondence

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";
}
Also used : Letter(ai.elimu.model.content.Letter) Sound(ai.elimu.model.content.Sound) LetterSoundCorrespondence(ai.elimu.model.content.LetterSoundCorrespondence) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LetterSoundCorrespondence (ai.elimu.model.content.LetterSoundCorrespondence)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Letter (ai.elimu.model.content.Letter)10 Sound (ai.elimu.model.content.Sound)10 Word (ai.elimu.model.content.Word)7 ArrayList (java.util.ArrayList)7 JSONArray (org.json.JSONArray)6 JSONObject (org.json.JSONObject)5 LetterSoundCorrespondenceContributionEvent (ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent)4 LetterSoundCorrespondenceGson (ai.elimu.model.v2.gson.content.LetterSoundCorrespondenceGson)4 IOException (java.io.IOException)4 CSVFormat (org.apache.commons.csv.CSVFormat)4 Contributor (ai.elimu.model.contributor.Contributor)3 WordGson (ai.elimu.model.v2.gson.content.WordGson)3 Gson (com.google.gson.Gson)3 WordContributionEvent (ai.elimu.model.contributor.WordContributionEvent)2 WordContributionEventGson (ai.elimu.model.v2.gson.crowdsource.WordContributionEventGson)2 Reader (java.io.Reader)2 StringWriter (java.io.StringWriter)2 Path (java.nio.file.Path)2