Skip to content

Commit

Permalink
Updated nanopub validation
Browse files Browse the repository at this point in the history
  • Loading branch information
wshayes committed Sep 2, 2020
1 parent 5a98c47 commit 3b2bc7f
Show file tree
Hide file tree
Showing 11 changed files with 420 additions and 356 deletions.
22 changes: 17 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Expand Up @@ -42,6 +42,7 @@ pytest-mypy = "^0.6.2"
pylint = "^2.5.3"
pydocstyle = "^5.0.2"
colorama = "^0.4.3"
pygments = "^2.6.1"

[tool.poetry.extras]
api = ["fastapi^0.61.0", "gunicorn^20.0.4", "uvicorn^0.11.8", "python-multipart^0.0.5", "starlette_prometheus^0.7.0", "aiofiles^0.5.0"]
Expand Down
48 changes: 47 additions & 1 deletion src/bel/core/utils.py
Expand Up @@ -8,7 +8,7 @@
import re
import tempfile
from timeit import default_timer
from typing import Any, Mapping
from typing import Any, Mapping, List, Tuple, Optional
from functools import wraps, partial
import asyncio

Expand Down Expand Up @@ -202,4 +202,50 @@ async def run(*args, loop=None, executor=None, **kwargs):
loop = asyncio.get_event_loop()
pfunc = partial(func, *args, **kwargs)
return await loop.run_in_executor(executor, pfunc)

return run


def html_wrap_span(
string: str, pairs: List[Tuple[int, int]], css_class: Optional[str] = "accentuate"
) -> str:
"""Wrap targeted area of Assertion with html highlighting
to visualize where the error or warning is targeted
Args:
string: string to insert html span - wrapping the accentuated content
pairs: list of tuples of start/end locations in the string to wrap
css_class: optional class to insert into the span html tag - defaults to 'accentuate'
Returns:
string with html spans around accentuated text
"""

start_html_span = f'<span class="{css_class}">'
end_html_span = "</span>"
last_right_section = ""

result_str = ""
for idx, pair in enumerate(pairs):
(left, right) = pair

if idx == 0:
result_str += string[0:left]
else:
result_str += last_right_section

result_str += start_html_span
result_str += string[left:right]
result_str += end_html_span

if idx < len(pairs) - 1:
next_left = pairs[idx + 1][0]
right_section = string[right:next_left]
last_right_section = right_section
else:
right_section = string[right:]

result_str += right_section

return result_str

0 comments on commit 3b2bc7f

Please sign in to comment.