Created
February 9, 2018 21:26
-
-
Save bandrzejczak/b9412a7cd49c69f3991b77149f061efb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Map<String, List<String>> makeWordMap( | |
List<String> sentences) { | |
Map<String, List<String>> result = | |
new HashMap<String, List<String>>(); | |
for (String sentence: sentences) { | |
for (String word: words(sentence)) { | |
List<String> sentencesForWord = result.get(word); | |
if (sentencesForWord == null) { | |
sentencesForWord = new ArrayList<String>(); | |
result.put(word, sentencesForWord); | |
} | |
sentencesForWord.add(sentence); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment