Search in sources :

Example 1 with RdfWrapper

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());
}
Also used : Concept(eu.europeana.metis.schema.jibx.Concept) RdfWrapper(eu.europeana.indexing.utils.RdfWrapper) PlaceType(eu.europeana.metis.schema.jibx.PlaceType) TimeSpanType(eu.europeana.metis.schema.jibx.TimeSpanType) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) EuropeanaProxy(eu.europeana.metis.schema.jibx.EuropeanaProxy) Test(org.junit.jupiter.api.Test)

Example 2 with RdfWrapper

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());
}
Also used : Concept(eu.europeana.metis.schema.jibx.Concept) PlaceType(eu.europeana.metis.schema.jibx.PlaceType) TimeSpanType(eu.europeana.metis.schema.jibx.TimeSpanType) AgentType(eu.europeana.metis.schema.jibx.AgentType) RdfWrapper(eu.europeana.indexing.utils.RdfWrapper) SameAs(eu.europeana.metis.schema.jibx.SameAs) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) Test(org.junit.jupiter.api.Test)

Example 3 with RdfWrapper

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());
}
Also used : RdfWrapper(eu.europeana.indexing.utils.RdfWrapper) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with RdfWrapper

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());
}
Also used : RdfWrapper(eu.europeana.indexing.utils.RdfWrapper) LicenseType(eu.europeana.indexing.utils.LicenseType) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with RdfWrapper

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));
}
Also used : RdfWrapper(eu.europeana.indexing.utils.RdfWrapper) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

RdfWrapper (eu.europeana.indexing.utils.RdfWrapper)23 Test (org.junit.jupiter.api.Test)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 PlaceType (eu.europeana.metis.schema.jibx.PlaceType)4 TimeSpanType (eu.europeana.metis.schema.jibx.TimeSpanType)4 Concept (eu.europeana.metis.schema.jibx.Concept)3 ProxyType (eu.europeana.metis.schema.jibx.ProxyType)3 RDF (eu.europeana.metis.schema.jibx.RDF)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 EnablingElementInventory (eu.europeana.indexing.tiers.metadata.EnablingElementsClassifier.EnablingElementInventory)2 MediaTier (eu.europeana.indexing.tiers.model.MediaTier)2 MetadataTierBreakdown (eu.europeana.indexing.tiers.view.MetadataTierBreakdown)2 LicenseType (eu.europeana.indexing.utils.LicenseType)2 AgentType (eu.europeana.metis.schema.jibx.AgentType)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 EnumSet (java.util.EnumSet)2 HashMap (java.util.HashMap)2