use of eu.europeana.indexing.tiers.view.MetadataTierBreakdown in project metis-framework by europeana.
the class RecordTierCalculationViewGenerator method tierClassification.
private RecordTierCalculationView tierClassification(final String xml) {
final RDF rdf;
try {
// Perform the tier classification
rdf = RdfConversionUtils.convertStringToRdf(xml);
final RdfWrapper rdfWrapper = new RdfWrapper(rdf);
final TierClassification<MediaTier, ContentTierBreakdown> mediaTierClassification = ClassifierFactory.getMediaClassifier().classify(rdfWrapper);
final TierClassification<MetadataTier, MetadataTierBreakdown> metadataTierClassification = ClassifierFactory.getMetadataClassifier().classify(rdfWrapper);
RecordTierCalculationSummary recordTierCalculationSummary = new RecordTierCalculationSummary();
recordTierCalculationSummary.setEuropeanaRecordId(europeanaId);
recordTierCalculationSummary.setProviderRecordId(providerId);
recordTierCalculationSummary.setContentTier(mediaTierClassification.getTier());
recordTierCalculationSummary.setMetadataTier(metadataTierClassification.getTier());
recordTierCalculationSummary.setPortalRecordLink(portalRecordLink);
final ContentTierBreakdown mediaTierClassificationWithErrors = new ContentTierBreakdown(mediaTierClassification.getClassification(), processingErrors);
return new RecordTierCalculationView(recordTierCalculationSummary, mediaTierClassificationWithErrors, metadataTierClassification.getClassification());
} catch (SerializationException e) {
throw new TierCalculationException("Error during calculation of tiers", e);
}
}
use of eu.europeana.indexing.tiers.view.MetadataTierBreakdown in project metis-framework by europeana.
the class MetadataClassifierTest method testClassify.
@Test
void testClassify() {
// The entity under consideration
final RdfWrapper testEntity = mock(RdfWrapper.class);
final LanguageClassifier languageClassifier = mock(LanguageClassifier.class);
final EnablingElementsClassifier enablingElementsClassifier = mock(EnablingElementsClassifier.class);
final ContextualClassesClassifier contextualClassesClassifier = mock(ContextualClassesClassifier.class);
// The tiers
final MetadataTier lowTier = MetadataTier.T0;
final MetadataTier middleTier = MetadataTier.TA;
final MetadataTier highTier = MetadataTier.TC;
assertThrows(NullPointerException.class, () -> new MetadataClassifier(null, null, null));
assertThrows(NullPointerException.class, () -> new MetadataClassifier(languageClassifier, null, null));
assertThrows(NullPointerException.class, () -> new MetadataClassifier(languageClassifier, enablingElementsClassifier, null));
when(languageClassifier.classifyBreakdown(testEntity)).thenReturn(new LanguageBreakdown(2, Set.of(PropertyType.DC_COVERAGE.name(), PropertyType.DC_DESCRIPTION.name()), lowTier));
when(enablingElementsClassifier.classifyBreakdown(testEntity)).thenReturn(new EnablingElementsBreakdown(Collections.emptySet(), Collections.emptySet(), middleTier));
when(contextualClassesClassifier.classifyBreakdown(testEntity)).thenReturn(new ContextualClassesBreakdown(5, Set.of(TimeSpanType.class.getSimpleName(), PlaceType.class.getSimpleName()), highTier));
final TierClassification<MetadataTier, MetadataTierBreakdown> metadataTierClassification = new MetadataClassifier(languageClassifier, enablingElementsClassifier, contextualClassesClassifier).classify(testEntity);
assertEquals(lowTier, metadataTierClassification.getTier());
assertNotNull(metadataTierClassification.getClassification());
}
use of eu.europeana.indexing.tiers.view.MetadataTierBreakdown in project metis-framework by europeana.
the class MetadataClassifier method classify.
@Override
public TierClassification<MetadataTier, MetadataTierBreakdown> classify(RdfWrapper entity) {
final LanguageBreakdown languageBreakdownTierClassification = languageClassifier.classifyBreakdown(entity);
final EnablingElementsBreakdown enablingElementsTierClassification = enablingElementsClassifier.classifyBreakdown(entity);
final ContextualClassesBreakdown contextualClassesTierClassification = contextualClassesClassifier.classifyBreakdown(entity);
final MetadataTierBreakdown metadataTierBreakdown = new MetadataTierBreakdown(languageBreakdownTierClassification, enablingElementsTierClassification, contextualClassesTierClassification);
MetadataTier metadataTier = Stream.of(languageBreakdownTierClassification.getMetadataTier(), enablingElementsTierClassification.getMetadataTier(), contextualClassesTierClassification.getMetadataTier()).reduce(Tier::min).orElseThrow(IllegalStateException::new);
return new TierClassification<>(metadataTier, metadataTierBreakdown);
}
Aggregations