private ScoredCandidates<Container> scoreContainers(
      Multiset<String> parents, int children, ResultDescription desc) {
    Builder<Container> candidates = DefaultScoredCandidates.fromSource(NAME);

    ResolvedContent containers = resolver.findByCanonicalUris(parents.elementSet());

    for (Multiset.Entry<String> parent : parents.entrySet()) {
      Maybe<Identified> possibledContainer = containers.get(parent.getElement());
      if (possibledContainer.hasValue()) {
        Identified identified = possibledContainer.requireValue();
        if (identified instanceof Container) {
          Container container = (Container) identified;
          Score score = score(parent.getCount(), children);
          candidates.addEquivalent(container, score);
          desc.appendText(
              "%s: scored %s (%s)", container.getCanonicalUri(), score, container.getTitle());
        } else {
          desc.appendText("%s: %s not container", parent, identified.getClass().getSimpleName());
        }
      } else {
        desc.appendText("%s: missing", parent);
      }
    }

    return candidates.build();
  }
Ejemplo n.º 2
0
  public ScoredCandidates<T> scoreCandidates(
      T content, Iterable<? extends T> candidates, ResultDescription desc) {
    Builder<T> equivalents = DefaultScoredCandidates.fromSource(name);
    desc.appendText("Scoring %s candidates", Iterables.size(candidates));

    for (T found : ImmutableSet.copyOf(candidates)) {
      equivalents.addEquivalent(found, score(content, found, desc));
    }

    return equivalents.build();
  }
  @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();
  }