Package dnb.analyze.nfo

Source Code of dnb.analyze.nfo.AbstractNfoParser

package dnb.analyze.nfo;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import dnb.analyze.MatchResult;


public abstract class AbstractNfoParser implements NfoParser {
 
  /**
   * Gets the <code>Pattern</code> whose 1st group matches the artist.
   * @return a <code>Pattern</code> instance, or <code>null</code> if no such pattern
   * exists for this nfo.
   */
  protected abstract Pattern getArtistPattern();
 
  /**
   * Gets the <code>Pattern</code> whose 1st group matches the title.
    * @return a <code>Pattern</code> instance, or <code>null</code> if no such pattern
   * exists for this nfo.
   */
  protected abstract Pattern getTitlePattern();
 
  /**
   * Gets the <code>Pattern</code> whose 1st group matches the genre.
   * @return a <code>Pattern</code> instance, or <code>null</code> if no such pattern
   * exists for this nfo.
   */
  protected abstract Pattern getGenrePattern();
 
  /**
   * Gets the <code>Pattern</code> whose 1st group matches the release date.
    * @return a <code>Pattern</code> instance, or <code>null</code> if no such pattern
   * exists for this nfo.
   */
  protected abstract Pattern getReleaseDatePattern();
 
  /**
   * Gets the <code>Pattern</code> whose 1st group matches the street date.
    * @return a <code>Pattern</code> instance, or <code>null</code> if no such pattern
   * exists for this nfo.
   */
  protected abstract Pattern getStreetDatePattern();

  protected void parseLabelcode(String labelCode, int matchResultOffset, Map<NfoField, MatchResult> result) {
    Matcher lc = NfoLyzer.LBLCODE.matcher(labelCode);
    if (lc.matches()) { // regular label code
      result.put(NfoField.LABEL_CODE,
          new MatchResult(matchResultOffset + lc.start(1),
              matchResultOffset + lc.end(1), lc.group(1),
              MatchResult.Source.NFO));
      result.put(NfoField.LABEL_CODE_NO,
          new MatchResult(matchResultOffset + lc.start(2),
              matchResultOffset + lc.end(2), lc.group(2),
              MatchResult.Source.NFO));
      result.put(NfoField.LABEL_CODE_SUFFIX,
          new MatchResult(matchResultOffset + lc.start(3),
              matchResultOffset + lc.end(3), lc.group(3),
              MatchResult.Source.NFO));
    } else {
      // XXX handling for irregular codes
      System.out.println("IRREG:" + labelCode);
    }     
  }
 
  public void parse(String nfo, Map<NfoField, MatchResult> result) {
     
    Matcher m;
    if (getArtistPattern() != null) {
      m = getArtistPattern().matcher(nfo);   
      if(m.find()) {
        result.put(NfoField.ARTIST, new MatchResult(m.start(1), m.end(1), m.group(1),
            MatchResult.Source.NFO));     
      }
    }
    if (getTitlePattern() != null) {
      m = getTitlePattern().matcher(nfo);
      if(m.find()) {       
        result.put(NfoField.ALBUM_TITLE, new MatchResult(m.start(1), m.end(1), m.group(1),
            MatchResult.Source.NFO));     
      }
    }
    if (getGenrePattern() != null) {
      m = getGenrePattern().matcher(nfo);   
      if(m.find()) {     
        result.put(NfoField.GENRE, new MatchResult(m.start(1), m.end(1), m.group(1),
            MatchResult.Source.NFO));           
      }
    }
    if (getReleaseDatePattern() != null) {
      m = getReleaseDatePattern().matcher(nfo);   
      if(m.find()) {     
        result.put(NfoField.RELEASE_DATE, new MatchResult(m.start(1), m.end(1), m.group(1),
            MatchResult.Source.NFO));           
      }
    }
    if (getStreetDatePattern() != null) {
      m = getStreetDatePattern().matcher(nfo);   
      if(m.find()) {     
        result.put(NfoField.STREET_DATE, new MatchResult(m.start(1), m.end(1), m.group(1),
            MatchResult.Source.NFO));           
      }
    }           
  }
}
TOP

Related Classes of dnb.analyze.nfo.AbstractNfoParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.