use of com.github.hakko.musiccabinet.domain.model.music.ArtistRelation in project musiccabinet by hakko.
the class ArtistSimilarityParserTest method verifyArtistRelation.
private void verifyArtistRelation(ArtistSimilarityParser parser, int artistRelationIndex, String artistName, float match) {
ArtistRelation relation = parser.getArtistRelations().get(artistRelationIndex);
assertTrue(relation.getTarget().getName().equals(artistName));
assertEquals(relation.getMatch(), match);
}
use of com.github.hakko.musiccabinet.domain.model.music.ArtistRelation in project musiccabinet by hakko.
the class ArtistSimilarityParserTest method resourceFileCorrectlyParsed.
@Test
public void resourceFileCorrectlyParsed() throws ApplicationException {
ArtistSimilarityParser parser = new ArtistSimilarityParserImpl(new ResourceUtil(ARTIST_SIMILARITY_FILE).getInputStream());
assertNotNull(parser.getArtist());
assertNotNull(parser.getArtistRelations());
assertTrue(parser.getArtist().getName().equals("Cher"));
assertEquals(parser.getArtistRelations().size(), 100);
for (ArtistRelation ar : parser.getArtistRelations()) {
assertNotNull(ar.getTarget());
}
verifyArtistRelation(parser, 0, "Sonny & Cher", 1.0f);
verifyArtistRelation(parser, 1, "Madonna", 0.476751f);
verifyArtistRelation(parser, 2, "Cyndi Lauper", 0.407297f);
verifyArtistRelation(parser, 99, "Lara Fabian", 0.0617754f);
}
use of com.github.hakko.musiccabinet.domain.model.music.ArtistRelation in project musiccabinet by hakko.
the class JdbcArtistRelationDaoTest method createAndValidateUpdatedArtistRelation.
@Test
public void createAndValidateUpdatedArtistRelation() {
deleteArtistRelations();
dao.createArtistRelations(sourceArtist1, Arrays.asList(ar1, ar2, ar3, ar4));
dao.createArtistRelations(sourceArtist2, Arrays.asList(ar5, ar6, ar7));
ar3.setMatch(0.55f);
ar7.setMatch(0.44f);
dao.createArtistRelations(sourceArtist2, Arrays.asList(ar5, ar7));
List<ArtistRelation> cherRelations = dao.getArtistRelations(sourceArtist1);
List<ArtistRelation> kylieRelations = dao.getArtistRelations(sourceArtist2);
assertNotNull(cherRelations);
assertNotNull(kylieRelations);
Assert.assertEquals(4, cherRelations.size());
Assert.assertEquals(3, kylieRelations.size());
for (ArtistRelation ar : Arrays.asList(ar1, ar2, ar4)) {
assertTrue(cherRelations.contains(ar));
}
assertFalse(cherRelations.contains(ar3));
for (ArtistRelation ar : Arrays.asList(ar5, ar6, ar7)) {
assertTrue(kylieRelations.contains(ar));
}
}
use of com.github.hakko.musiccabinet.domain.model.music.ArtistRelation in project musiccabinet by hakko.
the class JdbcArtistRelationDao method batchInsert.
private void batchInsert(Artist sourceArtist, List<ArtistRelation> ArtistRelations) {
int sourceArtistId = jdbcTemplate.queryForInt("select * from music.get_artist_id(?)", sourceArtist.getName());
String sql = "insert into music.artistrelation_import (source_id, target_artist_name, weight) values (?,?,?)";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.setBatchSize(1000);
batchUpdate.declareParameter(new SqlParameter("source_id", Types.INTEGER));
batchUpdate.declareParameter(new SqlParameter("target_artist_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("weight", Types.FLOAT));
for (ArtistRelation ar : ArtistRelations) {
batchUpdate.update(new Object[] { sourceArtistId, ar.getTarget().getName(), ar.getMatch() });
}
batchUpdate.flush();
}
use of com.github.hakko.musiccabinet.domain.model.music.ArtistRelation in project musiccabinet by hakko.
the class JdbcArtistRelationDao method getArtistRelations.
@Override
public List<ArtistRelation> getArtistRelations(Artist sourceArtist) {
final int sourceArtistId = jdbcTemplate.queryForInt("select * from music.get_artist_id(?)", sourceArtist.getName());
String sql = "select artist_name_capitalization, weight" + " from music.artistrelation" + " inner join music.artist on music.artistrelation.target_id = music.artist.id" + " where music.artistrelation.source_id = ?";
List<ArtistRelation> artistRelations = jdbcTemplate.query(sql, new Object[] { sourceArtistId }, new RowMapper<ArtistRelation>() {
@Override
public ArtistRelation mapRow(ResultSet rs, int rowNum) throws SQLException {
String artistName = rs.getString(1);
float match = rs.getFloat(2);
return new ArtistRelation(new Artist(artistName), match);
}
});
return artistRelations;
}
Aggregations