|
1 | 1 | package de.gwdg.metadataqa.api.calculator;
|
2 | 2 |
|
| 3 | +import de.gwdg.metadataqa.api.interfaces.MetricResult; |
| 4 | +import de.gwdg.metadataqa.api.json.JsonBranch; |
| 5 | +import de.gwdg.metadataqa.api.model.PathCacheFactory; |
| 6 | +import de.gwdg.metadataqa.api.model.XmlFieldInstance; |
| 7 | +import de.gwdg.metadataqa.api.model.pathcache.CsvPathCache; |
| 8 | +import de.gwdg.metadataqa.api.schema.BaseSchema; |
| 9 | +import de.gwdg.metadataqa.api.schema.CsvAwareSchema; |
| 10 | +import de.gwdg.metadataqa.api.schema.Format; |
| 11 | +import de.gwdg.metadataqa.api.schema.Schema; |
3 | 12 | import de.gwdg.metadataqa.api.schema.edm.EdmFullBeanSchema;
|
4 | 13 | import de.gwdg.metadataqa.api.schema.edm.EdmOaiPmhJsonSchema;
|
5 | 14 | import java.util.Arrays;
|
6 | 15 | import java.util.List;
|
| 16 | + |
| 17 | +import de.gwdg.metadataqa.api.uniqueness.SolrClient; |
| 18 | +import de.gwdg.metadataqa.api.uniqueness.SolrClientMock; |
| 19 | +import de.gwdg.metadataqa.api.uniqueness.SolrConfiguration; |
| 20 | +import de.gwdg.metadataqa.api.util.CsvReader; |
7 | 21 | import org.junit.Test;
|
8 | 22 | import static org.junit.Assert.*;
|
9 | 23 |
|
@@ -34,4 +48,63 @@ public void getCalculatorName() throws Exception {
|
34 | 48 | TfIdfCalculator calculator = new TfIdfCalculator(new EdmOaiPmhJsonSchema());
|
35 | 49 | assertEquals("uniqueness", calculator.getCalculatorName());
|
36 | 50 | }
|
| 51 | + |
| 52 | + @Test |
| 53 | + public void getSolrSearchPath() throws Exception { |
| 54 | + TfIdfCalculator calculator = new TfIdfCalculator(new EdmOaiPmhJsonSchema()); |
| 55 | + calculator.setSolrConfiguration(new SolrConfiguration()); |
| 56 | + |
| 57 | + assertEquals( |
| 58 | + "http://localhost:8983/solr/europeana/tvrh/?q=id:\"%s\"&version=2.2&indent=on&qt=tvrh&tv=true&tv.all=true" + |
| 59 | + "&f.includes.tv.tf=true&tv.fl=dc_title_txt,dc_description_txt,dcterms_alternative_txt&wt=json&json.nl=map&rows=1000&fl=id", |
| 60 | + calculator.getSolrSearchPath()); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void isTermCollectionEnabled() throws Exception { |
| 65 | + TfIdfCalculator calculator = new TfIdfCalculator(new EdmOaiPmhJsonSchema()); |
| 66 | + assertFalse(calculator.isTermCollectionEnabled()); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void enableTermCollection() throws Exception { |
| 71 | + TfIdfCalculator calculator = new TfIdfCalculator(new EdmOaiPmhJsonSchema()); |
| 72 | + calculator.enableTermCollection(true); |
| 73 | + assertTrue(calculator.isTermCollectionEnabled()); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public void emptyContructor() throws Exception { |
| 78 | + TfIdfCalculator calculator = new TfIdfCalculator(); |
| 79 | + assertNotNull(calculator); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + public void measure() throws Exception { |
| 84 | + SolrConfiguration solrConfiguration = new SolrConfiguration("localhost", "8983", "solr"); |
| 85 | + Schema schema = getSchema(Format.CSV); |
| 86 | + SolrClient solrClient = new SolrClientMock(solrConfiguration); |
| 87 | + CsvPathCache cache = (CsvPathCache) PathCacheFactory.getInstance(schema.getFormat(), "URL,two three"); |
| 88 | + cache.setCsvReader(new CsvReader().setHeader( ((CsvAwareSchema) schema).getHeader() )); |
| 89 | + cache.setRecordId(((List<XmlFieldInstance>)cache.get(schema.getRecordId().getJsonPath())).get(0).getValue()); |
| 90 | + |
| 91 | + TfIdfCalculator calculator = new TfIdfCalculator(schema); |
| 92 | + calculator.setSolrClient(solrClient); |
| 93 | + List<MetricResult> result = calculator.measure(cache); |
| 94 | + assertNotNull(result); |
| 95 | + assertEquals(1, result.size()); |
| 96 | + assertEquals(0.008826999437345252, result.get(0).getResultMap().get("url:sum")); |
| 97 | + assertEquals(0.0017653998874690505, result.get(0).getResultMap().get("url:avg")); |
| 98 | + assertEquals(0.0, result.get(0).getResultMap().get("name:sum")); |
| 99 | + assertEquals(0.0, result.get(0).getResultMap().get("name:avg")); |
| 100 | + } |
| 101 | + |
| 102 | + private Schema getSchema(Format format) { |
| 103 | + BaseSchema schema = new BaseSchema() |
| 104 | + .setFormat(format) |
| 105 | + .addField(new JsonBranch("url").setExtractable().setIndexField("url")) |
| 106 | + .addField(new JsonBranch("name").setExtractable().setIndexField("name")); |
| 107 | + schema.setRecordId(schema.getPathByLabel("url")); |
| 108 | + return schema; |
| 109 | + } |
37 | 110 | }
|
0 commit comments