We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Ontology: no desciption / error
When clicking on a oeo module  here
https://openenergy-platform.org/ontology/oeo
it simply states: " no description found". We should add texts.

Not sure whether toep reflects the correct status there, but on toep http://toep.iks.cs.ovgu.de/ontology/oeo throws a 404 it seems. 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ontology/views.py`
Content:
```
1 import os
2 import re
3 from collections import defaultdict
4 
5 from pathlib import Path
6 
7 from django.shortcuts import Http404, HttpResponse, redirect, render
8 from django.views import View
9 from rdflib import Graph
10 
11 from oeplatform.settings import (
12     ONTOLOGY_FOLDER,
13     ONTOLOGY_ROOT,
14     OPEN_ENERGY_ONTOLOGY_NAME,
15 )
16 
17 
18 def collect_modules(path):
19     modules = dict()
20 
21     for file in os.listdir(path):
22         if not os.path.isdir(os.path.join(path, file)):
23             match = re.match(r"^(?P<filename>.*)\.(?P<extension>\w+)$", file)
24             filename, extension = match.groups()
25             if filename not in modules:
26                 modules[filename] = dict(extensions=[], comment="No description found")
27             if extension == "owl":
28                 # g = Graph()
29                 # g.parse(os.path.join(path, file))
30                 # root = dict(g.namespaces())['']
31                 # comments = g.objects(root, RDFS.comment)
32                 # try:
33                 #    modules[filename]["comment"] = next(comments)
34                 # except StopIteration:
35                 modules[filename]["comment"] = "No description found"
36             modules[filename]["extensions"].append(extension)
37     return modules
38 
39 
40 class OntologyVersion(View):
41     def get(self, request, ontology="oeo", version=None):
42         onto_base_path = Path(ONTOLOGY_ROOT, ontology)
43 
44         if not onto_base_path.exists():
45             print("test")
46             raise Http404
47         versions = os.listdir(onto_base_path)
48         print(versions)
49         if not version:
50             version = max(
51                 (d for d in versions), key=lambda d: [int(x) for x in d.split(".")]
52             )
53         return render(
54             request,
55             "ontology/about.html",
56             dict(
57                 version=version,
58             ),
59         )
60 
61 
62 class OntologyOverview(View):
63     def get(self, request, ontology, module_or_id=None, version=None, imports=False):
64         onto_base_path = Path(ONTOLOGY_ROOT, ontology)
65 
66         if not onto_base_path.exists():
67             raise Http404
68         versions = os.listdir(onto_base_path)
69         if not version:
70             version = max(
71                 (d for d in versions), key=lambda d: [int(x) for x in d.split(".")]
72             )
73 
74         path = onto_base_path / version
75         # This is temporary (macOS related)
76         file = "oeo-full.owl"
77         Ontology_URI = path / file
78         g = Graph()
79         g.parse(Ontology_URI.as_posix())
80 
81         q_global = g.query(
82             """
83             SELECT DISTINCT ?s ?o
84             WHERE { ?s rdfs:subClassOf ?o
85             filter(!isBlank(?o))
86             }
87             """
88         )
89 
90         q_label = g.query(
91             """
92             SELECT DISTINCT ?s ?o
93             WHERE { ?s rdfs:label ?o }
94             """
95         )
96 
97         q_definition = g.query(
98             """
99             SELECT DISTINCT ?s ?o
100             WHERE { ?s obo:IAO_0000115 ?o }
101             """
102         )
103 
104         q_note = g.query(
105             """
106             SELECT DISTINCT ?s ?o
107             WHERE { ?s obo:IAO_0000116 ?o }
108             """
109         )
110 
111         q_main_description = g.query(
112             """
113             SELECT ?s ?o
114             WHERE { ?s dc:description ?o }
115             """
116         )
117 
118         classes_name = {}
119         for row in q_label:
120             class_name = row.s.split("/")[-1]
121             classes_name[class_name] = row.o
122 
123         classes_definitions = defaultdict(list)
124         for row in q_definition:
125             class_name = row.s.split("/")[-1]
126             classes_definitions[class_name].append(row.o)
127 
128         classes_notes = defaultdict(list)
129         for row in q_note:
130             class_name = row.s.split("/")[-1]
131             classes_notes[class_name].append(row.o)
132 
133         ontology_description = ""
134         for row in q_main_description:
135             if row.s.split("/")[-1] == "":
136                 ontology_description = row.o
137 
138         # Begin prepare data for oeo-viewer. Only need to be executed once per release
139         # graphLinks = []
140         # graphNodes = []
141         #
142         # for row in q_global:
143         #     source = row.o.split('/')[-1]
144         #     target = row.s.split('/')[-1]
145         #
146         #     #if source in classes_name.keys() and target in classes_name.keys():
147         #     graphLinks.append({
148         #         "source": source,
149         #         "target": target
150         #         })
151         #
152         #     target_found = False
153         #     source_found = False
154         #
155         #     for item in graphNodes:
156         #         if item["id"] == target:
157         #             target_found = True
158         #         if item["id"] == source:
159         #             source_found = True
160         #
161         #     try:
162         #         if not target_found:
163         #             graphNodes.append({
164         #                 "id": target,
165         #                 "name": classes_name[target],
166         #                 "description": classes_definitions[target],
167         #                 "editor_note": classes_notes[target]
168         #                 })
169         #
170         #         if not source_found:
171         #             graphNodes.append({
172         #                 "id": source,
173         #                 "name": classes_name[source],
174         #                 "description": classes_definitions[source],
175         #                 "editor_note": classes_notes[source]
176         #                 })
177         #     except:
178         #         pass
179         #
180         # with open('GraphData.json', 'w') as f:
181         #     json.dump({"nodes": graphNodes,
182         #                 "links": graphLinks}, f)
183         # End prepare data for oeo-viewer
184 
185         if "text/html" in request.headers.get("accept", "").split(","):
186             if module_or_id:
187                 sub_classes = []
188                 super_classes = []
189 
190                 for row in q_global:
191                     if module_or_id in row.o:
192                         sub_class_ID = row.s.split("/")[-1]
193                         sub_class_name = ""
194                         sub_class_definition = ""
195                         sub_class_note = ""
196                         if sub_class_ID in classes_name.keys():
197                             sub_class_name = classes_name[sub_class_ID]
198                             if sub_class_ID in classes_definitions.keys():
199                                 sub_class_definition = classes_definitions[sub_class_ID]
200                             if sub_class_ID in classes_notes.keys():
201                                 sub_class_note = classes_notes[sub_class_ID]
202                             sub_classes.append(
203                                 {
204                                     "URI": row.s,
205                                     "ID": sub_class_ID,
206                                     "name": sub_class_name,
207                                     "definitions": sub_class_definition,
208                                     "notes": sub_class_note,
209                                 }
210                             )
211                     if module_or_id in row.s:
212                         super_class_ID = row.o.split("/")[-1]
213                         super_class_name = ""
214                         super_class_definition = ""
215                         super_class_note = ""
216                         if super_class_ID in classes_name.keys():
217                             super_class_name = classes_name[super_class_ID]
218                             if super_class_ID in classes_definitions.keys():
219                                 super_class_definition = classes_definitions[
220                                     super_class_ID
221                                 ]
222                             if super_class_ID in classes_notes.keys():
223                                 super_class_note = classes_notes[super_class_ID]
224                             super_classes.append(
225                                 {
226                                     "URI": row.o,
227                                     "ID": super_class_ID,
228                                     "name": super_class_name,
229                                     "definitions": super_class_definition,
230                                     "notes": super_class_note,
231                                 }
232                             )
233 
234                 class_name = ""
235                 if module_or_id in classes_name.keys():
236                     class_name = classes_name[module_or_id]
237 
238                 class_definitions = ""
239                 if module_or_id in classes_definitions.keys():
240                     class_definitions = classes_definitions[module_or_id]
241 
242                 class_notes = ""
243                 if module_or_id in classes_notes.keys():
244                     class_notes = classes_notes[module_or_id]
245 
246                 return render(
247                     request,
248                     "ontology/class.html",
249                     dict(
250                         class_id=module_or_id,
251                         class_name=class_name,
252                         sub_classes=sub_classes,
253                         super_classes=super_classes,
254                         class_definitions=class_definitions,
255                         class_notes=class_notes,
256                     ),
257                 )
258             else:
259                 main_module = collect_modules(
260                     path
261                 )  # TODO fix varname - not clear what path this is
262                 if OPEN_ENERGY_ONTOLOGY_NAME in main_module.keys():
263                     main_module_name = OPEN_ENERGY_ONTOLOGY_NAME
264                 else:
265                     raise Exception(
266                         f"The main module '{OPEN_ENERGY_ONTOLOGY_NAME}' is not available in {path}."
267                     )
268 
269                 main_module = main_module[main_module_name]
270                 main_module["name"] = main_module_name
271                 submodules = collect_modules((path / "modules"))
272                 # Collect all file names
273                 imports = collect_modules(path / "imports")
274 
275                 return render(
276                     request,
277                     "ontology/oeo.html",
278                     dict(
279                         ontology=ontology,
280                         version=version,
281                         main_module=main_module,
282                         submodules=submodules.items(),
283                         imports=imports.items(),
284                         ontology_description=ontology_description,
285                     ),
286                 )
287         else:
288             module_name = None
289             if module_or_id:
290                 if imports:
291                     submodules = collect_modules(
292                         f"{ONTOLOGY_FOLDER}/{ontology}/{version}/imports"
293                     )
294                 else:
295                     submodules = collect_modules(
296                         f"{ONTOLOGY_FOLDER}/{ontology}/{version}/modules"
297                     )
298                 # If module_or_id is the name of a valid submodule, use this module
299                 if module_or_id in submodules:
300                     module_name = module_or_id
301                 if imports:
302                     return redirect(
303                         f"/ontology/{ontology}/releases/{version}/imports/{module_name}.owl"  # noqa
304                     )
305                 else:
306                     return redirect(
307                         f"/ontology/{ontology}/releases/{version}/{module_name}.owl"
308                     )
309             # If no module was requested or the requested id was not a module,
310             # serve main ontology
311             if module_name is None:
312                 main_module = collect_modules(f"{ONTOLOGY_FOLDER}/{ontology}/{version}")
313                 module_name = list(main_module.keys())[0]
314             return redirect(
315                 f"/ontology/{ontology}/releases/{version}/{module_name}.owl"
316             )
317 
318 
319 class OntologyStatics(View):
320     def get(self, request, ontology, file, version=None, extension=None, imports=False):
321         """
322         Returns the requested file `{file}.{extension}` of version `version`
323         of ontology `ontology`
324 
325         :param version: default: highest version in folder
326         :param extension: default: `.owl`
327         :return:
328         """
329 
330         onto_base_path = Path(ONTOLOGY_ROOT, ontology)
331 
332         if not extension:
333             extension = "owl"
334         if not version:
335             version = max(
336                 (d for d in os.listdir(onto_base_path)),
337                 key=lambda d: [int(x) for x in d.split(".")],
338             )
339         if imports:
340             file_path = onto_base_path / version / "imports" / f"{file}.{extension}"
341         else:
342             file_path = onto_base_path / version / f"{file}.{extension}"
343 
344         if os.path.exists(file_path):
345             with open(file_path, "br") as f:
346                 response = HttpResponse(
347                     f, content_type="application/rdf+xml; charset=utf-8"
348                 )
349                 response[
350                     "Content-Disposition"
351                 ] = f'attachment; filename="{file}.{extension}"'
352                 return response
353         else:
354             file_path = onto_base_path / version / "modules" / f"{file}.{extension}"
355             if not os.path.exists(file_path):
356                 raise Http404
357             with open(file_path, "br") as f:
358                 response = HttpResponse(
359                     f, content_type="application/rdf+xml; charset=utf-8"
360                 )
361                 response[
362                     "Content-Disposition"
363                 ] = f'attachment; filename="{file}.{extension}"'
364                 return response
365
```
--- 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/ontology/views.py b/ontology/views.py
--- a/ontology/views.py
+++ b/ontology/views.py
@@ -14,6 +14,8 @@
     OPEN_ENERGY_ONTOLOGY_NAME,
 )
 
+from rdflib import Graph
+
 
 def collect_modules(path):
     modules = dict()
@@ -25,14 +27,49 @@
             if filename not in modules:
                 modules[filename] = dict(extensions=[], comment="No description found")
             if extension == "owl":
-                # g = Graph()
-                # g.parse(os.path.join(path, file))
-                # root = dict(g.namespaces())['']
-                # comments = g.objects(root, RDFS.comment)
-                # try:
-                #    modules[filename]["comment"] = next(comments)
-                # except StopIteration:
-                modules[filename]["comment"] = "No description found"
+                g = Graph()
+                g.parse(os.path.join(path, file))
+
+                # Get the root namespace
+                root_namespace = next(iter(g.namespaces()))
+
+                # Set the namespaces in the graph
+                for prefix, uri in g.namespaces():
+                    g.bind(prefix, uri)
+
+                # Extract the description from the RDF graph (rdfs:comment)
+                comment_query = f"""
+                    SELECT ?description
+                    WHERE {{
+                        ?ontology rdf:type owl:Ontology .
+                        ?ontology rdfs:comment ?description .
+                    }}
+                """
+                # Execute the SPARQL query for comment
+                comment_results = g.query(comment_query, initNs={"": root_namespace})
+
+                # Update the comment in the modules dictionary if found
+                for row in comment_results:
+                    modules[filename]["comment"] = row[0]
+
+                # If the comment is still "No description found," try extracting from dc:description
+                if modules[filename]["comment"] == "No description found":
+                    description_query = f"""
+                        SELECT ?description
+                        WHERE {{
+                            ?ontology rdf:type owl:Ontology .
+                            ?ontology dc:description ?description .
+                        }}
+                    """
+                    # Execute the SPARQL query for description
+                    description_results = g.query(
+                        description_query, initNs={"": root_namespace}
+                    )
+
+                    # Update the comment in the modules dictionary if found
+                    for row in description_results:
+                        modules[filename]["comment"] = row[0]
+
             modules[filename]["extensions"].append(extension)
     return modules

{"golden_diff": "diff --git a/ontology/views.py b/ontology/views.py\n--- a/ontology/views.py\n+++ b/ontology/views.py\n@@ -14,6 +14,8 @@\n     OPEN_ENERGY_ONTOLOGY_NAME,\n )\n \n+from rdflib import Graph\n+\n \n def collect_modules(path):\n     modules = dict()\n@@ -25,14 +27,49 @@\n             if filename not in modules:\n                 modules[filename] = dict(extensions=[], comment=\"No description found\")\n             if extension == \"owl\":\n-                # g = Graph()\n-                # g.parse(os.path.join(path, file))\n-                # root = dict(g.namespaces())['']\n-                # comments = g.objects(root, RDFS.comment)\n-                # try:\n-                #    modules[filename][\"comment\"] = next(comments)\n-                # except StopIteration:\n-                modules[filename][\"comment\"] = \"No description found\"\n+                g = Graph()\n+                g.parse(os.path.join(path, file))\n+\n+                # Get the root namespace\n+                root_namespace = next(iter(g.namespaces()))\n+\n+                # Set the namespaces in the graph\n+                for prefix, uri in g.namespaces():\n+                    g.bind(prefix, uri)\n+\n+                # Extract the description from the RDF graph (rdfs:comment)\n+                comment_query = f\"\"\"\n+                    SELECT ?description\n+                    WHERE {{\n+                        ?ontology rdf:type owl:Ontology .\n+                        ?ontology rdfs:comment ?description .\n+                    }}\n+                \"\"\"\n+                # Execute the SPARQL query for comment\n+                comment_results = g.query(comment_query, initNs={\"\": root_namespace})\n+\n+                # Update the comment in the modules dictionary if found\n+                for row in comment_results:\n+                    modules[filename][\"comment\"] = row[0]\n+\n+                # If the comment is still \"No description found,\" try extracting from dc:description\n+                if modules[filename][\"comment\"] == \"No description found\":\n+                    description_query = f\"\"\"\n+                        SELECT ?description\n+                        WHERE {{\n+                            ?ontology rdf:type owl:Ontology .\n+                            ?ontology dc:description ?description .\n+                        }}\n+                    \"\"\"\n+                    # Execute the SPARQL query for description\n+                    description_results = g.query(\n+                        description_query, initNs={\"\": root_namespace}\n+                    )\n+\n+                    # Update the comment in the modules dictionary if found\n+                    for row in description_results:\n+                        modules[filename][\"comment\"] = row[0]\n+\n             modules[filename][\"extensions\"].append(extension)\n     return modules\n", "issue": "Ontology: no desciption / error\nWhen clicking on a oeo module  here\r\nhttps://openenergy-platform.org/ontology/oeo\r\nit simply states: \" no description found\". We should add texts.\r\n\r\nNot sure whether toep reflects the correct status there, but on toep http://toep.iks.cs.ovgu.de/ontology/oeo throws a 404 it seems. \n", "before_files": [{"content": "import os\nimport re\nfrom collections import defaultdict\n\nfrom pathlib import Path\n\nfrom django.shortcuts import Http404, HttpResponse, redirect, render\nfrom django.views import View\nfrom rdflib import Graph\n\nfrom oeplatform.settings import (\n    ONTOLOGY_FOLDER,\n    ONTOLOGY_ROOT,\n    OPEN_ENERGY_ONTOLOGY_NAME,\n)\n\n\ndef collect_modules(path):\n    modules = dict()\n\n    for file in os.listdir(path):\n        if not os.path.isdir(os.path.join(path, file)):\n            match = re.match(r\"^(?P<filename>.*)\\.(?P<extension>\\w+)$\", file)\n            filename, extension = match.groups()\n            if filename not in modules:\n                modules[filename] = dict(extensions=[], comment=\"No description found\")\n            if extension == \"owl\":\n                # g = Graph()\n                # g.parse(os.path.join(path, file))\n                # root = dict(g.namespaces())['']\n                # comments = g.objects(root, RDFS.comment)\n                # try:\n                #    modules[filename][\"comment\"] = next(comments)\n                # except StopIteration:\n                modules[filename][\"comment\"] = \"No description found\"\n            modules[filename][\"extensions\"].append(extension)\n    return modules\n\n\nclass OntologyVersion(View):\n    def get(self, request, ontology=\"oeo\", version=None):\n        onto_base_path = Path(ONTOLOGY_ROOT, ontology)\n\n        if not onto_base_path.exists():\n            print(\"test\")\n            raise Http404\n        versions = os.listdir(onto_base_path)\n        print(versions)\n        if not version:\n            version = max(\n                (d for d in versions), key=lambda d: [int(x) for x in d.split(\".\")]\n            )\n        return render(\n            request,\n            \"ontology/about.html\",\n            dict(\n                version=version,\n            ),\n        )\n\n\nclass OntologyOverview(View):\n    def get(self, request, ontology, module_or_id=None, version=None, imports=False):\n        onto_base_path = Path(ONTOLOGY_ROOT, ontology)\n\n        if not onto_base_path.exists():\n            raise Http404\n        versions = os.listdir(onto_base_path)\n        if not version:\n            version = max(\n                (d for d in versions), key=lambda d: [int(x) for x in d.split(\".\")]\n            )\n\n        path = onto_base_path / version\n        # This is temporary (macOS related)\n        file = \"oeo-full.owl\"\n        Ontology_URI = path / file\n        g = Graph()\n        g.parse(Ontology_URI.as_posix())\n\n        q_global = g.query(\n            \"\"\"\n            SELECT DISTINCT ?s ?o\n            WHERE { ?s rdfs:subClassOf ?o\n            filter(!isBlank(?o))\n            }\n            \"\"\"\n        )\n\n        q_label = g.query(\n            \"\"\"\n            SELECT DISTINCT ?s ?o\n            WHERE { ?s rdfs:label ?o }\n            \"\"\"\n        )\n\n        q_definition = g.query(\n            \"\"\"\n            SELECT DISTINCT ?s ?o\n            WHERE { ?s obo:IAO_0000115 ?o }\n            \"\"\"\n        )\n\n        q_note = g.query(\n            \"\"\"\n            SELECT DISTINCT ?s ?o\n            WHERE { ?s obo:IAO_0000116 ?o }\n            \"\"\"\n        )\n\n        q_main_description = g.query(\n            \"\"\"\n            SELECT ?s ?o\n            WHERE { ?s dc:description ?o }\n            \"\"\"\n        )\n\n        classes_name = {}\n        for row in q_label:\n            class_name = row.s.split(\"/\")[-1]\n            classes_name[class_name] = row.o\n\n        classes_definitions = defaultdict(list)\n        for row in q_definition:\n            class_name = row.s.split(\"/\")[-1]\n            classes_definitions[class_name].append(row.o)\n\n        classes_notes = defaultdict(list)\n        for row in q_note:\n            class_name = row.s.split(\"/\")[-1]\n            classes_notes[class_name].append(row.o)\n\n        ontology_description = \"\"\n        for row in q_main_description:\n            if row.s.split(\"/\")[-1] == \"\":\n                ontology_description = row.o\n\n        # Begin prepare data for oeo-viewer. Only need to be executed once per release\n        # graphLinks = []\n        # graphNodes = []\n        #\n        # for row in q_global:\n        #     source = row.o.split('/')[-1]\n        #     target = row.s.split('/')[-1]\n        #\n        #     #if source in classes_name.keys() and target in classes_name.keys():\n        #     graphLinks.append({\n        #         \"source\": source,\n        #         \"target\": target\n        #         })\n        #\n        #     target_found = False\n        #     source_found = False\n        #\n        #     for item in graphNodes:\n        #         if item[\"id\"] == target:\n        #             target_found = True\n        #         if item[\"id\"] == source:\n        #             source_found = True\n        #\n        #     try:\n        #         if not target_found:\n        #             graphNodes.append({\n        #                 \"id\": target,\n        #                 \"name\": classes_name[target],\n        #                 \"description\": classes_definitions[target],\n        #                 \"editor_note\": classes_notes[target]\n        #                 })\n        #\n        #         if not source_found:\n        #             graphNodes.append({\n        #                 \"id\": source,\n        #                 \"name\": classes_name[source],\n        #                 \"description\": classes_definitions[source],\n        #                 \"editor_note\": classes_notes[source]\n        #                 })\n        #     except:\n        #         pass\n        #\n        # with open('GraphData.json', 'w') as f:\n        #     json.dump({\"nodes\": graphNodes,\n        #                 \"links\": graphLinks}, f)\n        # End prepare data for oeo-viewer\n\n        if \"text/html\" in request.headers.get(\"accept\", \"\").split(\",\"):\n            if module_or_id:\n                sub_classes = []\n                super_classes = []\n\n                for row in q_global:\n                    if module_or_id in row.o:\n                        sub_class_ID = row.s.split(\"/\")[-1]\n                        sub_class_name = \"\"\n                        sub_class_definition = \"\"\n                        sub_class_note = \"\"\n                        if sub_class_ID in classes_name.keys():\n                            sub_class_name = classes_name[sub_class_ID]\n                            if sub_class_ID in classes_definitions.keys():\n                                sub_class_definition = classes_definitions[sub_class_ID]\n                            if sub_class_ID in classes_notes.keys():\n                                sub_class_note = classes_notes[sub_class_ID]\n                            sub_classes.append(\n                                {\n                                    \"URI\": row.s,\n                                    \"ID\": sub_class_ID,\n                                    \"name\": sub_class_name,\n                                    \"definitions\": sub_class_definition,\n                                    \"notes\": sub_class_note,\n                                }\n                            )\n                    if module_or_id in row.s:\n                        super_class_ID = row.o.split(\"/\")[-1]\n                        super_class_name = \"\"\n                        super_class_definition = \"\"\n                        super_class_note = \"\"\n                        if super_class_ID in classes_name.keys():\n                            super_class_name = classes_name[super_class_ID]\n                            if super_class_ID in classes_definitions.keys():\n                                super_class_definition = classes_definitions[\n                                    super_class_ID\n                                ]\n                            if super_class_ID in classes_notes.keys():\n                                super_class_note = classes_notes[super_class_ID]\n                            super_classes.append(\n                                {\n                                    \"URI\": row.o,\n                                    \"ID\": super_class_ID,\n                                    \"name\": super_class_name,\n                                    \"definitions\": super_class_definition,\n                                    \"notes\": super_class_note,\n                                }\n                            )\n\n                class_name = \"\"\n                if module_or_id in classes_name.keys():\n                    class_name = classes_name[module_or_id]\n\n                class_definitions = \"\"\n                if module_or_id in classes_definitions.keys():\n                    class_definitions = classes_definitions[module_or_id]\n\n                class_notes = \"\"\n                if module_or_id in classes_notes.keys():\n                    class_notes = classes_notes[module_or_id]\n\n                return render(\n                    request,\n                    \"ontology/class.html\",\n                    dict(\n                        class_id=module_or_id,\n                        class_name=class_name,\n                        sub_classes=sub_classes,\n                        super_classes=super_classes,\n                        class_definitions=class_definitions,\n                        class_notes=class_notes,\n                    ),\n                )\n            else:\n                main_module = collect_modules(\n                    path\n                )  # TODO fix varname - not clear what path this is\n                if OPEN_ENERGY_ONTOLOGY_NAME in main_module.keys():\n                    main_module_name = OPEN_ENERGY_ONTOLOGY_NAME\n                else:\n                    raise Exception(\n                        f\"The main module '{OPEN_ENERGY_ONTOLOGY_NAME}' is not available in {path}.\"\n                    )\n\n                main_module = main_module[main_module_name]\n                main_module[\"name\"] = main_module_name\n                submodules = collect_modules((path / \"modules\"))\n                # Collect all file names\n                imports = collect_modules(path / \"imports\")\n\n                return render(\n                    request,\n                    \"ontology/oeo.html\",\n                    dict(\n                        ontology=ontology,\n                        version=version,\n                        main_module=main_module,\n                        submodules=submodules.items(),\n                        imports=imports.items(),\n                        ontology_description=ontology_description,\n                    ),\n                )\n        else:\n            module_name = None\n            if module_or_id:\n                if imports:\n                    submodules = collect_modules(\n                        f\"{ONTOLOGY_FOLDER}/{ontology}/{version}/imports\"\n                    )\n                else:\n                    submodules = collect_modules(\n                        f\"{ONTOLOGY_FOLDER}/{ontology}/{version}/modules\"\n                    )\n                # If module_or_id is the name of a valid submodule, use this module\n                if module_or_id in submodules:\n                    module_name = module_or_id\n                if imports:\n                    return redirect(\n                        f\"/ontology/{ontology}/releases/{version}/imports/{module_name}.owl\"  # noqa\n                    )\n                else:\n                    return redirect(\n                        f\"/ontology/{ontology}/releases/{version}/{module_name}.owl\"\n                    )\n            # If no module was requested or the requested id was not a module,\n            # serve main ontology\n            if module_name is None:\n                main_module = collect_modules(f\"{ONTOLOGY_FOLDER}/{ontology}/{version}\")\n                module_name = list(main_module.keys())[0]\n            return redirect(\n                f\"/ontology/{ontology}/releases/{version}/{module_name}.owl\"\n            )\n\n\nclass OntologyStatics(View):\n    def get(self, request, ontology, file, version=None, extension=None, imports=False):\n        \"\"\"\n        Returns the requested file `{file}.{extension}` of version `version`\n        of ontology `ontology`\n\n        :param version: default: highest version in folder\n        :param extension: default: `.owl`\n        :return:\n        \"\"\"\n\n        onto_base_path = Path(ONTOLOGY_ROOT, ontology)\n\n        if not extension:\n            extension = \"owl\"\n        if not version:\n            version = max(\n                (d for d in os.listdir(onto_base_path)),\n                key=lambda d: [int(x) for x in d.split(\".\")],\n            )\n        if imports:\n            file_path = onto_base_path / version / \"imports\" / f\"{file}.{extension}\"\n        else:\n            file_path = onto_base_path / version / f\"{file}.{extension}\"\n\n        if os.path.exists(file_path):\n            with open(file_path, \"br\") as f:\n                response = HttpResponse(\n                    f, content_type=\"application/rdf+xml; charset=utf-8\"\n                )\n                response[\n                    \"Content-Disposition\"\n                ] = f'attachment; filename=\"{file}.{extension}\"'\n                return response\n        else:\n            file_path = onto_base_path / version / \"modules\" / f\"{file}.{extension}\"\n            if not os.path.exists(file_path):\n                raise Http404\n            with open(file_path, \"br\") as f:\n                response = HttpResponse(\n                    f, content_type=\"application/rdf+xml; charset=utf-8\"\n                )\n                response[\n                    \"Content-Disposition\"\n                ] = f'attachment; filename=\"{file}.{extension}\"'\n                return response\n", "path": "ontology/views.py"}], "after_files": [{"content": "import os\nimport re\nfrom collections import defaultdict\n\nfrom pathlib import Path\n\nfrom django.shortcuts import Http404, HttpResponse, redirect, render\nfrom django.views import View\nfrom rdflib import Graph\n\nfrom oeplatform.settings import (\n    ONTOLOGY_FOLDER,\n    ONTOLOGY_ROOT,\n    OPEN_ENERGY_ONTOLOGY_NAME,\n)\n\nfrom rdflib import Graph\n\n\ndef collect_modules(path):\n    modules = dict()\n\n    for file in os.listdir(path):\n        if not os.path.isdir(os.path.join(path, file)):\n            match = re.match(r\"^(?P<filename>.*)\\.(?P<extension>\\w+)$\", file)\n            filename, extension = match.groups()\n            if filename not in modules:\n                modules[filename] = dict(extensions=[], comment=\"No description found\")\n            if extension == \"owl\":\n                g = Graph()\n                g.parse(os.path.join(path, file))\n\n                # Get the root namespace\n                root_namespace = next(iter(g.namespaces()))\n\n                # Set the namespaces in the graph\n                for prefix, uri in g.namespaces():\n                    g.bind(prefix, uri)\n\n                # Extract the description from the RDF graph (rdfs:comment)\n                comment_query = f\"\"\"\n                    SELECT ?description\n                    WHERE {{\n                        ?ontology rdf:type owl:Ontology .\n                        ?ontology rdfs:comment ?description .\n                    }}\n                \"\"\"\n                # Execute the SPARQL query for comment\n                comment_results = g.query(comment_query, initNs={\"\": root_namespace})\n\n                # Update the comment in the modules dictionary if found\n                for row in comment_results:\n                    modules[filename][\"comment\"] = row[0]\n\n                # If the comment is still \"No description found,\" try extracting from dc:description\n                if modules[filename][\"comment\"] == \"No description found\":\n                    description_query = f\"\"\"\n                        SELECT ?description\n                        WHERE {{\n                            ?ontology rdf:type owl:Ontology .\n                            ?ontology dc:description ?description .\n                        }}\n                    \"\"\"\n                    # Execute the SPARQL query for description\n                    description_results = g.query(\n                        description_query, initNs={\"\": root_namespace}\n                    )\n\n                    # Update the comment in the modules dictionary if found\n                    for row in description_results:\n                        modules[filename][\"comment\"] = row[0]\n\n            modules[filename][\"extensions\"].append(extension)\n    return modules\n\n\nclass OntologyVersion(View):\n    def get(self, request, ontology=\"oeo\", version=None):\n        onto_base_path = Path(ONTOLOGY_ROOT, ontology)\n\n        if not onto_base_path.exists():\n            print(\"test\")\n            raise Http404\n        versions = os.listdir(onto_base_path)\n        print(versions)\n        if not version:\n            version = max(\n                (d for d in versions), key=lambda d: [int(x) for x in d.split(\".\")]\n            )\n        return render(\n            request,\n            \"ontology/about.html\",\n            dict(\n                version=version,\n            ),\n        )\n\n\nclass OntologyOverview(View):\n    def get(self, request, ontology, module_or_id=None, version=None, imports=False):\n        onto_base_path = Path(ONTOLOGY_ROOT, ontology)\n\n        if not onto_base_path.exists():\n            raise Http404\n        versions = os.listdir(onto_base_path)\n        if not version:\n            version = max(\n                (d for d in versions), key=lambda d: [int(x) for x in d.split(\".\")]\n            )\n\n        path = onto_base_path / version\n        # This is temporary (macOS related)\n        file = \"oeo-full.owl\"\n        Ontology_URI = path / file\n        g = Graph()\n        g.parse(Ontology_URI.as_posix())\n\n        q_global = g.query(\n            \"\"\"\n            SELECT DISTINCT ?s ?o\n            WHERE { ?s rdfs:subClassOf ?o\n            filter(!isBlank(?o))\n            }\n            \"\"\"\n        )\n\n        q_label = g.query(\n            \"\"\"\n            SELECT DISTINCT ?s ?o\n            WHERE { ?s rdfs:label ?o }\n            \"\"\"\n        )\n\n        q_definition = g.query(\n            \"\"\"\n            SELECT DISTINCT ?s ?o\n            WHERE { ?s obo:IAO_0000115 ?o }\n            \"\"\"\n        )\n\n        q_note = g.query(\n            \"\"\"\n            SELECT DISTINCT ?s ?o\n            WHERE { ?s obo:IAO_0000116 ?o }\n            \"\"\"\n        )\n\n        q_main_description = g.query(\n            \"\"\"\n            SELECT ?s ?o\n            WHERE { ?s dc:description ?o }\n            \"\"\"\n        )\n\n        classes_name = {}\n        for row in q_label:\n            class_name = row.s.split(\"/\")[-1]\n            classes_name[class_name] = row.o\n\n        classes_definitions = defaultdict(list)\n        for row in q_definition:\n            class_name = row.s.split(\"/\")[-1]\n            classes_definitions[class_name].append(row.o)\n\n        classes_notes = defaultdict(list)\n        for row in q_note:\n            class_name = row.s.split(\"/\")[-1]\n            classes_notes[class_name].append(row.o)\n\n        ontology_description = \"\"\n        for row in q_main_description:\n            if row.s.split(\"/\")[-1] == \"\":\n                ontology_description = row.o\n\n        # Begin prepare data for oeo-viewer. Only need to be executed once per release\n        # graphLinks = []\n        # graphNodes = []\n        #\n        # for row in q_global:\n        #     source = row.o.split('/')[-1]\n        #     target = row.s.split('/')[-1]\n        #\n        #     #if source in classes_name.keys() and target in classes_name.keys():\n        #     graphLinks.append({\n        #         \"source\": source,\n        #         \"target\": target\n        #         })\n        #\n        #     target_found = False\n        #     source_found = False\n        #\n        #     for item in graphNodes:\n        #         if item[\"id\"] == target:\n        #             target_found = True\n        #         if item[\"id\"] == source:\n        #             source_found = True\n        #\n        #     try:\n        #         if not target_found:\n        #             graphNodes.append({\n        #                 \"id\": target,\n        #                 \"name\": classes_name[target],\n        #                 \"description\": classes_definitions[target],\n        #                 \"editor_note\": classes_notes[target]\n        #                 })\n        #\n        #         if not source_found:\n        #             graphNodes.append({\n        #                 \"id\": source,\n        #                 \"name\": classes_name[source],\n        #                 \"description\": classes_definitions[source],\n        #                 \"editor_note\": classes_notes[source]\n        #                 })\n        #     except:\n        #         pass\n        #\n        # with open('GraphData.json', 'w') as f:\n        #     json.dump({\"nodes\": graphNodes,\n        #                 \"links\": graphLinks}, f)\n        # End prepare data for oeo-viewer\n\n        if \"text/html\" in request.headers.get(\"accept\", \"\").split(\",\"):\n            if module_or_id:\n                sub_classes = []\n                super_classes = []\n\n                for row in q_global:\n                    if module_or_id in row.o:\n                        sub_class_ID = row.s.split(\"/\")[-1]\n                        sub_class_name = \"\"\n                        sub_class_definition = \"\"\n                        sub_class_note = \"\"\n                        if sub_class_ID in classes_name.keys():\n                            sub_class_name = classes_name[sub_class_ID]\n                            if sub_class_ID in classes_definitions.keys():\n                                sub_class_definition = classes_definitions[sub_class_ID]\n                            if sub_class_ID in classes_notes.keys():\n                                sub_class_note = classes_notes[sub_class_ID]\n                            sub_classes.append(\n                                {\n                                    \"URI\": row.s,\n                                    \"ID\": sub_class_ID,\n                                    \"name\": sub_class_name,\n                                    \"definitions\": sub_class_definition,\n                                    \"notes\": sub_class_note,\n                                }\n                            )\n                    if module_or_id in row.s:\n                        super_class_ID = row.o.split(\"/\")[-1]\n                        super_class_name = \"\"\n                        super_class_definition = \"\"\n                        super_class_note = \"\"\n                        if super_class_ID in classes_name.keys():\n                            super_class_name = classes_name[super_class_ID]\n                            if super_class_ID in classes_definitions.keys():\n                                super_class_definition = classes_definitions[\n                                    super_class_ID\n                                ]\n                            if super_class_ID in classes_notes.keys():\n                                super_class_note = classes_notes[super_class_ID]\n                            super_classes.append(\n                                {\n                                    \"URI\": row.o,\n                                    \"ID\": super_class_ID,\n                                    \"name\": super_class_name,\n                                    \"definitions\": super_class_definition,\n                                    \"notes\": super_class_note,\n                                }\n                            )\n\n                class_name = \"\"\n                if module_or_id in classes_name.keys():\n                    class_name = classes_name[module_or_id]\n\n                class_definitions = \"\"\n                if module_or_id in classes_definitions.keys():\n                    class_definitions = classes_definitions[module_or_id]\n\n                class_notes = \"\"\n                if module_or_id in classes_notes.keys():\n                    class_notes = classes_notes[module_or_id]\n\n                return render(\n                    request,\n                    \"ontology/class.html\",\n                    dict(\n                        class_id=module_or_id,\n                        class_name=class_name,\n                        sub_classes=sub_classes,\n                        super_classes=super_classes,\n                        class_definitions=class_definitions,\n                        class_notes=class_notes,\n                    ),\n                )\n            else:\n                main_module = collect_modules(\n                    path\n                )  # TODO fix varname - not clear what path this is\n                if OPEN_ENERGY_ONTOLOGY_NAME in main_module.keys():\n                    main_module_name = OPEN_ENERGY_ONTOLOGY_NAME\n                else:\n                    raise Exception(\n                        f\"The main module '{OPEN_ENERGY_ONTOLOGY_NAME}' is not available in {path}.\"\n                    )\n\n                main_module = main_module[main_module_name]\n                main_module[\"name\"] = main_module_name\n                submodules = collect_modules((path / \"modules\"))\n                # Collect all file names\n                imports = collect_modules(path / \"imports\")\n\n                return render(\n                    request,\n                    \"ontology/oeo.html\",\n                    dict(\n                        ontology=ontology,\n                        version=version,\n                        main_module=main_module,\n                        submodules=submodules.items(),\n                        imports=imports.items(),\n                        ontology_description=ontology_description,\n                    ),\n                )\n        else:\n            module_name = None\n            if module_or_id:\n                if imports:\n                    submodules = collect_modules(\n                        f\"{ONTOLOGY_FOLDER}/{ontology}/{version}/imports\"\n                    )\n                else:\n                    submodules = collect_modules(\n                        f\"{ONTOLOGY_FOLDER}/{ontology}/{version}/modules\"\n                    )\n                # If module_or_id is the name of a valid submodule, use this module\n                if module_or_id in submodules:\n                    module_name = module_or_id\n                if imports:\n                    return redirect(\n                        f\"/ontology/{ontology}/releases/{version}/imports/{module_name}.owl\"  # noqa\n                    )\n                else:\n                    return redirect(\n                        f\"/ontology/{ontology}/releases/{version}/{module_name}.owl\"\n                    )\n            # If no module was requested or the requested id was not a module,\n            # serve main ontology\n            if module_name is None:\n                main_module = collect_modules(f\"{ONTOLOGY_FOLDER}/{ontology}/{version}\")\n                module_name = list(main_module.keys())[0]\n            return redirect(\n                f\"/ontology/{ontology}/releases/{version}/{module_name}.owl\"\n            )\n\n\nclass OntologyStatics(View):\n    def get(self, request, ontology, file, version=None, extension=None, imports=False):\n        \"\"\"\n        Returns the requested file `{file}.{extension}` of version `version`\n        of ontology `ontology`\n\n        :param version: default: highest version in folder\n        :param extension: default: `.owl`\n        :return:\n        \"\"\"\n\n        onto_base_path = Path(ONTOLOGY_ROOT, ontology)\n\n        if not extension:\n            extension = \"owl\"\n        if not version:\n            version = max(\n                (d for d in os.listdir(onto_base_path)),\n                key=lambda d: [int(x) for x in d.split(\".\")],\n            )\n        if imports:\n            file_path = onto_base_path / version / \"imports\" / f\"{file}.{extension}\"\n        else:\n            file_path = onto_base_path / version / f\"{file}.{extension}\"\n\n        if os.path.exists(file_path):\n            with open(file_path, \"br\") as f:\n                response = HttpResponse(\n                    f, content_type=\"application/rdf+xml; charset=utf-8\"\n                )\n                response[\n                    \"Content-Disposition\"\n                ] = f'attachment; filename=\"{file}.{extension}\"'\n                return response\n        else:\n            file_path = onto_base_path / version / \"modules\" / f\"{file}.{extension}\"\n            if not os.path.exists(file_path):\n                raise Http404\n            with open(file_path, \"br\") as f:\n                response = HttpResponse(\n                    f, content_type=\"application/rdf+xml; charset=utf-8\"\n                )\n                response[\n                    \"Content-Disposition\"\n                ] = f'attachment; filename=\"{file}.{extension}\"'\n                return response\n", "path": "ontology/views.py"}]}