Skip to content

Commit

Permalink
Revert "chore: elimu-ai#1677 Rename LetterSoundCorrespondence to Lett…
Browse files Browse the repository at this point in the history
…erSound"

This reverts commit 53371c0.
  • Loading branch information
Sneha65 committed Jul 7, 2024
1 parent 5c6c035 commit 3cf962a
Show file tree
Hide file tree
Showing 25 changed files with 139 additions and 129 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ai.elimu.dao;

import ai.elimu.model.content.LetterSound;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import java.util.List;
Expand All @@ -10,7 +10,7 @@ public interface LetterSoundContributionEventDao extends GenericDao<LetterSoundC

List<LetterSoundCorrespondenceContributionEvent> readAllOrderedByTimeDesc() throws DataAccessException;

List<LetterSoundCorrespondenceContributionEvent> readAll(LetterSound letterSound) throws DataAccessException;
List<LetterSoundCorrespondenceContributionEvent> readAll(LetterSoundCorrespondence letterSound) throws DataAccessException;

List<LetterSoundCorrespondenceContributionEvent> readAll(Contributor contributor) throws DataAccessException;

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/ai/elimu/dao/LetterSoundDao.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package ai.elimu.dao;

import ai.elimu.model.content.LetterSound;
import ai.elimu.model.content.Sound;
import ai.elimu.model.content.Letter;

import ai.elimu.model.content.LetterSoundCorrespondence;
import java.util.List;

import org.springframework.dao.DataAccessException;

public interface LetterSoundDao extends GenericDao<LetterSound> {
public interface LetterSoundDao extends GenericDao<LetterSoundCorrespondence> {

LetterSound read(List<Letter> letters, List<Sound> sounds) throws DataAccessException;
LetterSoundCorrespondence read(List<Letter> letters, List<Sound> sounds) throws DataAccessException;

List<LetterSound> readAllOrderedByUsage() throws DataAccessException;
List<LetterSoundCorrespondence> readAllOrderedByUsage() throws DataAccessException;

List<LetterSound> readAllOrderedByLettersLength() throws DataAccessException;
List<LetterSoundCorrespondence> readAllOrderedByLettersLength() throws DataAccessException;
}
4 changes: 2 additions & 2 deletions src/main/java/ai/elimu/dao/LetterSoundPeerReviewEventDao.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ai.elimu.dao;

import ai.elimu.model.content.LetterSound;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.model.contributor.LetterSoundCorrespondencePeerReviewEvent;
Expand All @@ -11,7 +11,7 @@ public interface LetterSoundPeerReviewEventDao extends GenericDao<LetterSoundCor

List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundCorrespondenceContributionEvent, Contributor contributor) throws DataAccessException;

List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSound letterSound) throws DataAccessException;
List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSoundCorrespondence letterSoundCorrespondence) throws DataAccessException;

List<LetterSoundCorrespondencePeerReviewEvent> readAll(Contributor contributor) throws DataAccessException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ai.elimu.dao.jpa;

import ai.elimu.model.content.LetterSound;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.dao.LetterSoundContributionEventDao;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.contributor.Contributor;
import java.util.List;
import org.springframework.dao.DataAccessException;
Expand All @@ -19,7 +19,7 @@ public List<LetterSoundCorrespondenceContributionEvent> readAllOrderedByTimeDesc
}

@Override
public List<LetterSoundCorrespondenceContributionEvent> readAll(LetterSound letterSound) throws DataAccessException {
public List<LetterSoundCorrespondenceContributionEvent> readAll(LetterSoundCorrespondence letterSound) throws DataAccessException {
return em.createQuery(
"SELECT e " +
"FROM LetterSoundCorrespondenceContributionEvent e " +
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/ai/elimu/dao/jpa/LetterSoundDaoJpa.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
package ai.elimu.dao.jpa;

import ai.elimu.model.content.LetterSound;
import ai.elimu.model.content.Sound;
import ai.elimu.model.content.Letter;

import ai.elimu.model.content.LetterSoundCorrespondence;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.dao.DataAccessException;
import ai.elimu.dao.LetterSoundDao;

public class LetterSoundDaoJpa extends GenericDaoJpa<LetterSound> implements LetterSoundDao {
public class LetterSoundDaoJpa extends GenericDaoJpa<LetterSoundCorrespondence> implements LetterSoundDao {

@Override
public LetterSound read(List<Letter> letters, List<Sound> sounds) throws DataAccessException {
public LetterSoundCorrespondence read(List<Letter> letters, List<Sound> sounds) throws DataAccessException {
// TODO: implement usage of CriteriaQuery/CriteriaQuery

String letterSoundCorrespondenceLetters = letters.stream().map(Letter::getText).collect(Collectors.joining());
String letterSoundCorrespondenceSounds = sounds.stream().map(Sound::getValueIpa).collect(Collectors.joining());
for (LetterSound letterSound : readAllOrderedByUsage()) {
String lettersAsString = letterSound.getLetters().stream().map(Letter::getText).collect(Collectors.joining());
String soundsAsString = letterSound.getSounds().stream().map(Sound::getValueIpa).collect(Collectors.joining());
for (LetterSoundCorrespondence letterSoundCorrespondence : readAllOrderedByUsage()) {
String lettersAsString = letterSoundCorrespondence.getLetters().stream().map(Letter::getText).collect(Collectors.joining());
String soundsAsString = letterSoundCorrespondence.getSounds().stream().map(Sound::getValueIpa).collect(Collectors.joining());
if (lettersAsString.equals(letterSoundCorrespondenceLetters) && soundsAsString.equals(letterSoundCorrespondenceSounds)) {
return letterSound;
return letterSoundCorrespondence;
}
}

return null;
}

@Override
public List<LetterSound> readAllOrderedByUsage() throws DataAccessException {
public List<LetterSoundCorrespondence> readAllOrderedByUsage() throws DataAccessException {
return em.createQuery(
"SELECT lsc " +
"FROM LetterSound lsc " +
"FROM LetterSoundCorrespondence lsc " +
"ORDER BY lsc.usageCount DESC")
.getResultList();
}

@Override
public List<LetterSound> readAllOrderedByLettersLength() throws DataAccessException {
public List<LetterSoundCorrespondence> readAllOrderedByLettersLength() throws DataAccessException {
return em.createQuery(
"SELECT lsc " +
"FROM LetterSound lsc " +
"FROM LetterSoundCorrespondence lsc " +
"ORDER BY lsc.letters.size DESC, lsc.usageCount DESC")
.getResultList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ai.elimu.dao.jpa;

import ai.elimu.dao.LetterSoundPeerReviewEventDao;
import ai.elimu.model.content.LetterSound;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.model.contributor.LetterSoundCorrespondencePeerReviewEvent;
Expand All @@ -24,7 +24,7 @@ public List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSoundCorresp
}

@Override
public List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSound letterSound) throws DataAccessException {
public List<LetterSoundCorrespondencePeerReviewEvent> readAll(LetterSoundCorrespondence letterSound) throws DataAccessException {
return em.createQuery(
"SELECT event " +
"FROM LetterSoundCorrespondencePeerReviewEvent event " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package ai.elimu.logic.converters;

import ai.elimu.model.content.LetterSound;
import org.apache.commons.lang.StringUtils;
import ai.elimu.model.content.LetterSoundCorrespondence;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import ai.elimu.dao.LetterSoundDao;

public class StringToLetterSoundCorrespondenceConverter implements Converter<String, LetterSound> {
public class StringToLetterSoundCorrespondenceConverter implements Converter<String, LetterSoundCorrespondence> {

@Autowired
private LetterSoundDao letterSoundDao;

/**
* Convert LetterSound id to LetterSound entity
* Convert LetterSoundCorrespondence id to LetterSoundCorrespondence entity
*/
public LetterSound convert(String id) {
public LetterSoundCorrespondence convert(String id) {
if (StringUtils.isBlank(id)) {
return null;
} else {
Long letterSoundCorrespondenceId = Long.parseLong(id);
LetterSound letterSound = letterSoundDao.read(letterSoundCorrespondenceId);
return letterSound;
LetterSoundCorrespondence letterSoundCorrespondence = letterSoundDao.read(letterSoundCorrespondenceId);
return letterSoundCorrespondence;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.OrderColumn;
import org.hibernate.validator.constraints.NotEmpty;

/**
* Contains information about the various sounds a letter (or letter combination) can represent.
*/
@Entity
public class LetterSound extends Content {
public class LetterSoundCorrespondence extends Content {

// @NotEmpty
@OrderColumn
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/ai/elimu/model/content/Word.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Word extends Content {
@NotEmpty
@OrderColumn
@ManyToMany(fetch = FetchType.EAGER)
private List<LetterSound> letterSounds;
private List<LetterSoundCorrespondence> letterSoundCorrespondences;

/**
* As an example, the verb "reading" will be linked to the root verb "read".
Expand All @@ -48,12 +48,12 @@ public void setText(String text) {
this.text = text;
}

public List<LetterSound> getLetterSoundCorrespondences() {
return letterSounds;
public List<LetterSoundCorrespondence> getLetterSoundCorrespondences() {
return letterSoundCorrespondences;
}

public void setLetterSoundCorrespondences(List<LetterSound> letterSounds) {
this.letterSounds = letterSounds;
public void setLetterSoundCorrespondences(List<LetterSoundCorrespondence> letterSoundCorrespondences) {
this.letterSoundCorrespondences = letterSoundCorrespondences;
}

public Word getRootWord() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ai.elimu.model.contributor;

import ai.elimu.model.content.LetterSound;
import ai.elimu.model.content.LetterSoundCorrespondence;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;
Expand All @@ -10,13 +10,13 @@ public class LetterSoundCorrespondenceContributionEvent extends ContributionEven

@NotNull
@ManyToOne
private LetterSound letterSound;
private LetterSoundCorrespondence letterSoundCorrespondence;

public LetterSound getLetterSoundCorrespondence() {
return letterSound;
public LetterSoundCorrespondence getLetterSoundCorrespondence() {
return letterSoundCorrespondence;
}

public void setLetterSoundCorrespondence(LetterSound letterSound) {
this.letterSound = letterSound;
public void setLetterSoundCorrespondence(LetterSoundCorrespondence letterSoundCorrespondence) {
this.letterSoundCorrespondence = letterSoundCorrespondence;
}
}
14 changes: 10 additions & 4 deletions src/main/java/ai/elimu/rest/v2/JpaToGsonConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

import ai.elimu.model.admin.Application;
import ai.elimu.model.admin.ApplicationVersion;
import ai.elimu.model.content.*;
import ai.elimu.model.content.LetterSound;
import ai.elimu.model.content.Sound;
import ai.elimu.model.content.Emoji;
import ai.elimu.model.content.Letter;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.content.StoryBook;
import ai.elimu.model.content.StoryBookChapter;
import ai.elimu.model.content.StoryBookParagraph;
import ai.elimu.model.content.Number;
import ai.elimu.model.content.Word;
import ai.elimu.model.content.multimedia.Audio;
import ai.elimu.model.content.multimedia.Image;
import ai.elimu.model.content.multimedia.Video;
Expand Down Expand Up @@ -76,7 +82,7 @@ public static SoundGson getSoundGson(Sound sound) {
}
}

public static LetterSoundGson getLetterSoundGson(LetterSound letterSound) {
public static LetterSoundGson getLetterSoundGson(LetterSoundCorrespondence letterSound) {
if (letterSound == null) {
return null;
} else {
Expand Down Expand Up @@ -123,7 +129,7 @@ public static WordGson getWordGson(Word word) {
// Word
wordGson.setText(word.getText());
List<LetterSoundGson> letterSounds = new ArrayList<>();
for (LetterSound letterSound : word.getLetterSoundCorrespondences()) {
for (LetterSoundCorrespondence letterSound : word.getLetterSoundCorrespondences()) {
LetterSoundGson letterSoundGson = getLetterSoundGson(letterSound);
letterSounds.add(letterSoundGson);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ai.elimu.rest.v2.content;

import ai.elimu.model.content.LetterSound;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.v2.gson.content.LetterSoundGson;
import ai.elimu.rest.v2.JpaToGsonConverter;
import com.google.gson.Gson;
Expand Down Expand Up @@ -29,7 +29,7 @@ public String handleGetRequest() {
logger.info("handleGetRequest");

JSONArray letterSoundsJsonArray = new JSONArray();
for (LetterSound letterSound : letterSoundDao.readAllOrderedByUsage()) {
for (LetterSoundCorrespondence letterSound : letterSoundDao.readAllOrderedByUsage()) {
LetterSoundGson letterSoundGson = JpaToGsonConverter.getLetterSoundGson(letterSound);
String json = new Gson().toJson(letterSoundGson);
letterSoundsJsonArray.put(new JSONObject(json));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ai.elimu.dao.WordDao;
import ai.elimu.model.content.Sound;
import ai.elimu.model.content.Letter;
import ai.elimu.model.content.LetterSound;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.content.Word;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -40,28 +40,28 @@ public synchronized void execute() {
logger.info("words.size(): " + words.size());
for (Word word : words) {
logger.info("word.getText(): " + word.getText());
for (LetterSound letterSound : word.getLetterSoundCorrespondences()) {
letterSoundCorrespondenceFrequencyMap.put(letterSound.getId(),
letterSoundCorrespondenceFrequencyMap.getOrDefault(letterSound.getId(), 0) + word.getUsageCount());
for (LetterSoundCorrespondence letterSoundCorrespondence : word.getLetterSoundCorrespondences()) {
letterSoundCorrespondenceFrequencyMap.put(letterSoundCorrespondence.getId(),
letterSoundCorrespondenceFrequencyMap.getOrDefault(letterSoundCorrespondence.getId(), 0) + word.getUsageCount());
}
}

// Update the values previously stored in the database
for (LetterSound letterSound : letterSoundDao.readAll()) {
logger.info("letterSound.getId(): " + letterSound.getId());
logger.info("letterSound Letters: \"" + letterSound.getLetters().stream().map(Letter::getText).collect(Collectors.joining()) + "\"");
logger.info("letterSound Sounds: /" + letterSound.getSounds().stream().map(Sound::getValueIpa).collect(Collectors.joining()) + "/");
logger.info("letterSound.getUsageCount() (before update): " + letterSound.getUsageCount());
for (LetterSoundCorrespondence letterSoundCorrespondence : letterSoundDao.readAll()) {
logger.info("letterSoundCorrespondence.getId(): " + letterSoundCorrespondence.getId());
logger.info("letterSoundCorrespondence Letters: \"" + letterSoundCorrespondence.getLetters().stream().map(Letter::getText).collect(Collectors.joining()) + "\"");
logger.info("letterSoundCorrespondence Sounds: /" + letterSoundCorrespondence.getSounds().stream().map(Sound::getValueIpa).collect(Collectors.joining()) + "/");
logger.info("letterSoundCorrespondence.getUsageCount() (before update): " + letterSoundCorrespondence.getUsageCount());

int newUsageCount = 0;
if (letterSoundCorrespondenceFrequencyMap.containsKey(letterSound.getId())) {
newUsageCount = letterSoundCorrespondenceFrequencyMap.get(letterSound.getId());
if (letterSoundCorrespondenceFrequencyMap.containsKey(letterSoundCorrespondence.getId())) {
newUsageCount = letterSoundCorrespondenceFrequencyMap.get(letterSoundCorrespondence.getId());
}
logger.info("newUsageCount: " + newUsageCount);

letterSound.setUsageCount(newUsageCount);
letterSoundDao.update(letterSound);
logger.info("letterSound.getUsageCount() (after update): " + letterSound.getUsageCount());
letterSoundCorrespondence.setUsageCount(newUsageCount);
letterSoundDao.update(letterSoundCorrespondence);
logger.info("letterSoundCorrespondence.getUsageCount() (after update): " + letterSoundCorrespondence.getUsageCount());
}

logger.info("execute complete");
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/ai/elimu/tasks/SoundUsageCountScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.apache.logging.log4j.Logger;
import ai.elimu.dao.WordDao;
import ai.elimu.model.content.Sound;
import ai.elimu.model.content.LetterSound;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.content.Word;
import org.apache.logging.log4j.LogManager;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -42,14 +42,14 @@ public synchronized void execute() {
// Integer = Usage count
Map<Long, Integer> soundFrequencyMap = new HashMap<>();

// Summarize the usage count of each Word's Sounds based on the LetterSound's
// 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 (LetterSound letterSound : word.getLetterSoundCorrespondences()) {
for (Sound sound : letterSound.getSounds()) {
soundFrequencyMap.put(sound.getId(), soundFrequencyMap.getOrDefault(sound.getId(), 0) + letterSound.getUsageCount());
for (LetterSoundCorrespondence letterSoundCorrespondence : word.getLetterSoundCorrespondences()) {
for (Sound sound : letterSoundCorrespondence.getSounds()) {
soundFrequencyMap.put(sound.getId(), soundFrequencyMap.getOrDefault(sound.getId(), 0) + letterSoundCorrespondence.getUsageCount());
}
}
}
Expand Down
Loading

0 comments on commit 3cf962a

Please sign in to comment.