I'm trying to write a scala function that generates n-grams from tweets.
The function will take two arguments, firstly a list of strings (the tweets we want to examine), and an integer n. If we set n to 2 (the default), then the result of the function will be a HashMultiset of 2-tuples, likewise if we set it to 3 then the result will be a HashMultiset of 3-tuples.
Is there any way to define such a function? I'd like to be explicit with my typing, so I'd prefer not to just define the function as returning a MultiSet of Any.
Here's the stub function I have so far, it only works for n==2:
def extract_ngrams(tweets:List[String], n:Int=2):HashMultiset[(String,String)] = {
val result = HashMultiset.create[(String,String)]()
result.add(("a", "a"))
result
}