Search in sources :

Example 1 with PlaceType

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

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

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

the class PlaceFieldInputTest method testPlace.

@Test
void testPlace() {
    PlaceImpl placeImpl = new PlaceImpl();
    placeImpl.setAbout("test about");
    RecordDao mongoServerMock = mock(RecordDao.class);
    Datastore datastoreMock = mock(Datastore.class);
    @SuppressWarnings("unchecked") Query<PlaceImpl> queryMock = mock(Query.class);
    when(mongoServerMock.getDatastore()).thenReturn(datastoreMock);
    when(datastoreMock.find(PlaceImpl.class)).thenReturn(queryMock);
    when(datastoreMock.save(placeImpl)).thenReturn(placeImpl);
    when(queryMock.filter(Filters.eq("about", placeImpl.getAbout()))).thenReturn(queryMock);
    PlaceType place = new PlaceType();
    place.setAbout("test about");
    List<AltLabel> altLabelList = new ArrayList<>();
    AltLabel altLabel = new AltLabel();
    Lang lang = new Lang();
    lang.setLang("en");
    altLabel.setLang(lang);
    altLabel.setString("test alt label");
    assertNotNull(altLabel);
    altLabelList.add(altLabel);
    place.setAltLabelList(altLabelList);
    List<Note> noteList = new ArrayList<>();
    Note note = new Note();
    note.setString("test note");
    assertNotNull(note);
    noteList.add(note);
    place.setNoteList(noteList);
    List<PrefLabel> prefLabelList = new ArrayList<>();
    PrefLabel prefLabel = new PrefLabel();
    prefLabel.setLang(lang);
    prefLabel.setString("test pred label");
    assertNotNull(prefLabel);
    prefLabelList.add(prefLabel);
    place.setPrefLabelList(prefLabelList);
    List<IsPartOf> isPartOfList = new ArrayList<>();
    IsPartOf isPartOf = new IsPartOf();
    isPartOf.setString("test resource");
    isPartOfList.add(isPartOf);
    place.setIsPartOfList(isPartOfList);
    Lat posLat = new Lat();
    posLat.setLat(Float.valueOf("1.0"));
    place.setLat(posLat);
    _Long posLong = new _Long();
    posLong.setLong(Float.valueOf("1.0"));
    place.setLong(posLong);
    // create mongo place
    PlaceImpl placeMongo = new PlaceFieldInput().apply(place);
    mongoServerMock.getDatastore().save(placeMongo);
    assertEquals(place.getAbout(), placeMongo.getAbout());
    assertEquals(place.getNoteList().get(0).getString(), placeMongo.getNote().values().iterator().next().get(0));
    assertTrue(placeMongo.getAltLabel().containsKey(place.getAltLabelList().get(0).getLang().getLang()));
    assertEquals(place.getAltLabelList().get(0).getString(), placeMongo.getAltLabel().values().iterator().next().get(0));
    assertEquals(place.getPrefLabelList().get(0).getString(), placeMongo.getPrefLabel().values().iterator().next().get(0));
    assertEquals(place.getIsPartOfList().get(0).getString(), placeMongo.getIsPartOf().values().iterator().next().get(0));
    assertEquals(Float.toString(place.getLat().getLat()), Float.toString(placeMongo.getLatitude()));
    assertEquals(Float.toString(place.getLong().getLong()), Float.toString(placeMongo.getLongitude()));
}
Also used : PlaceType(eu.europeana.metis.schema.jibx.PlaceType) eu.europeana.metis.schema.jibx._Long(eu.europeana.metis.schema.jibx._Long) IsPartOf(eu.europeana.metis.schema.jibx.IsPartOf) ArrayList(java.util.ArrayList) Lang(eu.europeana.metis.schema.jibx.LiteralType.Lang) RecordDao(eu.europeana.metis.mongo.dao.RecordDao) Datastore(dev.morphia.Datastore) AltLabel(eu.europeana.metis.schema.jibx.AltLabel) Note(eu.europeana.metis.schema.jibx.Note) PlaceImpl(eu.europeana.corelib.solr.entity.PlaceImpl) PrefLabel(eu.europeana.metis.schema.jibx.PrefLabel) Lat(eu.europeana.metis.schema.jibx.Lat) Test(org.junit.jupiter.api.Test)

Example 4 with PlaceType

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

the class LanguageTagStatisticsTest method testConstruction.

@Test
void testConstruction() {
    // Define some about values
    final String about1 = "about1";
    final String about2 = "about2";
    final String about3 = "about3";
    final String about4 = "about4";
    // Create contextual classes for later use. They are all valid to begin with.
    final PlaceType place1 = new PlaceType();
    place1.setPrefLabelList(Collections.singletonList(createPrefLabel("lang1", "value1")));
    place1.setAbout(about1);
    final PlaceType place2 = new PlaceType();
    place2.setPrefLabelList(Collections.singletonList(createPrefLabel("lang2", "value2")));
    place2.setAbout(about2);
    final TimeSpanType timeSpan = new TimeSpanType();
    timeSpan.setPrefLabelList(Collections.singletonList(createPrefLabel("lang3", "value3")));
    timeSpan.setAbout(about3);
    final Concept concept = new Concept();
    final Concept.Choice choiceA = new Concept.Choice();
    choiceA.setPrefLabel(createPrefLabel("lang4a", "value4a"));
    final Concept.Choice choiceB = new Concept.Choice();
    choiceB.setPrefLabel(createPrefLabel("lang4b", "value4b"));
    concept.setChoiceList(Arrays.asList(choiceA, choiceB));
    concept.setAbout(about4);
    // Test that they are all represented.
    final LanguageTagStatistics statistics1 = new LanguageTagStatistics(Arrays.asList(place1, place2), Collections.singletonList(timeSpan), Collections.singletonList(concept));
    assertEquals(new HashSet<>(Arrays.asList(about1, about2, about3, about4)), statistics1.getContextualClassesWithLanguage());
    assertTrue(statistics1.containsContextualClass(about1));
    assertTrue(statistics1.containsContextualClass(about2));
    assertTrue(statistics1.containsContextualClass(about3));
    assertTrue(statistics1.containsContextualClass(about4));
    // Now make some preflabels invalid.
    place1.getPrefLabelList().get(0).setLang(new Lang());
    place2.getPrefLabelList().get(0).setLang(null);
    timeSpan.getPrefLabelList().get(0).setString(" ");
    concept.getChoiceList().get(0).getPrefLabel().getLang().setLang(" ");
    final LanguageTagStatistics statistics2 = new LanguageTagStatistics(Arrays.asList(place1, place2), Collections.singletonList(timeSpan), Collections.singletonList(concept));
    assertEquals(Collections.singleton(about4), statistics2.getContextualClassesWithLanguage());
    concept.getChoiceList().get(1).getPrefLabel().setString(null);
    final LanguageTagStatistics statistics3 = new LanguageTagStatistics(Arrays.asList(place1, place2), Collections.singletonList(timeSpan), Collections.singletonList(concept));
    assertEquals(Collections.emptySet(), statistics3.getContextualClassesWithLanguage());
    // Now make some preflabel collections invalid
    place1.setPrefLabelList(Collections.emptyList());
    place2.setPrefLabelList(null);
    concept.getChoiceList().forEach(Concept.Choice::clearChoiceListSelect);
    concept.getChoiceList().get(0).setAltLabel(new AltLabel());
    concept.getChoiceList().get(0).getAltLabel().setString("altLabelValue");
    concept.getChoiceList().get(0).getAltLabel().setLang(createLang("altLabelLanguage"));
    concept.getChoiceList().get(1).setAltLabel(null);
    final LanguageTagStatistics statistics4 = new LanguageTagStatistics(Arrays.asList(place1, place2), Collections.singletonList(timeSpan), Collections.singletonList(concept));
    assertEquals(Collections.emptySet(), statistics4.getContextualClassesWithLanguage());
    concept.setChoiceList(null);
    final LanguageTagStatistics statistics5 = new LanguageTagStatistics(Arrays.asList(place1, place2), Collections.singletonList(timeSpan), Collections.singletonList(concept));
    assertEquals(Collections.emptySet(), statistics5.getContextualClassesWithLanguage());
}
Also used : Concept(eu.europeana.metis.schema.jibx.Concept) Choice(eu.europeana.metis.schema.jibx.EuropeanaType.Choice) PlaceType(eu.europeana.metis.schema.jibx.PlaceType) TimeSpanType(eu.europeana.metis.schema.jibx.TimeSpanType) AltLabel(eu.europeana.metis.schema.jibx.AltLabel) Lang(eu.europeana.metis.schema.jibx.LiteralType.Lang) Test(org.junit.jupiter.api.Test)

Example 5 with PlaceType

use of eu.europeana.metis.schema.jibx.PlaceType 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)

Aggregations

PlaceType (eu.europeana.metis.schema.jibx.PlaceType)9 Test (org.junit.jupiter.api.Test)8 Concept (eu.europeana.metis.schema.jibx.Concept)5 TimeSpanType (eu.europeana.metis.schema.jibx.TimeSpanType)5 RdfWrapper (eu.europeana.indexing.utils.RdfWrapper)3 AgentType (eu.europeana.metis.schema.jibx.AgentType)3 Lat (eu.europeana.metis.schema.jibx.Lat)3 ProxyType (eu.europeana.metis.schema.jibx.ProxyType)3 eu.europeana.metis.schema.jibx._Long (eu.europeana.metis.schema.jibx._Long)3 ArrayList (java.util.ArrayList)3 AltLabel (eu.europeana.metis.schema.jibx.AltLabel)2 IsPartOf (eu.europeana.metis.schema.jibx.IsPartOf)2 Lang (eu.europeana.metis.schema.jibx.LiteralType.Lang)2 Note (eu.europeana.metis.schema.jibx.Note)2 PrefLabel (eu.europeana.metis.schema.jibx.PrefLabel)2 SameAs (eu.europeana.metis.schema.jibx.SameAs)2 HashSet (java.util.HashSet)2 Datastore (dev.morphia.Datastore)1 PlaceImpl (eu.europeana.corelib.solr.entity.PlaceImpl)1 RecordDao (eu.europeana.metis.mongo.dao.RecordDao)1