We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
GeoMap counting doesn't eliminate duplicates inside documents
With `Locations` attribute for NY Times sometimes you get a result: `Ljubljana (Slovenia), Slovenia, Europe (Slovenia),` which would count Slovenia 3 times instead of once. For a specific county a given document should not increment the count for more than one.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `orangecontrib/text/widgets/owgeomap.py`
Content:
```
1 # coding: utf-8
2 import os
3 import re
4 from collections import defaultdict, Counter
5 from itertools import chain
6 from urllib.parse import urljoin
7 from urllib.request import pathname2url
8 
9 import numpy as np
10 from AnyQt.QtCore import Qt, QTimer, pyqtSlot, QUrl
11 from AnyQt.QtWidgets import QApplication, QSizePolicy
12 
13 from Orange.data import Table
14 from Orange.widgets import widget, gui, settings
15 from Orange.widgets.utils.itemmodels import VariableListModel
16 from orangecontrib.text.corpus import Corpus
17 from orangecontrib.text.country_codes import \
18     CC_EUROPE, INV_CC_EUROPE, SET_CC_EUROPE, \
19     CC_WORLD, INV_CC_WORLD, \
20     CC_USA, INV_CC_USA, SET_CC_USA
21 
22 CC_NAMES = re.compile('[\w\s\.\-]+')
23 
24 
25 class Map:
26     WORLD = 'world_mill_en'
27     EUROPE = 'europe_mill_en'
28     USA = 'us_aea_en'
29     all = (('World',  WORLD),
30            ('Europe', EUROPE),
31            ('USA',    USA))
32 
33 
34 class OWGeoMap(widget.OWWidget):
35     name = "GeoMap"
36     priority = 20000
37     icon = "icons/GeoMap.svg"
38     inputs = [("Data", Table, "on_data")]
39     outputs = [('Corpus', Corpus)]
40 
41     want_main_area = False
42 
43     selected_attr = settings.Setting('')
44     selected_map = settings.Setting(0)
45     regions = settings.Setting([])
46 
47     def __init__(self):
48         super().__init__()
49         self.data = None
50         self._create_layout()
51 
52     @pyqtSlot(str)
53     def region_selected(self, regions):
54         """Called from JavaScript"""
55         if not regions:
56             self.regions = []
57         if not regions or self.data is None:
58             return self.send('Corpus', None)
59         self.regions = regions.split(',')
60         attr = self.data.domain[self.selected_attr]
61         if attr.is_discrete: return  # TODO, FIXME: make this work for discrete attrs also
62         from Orange.data.filter import FilterRegex
63         filter = FilterRegex(attr, r'\b{}\b'.format(r'\b|\b'.join(self.regions)), re.IGNORECASE)
64         self.send('Corpus', self.data._filter_values(filter))
65 
66     def _create_layout(self):
67         box = gui.widgetBox(self.controlArea,
68                             orientation='horizontal')
69         self.varmodel = VariableListModel(parent=self)
70         self.attr_combo = gui.comboBox(box, self, 'selected_attr',
71                                        orientation=Qt.Horizontal,
72                                        label='Region attribute:',
73                                        callback=self.on_attr_change,
74                                        sendSelectedValue=True)
75         self.attr_combo.setModel(self.varmodel)
76         self.map_combo = gui.comboBox(box, self, 'selected_map',
77                                       orientation=Qt.Horizontal,
78                                       label='Map type:',
79                                       callback=self.on_map_change,
80                                       items=Map.all)
81         hexpand = QSizePolicy(QSizePolicy.Expanding,
82                               QSizePolicy.Fixed)
83         self.attr_combo.setSizePolicy(hexpand)
84         self.map_combo.setSizePolicy(hexpand)
85 
86         url = urljoin('file:',
87                       pathname2url(os.path.join(
88                           os.path.dirname(__file__),
89                           'resources',
90                          'owgeomap.html')))
91         self.webview = gui.WebviewWidget(self.controlArea, self, url=QUrl(url))
92         self.controlArea.layout().addWidget(self.webview)
93 
94         QTimer.singleShot(
95             0, lambda: self.webview.evalJS('REGIONS = {};'.format({Map.WORLD: CC_WORLD,
96                                                                    Map.EUROPE: CC_EUROPE,
97                                                                    Map.USA: CC_USA})))
98 
99     def _repopulate_attr_combo(self, data):
100         vars = [a for a in chain(data.domain.metas,
101                                  data.domain.attributes,
102                                  data.domain.class_vars)
103                 if a.is_string] if data else []
104         self.varmodel.wrap(vars)
105         # Select default attribute
106         self.selected_attr = next((var.name
107                                    for var in vars
108                                    if var.name.lower().startswith(('country', 'location', 'region'))),
109                                   vars[0].name if vars else '')
110 
111     def on_data(self, data):
112         if data and not isinstance(data, Corpus):
113             data = Corpus.from_table(data.domain, data)
114         self.data = data
115         self._repopulate_attr_combo(data)
116         if not data:
117             self.region_selected('')
118             QTimer.singleShot(0, lambda: self.webview.evalJS('DATA = {}; renderMap();'))
119         else:
120             QTimer.singleShot(0, self.on_attr_change)
121 
122     def on_map_change(self, map_code=''):
123         if map_code:
124             self.map_combo.setCurrentIndex(self.map_combo.findData(map_code))
125         else:
126             map_code = self.map_combo.itemData(self.selected_map)
127 
128         inv_cc_map, cc_map = {Map.USA: (INV_CC_USA, CC_USA),
129                               Map.WORLD: (INV_CC_WORLD, CC_WORLD),
130                               Map.EUROPE: (INV_CC_EUROPE, CC_EUROPE)} [map_code]
131         # Set country counts in JS
132         data = defaultdict(int)
133         for cc in getattr(self, 'cc_counts', ()):
134             key = inv_cc_map.get(cc, cc)
135             if key in cc_map:
136                 data[key] += self.cc_counts[cc]
137         # Draw the new map
138         self.webview.evalJS('DATA = {};'
139                             'MAP_CODE = "{}";'
140                             'SELECTED_REGIONS = {};'
141                             'renderMap();'.format(dict(data),
142                                                   map_code,
143                                                   self.regions))
144 
145     def on_attr_change(self):
146         if not self.selected_attr:
147             return
148         attr = self.data.domain[self.selected_attr]
149         self.cc_counts = Counter(chain.from_iterable(
150             set(name.strip() for name in CC_NAMES.findall(i.lower())) if len(i) > 3 else (i,)
151             for i in self.data.get_column_view(self.data.domain.index(attr))[0]))
152         # Auto-select region map
153         values = set(self.cc_counts)
154         if 0 == len(values - SET_CC_USA):
155             map_code = Map.USA
156         elif 0 == len(values - SET_CC_EUROPE):
157             map_code = Map.EUROPE
158         else:
159             map_code = Map.WORLD
160         self.on_map_change(map_code)
161 
162 
163 def main():
164     from Orange.data import Table, Domain, StringVariable
165 
166     words = np.column_stack([
167         'Slovenia Slovenia SVN USA Iraq Iraq Iraq Iraq France FR'.split(),
168         'Slovenia Slovenia SVN France FR Austria NL GB GB GB'.split(),
169         'Alabama AL Texas TX TX TX MS Montana US-MT MT'.split(),
170     ])
171     metas = [
172         StringVariable('World'),
173         StringVariable('Europe'),
174         StringVariable('USA'),
175     ]
176     domain = Domain([], metas=metas)
177     table = Table.from_numpy(domain,
178                              X=np.zeros((len(words), 0)),
179                              metas=words)
180     app = QApplication([''])
181     w = OWGeoMap()
182     w.on_data(table)
183     w.show()
184     app.exec()
185 
186 
187 if __name__ == "__main__":
188     main()
189
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/orangecontrib/text/widgets/owgeomap.py b/orangecontrib/text/widgets/owgeomap.py
--- a/orangecontrib/text/widgets/owgeomap.py
+++ b/orangecontrib/text/widgets/owgeomap.py
@@ -127,13 +127,14 @@
 
         inv_cc_map, cc_map = {Map.USA: (INV_CC_USA, CC_USA),
                               Map.WORLD: (INV_CC_WORLD, CC_WORLD),
-                              Map.EUROPE: (INV_CC_EUROPE, CC_EUROPE)} [map_code]
-        # Set country counts in JS
+                              Map.EUROPE: (INV_CC_EUROPE, CC_EUROPE)}[map_code]
+        # Set country counts for JS
         data = defaultdict(int)
-        for cc in getattr(self, 'cc_counts', ()):
-            key = inv_cc_map.get(cc, cc)
-            if key in cc_map:
-                data[key] += self.cc_counts[cc]
+        for locations in self._iter_locations():
+            keys = set(inv_cc_map.get(loc, loc) for loc in locations)
+            for key in keys:
+                if key in cc_map:
+                    data[key] += 1
         # Draw the new map
         self.webview.evalJS('DATA = {};'
                             'MAP_CODE = "{}";'
@@ -145,12 +146,8 @@
     def on_attr_change(self):
         if not self.selected_attr:
             return
-        attr = self.data.domain[self.selected_attr]
-        self.cc_counts = Counter(chain.from_iterable(
-            set(name.strip() for name in CC_NAMES.findall(i.lower())) if len(i) > 3 else (i,)
-            for i in self.data.get_column_view(self.data.domain.index(attr))[0]))
+        values = set(chain.from_iterable(self._iter_locations()))
         # Auto-select region map
-        values = set(self.cc_counts)
         if 0 == len(values - SET_CC_USA):
             map_code = Map.USA
         elif 0 == len(values - SET_CC_EUROPE):
@@ -159,6 +156,16 @@
             map_code = Map.WORLD
         self.on_map_change(map_code)
 
+    def _iter_locations(self):
+        """ Iterator that yields an iterable per documents with all its's
+        locations. """
+        attr = self.data.domain[self.selected_attr]
+        for i in self.data.get_column_view(self.data.domain.index(attr))[0]:
+            if len(i) > 3:
+                yield map(lambda x: x.strip(), CC_NAMES.findall(i.lower()))
+            else:
+                yield (i, )
+
 
 def main():
     from Orange.data import Table, Domain, StringVariable

{"golden_diff": "diff --git a/orangecontrib/text/widgets/owgeomap.py b/orangecontrib/text/widgets/owgeomap.py\n--- a/orangecontrib/text/widgets/owgeomap.py\n+++ b/orangecontrib/text/widgets/owgeomap.py\n@@ -127,13 +127,14 @@\n \n         inv_cc_map, cc_map = {Map.USA: (INV_CC_USA, CC_USA),\n                               Map.WORLD: (INV_CC_WORLD, CC_WORLD),\n-                              Map.EUROPE: (INV_CC_EUROPE, CC_EUROPE)} [map_code]\n-        # Set country counts in JS\n+                              Map.EUROPE: (INV_CC_EUROPE, CC_EUROPE)}[map_code]\n+        # Set country counts for JS\n         data = defaultdict(int)\n-        for cc in getattr(self, 'cc_counts', ()):\n-            key = inv_cc_map.get(cc, cc)\n-            if key in cc_map:\n-                data[key] += self.cc_counts[cc]\n+        for locations in self._iter_locations():\n+            keys = set(inv_cc_map.get(loc, loc) for loc in locations)\n+            for key in keys:\n+                if key in cc_map:\n+                    data[key] += 1\n         # Draw the new map\n         self.webview.evalJS('DATA = {};'\n                             'MAP_CODE = \"{}\";'\n@@ -145,12 +146,8 @@\n     def on_attr_change(self):\n         if not self.selected_attr:\n             return\n-        attr = self.data.domain[self.selected_attr]\n-        self.cc_counts = Counter(chain.from_iterable(\n-            set(name.strip() for name in CC_NAMES.findall(i.lower())) if len(i) > 3 else (i,)\n-            for i in self.data.get_column_view(self.data.domain.index(attr))[0]))\n+        values = set(chain.from_iterable(self._iter_locations()))\n         # Auto-select region map\n-        values = set(self.cc_counts)\n         if 0 == len(values - SET_CC_USA):\n             map_code = Map.USA\n         elif 0 == len(values - SET_CC_EUROPE):\n@@ -159,6 +156,16 @@\n             map_code = Map.WORLD\n         self.on_map_change(map_code)\n \n+    def _iter_locations(self):\n+        \"\"\" Iterator that yields an iterable per documents with all its's\n+        locations. \"\"\"\n+        attr = self.data.domain[self.selected_attr]\n+        for i in self.data.get_column_view(self.data.domain.index(attr))[0]:\n+            if len(i) > 3:\n+                yield map(lambda x: x.strip(), CC_NAMES.findall(i.lower()))\n+            else:\n+                yield (i, )\n+\n \n def main():\n     from Orange.data import Table, Domain, StringVariable\n", "issue": "GeoMap counting doesn't eliminate duplicates inside documents\nWith `Locations` attribute for NY Times sometimes you get a result: `Ljubljana (Slovenia), Slovenia, Europe (Slovenia),` which would count Slovenia 3 times instead of once. For a specific county a given document should not increment the count for more than one.\n", "before_files": [{"content": "# coding: utf-8\nimport os\nimport re\nfrom collections import defaultdict, Counter\nfrom itertools import chain\nfrom urllib.parse import urljoin\nfrom urllib.request import pathname2url\n\nimport numpy as np\nfrom AnyQt.QtCore import Qt, QTimer, pyqtSlot, QUrl\nfrom AnyQt.QtWidgets import QApplication, QSizePolicy\n\nfrom Orange.data import Table\nfrom Orange.widgets import widget, gui, settings\nfrom Orange.widgets.utils.itemmodels import VariableListModel\nfrom orangecontrib.text.corpus import Corpus\nfrom orangecontrib.text.country_codes import \\\n    CC_EUROPE, INV_CC_EUROPE, SET_CC_EUROPE, \\\n    CC_WORLD, INV_CC_WORLD, \\\n    CC_USA, INV_CC_USA, SET_CC_USA\n\nCC_NAMES = re.compile('[\\w\\s\\.\\-]+')\n\n\nclass Map:\n    WORLD = 'world_mill_en'\n    EUROPE = 'europe_mill_en'\n    USA = 'us_aea_en'\n    all = (('World',  WORLD),\n           ('Europe', EUROPE),\n           ('USA',    USA))\n\n\nclass OWGeoMap(widget.OWWidget):\n    name = \"GeoMap\"\n    priority = 20000\n    icon = \"icons/GeoMap.svg\"\n    inputs = [(\"Data\", Table, \"on_data\")]\n    outputs = [('Corpus', Corpus)]\n\n    want_main_area = False\n\n    selected_attr = settings.Setting('')\n    selected_map = settings.Setting(0)\n    regions = settings.Setting([])\n\n    def __init__(self):\n        super().__init__()\n        self.data = None\n        self._create_layout()\n\n    @pyqtSlot(str)\n    def region_selected(self, regions):\n        \"\"\"Called from JavaScript\"\"\"\n        if not regions:\n            self.regions = []\n        if not regions or self.data is None:\n            return self.send('Corpus', None)\n        self.regions = regions.split(',')\n        attr = self.data.domain[self.selected_attr]\n        if attr.is_discrete: return  # TODO, FIXME: make this work for discrete attrs also\n        from Orange.data.filter import FilterRegex\n        filter = FilterRegex(attr, r'\\b{}\\b'.format(r'\\b|\\b'.join(self.regions)), re.IGNORECASE)\n        self.send('Corpus', self.data._filter_values(filter))\n\n    def _create_layout(self):\n        box = gui.widgetBox(self.controlArea,\n                            orientation='horizontal')\n        self.varmodel = VariableListModel(parent=self)\n        self.attr_combo = gui.comboBox(box, self, 'selected_attr',\n                                       orientation=Qt.Horizontal,\n                                       label='Region attribute:',\n                                       callback=self.on_attr_change,\n                                       sendSelectedValue=True)\n        self.attr_combo.setModel(self.varmodel)\n        self.map_combo = gui.comboBox(box, self, 'selected_map',\n                                      orientation=Qt.Horizontal,\n                                      label='Map type:',\n                                      callback=self.on_map_change,\n                                      items=Map.all)\n        hexpand = QSizePolicy(QSizePolicy.Expanding,\n                              QSizePolicy.Fixed)\n        self.attr_combo.setSizePolicy(hexpand)\n        self.map_combo.setSizePolicy(hexpand)\n\n        url = urljoin('file:',\n                      pathname2url(os.path.join(\n                          os.path.dirname(__file__),\n                          'resources',\n                         'owgeomap.html')))\n        self.webview = gui.WebviewWidget(self.controlArea, self, url=QUrl(url))\n        self.controlArea.layout().addWidget(self.webview)\n\n        QTimer.singleShot(\n            0, lambda: self.webview.evalJS('REGIONS = {};'.format({Map.WORLD: CC_WORLD,\n                                                                   Map.EUROPE: CC_EUROPE,\n                                                                   Map.USA: CC_USA})))\n\n    def _repopulate_attr_combo(self, data):\n        vars = [a for a in chain(data.domain.metas,\n                                 data.domain.attributes,\n                                 data.domain.class_vars)\n                if a.is_string] if data else []\n        self.varmodel.wrap(vars)\n        # Select default attribute\n        self.selected_attr = next((var.name\n                                   for var in vars\n                                   if var.name.lower().startswith(('country', 'location', 'region'))),\n                                  vars[0].name if vars else '')\n\n    def on_data(self, data):\n        if data and not isinstance(data, Corpus):\n            data = Corpus.from_table(data.domain, data)\n        self.data = data\n        self._repopulate_attr_combo(data)\n        if not data:\n            self.region_selected('')\n            QTimer.singleShot(0, lambda: self.webview.evalJS('DATA = {}; renderMap();'))\n        else:\n            QTimer.singleShot(0, self.on_attr_change)\n\n    def on_map_change(self, map_code=''):\n        if map_code:\n            self.map_combo.setCurrentIndex(self.map_combo.findData(map_code))\n        else:\n            map_code = self.map_combo.itemData(self.selected_map)\n\n        inv_cc_map, cc_map = {Map.USA: (INV_CC_USA, CC_USA),\n                              Map.WORLD: (INV_CC_WORLD, CC_WORLD),\n                              Map.EUROPE: (INV_CC_EUROPE, CC_EUROPE)} [map_code]\n        # Set country counts in JS\n        data = defaultdict(int)\n        for cc in getattr(self, 'cc_counts', ()):\n            key = inv_cc_map.get(cc, cc)\n            if key in cc_map:\n                data[key] += self.cc_counts[cc]\n        # Draw the new map\n        self.webview.evalJS('DATA = {};'\n                            'MAP_CODE = \"{}\";'\n                            'SELECTED_REGIONS = {};'\n                            'renderMap();'.format(dict(data),\n                                                  map_code,\n                                                  self.regions))\n\n    def on_attr_change(self):\n        if not self.selected_attr:\n            return\n        attr = self.data.domain[self.selected_attr]\n        self.cc_counts = Counter(chain.from_iterable(\n            set(name.strip() for name in CC_NAMES.findall(i.lower())) if len(i) > 3 else (i,)\n            for i in self.data.get_column_view(self.data.domain.index(attr))[0]))\n        # Auto-select region map\n        values = set(self.cc_counts)\n        if 0 == len(values - SET_CC_USA):\n            map_code = Map.USA\n        elif 0 == len(values - SET_CC_EUROPE):\n            map_code = Map.EUROPE\n        else:\n            map_code = Map.WORLD\n        self.on_map_change(map_code)\n\n\ndef main():\n    from Orange.data import Table, Domain, StringVariable\n\n    words = np.column_stack([\n        'Slovenia Slovenia SVN USA Iraq Iraq Iraq Iraq France FR'.split(),\n        'Slovenia Slovenia SVN France FR Austria NL GB GB GB'.split(),\n        'Alabama AL Texas TX TX TX MS Montana US-MT MT'.split(),\n    ])\n    metas = [\n        StringVariable('World'),\n        StringVariable('Europe'),\n        StringVariable('USA'),\n    ]\n    domain = Domain([], metas=metas)\n    table = Table.from_numpy(domain,\n                             X=np.zeros((len(words), 0)),\n                             metas=words)\n    app = QApplication([''])\n    w = OWGeoMap()\n    w.on_data(table)\n    w.show()\n    app.exec()\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "orangecontrib/text/widgets/owgeomap.py"}], "after_files": [{"content": "# coding: utf-8\nimport os\nimport re\nfrom collections import defaultdict, Counter\nfrom itertools import chain\nfrom urllib.parse import urljoin\nfrom urllib.request import pathname2url\n\nimport numpy as np\nfrom AnyQt.QtCore import Qt, QTimer, pyqtSlot, QUrl\nfrom AnyQt.QtWidgets import QApplication, QSizePolicy\n\nfrom Orange.data import Table\nfrom Orange.widgets import widget, gui, settings\nfrom Orange.widgets.utils.itemmodels import VariableListModel\nfrom orangecontrib.text.corpus import Corpus\nfrom orangecontrib.text.country_codes import \\\n    CC_EUROPE, INV_CC_EUROPE, SET_CC_EUROPE, \\\n    CC_WORLD, INV_CC_WORLD, \\\n    CC_USA, INV_CC_USA, SET_CC_USA\n\nCC_NAMES = re.compile('[\\w\\s\\.\\-]+')\n\n\nclass Map:\n    WORLD = 'world_mill_en'\n    EUROPE = 'europe_mill_en'\n    USA = 'us_aea_en'\n    all = (('World',  WORLD),\n           ('Europe', EUROPE),\n           ('USA',    USA))\n\n\nclass OWGeoMap(widget.OWWidget):\n    name = \"GeoMap\"\n    priority = 20000\n    icon = \"icons/GeoMap.svg\"\n    inputs = [(\"Data\", Table, \"on_data\")]\n    outputs = [('Corpus', Corpus)]\n\n    want_main_area = False\n\n    selected_attr = settings.Setting('')\n    selected_map = settings.Setting(0)\n    regions = settings.Setting([])\n\n    def __init__(self):\n        super().__init__()\n        self.data = None\n        self._create_layout()\n\n    @pyqtSlot(str)\n    def region_selected(self, regions):\n        \"\"\"Called from JavaScript\"\"\"\n        if not regions:\n            self.regions = []\n        if not regions or self.data is None:\n            return self.send('Corpus', None)\n        self.regions = regions.split(',')\n        attr = self.data.domain[self.selected_attr]\n        if attr.is_discrete: return  # TODO, FIXME: make this work for discrete attrs also\n        from Orange.data.filter import FilterRegex\n        filter = FilterRegex(attr, r'\\b{}\\b'.format(r'\\b|\\b'.join(self.regions)), re.IGNORECASE)\n        self.send('Corpus', self.data._filter_values(filter))\n\n    def _create_layout(self):\n        box = gui.widgetBox(self.controlArea,\n                            orientation='horizontal')\n        self.varmodel = VariableListModel(parent=self)\n        self.attr_combo = gui.comboBox(box, self, 'selected_attr',\n                                       orientation=Qt.Horizontal,\n                                       label='Region attribute:',\n                                       callback=self.on_attr_change,\n                                       sendSelectedValue=True)\n        self.attr_combo.setModel(self.varmodel)\n        self.map_combo = gui.comboBox(box, self, 'selected_map',\n                                      orientation=Qt.Horizontal,\n                                      label='Map type:',\n                                      callback=self.on_map_change,\n                                      items=Map.all)\n        hexpand = QSizePolicy(QSizePolicy.Expanding,\n                              QSizePolicy.Fixed)\n        self.attr_combo.setSizePolicy(hexpand)\n        self.map_combo.setSizePolicy(hexpand)\n\n        url = urljoin('file:',\n                      pathname2url(os.path.join(\n                          os.path.dirname(__file__),\n                          'resources',\n                         'owgeomap.html')))\n        self.webview = gui.WebviewWidget(self.controlArea, self, url=QUrl(url))\n        self.controlArea.layout().addWidget(self.webview)\n\n        QTimer.singleShot(\n            0, lambda: self.webview.evalJS('REGIONS = {};'.format({Map.WORLD: CC_WORLD,\n                                                                   Map.EUROPE: CC_EUROPE,\n                                                                   Map.USA: CC_USA})))\n\n    def _repopulate_attr_combo(self, data):\n        vars = [a for a in chain(data.domain.metas,\n                                 data.domain.attributes,\n                                 data.domain.class_vars)\n                if a.is_string] if data else []\n        self.varmodel.wrap(vars)\n        # Select default attribute\n        self.selected_attr = next((var.name\n                                   for var in vars\n                                   if var.name.lower().startswith(('country', 'location', 'region'))),\n                                  vars[0].name if vars else '')\n\n    def on_data(self, data):\n        if data and not isinstance(data, Corpus):\n            data = Corpus.from_table(data.domain, data)\n        self.data = data\n        self._repopulate_attr_combo(data)\n        if not data:\n            self.region_selected('')\n            QTimer.singleShot(0, lambda: self.webview.evalJS('DATA = {}; renderMap();'))\n        else:\n            QTimer.singleShot(0, self.on_attr_change)\n\n    def on_map_change(self, map_code=''):\n        if map_code:\n            self.map_combo.setCurrentIndex(self.map_combo.findData(map_code))\n        else:\n            map_code = self.map_combo.itemData(self.selected_map)\n\n        inv_cc_map, cc_map = {Map.USA: (INV_CC_USA, CC_USA),\n                              Map.WORLD: (INV_CC_WORLD, CC_WORLD),\n                              Map.EUROPE: (INV_CC_EUROPE, CC_EUROPE)}[map_code]\n        # Set country counts for JS\n        data = defaultdict(int)\n        for locations in self._iter_locations():\n            keys = set(inv_cc_map.get(loc, loc) for loc in locations)\n            for key in keys:\n                if key in cc_map:\n                    data[key] += 1\n        # Draw the new map\n        self.webview.evalJS('DATA = {};'\n                            'MAP_CODE = \"{}\";'\n                            'SELECTED_REGIONS = {};'\n                            'renderMap();'.format(dict(data),\n                                                  map_code,\n                                                  self.regions))\n\n    def on_attr_change(self):\n        if not self.selected_attr:\n            return\n        values = set(chain.from_iterable(self._iter_locations()))\n        # Auto-select region map\n        if 0 == len(values - SET_CC_USA):\n            map_code = Map.USA\n        elif 0 == len(values - SET_CC_EUROPE):\n            map_code = Map.EUROPE\n        else:\n            map_code = Map.WORLD\n        self.on_map_change(map_code)\n\n    def _iter_locations(self):\n        \"\"\" Iterator that yields an iterable per documents with all its's\n        locations. \"\"\"\n        attr = self.data.domain[self.selected_attr]\n        for i in self.data.get_column_view(self.data.domain.index(attr))[0]:\n            if len(i) > 3:\n                yield map(lambda x: x.strip(), CC_NAMES.findall(i.lower()))\n            else:\n                yield (i, )\n\n\ndef main():\n    from Orange.data import Table, Domain, StringVariable\n\n    words = np.column_stack([\n        'Slovenia Slovenia SVN USA Iraq Iraq Iraq Iraq France FR'.split(),\n        'Slovenia Slovenia SVN France FR Austria NL GB GB GB'.split(),\n        'Alabama AL Texas TX TX TX MS Montana US-MT MT'.split(),\n    ])\n    metas = [\n        StringVariable('World'),\n        StringVariable('Europe'),\n        StringVariable('USA'),\n    ]\n    domain = Domain([], metas=metas)\n    table = Table.from_numpy(domain,\n                             X=np.zeros((len(words), 0)),\n                             metas=words)\n    app = QApplication([''])\n    w = OWGeoMap()\n    w.on_data(table)\n    w.show()\n    app.exec()\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "orangecontrib/text/widgets/owgeomap.py"}]}