Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
textgrid-python-clients
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DARIAH-DE
TextGridRep
textgrid-python-clients
Commits
c85b0c2e
Verified
Commit
c85b0c2e
authored
1 year ago
by
Ubbo Veentjer
Browse files
Options
Downloads
Patches
Plain Diff
feat(Aggregator): API for (html) rendering
parent
119b76af
No related branches found
No related tags found
1 merge request
!69
Resolve "add example notebook for counting all words in published text/xml"
Pipeline
#442585
passed
1 year ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tgclients/aggregator.py
+58
-0
58 additions, 0 deletions
src/tgclients/aggregator.py
tests/integration/test_aggregatgor_integration.py
+20
-0
20 additions, 0 deletions
tests/integration/test_aggregatgor_integration.py
with
78 additions
and
0 deletions
src/tgclients/aggregator.py
+
58
−
0
View file @
c85b0c2e
...
...
@@ -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
This diff is collapsed.
Click to expand it.
tests/integration/test_aggregatgor_integration.py
+
20
−
0
View file @
c85b0c2e
...
...
@@ -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>
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment