Skip to content

Commit ddb5d54

Browse files
authored
Add support for more x-jsonld-* keywords (#906)
- `x-jsonld-datatype` - `x-jsonld-language` - `x-jsonld-direction` - `x-jsonld-json` - `x-jsonld-graph` - `x-jsonld-reverse` Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 8adfe3c commit ddb5d54

6 files changed

Lines changed: 2568 additions & 90 deletions

File tree

benchmark/micro/jsonld.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ static auto Micro_JSONLD_Catalog(benchmark::State &state) -> void {
161161

162162
sourcemeta::blaze::Tweaks tweaks;
163163
tweaks.annotations = std::unordered_set<sourcemeta::core::JSON::StringView>{
164-
"x-jsonld-id", "x-jsonld-type"};
164+
sourcemeta::blaze::JSONLD_KEYWORDS.begin(),
165+
sourcemeta::blaze::JSONLD_KEYWORDS.end()};
165166
const auto schema_template{sourcemeta::blaze::compile(
166167
schema, sourcemeta::blaze::schema_walker,
167168
sourcemeta::blaze::schema_resolver,

contrib/jsonld.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ static auto run(const char *schema_path, const char *instance_path) -> int {
3939

4040
sourcemeta::blaze::Tweaks tweaks;
4141
tweaks.annotations = std::unordered_set<sourcemeta::core::JSON::StringView>{
42-
"x-jsonld-id", "x-jsonld-type"};
42+
sourcemeta::blaze::JSONLD_KEYWORDS.begin(),
43+
sourcemeta::blaze::JSONLD_KEYWORDS.end()};
4344
const auto schema_template{sourcemeta::blaze::compile(
4445
schema, sourcemeta::blaze::schema_walker,
4546
sourcemeta::blaze::schema_resolver,

src/output/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ target_link_libraries(sourcemeta_blaze_output PUBLIC
1717
sourcemeta::core::jsonpointer)
1818
target_link_libraries(sourcemeta_blaze_output PRIVATE
1919
sourcemeta::core::jsonld)
20+
target_link_libraries(sourcemeta_blaze_output PRIVATE
21+
sourcemeta::core::langtag)
22+
target_link_libraries(sourcemeta_blaze_output PRIVATE
23+
sourcemeta::core::text)
2024
target_link_libraries(sourcemeta_blaze_output PUBLIC
2125
sourcemeta::blaze::foundation)
2226
target_link_libraries(sourcemeta_blaze_output PUBLIC

src/output/include/sourcemeta/blaze/output_jsonld.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,33 @@
1111
#include <sourcemeta/blaze/evaluator.h>
1212
#include <sourcemeta/blaze/output_simple.h>
1313

14+
#include <array> // std::array
1415
#include <cstdint> // std::uint8_t
1516
#include <string> // std::string
1617
#include <variant> // std::variant
1718
#include <vector> // std::vector
1819

1920
namespace sourcemeta::blaze {
2021

22+
/// @ingroup output
23+
/// The x-jsonld-* keywords that jsonld() resolves. Use these as the annotation
24+
/// whitelist when compiling a schema so that its annotations are collected.
25+
inline constexpr std::array<sourcemeta::core::JSON::StringView, 8>
26+
JSONLD_KEYWORDS{{"x-jsonld-id", "x-jsonld-type", "x-jsonld-reverse",
27+
"x-jsonld-datatype", "x-jsonld-language",
28+
"x-jsonld-direction", "x-jsonld-json", "x-jsonld-graph"}};
29+
2130
/// @ingroup output
2231
/// The descriptor facet that a JSON-LD resolution error is about
23-
enum class JSONLDFacet : std::uint8_t { Type, Predicate };
32+
enum class JSONLDFacet : std::uint8_t {
33+
Type,
34+
Predicate,
35+
Datatype,
36+
Language,
37+
Direction,
38+
Graph,
39+
JSON
40+
};
2441

2542
/// @ingroup output
2643
/// The instance conforms but one of its JSON-LD annotations cannot be resolved
@@ -72,8 +89,9 @@ using JSONLDOutcome =
7289
/// })JSON");
7390
///
7491
/// sourcemeta::blaze::Tweaks tweaks;
75-
/// tweaks.annotations = std::unordered_set<sourcemeta::core::JSON::StringView>{
76-
/// "x-jsonld-id", "x-jsonld-type"};
92+
/// tweaks.annotations = std::unordered_set<sourcemeta::core::JSON::StringView>(
93+
/// sourcemeta::blaze::JSONLD_KEYWORDS.begin(),
94+
/// sourcemeta::blaze::JSONLD_KEYWORDS.end());
7795
///
7896
/// const auto schema_template{sourcemeta::blaze::compile(
7997
/// schema, sourcemeta::blaze::schema_walker,

0 commit comments

Comments
 (0)