@Override public ScoredCandidates<Container> generate(Container content, ResultDescription desc) { OptionalMap<String, EquivalenceSummary> childSummaries = summaryStore.summariesForUris(Iterables.transform(content.getChildRefs(), ChildRef.TO_URI)); Multiset<String> parents = HashMultiset.create(); for (EquivalenceSummary summary : Optional.presentInstances(childSummaries.values())) { Iterables.addAll( parents, Iterables.filter( Iterables.transform(summary.getEquivalents().values(), TO_PARENT), Predicates.notNull())); } return scoreContainers(parents, childSummaries.size(), desc); }
@Override public ScoredCandidates<Item> generate(Item subject, ResultDescription desc) { Builder<Item> result = DefaultScoredCandidates.fromSource("Container"); ParentRef parent = subject.getContainer(); if (parent != null) { String parentUri = parent.getUri(); OptionalMap<String, EquivalenceSummary> containerSummary = parentSummary(parentUri); Optional<EquivalenceSummary> optional = containerSummary.get(parentUri); if (optional.isPresent()) { EquivalenceSummary summary = optional.get(); for (Item child : childrenOf(summary.getCandidates())) { result.addEquivalent(child, Score.NULL_SCORE); } } } return result.build(); }
private void stitch( Episode subjectEpisode, EquivalenceSummary equivalenceSummary, Multimap<Container, Episode> equivalentsChildren, ReadableDescription desc) { String subjectUri = subjectEpisode.getCanonicalUri(); desc.startStage(subjectUri); Map<Publisher, ContentRef> equivalents = equivalenceSummary.getEquivalents(); Set<ContentRef> additionalEquivs = Sets.newHashSet(); for (Entry<Container, Collection<Episode>> contentHierarchy : equivalentsChildren.asMap().entrySet()) { Container container = contentHierarchy.getKey(); for (Episode equivChild : contentHierarchy.getValue()) { if (matchingSequenceNumbers(subjectEpisode, equivChild)) { Publisher publisher = equivChild.getPublisher(); ContentRef existingEquiv = equivalents.get(publisher); if (existingEquiv != null) { desc.appendText( "existing strong equiv %s not overwritten by %s", existingEquiv, equivChild); } else { desc.appendText("adding %s (%s)", equivChild, container); additionalEquivs.add(ContentRef.valueOf(equivChild)); } break; } } } if (!additionalEquivs.isEmpty()) { additionalEquivs.addAll(equivalents.values()); lookupWriter.writeLookup(ContentRef.valueOf(subjectEpisode), additionalEquivs, publishers); } desc.finishStage(); }