Skip to content

Commit

Permalink
Testing classification analysis.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkiraly committed Nov 27, 2019
1 parent 4134a9e commit b00ceb3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
import java.util.logging.Logger;
import java.util.regex.Pattern;

public class AuthorithyAnalizer {
public class AuthorithyAnalyzer {

private static final Logger logger = Logger.getLogger(
AuthorithyAnalizer.class.getCanonicalName()
AuthorithyAnalyzer.class.getCanonicalName()
);
private static Pattern NUMERIC = Pattern.compile("^\\d");

private MarcRecord marcRecord;
private AuthorityStatistics authoritiesStatistics;

public AuthorithyAnalizer(MarcRecord marcRecord,
public AuthorithyAnalyzer(MarcRecord marcRecord,
AuthorityStatistics authoritiesStatistics) {
this.marcRecord = marcRecord;
this.authoritiesStatistics = authoritiesStatistics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import de.gwdg.metadataqa.marc.MarcRecord;
import de.gwdg.metadataqa.marc.Utils;
import de.gwdg.metadataqa.marc.analysis.AuthorithyAnalizer;
import de.gwdg.metadataqa.marc.analysis.AuthorithyAnalyzer;
import de.gwdg.metadataqa.marc.analysis.AuthorityStatistics;
import de.gwdg.metadataqa.marc.cli.parameters.CommonParameters;
import de.gwdg.metadataqa.marc.cli.parameters.ValidatorParameters;
Expand Down Expand Up @@ -77,7 +77,7 @@ public void processRecord(Record marc4jRecord, int recordNumber) throws IOExcept

@Override
public void processRecord(MarcRecord marcRecord, int recordNumber) throws IOException {
AuthorithyAnalizer analyzer = new AuthorithyAnalizer(marcRecord, statistics);
AuthorithyAnalyzer analyzer = new AuthorithyAnalyzer(marcRecord, statistics);
int count = analyzer.process();
count((count > 0), hasClassifications);
count(count, histogram);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

import static org.junit.Assert.assertEquals;

public class AuthorithyAnalizerTest {
public class AuthorithyAnalyzerTest {

@Test
public void test() throws IOException, URISyntaxException {
List<String> lines = FileUtils.readLines("general/010000011.mrctxt");
MarcRecord record = MarcFactory.createFromFormattedText(lines);
AuthorityStatistics statistics = new AuthorityStatistics();

AuthorithyAnalizer analyzer = new AuthorithyAnalizer(record, statistics);
AuthorithyAnalyzer analyzer = new AuthorithyAnalyzer(record, statistics);
int count = analyzer.process();
assertEquals(3, count);
Map<Schema, Integer> recordStats = statistics.getRecords();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package de.gwdg.metadataqa.marc.analysis;

import de.gwdg.metadataqa.api.util.FileUtils;
import de.gwdg.metadataqa.marc.MarcFactory;
import de.gwdg.metadataqa.marc.MarcRecord;
import de.gwdg.metadataqa.marc.cli.utils.Schema;
import org.junit.Test;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;

public class ClassificationAnalyzerTest {

@Test
public void test() throws IOException, URISyntaxException {
List<String> lines = FileUtils.readLines("general/010000011.mrctxt");
MarcRecord record = MarcFactory.createFromFormattedText(lines);
ClassificationStatistics statistics = new ClassificationStatistics();

ClassificationAnalyzer analyzer = new ClassificationAnalyzer(record, statistics);
int count = analyzer.process();
assertEquals(1, count);
Map<Schema, Integer> recordStats = statistics.getRecords();
assertEquals(2, recordStats.size());
Schema first = (Schema) recordStats.keySet().toArray()[0];

assertEquals(
"Gemeinsame Normdatei: Beschreibung des Inhalts (Leipzig, Frankfurt: Deutsche Nationalbibliothek)",
first.getSchema());
assertEquals(1, (int) recordStats.get(first));
assertEquals(1, (int) statistics.getInstances().get(first));
Map<List<String>, Integer> subfieldMap = statistics.getSubfields().get(first);
assertEquals(1, subfieldMap.size());
List<String> list = (List<String>) subfieldMap.keySet().toArray()[0];
assertEquals("[0+, a, 2]", list.toString());

Schema second = (Schema) recordStats.keySet().toArray()[1];
assertEquals("Basisklassifikation", second.getSchema());
assertEquals(1, (int) statistics.getInstances().get(second));
subfieldMap = statistics.getSubfields().get(second);
assertEquals(1, subfieldMap.size());
list = (List<String>) subfieldMap.keySet().toArray()[0];
assertEquals("[a, 2]", list.toString());
}
}

0 comments on commit b00ceb3

Please sign in to comment.