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;
}
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();
}
}
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));
}
Aggregations