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