use of eu.europeana.metis.schema.jibx.AgentType 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());
}
use of eu.europeana.metis.schema.jibx.AgentType in project metis-framework by europeana.
the class RdfEntityUtilsTest method testRemoveMatchingEntities.
@Test
void testRemoveMatchingEntities() {
TEST_RDF.setProxyList(Collections.singletonList(PROXY_EUROPEANA));
String agentLink = "http://data.europeana.eu/agent/example1";
String conceptLink = "http://data.europeana.eu/concept/example1";
String placeLink = "http://data.europeana.eu/place/example1";
String timespanLink = "http://data.europeana.eu/timespan/example1";
RdfEntityUtils.appendLinkToEuropeanaProxy(TEST_RDF, agentLink, Sets.newHashSet(ProxyFieldType.DC_CREATOR));
RdfEntityUtils.appendLinkToEuropeanaProxy(TEST_RDF, conceptLink, Sets.newHashSet(ProxyFieldType.DC_SUBJECT));
RdfEntityUtils.appendLinkToEuropeanaProxy(TEST_RDF, placeLink, Sets.newHashSet(ProxyFieldType.DC_COVERAGE));
RdfEntityUtils.appendLinkToEuropeanaProxy(TEST_RDF, timespanLink, Sets.newHashSet(ProxyFieldType.DCTERMS_CREATED));
final AgentType agentType = new AgentType();
agentType.setAbout(agentLink);
TEST_RDF.setAgentList(new ArrayList<>(Collections.singleton(agentType)));
final Concept concept = new Concept();
concept.setAbout(conceptLink);
TEST_RDF.setConceptList(new ArrayList<>(Collections.singleton(concept)));
final PlaceType placeType = new PlaceType();
placeType.setAbout(placeLink);
TEST_RDF.setPlaceList(new ArrayList<>(Collections.singleton(placeType)));
final TimeSpanType timeSpanType = new TimeSpanType();
timeSpanType.setAbout(timespanLink);
TEST_RDF.setTimeSpanList(new ArrayList<>(Collections.singleton(timeSpanType)));
assertEquals(4, TEST_RDF.getProxyList().get(0).getChoiceList().size());
assertEquals(agentLink, TEST_RDF.getProxyList().get(0).getChoiceList().get(0).getCreator().getResource().getResource());
assertEquals(1, TEST_RDF.getAgentList().size());
assertEquals(conceptLink, TEST_RDF.getProxyList().get(0).getChoiceList().get(1).getSubject().getResource().getResource());
assertEquals(1, TEST_RDF.getConceptList().size());
assertEquals(placeLink, TEST_RDF.getProxyList().get(0).getChoiceList().get(2).getCoverage().getResource().getResource());
assertEquals(1, TEST_RDF.getPlaceList().size());
assertEquals(timespanLink, TEST_RDF.getProxyList().get(0).getChoiceList().get(3).getCreated().getResource().getResource());
assertEquals(1, TEST_RDF.getTimeSpanList().size());
// Find the correct links
final Set<String> links = new HashSet<>();
links.add(agentLink);
links.add(conceptLink);
links.add(placeLink);
links.add(timespanLink);
RdfEntityUtils.removeMatchingEntities(TEST_RDF, links);
assertEquals(0, TEST_RDF.getProxyList().get(0).getChoiceList().size());
assertEquals(0, TEST_RDF.getAgentList().size());
assertEquals(0, TEST_RDF.getConceptList().size());
assertEquals(0, TEST_RDF.getPlaceList().size());
assertEquals(0, TEST_RDF.getTimeSpanList().size());
}
use of eu.europeana.metis.schema.jibx.AgentType in project metis-framework by europeana.
the class EntityMergeEngine method convertAgent.
private static AgentType convertAgent(Agent agent) {
AgentType agentType = new AgentType();
// about
ItemExtractorUtils.setAbout(agent, agentType);
// altLabelList
agentType.setAltLabelList(ItemExtractorUtils.extractLabels(agent.getAltLabelList(), AltLabel::new));
// begin
agentType.setBegin(ItemExtractorUtils.extractFirstLabel(agent.getBeginList(), Begin::new));
// biographicalInformation
agentType.setBiographicalInformationList(ItemExtractorUtils.extractLabelResources(agent.getBiographicalInformation(), BiographicalInformation::new));
agentType.setProfessionOrOccupationList(ItemExtractorUtils.extractLabelResources(agent.getProfessionOrOccupation(), ProfessionOrOccupation::new));
// dateList
agentType.setDateList(ItemExtractorUtils.extractLabelResources(agent.getDate(), Date::new));
// placeOfBirth
agentType.setPlaceOfBirthList(ItemExtractorUtils.extractLabelResources(agent.getPlaceOfBirth(), PlaceOfBirth::new));
// placeOfDeath
agentType.setPlaceOfDeathList(ItemExtractorUtils.extractLabelResources(agent.getPlaceOfDeath(), PlaceOfDeath::new));
// dateOfBirth
agentType.setDateOfBirth(ItemExtractorUtils.extractFirstLabel(agent.getDateOfBirth(), DateOfBirth::new));
// dateofDeath
agentType.setDateOfDeath(ItemExtractorUtils.extractFirstLabel(agent.getDateOfDeath(), DateOfDeath::new));
// dateOfEstablishment
agentType.setDateOfEstablishment(ItemExtractorUtils.extractFirstLabel(agent.getDateOfEstablishment(), DateOfEstablishment::new));
// dateofTermination
agentType.setDateOfTermination(ItemExtractorUtils.extractFirstLabel(agent.getDateOfTermination(), DateOfTermination::new));
// end
agentType.setEnd(ItemExtractorUtils.extractFirstLabel(agent.getEndList(), End::new));
// gender
agentType.setGender(ItemExtractorUtils.extractFirstLabel(agent.getGender(), Gender::new));
// hasMetList
agentType.setHasMetList(ItemExtractorUtils.extractResources(agent.getHasMet(), HasMet::new));
// hasPartList: not available
// identifierList
agentType.setIdentifierList(ItemExtractorUtils.extractLabels(agent.getIdentifier(), Identifier::new));
// isPartOfList: not available
// isRelatedToList
agentType.setIsRelatedToList(ItemExtractorUtils.extractLabelResources(agent.getIsRelatedTo(), IsRelatedTo::new));
// nameList: not available
// noteList
agentType.setNoteList(ItemExtractorUtils.extractLabels(agent.getNotes(), Note::new));
// prefLabelList
agentType.setPrefLabelList(ItemExtractorUtils.extractLabels(agent.getPrefLabelList(), PrefLabel::new));
// professionOrOccupationList
agentType.setProfessionOrOccupationList(ItemExtractorUtils.extractLabelResources(agent.getProfessionOrOccupation(), ProfessionOrOccupation::new));
// sameAsList
agentType.setSameAList(ItemExtractorUtils.extractResources(agent.getSameAs(), SameAs::new));
return agentType;
}
use of eu.europeana.metis.schema.jibx.AgentType in project metis-framework by europeana.
the class DereferenceUtilsTest method testAgentListExtractedValues.
@Test
void testAgentListExtractedValues() {
RDF rdf = new RDF();
ProxyType proxy = new ProxyType();
ArrayList<ProxyType> proxyList = new ArrayList<>();
proxyList.add(proxy);
rdf.setProxyList(proxyList);
AgentType agent = new AgentType();
agent.setAbout("http://dummy1.dum");
HasMet hasMet = new HasMet();
hasMet.setResource("http://dummy2.dum");
ArrayList<HasMet> hasMetList = new ArrayList<>();
hasMetList.add(hasMet);
agent.setHasMetList(hasMetList);
IsRelatedTo isRelatedTo = new IsRelatedTo();
ResourceOrLiteralType.Resource resource3 = new ResourceOrLiteralType.Resource();
resource3.setResource("http://dummy3.dum");
isRelatedTo.setResource(resource3);
ArrayList<IsRelatedTo> isRelatedToList = new ArrayList<>();
isRelatedToList.add(isRelatedTo);
agent.setIsRelatedToList(isRelatedToList);
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);
agent.setIsPartOfList(isPartOfList);
ProfessionOrOccupation professionOrOccupation = new ProfessionOrOccupation();
ResourceOrLiteralType.Resource resource5 = new ResourceOrLiteralType.Resource();
resource5.setResource("http://dummy5.dum");
professionOrOccupation.setResource(resource5);
agent.setProfessionOrOccupationList(Collections.singletonList(professionOrOccupation));
Note note = new Note();
note.setString("Note");
ArrayList<Note> noteList = new ArrayList<>();
noteList.add(note);
agent.setNoteList(noteList);
ArrayList<AgentType> agentList = new ArrayList<>();
agentList.add(agent);
rdf.setAgentList(agentList);
Set<String> result = DereferenceUtils.extractReferencesForDereferencing(rdf);
assertNotNull(result);
assertEquals(2, result.size());
assertTrue(result.contains("http://dummy4.dum"));
assertTrue(result.contains("http://dummy5.dum"));
}
use of eu.europeana.metis.schema.jibx.AgentType in project metis-framework by europeana.
the class ContextualClassesBreakdownClassifierTest method testEntityQualifiesForAgent.
@Test
void testEntityQualifiesForAgent() {
// Create objects
final ContextualClassesClassifier classifier = spy(new ContextualClassesClassifier());
final AgentType agent = new AgentType();
final List<PrefLabel> prefLabelList = new ArrayList<>();
final Begin begin = new Begin();
final DateOfBirth dateOfBirth = new DateOfBirth();
final List<PlaceOfBirth> placeOfBirthList = new ArrayList<>();
final End end = new End();
final DateOfDeath dateOfDeath = new DateOfDeath();
final List<PlaceOfDeath> placeOfDeathList = new ArrayList<>();
final List<ProfessionOrOccupation> professionOrOccupationList = new ArrayList<>();
// Test empty agent
assertFalse(classifier.entityQualifies(agent));
// Set values
agent.setPrefLabelList(prefLabelList);
agent.setBegin(begin);
agent.setDateOfBirth(dateOfBirth);
agent.setPlaceOfBirthList(placeOfBirthList);
agent.setEnd(end);
agent.setDateOfDeath(dateOfDeath);
agent.setPlaceOfDeathList(placeOfDeathList);
agent.setProfessionOrOccupationList(professionOrOccupationList);
// Test prefLabel absent (and rest present)
doReturn(false).when(classifier).hasLiteralProperty(prefLabelList);
doReturn(true).when(classifier).hasProperty(begin);
doReturn(true).when(classifier).hasProperty(dateOfBirth);
doReturn(true).when(classifier).hasResourceOrLiteralProperty(placeOfBirthList);
doReturn(true).when(classifier).hasProperty(end);
doReturn(true).when(classifier).hasProperty(dateOfDeath);
doReturn(true).when(classifier).hasResourceOrLiteralProperty(placeOfDeathList);
doReturn(true).when(classifier).hasResourceOrLiteralProperty(professionOrOccupationList);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel present (and rest absent)
doReturn(true).when(classifier).hasLiteralProperty(prefLabelList);
doReturn(false).when(classifier).hasProperty(begin);
doReturn(false).when(classifier).hasProperty(dateOfBirth);
doReturn(false).when(classifier).hasResourceOrLiteralProperty(placeOfBirthList);
doReturn(false).when(classifier).hasProperty(end);
doReturn(false).when(classifier).hasProperty(dateOfDeath);
doReturn(false).when(classifier).hasResourceOrLiteralProperty(placeOfDeathList);
doReturn(false).when(classifier).hasResourceOrLiteralProperty(professionOrOccupationList);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and begin present
doReturn(true).when(classifier).hasProperty(begin);
assertTrue(classifier.entityQualifies(agent));
doReturn(false).when(classifier).hasProperty(begin);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and dateOfBirth present
doReturn(true).when(classifier).hasProperty(dateOfBirth);
assertTrue(classifier.entityQualifies(agent));
doReturn(false).when(classifier).hasProperty(dateOfBirth);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and placeOfBirth present
doReturn(true).when(classifier).hasResourceOrLiteralProperty(placeOfBirthList);
assertTrue(classifier.entityQualifies(agent));
doReturn(false).when(classifier).hasResourceOrLiteralProperty(placeOfBirthList);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and end present
doReturn(true).when(classifier).hasProperty(end);
assertTrue(classifier.entityQualifies(agent));
doReturn(false).when(classifier).hasProperty(end);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and dateOfDeath present
doReturn(true).when(classifier).hasProperty(dateOfDeath);
assertTrue(classifier.entityQualifies(agent));
doReturn(false).when(classifier).hasProperty(dateOfDeath);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and placeOfDeath present
doReturn(true).when(classifier).hasResourceOrLiteralProperty(placeOfDeathList);
assertTrue(classifier.entityQualifies(agent));
doReturn(false).when(classifier).hasResourceOrLiteralProperty(placeOfDeathList);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and professionOrOccupation present
doReturn(true).when(classifier).hasResourceOrLiteralProperty(professionOrOccupationList);
assertTrue(classifier.entityQualifies(agent));
}
Aggregations