Search in sources :

Example 1 with Choice

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

the class EnablingElementsBreakdownClassifierTest method testAnalyzeForElements.

@Test
void testAnalyzeForElements() {
    // Create some objects.
    final EnablingElementsClassifier classifier = new EnablingElementsClassifier();
    final String link = "link";
    final Map<String, Set<Class<? extends AboutType>>> contextualObjectMap = Collections.singletonMap(link, EnumSet.allOf(ContextualClassGroup.class).stream().map(ContextualClassGroup::getContextualClass).collect(Collectors.toSet()));
    // Create proxy with Created and a HasMet.
    final Created created = new Created();
    created.setString(link);
    created.setResource(new Resource());
    created.getResource().setResource(link);
    final HasMet hasMet = new HasMet();
    hasMet.setResource(link);
    final ProxyType proxy = new ProxyType();
    proxy.setChoiceList(Collections.singletonList(new Choice()));
    proxy.getChoiceList().get(0).setCreated(created);
    proxy.setHasMetList(Collections.singletonList(hasMet));
    final List<ProxyType> proxies = Collections.singletonList(proxy);
    // Test for some queries that the answer is the same as calling the enum directly. The enum
    // itself is tested in its own unit test class.
    assertEquals(EnablingElement.EDM_HAS_MET.analyze(proxies, contextualObjectMap), classifier.analyzeForElement(EnablingElement.EDM_HAS_MET, proxies, contextualObjectMap));
    assertEquals(EnablingElement.DCTERMS_CREATED.analyze(proxies, contextualObjectMap), classifier.analyzeForElement(EnablingElement.DCTERMS_CREATED, proxies, contextualObjectMap));
    assertEquals(EnablingElement.DCTERMS_ISSUED.analyze(proxies, contextualObjectMap), classifier.analyzeForElement(EnablingElement.DCTERMS_ISSUED, proxies, contextualObjectMap));
}
Also used : HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) Set(java.util.Set) Choice(eu.europeana.metis.schema.jibx.EuropeanaType.Choice) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) HasMet(eu.europeana.metis.schema.jibx.HasMet) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) Created(eu.europeana.metis.schema.jibx.Created) Test(org.junit.jupiter.api.Test)

Example 2 with Choice

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

the class ResourceLinkFromProxyTest method testGetLinksAndValuesInChoice.

private <T extends ResourceOrLiteralType> void testGetLinksAndValuesInChoice(ResourceLinkFromProxy resource, Supplier<T> constructor, BiConsumer<Choice, T> setter) {
    // Create objects
    final ProxyType proxy = new ProxyType();
    final T value1 = constructor.get();
    final T value2 = constructor.get();
    // Test with null list
    proxy.setChoiceList(null);
    assertNoLinks(proxy, resource);
    assertNoValues(proxy, resource);
    // Test with null or empty choices
    proxy.setChoiceList(Arrays.asList(null, new Choice()));
    setter.accept(proxy.getChoiceList().get(1), null);
    assertNoLinks(proxy, resource);
    assertNoValues(proxy, resource);
    // Test with null value and empty value
    proxy.setChoiceList(Arrays.asList(new Choice(), new Choice()));
    setter.accept(proxy.getChoiceList().get(0), value1);
    setter.accept(proxy.getChoiceList().get(1), value2);
    value1.setResource(null);
    value1.setString(null);
    value2.setResource(new Resource());
    value2.getResource().setResource(" ");
    value2.setString(" ");
    assertNoLinks(proxy, resource);
    assertNoValues(proxy, resource);
    // Test with actual value
    final String testResource1 = "test resource 1";
    final String testResource2 = "test resource 2";
    final String testLiteral1 = "test literal 1";
    final String testLiteral2 = "test literal 2";
    value1.setResource(new Resource());
    value1.getResource().setResource(testResource1);
    value2.getResource().setResource(testResource2);
    value1.setString(testLiteral1);
    value2.setString(testLiteral2);
    final List<String> linksDifferent = resource.getLinkAndValueGetter().getLinks(proxy).collect(Collectors.toList());
    assertEquals(Arrays.asList(testResource1, testResource2), linksDifferent);
    final List<String> valuesDifferent = resource.getLinkAndValueGetter().getValues(proxy).collect(Collectors.toList());
    assertEquals(Arrays.asList(testLiteral1, testLiteral2), valuesDifferent);
    // Test with the same values
    value2.getResource().setResource(testResource1);
    value2.setString(testLiteral1);
    final List<String> linksSame = resource.getLinkAndValueGetter().getLinks(proxy).collect(Collectors.toList());
    assertEquals(Arrays.asList(testResource1, testResource1), linksSame);
    final List<String> valuesSame = resource.getLinkAndValueGetter().getValues(proxy).collect(Collectors.toList());
    assertEquals(Arrays.asList(testLiteral1, testLiteral1), valuesSame);
}
Also used : Choice(eu.europeana.metis.schema.jibx.EuropeanaType.Choice) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) ProxyType(eu.europeana.metis.schema.jibx.ProxyType)

Example 3 with Choice

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

the class MetisRecordParserTest method testExtractedFieldValuesForEnrichment.

@Test
public void testExtractedFieldValuesForEnrichment() {
    RDF rdf = new RDF();
    ProxyType proxy = new ProxyType();
    ArrayList<Choice> choiceList = new ArrayList<>();
    Choice choice1 = new Choice();
    Creator creator = new Creator();
    creator.setString("Creator");
    Lang language1 = new Lang();
    language1.setLang("English");
    creator.setLang(language1);
    choice1.setCreator(creator);
    choiceList.add(choice1);
    Choice choice2 = new Choice();
    Contributor contributor = new Contributor();
    contributor.setString("Contributor");
    Lang language2 = new Lang();
    language2.setLang("Dutch");
    contributor.setLang(language2);
    choice2.setContributor(contributor);
    choiceList.add(choice2);
    Choice choice3 = new Choice();
    Date date = new Date();
    date.setString("Date");
    Lang language3 = new Lang();
    language3.setLang("German");
    date.setLang(language3);
    choice3.setDate(date);
    choiceList.add(choice3);
    Choice choice4 = new Choice();
    Issued issued = new Issued();
    issued.setString("Issued");
    Lang language4 = new Lang();
    language4.setLang("French");
    issued.setLang(language4);
    choice4.setIssued(issued);
    choiceList.add(choice4);
    Choice choice5 = new Choice();
    Created created = new Created();
    created.setString("Created");
    Lang language5 = new Lang();
    language5.setLang("Italian");
    created.setLang(language5);
    choice5.setCreated(created);
    choiceList.add(choice5);
    Choice choice6 = new Choice();
    Coverage coverage = new Coverage();
    coverage.setString("Coverage");
    Lang language6 = new Lang();
    language6.setLang("Spanish");
    coverage.setLang(language6);
    choice6.setCoverage(coverage);
    choiceList.add(choice6);
    Choice choice7 = new Choice();
    Temporal temporal = new Temporal();
    temporal.setString("Temporal");
    Lang language7 = new Lang();
    language7.setLang("Polish");
    temporal.setLang(language7);
    choice7.setTemporal(temporal);
    choiceList.add(choice7);
    Choice choice8 = new Choice();
    Type type = new Type();
    type.setString("Type");
    Lang language8 = new Lang();
    language8.setLang("Romanian");
    type.setLang(language8);
    choice8.setType(type);
    choiceList.add(choice8);
    Choice choice9 = new Choice();
    Spatial spatial = new Spatial();
    spatial.setString("Spatial");
    Lang language9 = new Lang();
    language9.setLang("Greek");
    spatial.setLang(language9);
    choice9.setSpatial(spatial);
    choiceList.add(choice9);
    Choice choice10 = new Choice();
    Subject subject = new Subject();
    subject.setString("Subject");
    Lang language10 = new Lang();
    language10.setLang("Bulgarian");
    subject.setLang(language10);
    choice10.setSubject(subject);
    choiceList.add(choice10);
    // Should be rejected
    Choice choice11 = new Choice();
    Extent extent = new Extent();
    extent.setString("Extent");
    Lang language11 = new Lang();
    language11.setLang("Ukrainian");
    extent.setLang(language11);
    choice11.setExtent(extent);
    choiceList.add(choice11);
    proxy.setChoiceList(choiceList);
    ArrayList<ProxyType> proxyList = new ArrayList<>();
    proxyList.add(proxy);
    // Should be rejected
    ProxyType proxyEuropeana = new ProxyType();
    EuropeanaProxy europeanaProxy = new EuropeanaProxy();
    europeanaProxy.setEuropeanaProxy(true);
    proxyEuropeana.setEuropeanaProxy(europeanaProxy);
    proxyList.add(proxyEuropeana);
    rdf.setProxyList(proxyList);
    Set<SearchTermContext> result = new MetisRecordParser().parseSearchTerms(rdf);
    assertNotNull(result);
    assertEquals(10, result.size());
    ArrayList<String> resultProcessed = new ArrayList<>();
    for (SearchTermContext searchValue : result) {
        resultProcessed.add(searchValue.getTextValue() + "|" + searchValue.getLanguage());
    }
    assertTrue(resultProcessed.contains("Creator|English"));
    assertTrue(resultProcessed.contains("Contributor|Dutch"));
    assertTrue(resultProcessed.contains("Date|German"));
    assertTrue(resultProcessed.contains("Issued|French"));
    assertTrue(resultProcessed.contains("Created|Italian"));
    assertTrue(resultProcessed.contains("Coverage|Spanish"));
    assertTrue(resultProcessed.contains("Temporal|Polish"));
    assertTrue(resultProcessed.contains("Type|Romanian"));
    assertTrue(resultProcessed.contains("Spatial|Greek"));
    assertTrue(resultProcessed.contains("Subject|Bulgarian"));
}
Also used : Choice(eu.europeana.metis.schema.jibx.EuropeanaType.Choice) Extent(eu.europeana.metis.schema.jibx.Extent) ArrayList(java.util.ArrayList) Contributor(eu.europeana.metis.schema.jibx.Contributor) Lang(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Lang) Coverage(eu.europeana.metis.schema.jibx.Coverage) Creator(eu.europeana.metis.schema.jibx.Creator) Date(eu.europeana.metis.schema.jibx.Date) Subject(eu.europeana.metis.schema.jibx.Subject) EuropeanaProxy(eu.europeana.metis.schema.jibx.EuropeanaProxy) Created(eu.europeana.metis.schema.jibx.Created) SearchTermContext(eu.europeana.enrichment.api.internal.SearchTermContext) Type(eu.europeana.metis.schema.jibx.Type) EuropeanaAggregationType(eu.europeana.metis.schema.jibx.EuropeanaAggregationType) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) Temporal(eu.europeana.metis.schema.jibx.Temporal) RDF(eu.europeana.metis.schema.jibx.RDF) Spatial(eu.europeana.metis.schema.jibx.Spatial) Issued(eu.europeana.metis.schema.jibx.Issued) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) Test(org.junit.jupiter.api.Test)

Example 4 with Choice

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

the class EnrichmentUtilsTest method testSetAdditionalDataAllYearFieldValues.

@Test
void testSetAdditionalDataAllYearFieldValues() {
    Choice dateChoice = new Choice();
    Date date = new Date();
    Choice temporalChoice = new Choice();
    Temporal temporal = new Temporal();
    Choice createdChoice = new Choice();
    Created created = new Created();
    Choice issuedChoice = new Choice();
    Issued issued = new Issued();
    date.setString("1990");
    dateChoice.setDate(date);
    temporal.setString("1991");
    temporalChoice.setTemporal(temporal);
    created.setString("1992");
    createdChoice.setCreated(created);
    issued.setString("1993");
    issuedChoice.setIssued(issued);
    ArrayList<Choice> choices = new ArrayList<>();
    choices.add(dateChoice);
    choices.add(temporalChoice);
    choices.add(createdChoice);
    choices.add(issuedChoice);
    PROXY_PROVIDER.setChoiceList(choices);
    ArrayList<ProxyType> proxyList = new ArrayList<>();
    proxyList.add(PROXY_EUROPEANA);
    proxyList.add(PROXY_PROVIDER);
    TEST_RDF.setProxyList(proxyList);
    EnrichmentUtils.setAdditionalData(TEST_RDF);
    ProxyType proxyResult = TEST_RDF.getProxyList().stream().filter(x -> x.getEuropeanaProxy().isEuropeanaProxy()).collect(Collectors.toList()).get(0);
    assertEquals(4, proxyResult.getYearList().size());
    assertEquals("1990", proxyResult.getYearList().get(0).getString());
    assertEquals("1991", proxyResult.getYearList().get(1).getString());
    assertEquals("1992", proxyResult.getYearList().get(2).getString());
    assertEquals("1993", proxyResult.getYearList().get(3).getString());
}
Also used : Choice(eu.europeana.metis.schema.jibx.EuropeanaType.Choice) Temporal(eu.europeana.metis.schema.jibx.Temporal) Issued(eu.europeana.metis.schema.jibx.Issued) ArrayList(java.util.ArrayList) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) Date(eu.europeana.metis.schema.jibx.Date) Created(eu.europeana.metis.schema.jibx.Created) Test(org.junit.jupiter.api.Test)

Example 5 with Choice

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

the class EnrichmentUtilsTest method testSetAdditionalDataCompletenessMoreThanZero.

@Test
void testSetAdditionalDataCompletenessMoreThanZero() {
    Aggregation aggregation = spy(new Aggregation());
    Choice dateChoice = new Choice();
    Date date = new Date();
    Choice titleChoice = new Choice();
    Title title = new Title();
    date.setString("1990");
    dateChoice.setDate(date);
    title.setString("The Sudbury Neutrino Observatory: Observation of Flavor Change for Solar Neutrinos");
    titleChoice.setTitle(title);
    ArrayList<Choice> choices = new ArrayList<>();
    choices.add(dateChoice);
    choices.add(titleChoice);
    PROXY_PROVIDER.setChoiceList(choices);
    ArrayList<ProxyType> proxyList = new ArrayList<>();
    proxyList.add(PROXY_EUROPEANA);
    proxyList.add(PROXY_PROVIDER);
    TEST_RDF.setProxyList(proxyList);
    _Object object = new _Object();
    object.setResource("/260/_kmo_av_sid_45006");
    doReturn(object).when(aggregation).getObject();
    doReturn(Collections.singletonList(aggregation)).when(TEST_RDF).getAggregationList();
    EnrichmentUtils.setAdditionalData(TEST_RDF);
    EuropeanaAggregationType aggregationTypeResult = TEST_RDF.getEuropeanaAggregationList().get(0);
    assertTrue(Integer.parseInt(aggregationTypeResult.getCompleteness().getString()) > 0);
}
Also used : Aggregation(eu.europeana.metis.schema.jibx.Aggregation) Choice(eu.europeana.metis.schema.jibx.EuropeanaType.Choice) ArrayList(java.util.ArrayList) Title(eu.europeana.metis.schema.jibx.Title) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) eu.europeana.metis.schema.jibx._Object(eu.europeana.metis.schema.jibx._Object) EuropeanaAggregationType(eu.europeana.metis.schema.jibx.EuropeanaAggregationType) Date(eu.europeana.metis.schema.jibx.Date) Test(org.junit.jupiter.api.Test)

Aggregations

Choice (eu.europeana.metis.schema.jibx.EuropeanaType.Choice)14 Test (org.junit.jupiter.api.Test)10 ProxyType (eu.europeana.metis.schema.jibx.ProxyType)8 ArrayList (java.util.ArrayList)7 Resource (eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource)5 Temporal (eu.europeana.metis.schema.jibx.Temporal)5 Coverage (eu.europeana.metis.schema.jibx.Coverage)4 Created (eu.europeana.metis.schema.jibx.Created)4 Date (eu.europeana.metis.schema.jibx.Date)4 ResourceOrLiteralType (eu.europeana.metis.schema.jibx.ResourceOrLiteralType)4 HashSet (java.util.HashSet)4 Issued (eu.europeana.metis.schema.jibx.Issued)3 Spatial (eu.europeana.metis.schema.jibx.Spatial)3 Subject (eu.europeana.metis.schema.jibx.Subject)3 Type (eu.europeana.metis.schema.jibx.Type)3 ProxyFieldType (eu.europeana.enrichment.api.internal.ProxyFieldType)2 Contributor (eu.europeana.metis.schema.jibx.Contributor)2 Creator (eu.europeana.metis.schema.jibx.Creator)2 CurrentLocation (eu.europeana.metis.schema.jibx.CurrentLocation)2 EuropeanaAggregationType (eu.europeana.metis.schema.jibx.EuropeanaAggregationType)2