Search in sources :

Example 1 with AboutType

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

the class MetisRecordParser method parseReferences.

@Override
public Set<ReferenceTermContext> parseReferences(RDF rdf) {
    // Get all direct references (also look in Europeana proxy as it may have been dereferenced - we
    // use this below to follow sameAs links).
    final List<ProxyType> proxies = Optional.ofNullable(rdf.getProxyList()).stream().flatMap(Collection::stream).filter(Objects::nonNull).collect(Collectors.toList());
    final Map<String, Set<ProxyFieldType>> directReferences = new HashMap<>();
    for (ProxyFieldType field : ProxyFieldType.values()) {
        final Set<String> directLinks = proxies.stream().map(field::extractFieldLinksForEnrichment).flatMap(Set::stream).collect(Collectors.toSet());
        for (String directLink : directLinks) {
            directReferences.computeIfAbsent(directLink, key -> new HashSet<>()).add(field);
        }
    }
    // Get all sameAs links from the directly referenced contextual entities.
    final Map<String, Set<ProxyFieldType>> indirectReferences = new HashMap<>();
    final Consumer<AboutType> contextualTypeProcessor = contextualClass -> {
        final Set<ProxyFieldType> linkTypes = Optional.ofNullable(directReferences.get(contextualClass.getAbout())).orElseGet(Collections::emptySet);
        if (!linkTypes.isEmpty()) {
            for (String sameAsLink : getSameAsLinks(contextualClass)) {
                indirectReferences.computeIfAbsent(sameAsLink, key -> new HashSet<>()).addAll(linkTypes);
            }
        }
    };
    Optional.ofNullable(rdf.getAgentList()).orElseGet(Collections::emptyList).forEach(contextualTypeProcessor);
    Optional.ofNullable(rdf.getConceptList()).orElseGet(Collections::emptyList).forEach(contextualTypeProcessor);
    Optional.ofNullable(rdf.getPlaceList()).orElseGet(Collections::emptyList).forEach(contextualTypeProcessor);
    Optional.ofNullable(rdf.getTimeSpanList()).orElseGet(Collections::emptyList).forEach(contextualTypeProcessor);
    // Merge the two maps.
    final Map<String, Set<ProxyFieldType>> resultMap = mergeMapInto(directReferences, indirectReferences);
    // Clean up the result: no null values. But objects we already have need to
    // stay: maybe they are matched using a sameAs link.
    resultMap.remove(null);
    // Convert and done
    final Set<ReferenceTermContext> result = new HashSet<>();
    for (Map.Entry<String, Set<ProxyFieldType>> entry : resultMap.entrySet()) {
        ReferenceTermContext value;
        try {
            value = new ReferenceTermContext(new URL(entry.getKey()), entry.getValue());
            result.add(value);
        } catch (MalformedURLException e) {
            LOGGER.debug("Invalid enrichment reference found: {}", entry.getKey());
        }
    }
    return result;
}
Also used : Concept(eu.europeana.metis.schema.jibx.Concept) URL(java.net.URL) AggregationFieldType(eu.europeana.enrichment.api.internal.AggregationFieldType) TimeSpanType(eu.europeana.metis.schema.jibx.TimeSpanType) LoggerFactory(org.slf4j.LoggerFactory) RecordParser(eu.europeana.enrichment.api.internal.RecordParser) HashMap(java.util.HashMap) RDF(eu.europeana.metis.schema.jibx.RDF) StringUtils(org.apache.commons.lang3.StringUtils) ProxyFieldType(eu.europeana.enrichment.api.internal.ProxyFieldType) ResourceType(eu.europeana.metis.schema.jibx.ResourceType) HashSet(java.util.HashSet) AboutType(eu.europeana.metis.schema.jibx.AboutType) RdfEntityUtils(eu.europeana.enrichment.utils.RdfEntityUtils) FieldType(eu.europeana.enrichment.api.internal.FieldType) SearchTermContext(eu.europeana.enrichment.api.internal.SearchTermContext) Map(java.util.Map) FieldValue(eu.europeana.enrichment.api.internal.FieldValue) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) PlaceType(eu.europeana.metis.schema.jibx.PlaceType) ReferenceTermContext(eu.europeana.enrichment.api.internal.ReferenceTermContext) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) AgentType(eu.europeana.metis.schema.jibx.AgentType) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) Optional(java.util.Optional) Collections(java.util.Collections) MalformedURLException(java.net.MalformedURLException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ReferenceTermContext(eu.europeana.enrichment.api.internal.ReferenceTermContext) URL(java.net.URL) ProxyFieldType(eu.europeana.enrichment.api.internal.ProxyFieldType) Collection(java.util.Collection) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) AboutType(eu.europeana.metis.schema.jibx.AboutType)

Example 2 with AboutType

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

the class ItemExtractorUtilsTest method testSetAbout.

@Test
void testSetAbout() {
    EnrichmentBase enrichmentBase = new Agent();
    AboutType aboutType = new AboutType();
    enrichmentBase.setAbout("About");
    ItemExtractorUtils.setAbout(enrichmentBase, aboutType);
    assertEquals("About", aboutType.getAbout());
}
Also used : Agent(eu.europeana.enrichment.api.external.model.Agent) EnrichmentBase(eu.europeana.enrichment.api.external.model.EnrichmentBase) AboutType(eu.europeana.metis.schema.jibx.AboutType) Test(org.junit.jupiter.api.Test)

Example 3 with AboutType

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

the class RdfEntityUtils method replaceValueWithLinkInAggregation.

/**
 * Replace matching aggregation values with their found corresponding links.
 *
 * @param rdf the rdf to update
 * @param link the about value to use
 * @param searchTermAggregation the aggregation search term to use for finding the matched values
 */
public static void replaceValueWithLinkInAggregation(RDF rdf, String link, SearchTermContext searchTermAggregation) {
    final List<Aggregation> aggregationList = rdf.getAggregationList();
    for (FieldType<? extends AboutType> aggregationFieldType : searchTermAggregation.getFieldTypes()) {
        aggregationList.stream().flatMap(((AggregationFieldType) aggregationFieldType)::extractFields).filter(resourceOrLiteralType -> resourceOrLiteralAndSearchTermEquality(resourceOrLiteralType, searchTermAggregation)).forEach(resourceOrLiteralType -> {
            final Resource resource = new Resource();
            resource.setResource(link);
            resourceOrLiteralType.setResource(resource);
            resourceOrLiteralType.setLang(new Lang());
            resourceOrLiteralType.setString("");
        });
    }
}
Also used : Aggregation(eu.europeana.metis.schema.jibx.Aggregation) Arrays(java.util.Arrays) AggregationFieldType(eu.europeana.enrichment.api.internal.AggregationFieldType) SearchTerm(eu.europeana.enrichment.api.internal.SearchTerm) RDF(eu.europeana.metis.schema.jibx.RDF) Supplier(java.util.function.Supplier) StringUtils(org.apache.commons.lang3.StringUtils) Aggregation(eu.europeana.metis.schema.jibx.Aggregation) ResourceOrLiteralType(eu.europeana.metis.schema.jibx.ResourceOrLiteralType) ArrayList(java.util.ArrayList) ProxyFieldType(eu.europeana.enrichment.api.internal.ProxyFieldType) AboutType(eu.europeana.metis.schema.jibx.AboutType) Lang(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Lang) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) FieldType(eu.europeana.enrichment.api.internal.FieldType) SearchTermContext(eu.europeana.enrichment.api.internal.SearchTermContext) Map(java.util.Map) EuropeanaType(eu.europeana.metis.schema.jibx.EuropeanaType) EnumMap(java.util.EnumMap) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) Optional(java.util.Optional) Collections(java.util.Collections) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) Lang(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Lang)

Example 4 with AboutType

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

the class EnablingElementTest method testChoiceElementWithCandidateGroups.

private <T extends ResourceOrLiteralType> void testChoiceElementWithCandidateGroups(EnablingElement element, Set<ContextualClassGroup> candidates, Supplier<T> constructor, BiConsumer<Choice, T> setter) {
    // Do the testing on the links.
    final BiConsumer<ProxyType, List<T>> objectSetter = (proxy, values) -> {
        proxy.setChoiceList(new ArrayList<>());
        Optional.ofNullable(values).stream().flatMap(Collection::stream).forEach(value -> {
            final Choice choice = new Choice();
            proxy.getChoiceList().add(choice);
            setter.accept(choice, value);
        });
    };
    final BiConsumer<T, String> linkSetter = (value, link) -> {
        value.setResource(new Resource());
        value.getResource().setResource(link);
    };
    testElementWithCandidateGroups(element, candidates, constructor, objectSetter, linkSetter);
    // Test literals: they do not create any match (but links still do, proving the setup is correct).
    final String link = "link";
    final Map<String, Set<Class<? extends AboutType>>> typeMap = Collections.singletonMap(link, getTypes(EnumSet.allOf(ContextualClassGroup.class)));
    final T value = constructor.get();
    value.setString(link);
    final ProxyType proxy = new ProxyType();
    objectSetter.accept(proxy, Collections.singletonList(value));
    assertTrue(element.analyze(Collections.singletonList(proxy), typeMap).isEmpty());
    linkSetter.accept(value, link);
    assertEquals(candidates, element.analyze(Collections.singletonList(proxy), typeMap));
}
Also used : Arrays(java.util.Arrays) Publisher(eu.europeana.metis.schema.jibx.Publisher) Temporal(eu.europeana.metis.schema.jibx.Temporal) HashMap(java.util.HashMap) Subject(eu.europeana.metis.schema.jibx.Subject) Supplier(java.util.function.Supplier) ResourceOrLiteralType(eu.europeana.metis.schema.jibx.ResourceOrLiteralType) ArrayList(java.util.ArrayList) HasMet(eu.europeana.metis.schema.jibx.HasMet) ResourceType(eu.europeana.metis.schema.jibx.ResourceType) HashSet(java.util.HashSet) AboutType(eu.europeana.metis.schema.jibx.AboutType) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Medium(eu.europeana.metis.schema.jibx.Medium) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CurrentLocation(eu.europeana.metis.schema.jibx.CurrentLocation) EnumSet(java.util.EnumSet) Created(eu.europeana.metis.schema.jibx.Created) Type(eu.europeana.metis.schema.jibx.Type) Creator(eu.europeana.metis.schema.jibx.Creator) Collection(java.util.Collection) Set(java.util.Set) Issued(eu.europeana.metis.schema.jibx.Issued) Choice(eu.europeana.metis.schema.jibx.EuropeanaType.Choice) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) Spatial(eu.europeana.metis.schema.jibx.Spatial) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Contributor(eu.europeana.metis.schema.jibx.Contributor) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) Format(eu.europeana.metis.schema.jibx.Format) Optional(java.util.Optional) Collections(java.util.Collections) Choice(eu.europeana.metis.schema.jibx.EuropeanaType.Choice) HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ProxyType(eu.europeana.metis.schema.jibx.ProxyType)

Aggregations

AboutType (eu.europeana.metis.schema.jibx.AboutType)4 ProxyType (eu.europeana.metis.schema.jibx.ProxyType)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 AggregationFieldType (eu.europeana.enrichment.api.internal.AggregationFieldType)2 FieldType (eu.europeana.enrichment.api.internal.FieldType)2 ProxyFieldType (eu.europeana.enrichment.api.internal.ProxyFieldType)2 SearchTermContext (eu.europeana.enrichment.api.internal.SearchTermContext)2 RDF (eu.europeana.metis.schema.jibx.RDF)2 ResourceOrLiteralType (eu.europeana.metis.schema.jibx.ResourceOrLiteralType)2 Resource (eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource)2 ResourceType (eu.europeana.metis.schema.jibx.ResourceType)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Supplier (java.util.function.Supplier)2