Assignment 6 (work in progress).
[Scala.git] / Assignment_06 / src / main / scala / package.scala
diff --git a/Assignment_06/src/main/scala/package.scala b/Assignment_06/src/main/scala/package.scala
new file mode 100644 (file)
index 0000000..d0f1855
--- /dev/null
@@ -0,0 +1,29 @@
+import java.io.File\r
+\r
+/**\r
+ * Sentence anagrams generation\r
+ * MSE course, T-AdvPrPa course\r
+ */\r
+package object anagrams {\r
+\r
+       /**\r
+        * Loads a file dictionary which should be located in the src directory\r
+        */\r
+       def loadDictionary() = {\r
+               val wordstream = Option {\r
+                       getClass.getClassLoader.getResourceAsStream("resources/linuxwords.txt")\r
+               } getOrElse {\r
+                       sys.error("Could not load word list, dictionary file not found")\r
+               }\r
+               try {\r
+                       val s = io.Source.fromInputStream(wordstream)\r
+                       s.getLines.toList\r
+               } catch {\r
+                       case e: Exception ⇒\r
+                               println("Could not load word list: " + e)\r
+                               throw e\r
+               } finally {\r
+                       wordstream.close()\r
+               }\r
+       }\r
+}\r