Search in sources :

Example 11 with Allophone

use of ai.elimu.model.content.Allophone in project webapp by elimu-ai.

the class WordCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Word word, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Word existingWord = wordDao.readByText(word.getLocale(), word.getText());
    if (existingWord != null) {
        result.rejectValue("text", "NonUnique");
    }
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    List<Allophone> allophones = allophoneDao.readAllOrderedByUsage(contributor.getLocale());
    // Verify that only valid Allophones are used
    String allAllophonesCombined = "";
    for (Allophone allophone : allophones) {
        allAllophonesCombined += allophone.getValueIpa();
    }
    if (StringUtils.isNotBlank(word.getPhonetics())) {
        for (char allophoneCharacter : word.getPhonetics().toCharArray()) {
            String allophone = String.valueOf(allophoneCharacter);
            if (!allAllophonesCombined.contains(allophone)) {
                result.rejectValue("phonetics", "Invalid");
                break;
            }
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("word", word);
        model.addAttribute("allophones", allophones);
        model.addAttribute("wordTypes", WordType.values());
        model.addAttribute("spellingConsistencies", SpellingConsistency.values());
        return "content/word/create";
    } else {
        if (!"I".equals(word.getText())) {
            word.setText(word.getText().toLowerCase());
        }
        word.setTimeLastUpdate(Calendar.getInstance());
        wordDao.create(word);
        WordRevisionEvent wordRevisionEvent = new WordRevisionEvent();
        wordRevisionEvent.setContributor(contributor);
        wordRevisionEvent.setCalendar(Calendar.getInstance());
        wordRevisionEvent.setWord(word);
        wordRevisionEvent.setText(word.getText());
        wordRevisionEvent.setPhonetics(word.getPhonetics());
        wordRevisionEventDao.create(wordRevisionEvent);
        // Label Image with Word of matching title
        Image matchingImage = imageDao.read(word.getText(), word.getLocale());
        if (matchingImage != null) {
            Set<Word> labeledWords = matchingImage.getWords();
            if (!labeledWords.contains(word)) {
                labeledWords.add(word);
                matchingImage.setWords(labeledWords);
                imageDao.update(matchingImage);
            }
        }
        // Delete syllables that are actual words
        Syllable syllable = syllableDao.readByText(contributor.getLocale(), word.getText());
        if (syllable != null) {
            syllableDao.delete(syllable);
        }
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            String text = URLEncoder.encode(contributor.getFirstName() + " just added a new Word:\n" + "• Language: \"" + word.getLocale().getLanguage() + "\"\n" + "• Text: \"" + word.getText() + "\"\n" + "• Phonetics (IPA): /" + word.getPhonetics() + "/\n" + "• Word type: " + word.getWordType() + "\n" + "• Spelling consistency: " + word.getSpellingConsistency() + "\n" + "See ") + "http://elimu.ai/content/word/edit/" + word.getId();
            String iconUrl = contributor.getImageUrl();
            SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
        }
        return "redirect:/content/word/list#" + word.getId();
    }
}
Also used : Word(ai.elimu.model.content.Word) Allophone(ai.elimu.model.content.Allophone) Contributor(ai.elimu.model.Contributor) WordRevisionEvent(ai.elimu.model.contributor.WordRevisionEvent) Image(ai.elimu.model.content.multimedia.Image) Syllable(ai.elimu.model.content.Syllable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with Allophone

use of ai.elimu.model.content.Allophone in project webapp by elimu-ai.

the class WordCreateController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
    logger.info("handleRequest");
    Word word = new Word();
    model.addAttribute("word", word);
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    List<Allophone> allophones = allophoneDao.readAllOrderedByUsage(contributor.getLocale());
    model.addAttribute("allophones", allophones);
    model.addAttribute("wordTypes", WordType.values());
    model.addAttribute("spellingConsistencies", SpellingConsistency.values());
    return "content/word/create";
}
Also used : Word(ai.elimu.model.content.Word) Allophone(ai.elimu.model.content.Allophone) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Allophone

use of ai.elimu.model.content.Allophone in project webapp by elimu-ai.

the class WordEditController method handleRequest.

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(Model model, @PathVariable Long id, HttpSession session) {
    logger.info("handleRequest");
    Word word = wordDao.read(id);
    model.addAttribute("word", word);
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    List<Allophone> allophones = allophoneDao.readAllOrderedByUsage(contributor.getLocale());
    model.addAttribute("allophones", allophones);
    model.addAttribute("wordTypes", WordType.values());
    model.addAttribute("spellingConsistencies", SpellingConsistency.values());
    model.addAttribute("wordRevisionEvents", wordRevisionEventDao.readAll(word));
    Audio audio = audioDao.read(word.getText(), contributor.getLocale());
    model.addAttribute("audio", audio);
    // Look up Multimedia content that has been labeled with this Word
    List<Image> labeledImages = imageDao.readAllLabeled(word, contributor.getLocale());
    // TODO: labeled Audios
    model.addAttribute("labeledImages", labeledImages);
    return "content/word/edit";
}
Also used : Word(ai.elimu.model.content.Word) Allophone(ai.elimu.model.content.Allophone) Contributor(ai.elimu.model.Contributor) Audio(ai.elimu.model.content.multimedia.Audio) Image(ai.elimu.model.content.multimedia.Image) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with Allophone

use of ai.elimu.model.content.Allophone in project webapp by elimu-ai.

the class AllophoneDaoTest method testLowerCaseVsUpperCase.

@Test
public void testLowerCaseVsUpperCase() {
    Locale locale = Locale.values()[(int) (Math.random() * Locale.values().length)];
    logger.info("locale: " + locale);
    Allophone allophoneLowerCaseT = new Allophone();
    allophoneLowerCaseT.setLocale(locale);
    allophoneLowerCaseT.setValueIpa("t");
    allophoneLowerCaseT.setValueSampa("t");
    allophoneDao.create(allophoneLowerCaseT);
    Allophone allophoneUpperCaseT = new Allophone();
    allophoneUpperCaseT.setLocale(locale);
    allophoneUpperCaseT.setValueIpa("θ");
    allophoneUpperCaseT.setValueSampa("T");
    allophoneDao.create(allophoneUpperCaseT);
    assertThat(allophoneDao.readByValueSampa(locale, "t").getValueSampa(), is("t"));
    assertThat(allophoneDao.readByValueSampa(locale, "T").getValueSampa(), is("T"));
}
Also used : Locale(ai.elimu.model.enums.Locale) Allophone(ai.elimu.model.content.Allophone) Test(org.junit.Test)

Example 15 with Allophone

use of ai.elimu.model.content.Allophone in project webapp by elimu-ai.

the class AllophoneCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(@Valid Allophone allophone, BindingResult result, Model model, HttpSession session) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (StringUtils.isNotBlank(allophone.getValueIpa())) {
        Allophone existingAllophone = allophoneDao.readByValueIpa(allophone.getLocale(), allophone.getValueIpa());
        if (existingAllophone != null) {
            result.rejectValue("valueIpa", "NonUnique");
        }
    }
    if (StringUtils.isNotBlank(allophone.getValueSampa())) {
        Allophone existingAllophone = allophoneDao.readByValueSampa(allophone.getLocale(), allophone.getValueSampa());
        if (existingAllophone != null) {
            result.rejectValue("valueSampa", "NonUnique");
        }
    }
    if (result.hasErrors()) {
        model.addAttribute("allophone", allophone);
        model.addAttribute("soundTypes", SoundType.values());
        return "content/allophone/create";
    } else {
        allophone.setTimeLastUpdate(Calendar.getInstance());
        allophoneDao.create(allophone);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            String text = URLEncoder.encode(contributor.getFirstName() + " just created an Allophone:\n" + "• Language: \"" + allophone.getLocale().getLanguage() + "\"\n" + "• IPA: /" + allophone.getValueIpa() + "/\n" + "• X-SAMPA: \"" + allophone.getValueSampa() + "\"\n" + "• Sound type: \"" + allophone.getSoundType() + "\"\n" + "See ") + "http://elimu.ai/content/allophone/edit/" + allophone.getId();
            String iconUrl = contributor.getImageUrl();
            SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
        }
        return "redirect:/content/allophone/list#" + allophone.getId();
    }
}
Also used : Allophone(ai.elimu.model.content.Allophone) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Allophone (ai.elimu.model.content.Allophone)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 Contributor (ai.elimu.model.Contributor)11 Word (ai.elimu.model.content.Word)5 ArrayList (java.util.ArrayList)5 Letter (ai.elimu.model.content.Letter)4 AllophoneGson (ai.elimu.model.gson.content.AllophoneGson)4 Locale (ai.elimu.model.enums.Locale)3 Syllable (ai.elimu.model.content.Syllable)2 Audio (ai.elimu.model.content.multimedia.Audio)2 Image (ai.elimu.model.content.multimedia.Image)2 WordRevisionEvent (ai.elimu.model.contributor.WordRevisionEvent)2 Test (org.junit.Test)2 LetterGson (ai.elimu.model.gson.content.LetterGson)1 SyllableGson (ai.elimu.model.gson.content.SyllableGson)1 WordGson (ai.elimu.model.gson.content.WordGson)1 Gson (com.google.gson.Gson)1 HashMap (java.util.HashMap)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1