Search in sources :

Example 21 with Allophone

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

the class LetterListController method getAllophones.

private List<Allophone> getAllophones(Locale locale, String... ipaValues) {
    List<Allophone> allophones = new ArrayList<>();
    for (String ipaValue : ipaValues) {
        Allophone allophone = allophoneDao.readByValueIpa(locale, ipaValue);
        allophones.add(allophone);
    }
    return allophones;
}
Also used : Allophone(ai.elimu.model.content.Allophone) ArrayList(java.util.ArrayList)

Example 22 with Allophone

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

the class WordEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Word word, BindingResult result, Model model, HttpServletRequest request) {
    logger.info("handleSubmit");
    Word existingWord = wordDao.readByText(word.getLocale(), word.getText());
    if ((existingWord != null) && !existingWord.getId().equals(word.getId())) {
        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());
        model.addAttribute("wordRevisionEvents", wordRevisionEventDao.readAll(word));
        Audio audio = audioDao.read(word.getText(), contributor.getLocale());
        model.addAttribute("audio", audio);
        return "content/word/edit";
    } else {
        if (!"I".equals(word.getText())) {
            word.setText(word.getText().toLowerCase());
        }
        word.setTimeLastUpdate(Calendar.getInstance());
        word.setRevisionNumber(word.getRevisionNumber() + 1);
        wordDao.update(word);
        WordRevisionEvent wordRevisionEvent = new WordRevisionEvent();
        wordRevisionEvent.setContributor(contributor);
        wordRevisionEvent.setCalendar(Calendar.getInstance());
        wordRevisionEvent.setWord(word);
        wordRevisionEvent.setText(word.getText());
        wordRevisionEvent.setPhonetics(word.getPhonetics());
        if (StringUtils.isNotBlank(request.getParameter("comment"))) {
            wordRevisionEvent.setComment(request.getParameter("comment"));
        }
        wordRevisionEventDao.create(wordRevisionEvent);
        // 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 updated a 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" + "• Comment: \"" + wordRevisionEvent.getComment() + "\"\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) Audio(ai.elimu.model.content.multimedia.Audio) Syllable(ai.elimu.model.content.Syllable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with Allophone

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

the class AllophoneDaoTest method testStoreSoundType.

@Test
public void testStoreSoundType() {
    Locale locale = Locale.values()[(int) (Math.random() * Locale.values().length)];
    logger.info("locale: " + locale);
    Allophone allophone = new Allophone();
    allophone.setLocale(locale);
    allophone.setValueIpa("ɛ");
    allophone.setValueSampa("E");
    allophone.setSoundType(SoundType.VOWEL);
    allophoneDao.create(allophone);
    assertThat(allophoneDao.readByValueSampa(locale, "E").getSoundType(), is(SoundType.VOWEL));
}
Also used : Locale(ai.elimu.model.enums.Locale) Allophone(ai.elimu.model.content.Allophone) Test(org.junit.Test)

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