Search in sources :

Example 1 with SameAs

use of eu.europeana.metis.schema.jibx.SameAs 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 2 with SameAs

use of eu.europeana.metis.schema.jibx.SameAs in project metis-framework by europeana.

the class DereferenceUtilsTest method testPlaceListExtractedValues.

@Test
void testPlaceListExtractedValues() {
    RDF rdf = new RDF();
    ProxyType proxy = new ProxyType();
    ArrayList<ProxyType> proxyList = new ArrayList<>();
    proxyList.add(proxy);
    rdf.setProxyList(proxyList);
    PlaceType place = new PlaceType();
    place.setAbout("http://dummy1.dum");
    IsPartOf isPartOf = new IsPartOf();
    ResourceOrLiteralType.Resource resource3 = new ResourceOrLiteralType.Resource();
    resource3.setResource("http://dummy2.dum");
    isPartOf.setResource(resource3);
    ArrayList<IsPartOf> isPartOfList = new ArrayList<>();
    isPartOfList.add(isPartOf);
    place.setIsPartOfList(isPartOfList);
    SameAs sameAs = new SameAs();
    sameAs.setResource("http://dummy3.dum");
    ArrayList<SameAs> sameAsList = new ArrayList<>();
    sameAsList.add(sameAs);
    place.setSameAList(sameAsList);
    HasPart hasPart = new HasPart();
    Resource resource4 = new Resource();
    resource4.setResource("http://dummy4.dum");
    hasPart.setResource(resource4);
    ArrayList<HasPart> hasPartList = new ArrayList<>();
    hasPartList.add(hasPart);
    place.setHasPartList(hasPartList);
    // Should be rejected
    Note note = new Note();
    note.setString("Note");
    ArrayList<Note> noteList = new ArrayList<>();
    noteList.add(note);
    place.setNoteList(noteList);
    ArrayList<PlaceType> placeList = new ArrayList<>();
    placeList.add(place);
    rdf.setPlaceList(placeList);
    Set<String> result = DereferenceUtils.extractReferencesForDereferencing(rdf);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertTrue(result.contains("http://dummy2.dum"));
}
Also used : PlaceType(eu.europeana.metis.schema.jibx.PlaceType) IsPartOf(eu.europeana.metis.schema.jibx.IsPartOf) ArrayList(java.util.ArrayList) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) HasPart(eu.europeana.metis.schema.jibx.HasPart) SameAs(eu.europeana.metis.schema.jibx.SameAs) RDF(eu.europeana.metis.schema.jibx.RDF) Note(eu.europeana.metis.schema.jibx.Note) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) ResourceOrLiteralType(eu.europeana.metis.schema.jibx.ResourceOrLiteralType) Test(org.junit.jupiter.api.Test)

Example 3 with SameAs

use of eu.europeana.metis.schema.jibx.SameAs in project metis-framework by europeana.

the class DereferenceUtilsTest method testTimeSpanListExtractedValues.

@Test
void testTimeSpanListExtractedValues() {
    RDF rdf = new RDF();
    ProxyType proxy = new ProxyType();
    ArrayList<ProxyType> proxyList = new ArrayList<>();
    proxyList.add(proxy);
    rdf.setProxyList(proxyList);
    TimeSpanType timeSpan = new TimeSpanType();
    timeSpan.setAbout("http://dummy1.dum");
    HasPart hasPart = new HasPart();
    Resource resource3 = new Resource();
    resource3.setResource("http://dummy2.dum");
    hasPart.setResource(resource3);
    ArrayList<HasPart> hasPartList = new ArrayList<>();
    hasPartList.add(hasPart);
    timeSpan.setHasPartList(hasPartList);
    IsPartOf isPartOf = new IsPartOf();
    ResourceOrLiteralType.Resource resource4 = new ResourceOrLiteralType.Resource();
    resource4.setResource("http://dummy4.dum");
    isPartOf.setResource(resource4);
    ArrayList<IsPartOf> isPartOfList = new ArrayList<>();
    isPartOfList.add(isPartOf);
    timeSpan.setIsPartOfList(isPartOfList);
    SameAs sameAs = new SameAs();
    sameAs.setResource("http://dummy5.dum");
    ArrayList<SameAs> sameAsList = new ArrayList<>();
    sameAsList.add(sameAs);
    timeSpan.setSameAList(sameAsList);
    // Should be rejected
    Note note = new Note();
    note.setString("Note");
    ArrayList<Note> noteList = new ArrayList<>();
    noteList.add(note);
    timeSpan.setNoteList(noteList);
    ArrayList<TimeSpanType> timeSpanList = new ArrayList<>();
    timeSpanList.add(timeSpan);
    rdf.setTimeSpanList(timeSpanList);
    Set<String> result = DereferenceUtils.extractReferencesForDereferencing(rdf);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertTrue(result.contains("http://dummy4.dum"));
}
Also used : TimeSpanType(eu.europeana.metis.schema.jibx.TimeSpanType) IsPartOf(eu.europeana.metis.schema.jibx.IsPartOf) ArrayList(java.util.ArrayList) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) HasPart(eu.europeana.metis.schema.jibx.HasPart) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) SameAs(eu.europeana.metis.schema.jibx.SameAs) RDF(eu.europeana.metis.schema.jibx.RDF) Note(eu.europeana.metis.schema.jibx.Note) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) ResourceOrLiteralType(eu.europeana.metis.schema.jibx.ResourceOrLiteralType) Test(org.junit.jupiter.api.Test)

Aggregations

ProxyType (eu.europeana.metis.schema.jibx.ProxyType)3 SameAs (eu.europeana.metis.schema.jibx.SameAs)3 Test (org.junit.jupiter.api.Test)3 HasPart (eu.europeana.metis.schema.jibx.HasPart)2 IsPartOf (eu.europeana.metis.schema.jibx.IsPartOf)2 Note (eu.europeana.metis.schema.jibx.Note)2 PlaceType (eu.europeana.metis.schema.jibx.PlaceType)2 RDF (eu.europeana.metis.schema.jibx.RDF)2 ResourceOrLiteralType (eu.europeana.metis.schema.jibx.ResourceOrLiteralType)2 Resource (eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource)2 TimeSpanType (eu.europeana.metis.schema.jibx.TimeSpanType)2 ArrayList (java.util.ArrayList)2 RdfWrapper (eu.europeana.indexing.utils.RdfWrapper)1 AgentType (eu.europeana.metis.schema.jibx.AgentType)1 Concept (eu.europeana.metis.schema.jibx.Concept)1