From 2543398575125331f41874d6dab919f44570073f Mon Sep 17 00:00:00 2001 From: Jim Balhoff Date: Thu, 26 Mar 2020 13:27:51 -0400 Subject: [PATCH] Return 0 count for frequency query when term is not matched in SPARQL query. Fixes #191. --- src/main/scala/org/phenoscape/kb/Similarity.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/scala/org/phenoscape/kb/Similarity.scala b/src/main/scala/org/phenoscape/kb/Similarity.scala index e03b8272..4bc79b99 100644 --- a/src/main/scala/org/phenoscape/kb/Similarity.scala +++ b/src/main/scala/org/phenoscape/kb/Similarity.scala @@ -303,7 +303,11 @@ object Similarity { } App.executeSPARQLQueryString(query.text, qs => IRI.create(qs.getResource("term").getURI) -> - qs.getLiteral("count").getInt).map(_.toMap) + qs.getLiteral("count").getInt).map(_.toMap).map { result => + val foundTerms = result.keySet + // add in 0 counts for terms not returned by the query + result ++ (terms -- foundTerms).map(_ -> 0) + } } type TermFrequencyTable = Map[IRI, Int]