Search in sources :

Example 1 with PrefLabel

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

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

the class TimespanFieldInputTest method testTimespan.

@Test
void testTimespan() {
    TimeSpanType timespan = new TimeSpanType();
    timespan.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);
    timespan.setAltLabelList(altLabelList);
    Begin begin = new Begin();
    begin.setString("test begin");
    timespan.setBegin(begin);
    End end = new End();
    end.setString("test end");
    timespan.setEnd(end);
    List<Note> noteList = new ArrayList<>();
    Note note = new Note();
    note.setString("test note");
    assertNotNull(note);
    noteList.add(note);
    timespan.setNoteList(noteList);
    List<PrefLabel> prefLabelList = new ArrayList<>();
    PrefLabel prefLabel = new PrefLabel();
    prefLabel.setLang(lang);
    prefLabel.setString("test pred label");
    assertNotNull(prefLabel);
    prefLabelList.add(prefLabel);
    timespan.setPrefLabelList(prefLabelList);
    List<HiddenLabel> hiddelLabelList = new ArrayList<>();
    HiddenLabel hiddenLabel = new HiddenLabel();
    hiddenLabel.setLang(lang);
    hiddenLabel.setString("test hidden label");
    assertNotNull(hiddenLabel);
    hiddelLabelList.add(hiddenLabel);
    timespan.setHiddenLabelList(hiddelLabelList);
    List<IsPartOf> isPartOfList = new ArrayList<>();
    IsPartOf isPartOf = new IsPartOf();
    eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource isPartOfResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
    isPartOfResource.setResource("test resource");
    isPartOf.setResource(isPartOfResource);
    isPartOfList.add(isPartOf);
    timespan.setIsPartOfList(isPartOfList);
    TimespanImpl timespanImpl = new TimespanImpl();
    timespanImpl.setAbout(timespan.getAbout());
    // create mongo
    RecordDao mongoServerMock = mock(RecordDao.class);
    Datastore datastoreMock = mock(Datastore.class);
    @SuppressWarnings("unchecked") Query<TimespanImpl> queryMock = mock(Query.class);
    when(mongoServerMock.getDatastore()).thenReturn(datastoreMock);
    when(datastoreMock.find(TimespanImpl.class)).thenReturn(queryMock);
    when(datastoreMock.save(timespanImpl)).thenReturn(timespanImpl);
    when(queryMock.filter(Filters.eq("about", timespan.getAbout()))).thenReturn(queryMock);
    TimespanImpl timespanMongo = new TimespanFieldInput().apply(timespan);
    mongoServerMock.getDatastore().save(timespanMongo);
    assertEquals(timespan.getAbout(), timespanMongo.getAbout());
    assertEquals(timespan.getBegin().getString(), timespanMongo.getBegin().values().iterator().next().get(0));
    assertEquals(timespan.getEnd().getString(), timespanMongo.getEnd().values().iterator().next().get(0));
    assertEquals(timespan.getNoteList().get(0).getString(), timespanMongo.getNote().values().iterator().next().get(0));
    assertTrue(timespanMongo.getAltLabel().containsKey(timespan.getAltLabelList().get(0).getLang().getLang()));
    assertTrue(timespanMongo.getPrefLabel().containsKey(timespan.getPrefLabelList().get(0).getLang().getLang()));
    assertTrue(timespanMongo.getHiddenLabel().containsKey(timespan.getHiddenLabelList().get(0).getLang().getLang()));
    assertEquals(timespan.getAltLabelList().get(0).getString(), timespanMongo.getAltLabel().values().iterator().next().get(0));
    assertEquals(timespan.getPrefLabelList().get(0).getString(), timespanMongo.getPrefLabel().values().iterator().next().get(0));
    assertEquals(timespan.getIsPartOfList().get(0).getResource().getResource(), timespanMongo.getIsPartOf().values().iterator().next().get(0));
}
Also used : HiddenLabel(eu.europeana.metis.schema.jibx.HiddenLabel) TimespanImpl(eu.europeana.corelib.solr.entity.TimespanImpl) ArrayList(java.util.ArrayList) RecordDao(eu.europeana.metis.mongo.dao.RecordDao) Begin(eu.europeana.metis.schema.jibx.Begin) PrefLabel(eu.europeana.metis.schema.jibx.PrefLabel) TimeSpanType(eu.europeana.metis.schema.jibx.TimeSpanType) IsPartOf(eu.europeana.metis.schema.jibx.IsPartOf) Lang(eu.europeana.metis.schema.jibx.LiteralType.Lang) Datastore(dev.morphia.Datastore) AltLabel(eu.europeana.metis.schema.jibx.AltLabel) Note(eu.europeana.metis.schema.jibx.Note) End(eu.europeana.metis.schema.jibx.End) Test(org.junit.jupiter.api.Test)

Example 3 with PrefLabel

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

the class LanguageTagStatisticsTest method createPrefLabel.

private PrefLabel createPrefLabel(String language, String value) {
    final PrefLabel label = new PrefLabel();
    label.setLang(createLang(language));
    label.setString(value);
    return label;
}
Also used : PrefLabel(eu.europeana.metis.schema.jibx.PrefLabel)

Example 4 with PrefLabel

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

the class ContextualClassesBreakdownClassifierTest method testEntityQualifiesForConcept.

@Test
void testEntityQualifiesForConcept() {
    // Create objects
    final ContextualClassesClassifier classifier = spy(new ContextualClassesClassifier());
    final Concept concept = new Concept();
    final PrefLabel prefLabel = new PrefLabel();
    final Note note = new Note();
    final Broader broader = new Broader();
    final Narrower narrower = new Narrower();
    final ExactMatch exactMatch = new ExactMatch();
    final CloseMatch closeMatch = new CloseMatch();
    final Related related = new Related();
    // Test empty concept
    concept.setChoiceList(null);
    assertFalse(classifier.entityQualifies(concept));
    concept.setChoiceList(new ArrayList<>());
    assertFalse(classifier.entityQualifies(concept));
    concept.getChoiceList().add(new Choice());
    assertFalse(classifier.entityQualifies(concept));
    // Set values
    concept.setChoiceList(IntStream.range(0, 7).mapToObj(index -> new Choice()).collect(Collectors.toList()));
    concept.getChoiceList().get(0).setPrefLabel(prefLabel);
    concept.getChoiceList().get(1).setNote(note);
    concept.getChoiceList().get(2).setBroader(broader);
    concept.getChoiceList().get(3).setNarrower(narrower);
    concept.getChoiceList().get(4).setExactMatch(exactMatch);
    concept.getChoiceList().get(5).setCloseMatch(closeMatch);
    concept.getChoiceList().get(6).setRelated(related);
    // Test prefLabel absent (and rest present)
    doReturn(false).when(classifier).hasProperty(prefLabel);
    doReturn(true).when(classifier).hasProperty(note);
    doReturn(true).when(classifier).hasProperty(broader);
    doReturn(true).when(classifier).hasProperty(narrower);
    doReturn(true).when(classifier).hasProperty(exactMatch);
    doReturn(true).when(classifier).hasProperty(closeMatch);
    doReturn(true).when(classifier).hasProperty(related);
    assertFalse(classifier.entityQualifies(concept));
    // Test prefLabel present (and rest absent)
    doReturn(true).when(classifier).hasProperty(prefLabel);
    doReturn(false).when(classifier).hasProperty(note);
    doReturn(false).when(classifier).hasProperty(broader);
    doReturn(false).when(classifier).hasProperty(narrower);
    doReturn(false).when(classifier).hasProperty(exactMatch);
    doReturn(false).when(classifier).hasProperty(closeMatch);
    doReturn(false).when(classifier).hasProperty(related);
    assertFalse(classifier.entityQualifies(concept));
    // Test prefLabel and note present
    doReturn(true).when(classifier).hasProperty(note);
    assertTrue(classifier.entityQualifies(concept));
    doReturn(false).when(classifier).hasProperty(note);
    assertFalse(classifier.entityQualifies(concept));
    // Test prefLabel and broader present
    doReturn(true).when(classifier).hasProperty(broader);
    assertTrue(classifier.entityQualifies(concept));
    doReturn(false).when(classifier).hasProperty(broader);
    assertFalse(classifier.entityQualifies(concept));
    // Test prefLabel and narrower present
    doReturn(true).when(classifier).hasProperty(narrower);
    assertTrue(classifier.entityQualifies(concept));
    doReturn(false).when(classifier).hasProperty(narrower);
    assertFalse(classifier.entityQualifies(concept));
    // Test prefLabel and exactMatch present
    doReturn(true).when(classifier).hasProperty(exactMatch);
    assertTrue(classifier.entityQualifies(concept));
    doReturn(false).when(classifier).hasProperty(exactMatch);
    assertFalse(classifier.entityQualifies(concept));
    // Test prefLabel and closeMatch present
    doReturn(true).when(classifier).hasProperty(closeMatch);
    assertTrue(classifier.entityQualifies(concept));
    doReturn(false).when(classifier).hasProperty(closeMatch);
    assertFalse(classifier.entityQualifies(concept));
    // Test prefLabel and related present
    doReturn(true).when(classifier).hasProperty(related);
    assertTrue(classifier.entityQualifies(concept));
    doReturn(false).when(classifier).hasProperty(related);
    assertFalse(classifier.entityQualifies(concept));
}
Also used : Concept(eu.europeana.metis.schema.jibx.Concept) ExactMatch(eu.europeana.metis.schema.jibx.ExactMatch) Broader(eu.europeana.metis.schema.jibx.Broader) Narrower(eu.europeana.metis.schema.jibx.Narrower) Related(eu.europeana.metis.schema.jibx.Related) Choice(eu.europeana.metis.schema.jibx.Concept.Choice) Note(eu.europeana.metis.schema.jibx.Note) CloseMatch(eu.europeana.metis.schema.jibx.CloseMatch) PrefLabel(eu.europeana.metis.schema.jibx.PrefLabel) Test(org.junit.jupiter.api.Test)

Example 5 with PrefLabel

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

the class ContextualClassesBreakdownClassifierTest method testEntityQualifiesForPlace.

@Test
void testEntityQualifiesForPlace() {
    // Create objects
    final ContextualClassesClassifier classifier = spy(new ContextualClassesClassifier());
    final PlaceType place = new PlaceType();
    final List<PrefLabel> prefLabelList = new ArrayList<>();
    // Test empty time span
    assertFalse(classifier.entityQualifies(place));
    // Set values
    place.setPrefLabelList(prefLabelList);
    place.setLat(new Lat());
    place.getLat().setLat(0.0F);
    place.setLong(new _Long());
    place.getLong().setLong(0.0F);
    // Test all present
    doReturn(true).when(classifier).hasLiteralProperty(prefLabelList);
    assertTrue(classifier.entityQualifies(place));
    // Test without pref label list
    doReturn(false).when(classifier).hasLiteralProperty(prefLabelList);
    assertFalse(classifier.entityQualifies(place));
    doReturn(true).when(classifier).hasLiteralProperty(prefLabelList);
    assertTrue(classifier.entityQualifies(place));
    // Test without lat
    place.getLat().setLat(null);
    assertFalse(classifier.entityQualifies(place));
    place.setLat(null);
    assertFalse(classifier.entityQualifies(place));
    place.setLat(new Lat());
    place.getLat().setLat(0.0F);
    assertTrue(classifier.entityQualifies(place));
    // Test without lon
    place.getLong().setLong(null);
    assertFalse(classifier.entityQualifies(place));
    place.setLong(null);
    assertFalse(classifier.entityQualifies(place));
}
Also used : PlaceType(eu.europeana.metis.schema.jibx.PlaceType) eu.europeana.metis.schema.jibx._Long(eu.europeana.metis.schema.jibx._Long) ArrayList(java.util.ArrayList) PrefLabel(eu.europeana.metis.schema.jibx.PrefLabel) Lat(eu.europeana.metis.schema.jibx.Lat) Test(org.junit.jupiter.api.Test)

Aggregations

PrefLabel (eu.europeana.metis.schema.jibx.PrefLabel)8 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)6 Note (eu.europeana.metis.schema.jibx.Note)5 Datastore (dev.morphia.Datastore)4 RecordDao (eu.europeana.metis.mongo.dao.RecordDao)4 AltLabel (eu.europeana.metis.schema.jibx.AltLabel)4 Lang (eu.europeana.metis.schema.jibx.LiteralType.Lang)4 Begin (eu.europeana.metis.schema.jibx.Begin)3 End (eu.europeana.metis.schema.jibx.End)3 AgentType (eu.europeana.metis.schema.jibx.AgentType)2 Concept (eu.europeana.metis.schema.jibx.Concept)2 IsPartOf (eu.europeana.metis.schema.jibx.IsPartOf)2 Lat (eu.europeana.metis.schema.jibx.Lat)2 PlaceType (eu.europeana.metis.schema.jibx.PlaceType)2 eu.europeana.metis.schema.jibx._Long (eu.europeana.metis.schema.jibx._Long)2 AgentImpl (eu.europeana.corelib.solr.entity.AgentImpl)1 ConceptImpl (eu.europeana.corelib.solr.entity.ConceptImpl)1 PlaceImpl (eu.europeana.corelib.solr.entity.PlaceImpl)1 TimespanImpl (eu.europeana.corelib.solr.entity.TimespanImpl)1