Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix html-manifest.jsonld#tr-011 #31

Merged
merged 3 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions tests/test_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ def _get_id(test_case: TestCase) -> str | None:
ids=_get_id,
)
def test_to_rdf(test_case: TestCase):
raw_document = test_case.raw_document

if isinstance(test_case.result, str):
try:
expanded_document = yaml_ld.to_rdf(
raw_document,
rdf_document = yaml_ld.to_rdf(
test_case.input,
extract_all_scripts=test_case.extract_all_scripts,
)
except YAMLLDError as error:
Expand All @@ -53,10 +51,10 @@ def test_to_rdf(test_case: TestCase):
pytest.fail(str(FailureToFail(
expected_error_code=test_case.result,
raw_document=test_case.raw_document,
expanded_document=expanded_document,
expanded_document=rdf_document,
)))

actual_dataset = yaml_ld.to_rdf(raw_document)
actual_dataset = yaml_ld.to_rdf(test_case.raw_document)
raw_expected_quads = test_case.raw_expected_document

actual_triples = actual_dataset['@default']
Expand Down
4 changes: 2 additions & 2 deletions yaml_ld/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from yaml_ld.errors import CycleDetected, MappingKeyError
from yaml_ld.models import (
Document, ProcessingMode,
DocumentLoader, BaseOptions, ExtractAllScripts,
DocumentLoader, BaseOptions, ExtractAllScripts, SerializedDocument,
)
from yaml_ld.parse import parse # noqa: WPS347

Expand All @@ -21,7 +21,7 @@ class ExpandOptions(BaseOptions):


def expand( # noqa: C901, WPS211
document: str | bytes | Document | Path | URL,
document: SerializedDocument | Document,
base: Annotated[str | None, Help('The base IRI to use.')] = None,
context: Annotated[
Document | None,
Expand Down
13 changes: 12 additions & 1 deletion yaml_ld/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
from enum import Enum
from typing import Any, Annotated
from pathlib import Path
from typing import Any, Annotated, NewType

from pydantic import BaseModel, Field
from urlpath import URL

Document = dict[str, Any] # type: ignore
DocumentLoader = Any # type: ignore # FIXME: This is actually a callable.


SerializedDocument = Annotated[ # type: ignore
str | bytes | Path | URL,
(
'Either a document serialized to a sequence of characters (or bytes) '
'or a location where one can be found.'
),
]


ExtractAllScripts = Annotated[
bool,
'Extract all JSON-LD script elements, as opposed to only the first one.',
Expand Down
9 changes: 7 additions & 2 deletions yaml_ld/to_rdf.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from pathlib import Path
from typing import Annotated

from pyld import jsonld
from urlpath import URL

import yaml_ld
from yaml_ld.annotations import Help
from yaml_ld.models import Document, DocumentLoader, ExtractAllScripts
from yaml_ld.models import (
Document, DocumentLoader, ExtractAllScripts,
SerializedDocument,
)
from yaml_ld.rdf import Dataset


def to_rdf(
document: str | bytes | Document,
document: SerializedDocument | Document,
base: Annotated[str | None, Help('The base IRI to use.')] = None,
extract_all_scripts: ExtractAllScripts = False,
document_loader: DocumentLoader | None = None,
Expand Down
Loading