From c04ce2c7971f87369ce72dc504611137e1da583e Mon Sep 17 00:00:00 2001
From: "Verbeek, J.M. (Janneke)" <j.verbeek@student.ru.nl>
Date: Mon, 16 Dec 2019 12:23:59 +0100
Subject: [PATCH] Fixed bugs

---
 umbra/controller.py       |  1 +
 umbra/dutchwordnet_tst.py |  2 +-
 umbra/filereader.py       | 12 ++-------
 umbra/semantic_checker.py | 11 +++++---
 umbra/tests/context.py    | 21 ++++++++++++---
 umbra/tests/test_dwn.py   | 57 +++++++++++++++++++++++++++++++++++++++
 umbra/tests/test_view.py  | 24 +++++++++++++++++
 umbra/view.py             | 21 ++++-----------
 8 files changed, 114 insertions(+), 35 deletions(-)
 create mode 100644 umbra/tests/test_dwn.py

diff --git a/umbra/controller.py b/umbra/controller.py
index 9d957cd7..276bfcb3 100644
--- a/umbra/controller.py
+++ b/umbra/controller.py
@@ -1,6 +1,7 @@
 from filereader import CSVReader
 from filereader import CSVWriter
 from utils import Utils as ut
+import tkinter
 import os
 
 
diff --git a/umbra/dutchwordnet_tst.py b/umbra/dutchwordnet_tst.py
index 33f880d9..d55da48f 100644
--- a/umbra/dutchwordnet_tst.py
+++ b/umbra/dutchwordnet_tst.py
@@ -8,7 +8,7 @@ instance.load_synonyms_dicts()
 sc = SemanticChecker(instance)
 #A test case for when the second word is a hypernym of the first
 print(sc.semantically_related('hond','carnivoor'))
-#A test case for when the first word is a hypernym of the second
+#A test case for when willen we daarvoorthe first word is a hypernym of the second
 print(sc.semantically_related('carnivoor','hond'))
 #A test case for when both words are known yet not related.
 print(sc.semantically_related('water','hond'))
diff --git a/umbra/filereader.py b/umbra/filereader.py
index 31a534be..77b2b987 100644
--- a/umbra/filereader.py
+++ b/umbra/filereader.py
@@ -110,16 +110,7 @@ class FileWriter(ABC):
     @abstractmethod
     def write(self):
         pass
-
-    def write_per_part(self):
-        """
-        Write result per participant.
-        """
-        for pn, pr in self.data:
-            results, stats = _format_results(pn, pr)
-            self.path = _participant_path(pn)
-            self.write()
-
+        
     @abstractmethod
     def _participant_path(self, number):
         pass
@@ -178,6 +169,7 @@ class CSVWriter(FileWriter):
         info = "Total " + str(info[0]), "Shadowed " + str(info[1]), "Skipped"\
             " " + str(info[2])
         sc = []
+        print(path)
         for entry in source:
             sc.append([entry.word, entry.onset, entry.offset, entry.shadowed])
         with open(path+'.csv', 'w') as f:
diff --git a/umbra/semantic_checker.py b/umbra/semantic_checker.py
index e4b0c47a..0d39ce17 100644
--- a/umbra/semantic_checker.py
+++ b/umbra/semantic_checker.py
@@ -6,7 +6,7 @@ from utils import Utils as ut
 
 class SemanticChecker:
 
-    def __init__(self):
+    def __init__(self, parser=""):
         """
         Constructor
 
@@ -14,9 +14,12 @@ class SemanticChecker:
             parser: object of the Wn_grid_parser class
         """
         self._path = "OpenDutchWordnet/resources/odwn/odwn_orbn_gwg-LMF_1.3.xml.gz"
-        self._parser = Wn_grid_parser(ut.get_path(self._path))
-            # "./umbra/OpenDutchWordnet/resources/odwn/odwn_orbn_gwg-LMF_1.3.xml.gz") # Ubuntu path, temporary 'fix'
-        self._parser.load_synonyms_dicts()
+        if parser != "":
+            self._parser = parser
+        else:
+            self._parser = Wn_grid_parser(ut.get_path(self._path))
+                # "./umbra/OpenDutchWordnet/resources/odwn/odwn_orbn_gwg-LMF_1.3.xml.gz") # Ubuntu path, temporary 'fix'
+            self._parser.load_synonyms_dicts()
         self._lemma2synsets = getattr(self._parser,'lemma2synsets')
         self._reltypes = getattr(self._parser,'reltypes')
         self._syn_ids = getattr(self._parser,'syn_ids')
diff --git a/umbra/tests/context.py b/umbra/tests/context.py
index a0421618..0f971d8e 100644
--- a/umbra/tests/context.py
+++ b/umbra/tests/context.py
@@ -1,6 +1,19 @@
-import os
-import sys
+class XTest(pyfakefs.fake_filesystem_unittest.TestCase):
 
-sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../umbra')))
+    @classmethod
+    def setUpClass(cls):
+        print("setup class")
 
-from controller import Controller
+    def setUp(self):
+        self.setUpPyfakefs()
+        print("setup")
+
+    def tearDown(self):
+        print("teardown controller test")
+
+    @classmethod
+    def tearDownClass(cls):
+        print("teardown class")
+
+
+print("hello world");
diff --git a/umbra/tests/test_dwn.py b/umbra/tests/test_dwn.py
new file mode 100644
index 00000000..435f40bf
--- /dev/null
+++ b/umbra/tests/test_dwn.py
@@ -0,0 +1,57 @@
+from ..OpenDutchWordnet.wn_grid_parser import Wn_grid_parser
+from ..semantic_checker import SemanticChecker
+from ..utils import Utils as ut
+import unittest
+
+class DWNTest(unittest.TestCase):
+
+    @classmethod
+    def setUpClass(self):
+        instance = Wn_grid_parser("./OpenDutchWordnet/resources/odwn/" \
+            "odwn_orbn_gwg-LMF_1.3.xml.gz")
+        instance.load_synonyms_dicts()
+        self.sc = SemanticChecker(instance)
+        print("setup class dwn")
+
+    def setUp(self):
+        print("setup")
+
+    def test_hypernym(self):
+        self.assertTrue(self.sc.semantically_related('hond', 'carnivoor'))
+
+    def test_hyponym(self):
+        self.assertTrue(self.sc.semantically_related('carnivoor', 'hond'))
+
+    def test_known(self):
+        self.assertFalse(self.sc.semantically_related('water', 'hond'))
+
+    def test_synonym(self):
+        self.assertTrue(self.sc.semantically_related('huis', 'woning'))
+
+    def test_first_unknown(self):
+        self.assertFalse(self.sc.semantically_related('huis', 'foo'))
+
+    def test_shared_hypernym(self):
+        self.assertTrue(self.sc.semantically_related('vork', 'mes'))
+
+    def test_second_unknown(self):
+        self.assertFalse(self.sc.semantically_related('foo', 'carnivoor'))
+
+    def test_both_unknown(self):
+        self.assertFalse(self.sc.semantically_related('baz', 'foo'))
+
+    def test_article(self):
+        self.assertFalse(self.sc.semantically_related('de', 'het'))
+
+    def test_numeral(self):
+        self.assertFalse(self.sc.semantically_related('een', 'ander'))
+
+    def test_foreign(self):
+        self.assertFalse(self.sc.semantically_related('dog', 'pet'))
+
+    def tearDown(self):
+        print("teardown controller test")
+
+    @classmethod
+    def tearDownClass(cls):
+        print("teardown class")
diff --git a/umbra/tests/test_view.py b/umbra/tests/test_view.py
index e69de29b..c35339df 100644
--- a/umbra/tests/test_view.py
+++ b/umbra/tests/test_view.py
@@ -0,0 +1,24 @@
+import unittest
+import unittest.mock as mock
+from ..view import View
+import pyfakefs
+
+
+class ControllerTest(pyfakefs.fake_filesystem_unittest.TestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        print("setup class")
+
+    def setUp(self):
+        print("setup")
+
+    def test_button_creation(self):
+        assert 0 == 0
+
+    def tearDown(self):
+        print("teaeenrdown controller test")
+
+    @classmethod
+    def tearDownClass(cls):
+        print("teardown class")
diff --git a/umbra/view.py b/umbra/view.py
index 87c567a4..ee151624 100644
--- a/umbra/view.py
+++ b/umbra/view.py
@@ -17,7 +17,7 @@ class View:
         self._center_window()
 
         # Draw splash
-        self._splash = SplashView(self._window)
+        #self._splash = SplashView(self._window)
 
         # Create rest of GUI
         self._window.wm_title("Umbra")
@@ -52,18 +52,10 @@ class View:
 
         # Message
         self._create_label('message', self._frame, "", 5, 1)
-        self._spit = False
 
-        # Window Icon
-        self._window.iconbitmap("./resources/logo.ico")
-
-    @property
-    def spit(self):
-        return self._spit
 
-    @spit.setter
-    def spit(self, boolean):
-        self._spit = boolean
+        # Window Icon
+        #self._window.iconbitmap("./resources/logo.ico")
 
     def display(self):
         """Start main loop, displaying GUI elements."""
@@ -181,10 +173,7 @@ class View:
 
     def ask_save_location(self):
         """Ask user for location to save file."""
-        path = filedialog.asksaveasfilename(title="Save file",
-                                            parent=self._window,
-                                            filetypes=((".txt files", "*.txt"),
-                                                       ("all files", "*.*")))
+        path = filedialog.askdirectory()
         if path == "":
             self.update_message('not_saved')
         return path
@@ -382,7 +371,7 @@ class Options(View):
 
 
 class SplashView(tk.Toplevel):
-    """A splash screen while the rest of the application is loading. """
+    """A splash screen while the rresourcesest of the application is loading. """
 
     def __init__(self, parent):
         tk.Toplevel.__init__(self, parent)
-- 
GitLab