@Test void testComputeSimilarities() { assertEquals( 0.5, similarity.computeScore(Lists.newArrayList(idBeet), Lists.newArrayList(idCarrot)), 0.01); assertEquals( 1.0, similarity.computeScore(Lists.newArrayList(idBlueCarrot), Lists.newArrayList(idCarrot)), 0.01); assertEquals( 0.5, similarity.computeScore(Lists.newArrayList(idPumpkin), Lists.newArrayList(idCarrot)), 0.01); assertEquals( 0.0, similarity.computeScore(Lists.newArrayList(idLeafVegetable), Lists.newArrayList(idCarrot)), 0.01); }
@Override public double computeScore(Collection<TermId> query, Collection<TermId> target) { final Set<TermId> termIdsQuery = ontology.getAllAncestorTermIds(query, false); final Set<TermId> termIdsTarget = ontology.getAllAncestorTermIds(target, false); double overlap = Sets.intersection(termIdsQuery, termIdsTarget).size(); if (!normalized) { return overlap; } else { return overlap / Math.min(termIdsQuery.size(), termIdsTarget.size()); } }
TermOverlapSimilarity implements Similarity { @Override public double computeScore(Collection<TermId> query, Collection<TermId> target) { final Set<TermId> termIdsQuery = ontology.getAllAncestorTermIds(query, false); final Set<TermId> termIdsTarget = ontology.getAllAncestorTermIds(target, false); double overlap = Sets.intersection(termIdsQuery, termIdsTarget).size(); if (!normalized) { return overlap; } else { return overlap / Math.min(termIdsQuery.size(), termIdsTarget.size()); } } }
TermOverlapSimilarity implements Similarity { @Override public double computeScore(Collection<TermId> query, Collection<TermId> target) { final Set<TermId> termIdsQuery = ontology.getAllAncestorTermIds(query, false); final Set<TermId> termIdsTarget = ontology.getAllAncestorTermIds(target, false); double overlap = Sets.intersection(termIdsQuery, termIdsTarget).size(); if (!normalized) { return overlap; } else { return overlap / Math.min(termIdsQuery.size(), termIdsTarget.size()); } } TermOverlapSimilarity(Ontology ontology);  TermOverlapSimilarity(Ontology ontology, boolean normalized); }
TermOverlapSimilarity implements Similarity { @Override public double computeScore(Collection<TermId> query, Collection<TermId> target) { final Set<TermId> termIdsQuery = ontology.getAllAncestorTermIds(query, false); final Set<TermId> termIdsTarget = ontology.getAllAncestorTermIds(target, false); double overlap = Sets.intersection(termIdsQuery, termIdsTarget).size(); if (!normalized) { return overlap; } else { return overlap / Math.min(termIdsQuery.size(), termIdsTarget.size()); } } TermOverlapSimilarity(Ontology ontology);  TermOverlapSimilarity(Ontology ontology, boolean normalized); @Override String getName(); @Override String getParameters(); @Override boolean isSymmetric(); @Override double computeScore(Collection<TermId> query, Collection<TermId> target); }
TermOverlapSimilarity implements Similarity { @Override public double computeScore(Collection<TermId> query, Collection<TermId> target) { final Set<TermId> termIdsQuery = ontology.getAllAncestorTermIds(query, false); final Set<TermId> termIdsTarget = ontology.getAllAncestorTermIds(target, false); double overlap = Sets.intersection(termIdsQuery, termIdsTarget).size(); if (!normalized) { return overlap; } else { return overlap / Math.min(termIdsQuery.size(), termIdsTarget.size()); } } TermOverlapSimilarity(Ontology ontology);  TermOverlapSimilarity(Ontology ontology, boolean normalized); @Override String getName(); @Override String getParameters(); @Override boolean isSymmetric(); @Override double computeScore(Collection<TermId> query, Collection<TermId> target);  }