@Test void createWordIDF() { String ontologyIri = "http: Ontology ontology = ontologyFactory.create(); ontology.setOntologyIri(ontologyIri); when(dataService.findOne( ONTOLOGY, new QueryImpl<>().eq(OntologyMetadata.ONTOLOGY_IRI, ontologyIri))) .thenReturn(ontology); when(dataService.count( ONTOLOGY_TERM, new QueryImpl<>().eq(OntologyTermMetadata.ONTOLOGY, ontology))) .thenReturn((long) 100); QueryRule queryRule = new QueryRule( singletonList( new QueryRule( OntologyTermMetadata.ONTOLOGY_TERM_SYNONYM, Operator.FUZZY_MATCH, "hear"))); queryRule.setOperator(Operator.DIS_MAX); QueryRule finalQuery = new QueryRule( asList( new QueryRule(OntologyTermMetadata.ONTOLOGY, Operator.EQUALS, ontology), new QueryRule(Operator.AND), queryRule)); when(dataService.count(ONTOLOGY_TERM, new QueryImpl<>(finalQuery))).thenReturn((long) 30); QueryRule queryRule2 = new QueryRule( singletonList( new QueryRule( OntologyTermMetadata.ONTOLOGY_TERM_SYNONYM, Operator.FUZZY_MATCH, "impair"))); queryRule2.setOperator(Operator.DIS_MAX); QueryRule finalQuery2 = new QueryRule( asList( new QueryRule(OntologyTermMetadata.ONTOLOGY, Operator.EQUALS, ontology), new QueryRule(Operator.AND), queryRule2)); when(dataService.count(ONTOLOGY_TERM, new QueryImpl<>(finalQuery2))).thenReturn((long) 10); Map<String, Double> expectedWordIDF = informationContentService.createWordIDF("hearing impairment", ontologyIri); assertEquals(2, expectedWordIDF.get("hear").intValue()); assertEquals(3, expectedWordIDF.get("impair").intValue()); }
Map<String, Double> createWordIDF(String queryString, String ontologyIri) { Map<String, Double> wordFreqMap = new HashMap<>(); Set<String> wordsInQueryString = createStemmedWordSet(queryString); wordsInQueryString.stream() .forEach( word -> { Double wordIDF = null; try { wordIDF = cachedInverseDocumentFreq.get(new OntologyWord(ontologyIri, word)); } catch (ExecutionException e) { throw new UncheckedExecutionException(e); } if (wordIDF != null && wordIDF != 0) { wordFreqMap.put(word, wordIDF); } }); return wordFreqMap; }
InformationContentService { Map<String, Double> createWordIDF(String queryString, String ontologyIri) { Map<String, Double> wordFreqMap = new HashMap<>(); Set<String> wordsInQueryString = createStemmedWordSet(queryString); wordsInQueryString.stream() .forEach( word -> { Double wordIDF = null; try { wordIDF = cachedInverseDocumentFreq.get(new OntologyWord(ontologyIri, word)); } catch (ExecutionException e) { throw new UncheckedExecutionException(e); } if (wordIDF != null && wordIDF != 0) { wordFreqMap.put(word, wordIDF); } }); return wordFreqMap; } }
InformationContentService { Map<String, Double> createWordIDF(String queryString, String ontologyIri) { Map<String, Double> wordFreqMap = new HashMap<>(); Set<String> wordsInQueryString = createStemmedWordSet(queryString); wordsInQueryString.stream() .forEach( word -> { Double wordIDF = null; try { wordIDF = cachedInverseDocumentFreq.get(new OntologyWord(ontologyIri, word)); } catch (ExecutionException e) { throw new UncheckedExecutionException(e); } if (wordIDF != null && wordIDF != 0) { wordFreqMap.put(word, wordIDF); } }); return wordFreqMap; } InformationContentService(DataService dataService); }
InformationContentService { Map<String, Double> createWordIDF(String queryString, String ontologyIri) { Map<String, Double> wordFreqMap = new HashMap<>(); Set<String> wordsInQueryString = createStemmedWordSet(queryString); wordsInQueryString.stream() .forEach( word -> { Double wordIDF = null; try { wordIDF = cachedInverseDocumentFreq.get(new OntologyWord(ontologyIri, word)); } catch (ExecutionException e) { throw new UncheckedExecutionException(e); } if (wordIDF != null && wordIDF != 0) { wordFreqMap.put(word, wordIDF); } }); return wordFreqMap; } InformationContentService(DataService dataService); Map<String, Double> redistributedNGramScore(String queryString, String ontologyIri); Set<String> createStemmedWordSet(String queryString); }
InformationContentService { Map<String, Double> createWordIDF(String queryString, String ontologyIri) { Map<String, Double> wordFreqMap = new HashMap<>(); Set<String> wordsInQueryString = createStemmedWordSet(queryString); wordsInQueryString.stream() .forEach( word -> { Double wordIDF = null; try { wordIDF = cachedInverseDocumentFreq.get(new OntologyWord(ontologyIri, word)); } catch (ExecutionException e) { throw new UncheckedExecutionException(e); } if (wordIDF != null && wordIDF != 0) { wordFreqMap.put(word, wordIDF); } }); return wordFreqMap; } InformationContentService(DataService dataService); Map<String, Double> redistributedNGramScore(String queryString, String ontologyIri); Set<String> createStemmedWordSet(String queryString);  }