Search in sources :

Example 6 with TrackRelation

use of com.github.hakko.musiccabinet.domain.model.music.TrackRelation in project musiccabinet by hakko.

the class TrackSimilarityHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    if (TAG_SIMILAR_TRACKS.equals(qName)) {
        artistName = attributes.getValue(TAG_ARTIST);
        trackName = attributes.getValue(TAG_TRACK);
        sourceTrack = new Track(artistName, trackName);
    } else if (TAG_TRACK.equals(qName)) {
        scope = TRACK;
        currentTrackRelation = new TrackRelation();
        currentTrackRelation.setTarget(new Track());
    } else if (TAG_ARTIST.equals(qName)) {
        scope = ARTIST;
    } else {
        state = xmlToStateMap.get(qName);
        if (state != null) {
            characterData = new StringBuilder();
        }
    }
}
Also used : TrackRelation(com.github.hakko.musiccabinet.domain.model.music.TrackRelation) Track(com.github.hakko.musiccabinet.domain.model.music.Track)

Example 7 with TrackRelation

use of com.github.hakko.musiccabinet.domain.model.music.TrackRelation in project musiccabinet by hakko.

the class TrackSimilarityParserTest method verifyTrackRelation.

private void verifyTrackRelation(TrackSimilarityParser parser, int trackRelationIndex, String artistName, String trackName, float match) {
    TrackRelation relation = parser.getTrackRelations().get(trackRelationIndex);
    assertTrue(relation.getTarget().getArtist().getName().equals(artistName));
    assertTrue(relation.getTarget().getName().equals(trackName));
    assertEquals(relation.getMatch(), match);
}
Also used : TrackRelation(com.github.hakko.musiccabinet.domain.model.music.TrackRelation)

Example 8 with TrackRelation

use of com.github.hakko.musiccabinet.domain.model.music.TrackRelation in project musiccabinet by hakko.

the class TrackSimilarityParserTest method resourceFileCorrectlyParsed.

@Test
public void resourceFileCorrectlyParsed() throws ApplicationException {
    TrackSimilarityParser parser = new TrackSimilarityParserImpl(new ResourceUtil(TRACK_SIMILARITY_FILE).getInputStream());
    assertNotNull(parser.getTrack());
    assertNotNull(parser.getTrackRelations());
    assertTrue(parser.getTrack().getArtist().getName().equals("Cher"));
    assertTrue(parser.getTrack().getName().equals("Believe"));
    assertEquals(parser.getTrackRelations().size(), 250);
    for (TrackRelation tr : parser.getTrackRelations()) {
        assertNotNull(tr.getTarget());
        assertNotNull(tr.getTarget().getArtist());
    }
    verifyTrackRelation(parser, 0, "Cher", "Strong Enough", 1.0f);
    verifyTrackRelation(parser, 1, "Cher", "All Or Nothing", 0.961879f);
    verifyTrackRelation(parser, 2, "Madonna", "Vogue", 0.291088f);
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) TrackRelation(com.github.hakko.musiccabinet.domain.model.music.TrackRelation) Test(org.junit.Test)

Aggregations

TrackRelation (com.github.hakko.musiccabinet.domain.model.music.TrackRelation)8 Test (org.junit.Test)4 Track (com.github.hakko.musiccabinet.domain.model.music.Track)2 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)2 PlaylistItem (com.github.hakko.musiccabinet.domain.model.aggr.PlaylistItem)1 File (com.github.hakko.musiccabinet.domain.model.library.File)1 TrackSimilarityParser (com.github.hakko.musiccabinet.parser.lastfm.TrackSimilarityParser)1 TrackSimilarityParserImpl (com.github.hakko.musiccabinet.parser.lastfm.TrackSimilarityParserImpl)1 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1 BatchSqlUpdate (org.springframework.jdbc.object.BatchSqlUpdate)1