Spaces:
Sleeping
Sleeping
Sync from GitHub via hub-sync
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"""Gradio demo for ``bcql_py`` query validation.
|
| 2 |
|
| 3 |
A small, illustrative web UI that lets users paste a BlackLab Corpus Query Language
|
| 4 |
-
(BCQL) query, optionally pick or customize a
|
| 5 |
and inspect parsing / validation results in real time.
|
| 6 |
|
| 7 |
Run locally with::
|
|
@@ -191,7 +191,7 @@ def _build_custom_spec(
|
|
| 191 |
span_tags: str,
|
| 192 |
relations: str,
|
| 193 |
) -> CorpusSpec:
|
| 194 |
-
"""Construct a
|
| 195 |
closed = _parse_closed_attributes(closed_attrs)
|
| 196 |
span_tag_list = _parse_csv(span_tags)
|
| 197 |
relation_list = _parse_csv(relations)
|
|
@@ -207,7 +207,7 @@ def _build_custom_spec(
|
|
| 207 |
|
| 208 |
|
| 209 |
def _format_syntax_error(error: BCQLSyntaxError) -> str:
|
| 210 |
-
"""Format a
|
| 211 |
lines = ["**Syntax error**", "", f"> {error.message}"]
|
| 212 |
if error.query and error.position is not None:
|
| 213 |
lines.extend(
|
|
@@ -223,7 +223,7 @@ def _format_syntax_error(error: BCQLSyntaxError) -> str:
|
|
| 223 |
|
| 224 |
|
| 225 |
def _format_validation_error(error: BCQLValidationError) -> str:
|
| 226 |
-
"""Format a
|
| 227 |
if len(error.issues) == 1:
|
| 228 |
issue = error.issues[0]
|
| 229 |
parts = [
|
|
@@ -272,8 +272,7 @@ def validate_query(
|
|
| 272 |
|
| 273 |
Returns:
|
| 274 |
Tuple of ``(status_html, error_markdown, ast_dict, canonical_bcql)``.
|
| 275 |
-
``ast_dict`` is a plain dict
|
| 276 |
-
when no AST was produced.
|
| 277 |
"""
|
| 278 |
query = (query or "").strip()
|
| 279 |
if not query:
|
|
@@ -337,14 +336,14 @@ def validate_query(
|
|
| 337 |
def validate_example(
|
| 338 |
query: str, preset_name: str
|
| 339 |
) -> tuple[str, str, dict[str, Any]]:
|
| 340 |
-
"""Wrapper around
|
| 341 |
return validate_query(
|
| 342 |
query, preset_name, False, "", "", False, True, True, "", "", False
|
| 343 |
)
|
| 344 |
|
| 345 |
|
| 346 |
def render_spec_description(preset_name: str) -> str:
|
| 347 |
-
"""Markdown description of the selected preset's
|
| 348 |
spec = PRESETS.get(preset_name)
|
| 349 |
if spec is None:
|
| 350 |
return (
|
|
|
|
| 1 |
"""Gradio demo for ``bcql_py`` query validation.
|
| 2 |
|
| 3 |
A small, illustrative web UI that lets users paste a BlackLab Corpus Query Language
|
| 4 |
+
(BCQL) query, optionally pick or customize a [CorpusSpec][bcql_py.validation.CorpusSpec],
|
| 5 |
and inspect parsing / validation results in real time.
|
| 6 |
|
| 7 |
Run locally with::
|
|
|
|
| 191 |
span_tags: str,
|
| 192 |
relations: str,
|
| 193 |
) -> CorpusSpec:
|
| 194 |
+
"""Construct a [CorpusSpec][bcql_py.validation.CorpusSpec] from the custom-spec form fields."""
|
| 195 |
closed = _parse_closed_attributes(closed_attrs)
|
| 196 |
span_tag_list = _parse_csv(span_tags)
|
| 197 |
relation_list = _parse_csv(relations)
|
|
|
|
| 207 |
|
| 208 |
|
| 209 |
def _format_syntax_error(error: BCQLSyntaxError) -> str:
|
| 210 |
+
"""Format a [BCQLSyntaxError][bcql_py.exceptions.BCQLSyntaxError] as a fenced markdown snippet with caret."""
|
| 211 |
lines = ["**Syntax error**", "", f"> {error.message}"]
|
| 212 |
if error.query and error.position is not None:
|
| 213 |
lines.extend(
|
|
|
|
| 223 |
|
| 224 |
|
| 225 |
def _format_validation_error(error: BCQLValidationError) -> str:
|
| 226 |
+
"""Format a [BCQLValidationError][bcql_py.exceptions.BCQLValidationError] as a markdown bullet list."""
|
| 227 |
if len(error.issues) == 1:
|
| 228 |
issue = error.issues[0]
|
| 229 |
parts = [
|
|
|
|
| 272 |
|
| 273 |
Returns:
|
| 274 |
Tuple of ``(status_html, error_markdown, ast_dict, canonical_bcql)``.
|
| 275 |
+
``ast_dict`` is a plain dict; empty when no AST was produced.
|
|
|
|
| 276 |
"""
|
| 277 |
query = (query or "").strip()
|
| 278 |
if not query:
|
|
|
|
| 336 |
def validate_example(
|
| 337 |
query: str, preset_name: str
|
| 338 |
) -> tuple[str, str, dict[str, Any]]:
|
| 339 |
+
"""Wrapper around validate_query for ``gr.Examples`` (2-arg signature)."""
|
| 340 |
return validate_query(
|
| 341 |
query, preset_name, False, "", "", False, True, True, "", "", False
|
| 342 |
)
|
| 343 |
|
| 344 |
|
| 345 |
def render_spec_description(preset_name: str) -> str:
|
| 346 |
+
"""Markdown description of the selected preset's [CorpusSpec][bcql_py.validation.CorpusSpec]."""
|
| 347 |
spec = PRESETS.get(preset_name)
|
| 348 |
if spec is None:
|
| 349 |
return (
|