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