Skip to content

Commit

Permalink
adds ConferenceCorpusQueries
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Nov 22, 2023
1 parent 6d473a5 commit 4a030e3
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 3 deletions.
3 changes: 2 additions & 1 deletion corpus/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def getQueryManager(cls,lang='sql',name="queries",debug=False):
debug(bool): if True set debugging on
'''
cachedir=EventStorage.getStorageConfig().getCachePath()
for path in cachedir,os.path.dirname(__file__)+"/../resources":
resources_path=os.path.dirname(__file__)+"/../resources"
for path in cachedir,resources_path:
qYamlFile=f"{path}/{name}.yaml"
if os.path.isfile(qYamlFile):
qm=QueryManager(lang=lang,debug=debug,queriesPath=qYamlFile)
Expand Down
42 changes: 42 additions & 0 deletions corpus/web/cc_queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Created on 2023-11-22
@author: wf
"""

from ngwidgets.widgets import Link
from corpus.eventcorpus import EventStorage

class ConferenceCorpusQueries:
"""
Class for managing and displaying queries related to a conference corpus.
This class provides functionalities for accessing and rendering queries
related to conference data stored in an EventStorage system.
"""

def __init__(self):
"""
Initialize the ConferenceCorpusQueries instance.
Sets up the query manager by retrieving it from the EventStorage.
"""
self.queryManager = EventStorage.getQueryManager() # Type: QueryManager

def as_html(self) -> str:
"""
Generate an HTML representation of the queries.
Iterates through the available queries and creates an HTML unordered list
with links to each query.
Returns:
str: HTML string representing the list of queries.
"""
markup = "<ul>"
for queryName in self.queryManager.queriesByName:
url = f"/query/{queryName}"
link = Link.create(url, queryName,url_encode=True)
markup += f"\n <li>{link}"
markup += "\n</ul>"
return markup
17 changes: 16 additions & 1 deletion corpus/web/cc_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from corpus.lookup import CorpusLookup
from corpus.web.eventseries import EventSeriesAPI
from corpus.web.cc_stats import Dashboard

from corpus.web.cc_queries import ConferenceCorpusQueries

class ConferenceCorpusWebserver(InputWebserver):
"""
Webserver for the Conference Corpus
Expand All @@ -34,11 +35,16 @@ def __init__(self):
InputWebserver.__init__(self, config=ConferenceCorpusWebserver.get_config())
self.lookup=CorpusLookup()
self.event_series_api=EventSeriesAPI(self.lookup)
self.queries=ConferenceCorpusQueries()

@ui.page("/stats")
async def stats(client:Client):
return await self.show_stats_dashboard()

@ui.page("/queries")
async def show_queries(client:Client):
return await self.show_queries()

@app.get('/eventseries/{name}')
def get_eventseries(name: str, bks: str = "", reduce: bool = False, format: str = "json"):
# Use the parameters directly in the API calls
Expand Down Expand Up @@ -73,6 +79,15 @@ async def show_stats_dashboard(self):
def show():
self.dashboard=Dashboard(self)
await self.setup_content_div(show)

async def show_queries(self):
"""
show the list of available queries
"""
def show():
ui.html(self.queries.as_html())
await self.setup_content_div(show)


def configure_menu(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies = [
# https://github.com/WolfgangFahl/PyGenericSpreadSheet/
"pyGenericSpreadSheet>=0.2.4",
#https://pypi.org/project/ngwidgets/
"ngwidgets>=0.4.3"
"ngwidgets>=0.4.4"
]

dynamic = ["version"]
Expand Down
38 changes: 38 additions & 0 deletions tests/test_cc_queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Created on 22.11.2023
@author: wf
This module contains tests for querying the Conference Corpus.
The `TestConferenceCorpusQueries` class extends `Basetest` and provides
methods to test queries against the Conference Corpus. It particularly focuses
on the ability to generate HTML markup from the corpus queries.
"""

from ngwidgets.basetest import Basetest
from corpus.web.cc_queries import ConferenceCorpusQueries

class TestConferenceCorpusQueries(Basetest):
"""Test class for querying the Conference Corpus.
This class tests the functionality of ConferenceCorpusQueries,
specifically its ability to convert query results to HTML format.
"""

def test_cc_queries(self) -> None:
"""
Test the generation of HTML markup from conference corpus queries.
This method checks if the ConferenceCorpusQueries can successfully
convert its query results into HTML format and contains specific
HTML tags indicating a successful conversion.
"""
ccq = ConferenceCorpusQueries()
markup = ccq.as_html()
debug = self.debug
# Uncomment the next line to enable debugging output
# debug = True
if debug:
print(markup)
self.assertTrue("<li><a" in markup) # Checking for specific HTML tag in output

0 comments on commit 4a030e3

Please sign in to comment.