use of eu.europeana.indexing.utils.RdfWrapper in project metis-framework by europeana.
the class LanguageClassifierTest method testCreateLanguageTagStatistics.
@Test
void testCreateLanguageTagStatistics() {
// Create the RDF
final RdfWrapper rdf = mock(RdfWrapper.class);
// Create the contextual classes
final PlaceType place1 = new PlaceType();
place1.setAbout("place about 1");
final PlaceType place2 = new PlaceType();
place2.setAbout("place about 2");
final TimeSpanType timeSpan = new TimeSpanType();
timeSpan.setAbout("time span about");
final Concept concept = new Concept();
concept.setAbout("concept about");
doReturn(Arrays.asList(place1, place2)).when(rdf).getPlaces();
doReturn(Collections.singletonList(timeSpan)).when(rdf).getTimeSpans();
doReturn(Collections.singletonList(concept)).when(rdf).getConcepts();
// Create proxies
final ProxyType providerProxy1 = new ProxyType();
providerProxy1.setEuropeanaProxy(new EuropeanaProxy());
providerProxy1.getEuropeanaProxy().setEuropeanaProxy(false);
final ProxyType providerProxy2 = new ProxyType();
providerProxy2.setEuropeanaProxy(new EuropeanaProxy());
providerProxy2.getEuropeanaProxy().setEuropeanaProxy(false);
doReturn(Arrays.asList(providerProxy1, providerProxy2, null)).when(rdf).getProviderProxies();
// Test the method.
final LanguageClassifier classifier = spy(new LanguageClassifier());
final LanguageTagStatistics result = classifier.createLanguageTagStatistics(rdf);
verify(classifier, times(1)).addProxyToStatistics(providerProxy1, result);
verify(classifier, times(1)).addProxyToStatistics(providerProxy2, result);
verify(classifier, times(2)).addProxyToStatistics(any(), any());
}
use of eu.europeana.indexing.utils.RdfWrapper in project metis-framework by europeana.
the class ContextualClassesBreakdownClassifierTest method countQualifyingContextualClassTypes.
@Test
void countQualifyingContextualClassTypes() {
// Create mocks of the classifier and test empty object.
final ContextualClassesClassifier classifier = spy(new ContextualClassesClassifier());
final RdfWrapper entity = mock(RdfWrapper.class);
assertEquals(0, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
// Create the contextual objects.
final List<AgentType> agents = Collections.singletonList(new AgentType());
final List<Concept> concepts = Collections.singletonList(new Concept());
final List<PlaceType> places = Arrays.asList(new PlaceType(), new PlaceType());
final List<TimeSpanType> timeSpans = Collections.singletonList(new TimeSpanType());
doReturn(agents).when(entity).getAgents();
doReturn(concepts).when(entity).getConcepts();
doReturn(places).when(entity).getPlaces();
doReturn(timeSpans).when(entity).getTimeSpans();
// Set the about values in the contextual objects
final String agentAbout = "agentAbout";
final String conceptAbout = "conceptAbout";
final String linkedPlaceAbout = "linkedPlaceAbout";
final String unlinkedPlaceAbout = "unlinkedPlaceAbout";
final String existingTimespanAbout = "existingTimeSpanAbout";
final String absentTimespanAbout = "absentTimeSpanAbout";
agents.get(0).setAbout(agentAbout);
concepts.get(0).setAbout(conceptAbout);
places.get(0).setAbout(linkedPlaceAbout);
places.get(1).setAbout(unlinkedPlaceAbout);
timeSpans.get(0).setAbout(existingTimespanAbout);
// Create links to most objects and check that they are indeed obtainable.
final List<ProxyType> proxies = Arrays.asList(new ProxyType(), new ProxyType());
doReturn(proxies).when(entity).getProviderProxies();
proxies.get(0).setSameAList(Arrays.asList(new SameAs(), new SameAs(), new SameAs()));
proxies.get(1).setSameAList(Arrays.asList(new SameAs(), new SameAs(), new SameAs()));
proxies.get(0).getSameAList().get(0).setResource(agentAbout);
proxies.get(0).getSameAList().get(1).setResource(conceptAbout);
proxies.get(0).getSameAList().get(2).setResource(linkedPlaceAbout);
proxies.get(1).getSameAList().get(0).setResource(agentAbout);
proxies.get(1).getSameAList().get(1).setResource(existingTimespanAbout);
proxies.get(1).getSameAList().get(2).setResource(absentTimespanAbout);
assertEquals(new HashSet<>(Arrays.asList(agentAbout, conceptAbout, linkedPlaceAbout)), ResourceLinkFromProxy.SAME_AS.getLinkAndValueGetter().getLinks(proxies.get(0)).collect(Collectors.toSet()));
assertEquals(new HashSet<>(Arrays.asList(agentAbout, existingTimespanAbout, absentTimespanAbout)), ResourceLinkFromProxy.SAME_AS.getLinkAndValueGetter().getLinks(proxies.get(1)).collect(Collectors.toSet()));
// Do the tests for no qualifying entities (except the unlinked one).
doReturn(false).when(classifier).entityQualifies(agents.get(0));
doReturn(false).when(classifier).entityQualifies(concepts.get(0));
doReturn(false).when(classifier).entityQualifies(places.get(0));
doReturn(true).when(classifier).entityQualifies(places.get(1));
doReturn(false).when(classifier).entityQualifies(timeSpans.get(0));
assertEquals(0, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
// Make some of them qualifying and do the tests again.
doReturn(true).when(classifier).entityQualifies(agents.get(0));
assertEquals(1, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
doReturn(true).when(classifier).entityQualifies(concepts.get(0));
assertEquals(2, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
doReturn(true).when(classifier).entityQualifies(places.get(0));
assertEquals(3, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
doReturn(true).when(classifier).entityQualifies(timeSpans.get(0));
assertEquals(4, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
// Make some of them non-qualifying and do the tests again.
doReturn(false).when(classifier).entityQualifies(agents.get(0));
assertEquals(3, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
doReturn(false).when(classifier).entityQualifies(concepts.get(0));
assertEquals(2, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
doReturn(false).when(classifier).entityQualifies(places.get(0));
assertEquals(1, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
doReturn(false).when(classifier).entityQualifies(timeSpans.get(0));
assertEquals(0, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
}
use of eu.europeana.indexing.utils.RdfWrapper in project metis-framework by europeana.
the class AbstractMediaClassifierTest method testClassify_PreClassify.
@Test
void testClassify_PreClassify() {
final RdfWrapper entity = mock(RdfWrapper.class);
doReturn(MediaTier.T0).when(classifier).preClassifyEntity(entity);
assertEquals(MediaTier.T0, classifier.classify(entity).getTier());
}
use of eu.europeana.indexing.utils.RdfWrapper in project metis-framework by europeana.
the class AbstractMediaClassifierTest method testClassify_WithoutWebResources.
@Test
void testClassify_WithoutWebResources() {
final RdfWrapper entity = mock(RdfWrapper.class);
final boolean hasLandingPage = true;
final boolean hasThumbnails = true;
final LicenseType entityLicense = LicenseType.OPEN;
doReturn(hasLandingPage).when(entity).hasLandingPage();
doReturn(hasThumbnails).when(entity).hasThumbnails();
doReturn(entityLicense).when(entity).getLicenseType();
doReturn(null).when(classifier).preClassifyEntity(entity);
doReturn(Collections.emptyList()).when(entity).getWebResourceWrappers(EnumSet.of(WebResourceLinkType.HAS_VIEW, WebResourceLinkType.IS_SHOWN_BY));
// Has embeddable media will be true
doReturn(Set.of("http://soundcloud.com/")).when(entity).getUrlsOfTypes(Set.of(WebResourceLinkType.IS_SHOWN_BY));
doReturn(MediaTier.T0).when(classifier).classifyEntityWithoutWebResources(entity, hasLandingPage);
assertEquals(MediaTier.T0, classifier.classify(entity).getTier());
}
use of eu.europeana.indexing.utils.RdfWrapper in project metis-framework by europeana.
the class ImageClassifierTest method testPreClassifyEntity.
/**
* Whether there are thumbnails is handled by pre-classification: if there are none, we know that the tier must be 0.
*/
@Test
void testPreClassifyEntity() {
final RdfWrapper entity = mock(RdfWrapper.class);
doReturn(true).when(entity).hasThumbnails();
assertNull(classifier.preClassifyEntity(entity));
doReturn(false).when(entity).hasThumbnails();
assertEquals(MediaTier.T0, classifier.preClassifyEntity(entity));
}
Aggregations