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));
}
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);
}
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"));
}
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());
}
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);
}
Aggregations