Created
January 17, 2012 07:03
-
-
Save mark-cooper/1625355 to your computer and use it in GitHub Desktop.
Reading Open Library marc records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.libcode.www.openlibrary; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import org.marc4j.MarcPermissiveStreamReader; | |
import org.marc4j.marc.Record; | |
public class OpenLibraryMarc { | |
public static String ol_marc_records = "/home/mcooper/Downloads/all_meta.mrc"; | |
public static void main(String[] args) throws FileNotFoundException { | |
long startTime = System.currentTimeMillis(); | |
validMarcReport(ol_marc_records, false); | |
long endTime = System.currentTimeMillis(); | |
System.out.println("Total execution time: " + (millisToSeconds(endTime - startTime)) + "s"); | |
System.out.println(); | |
startTime = System.currentTimeMillis(); | |
validMarcReport(ol_marc_records, true); | |
endTime = System.currentTimeMillis(); | |
System.out.println("Total execution time: " + (millisToSeconds(endTime - startTime)) + "s"); | |
System.out.println(); | |
} | |
public static void validMarcReport(String file, boolean permissive) throws FileNotFoundException { | |
MarcPermissiveStreamReader reader = new MarcPermissiveStreamReader(new FileInputStream(new File(ol_marc_records)), permissive, false); | |
int valid = 0; | |
int error = 0; | |
while(reader.hasNext()) { | |
try { | |
@SuppressWarnings("unused") | |
Record record = reader.next(); | |
valid += 1; | |
} catch (Exception e) { | |
error += 1; | |
} | |
} | |
if(permissive) { | |
System.out.println("PERMISSIVE READ"); | |
} else { | |
System.out.println("DEFAULT READ"); | |
} | |
System.out.println("VALID RECORDS: " + valid); | |
if(permissive) error /= 3; | |
System.out.println("ERROR RECORDS: " + error); | |
System.out.println("TOTAL RECORDS: " + (valid + error)); | |
} | |
public static long millisToSeconds(long milli) { | |
return (long) (milli * 0.001); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment