Skip to content
Snippets Groups Projects
Verified Commit c85b0c2e authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

feat(Aggregator): API for (html) rendering

parent 119b76af
No related branches found
No related tags found
1 merge request!69Resolve "add example notebook for counting all words in published text/xml"
Pipeline #442585 passed
......@@ -100,3 +100,61 @@ class Aggregator:
response = self._requests.get(url + textgrid_uris, params={ 'sid': sid },
timeout=self._config.http_timeout)
return response
@overload
def render(self,
textgrid_uris: str,
sid: Optional[str] = None,
stylesheet_uri: Optional[str] = None,
mediatype: Optional[str] = None,
linkPattern: Optional[str] = None,
sandbox: Optional[bool] = None
) -> Response:
...
@overload
def render(self, textgrid_uris: List[str],
sid: Optional[str] = None,
stylesheet_uri: Optional[str] = None,
mediatype: Optional[str] = None,
linkPattern: Optional[str] = None,
sandbox: Optional[bool] = None
) -> Response:
...
def render(self,
textgrid_uris: Union[str, List[str]],
sid: Optional[str] = None,
stylesheet_uri: Optional[str] = None,
mediatype: Optional[str] = None,
linkPattern: Optional[str] = None,
sandbox: Optional[bool] = None
) -> Response:
"""Apply an XSLT stylesheet to one or more TextGrid URIs.
Will render (X)HTML by default with XSLT stylesheets from tei-c.org
see https://textgridlab.org/doc/services/submodules/aggregator/docs/html.html
Args:
textgrid_uris (List[str] or str): a single or a list of TextGrid URIs
sid (Optional[str], optional): Session ID. Defaults to None.
stylesheet_uri (Optional[str], optional): alternative XSLT stylesheet to use. Must be a TextGrid URI.
mediatype (Optional[str], optional): The requested content type. E.g., text/html or text/xml. Default is text/html
linkPattern (Optional[str], optional): URL pattern for links. @URI@ will be replaced with the textgrid: URI.
sandbox (Optional[bool], optional): access sandboxed data. Defaults to false
Returns:
Response: the respone with the TEI corpus in the body
"""
if isinstance(textgrid_uris, list):
textgrid_uris = ','.join(textgrid_uris)
url = self._url + '/html/'
response = self._requests.get(url + textgrid_uris,
params={
'sid': sid,
'stylesheet': stylesheet_uri,
'mediatype': mediatype,
'linkPattern': linkPattern,
'sandbox': sandbox
},
timeout=self._config.http_timeout)
return response
......@@ -93,3 +93,23 @@ class TestAggregatorIntegration:
assert res.status_code == 200
assert res.text.startswith('<?xml version=\'1.0\' encoding=\'UTF-8\'?><teiCorpus')
assert res.text.endswith('</TEI></teiCorpus>')
@staticmethod
def test_single_render(aggregator):
"""get html for single uri # noqa: DAR101
"""
uri = 'textgrid:kv2q.0'
res = aggregator.render(uri)
assert res.status_code == 200
assert res.text.startswith('<?xml version="1.0" encoding="UTF-8"?><html')
assert res.text.endswith('</body></html>')
@staticmethod
def test_render_urilist(aggregator):
"""get html for two uris # noqa: DAR101
"""
uri = ['textgrid:kv2v.0', 'textgrid:kv2q.0']
res = aggregator.render(uri)
assert res.status_code == 200
assert res.text.startswith('<?xml version="1.0" encoding="UTF-8"?><html')
assert res.text.endswith('</body></html>')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment