Assignment 6 (work in progress).
[Scala.git] / Assignment_06 / src / main / scala / package.scala
1 import java.io.File
2
3 /**
4 * Sentence anagrams generation
5 * MSE course, T-AdvPrPa course
6 */
7 package object anagrams {
8
9 /**
10 * Loads a file dictionary which should be located in the src directory
11 */
12 def loadDictionary() = {
13 val wordstream = Option {
14 getClass.getClassLoader.getResourceAsStream("resources/linuxwords.txt")
15 } getOrElse {
16 sys.error("Could not load word list, dictionary file not found")
17 }
18 try {
19 val s = io.Source.fromInputStream(wordstream)
20 s.getLines.toList
21 } catch {
22 case e: Exception ⇒
23 println("Could not load word list: " + e)
24 throw e
25 } finally {
26 wordstream.close()
27 }
28 }
29 }