Skip to content

Commit

Permalink
Add error messaging to generator tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-fox committed Jan 17, 2024
1 parent d71ebff commit 576b030
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ Creating a NGSI-LD @context file for normalized interactions datamodels.context-

生成されたファイルを開くと、次の構造が見つかります:

```jsonld
```json
{
"@context": {
"type": "@type",
Expand Down Expand Up @@ -578,7 +578,7 @@ NGSI-LD の `@context` はすべての NGSI-LD CRUD 操作に使用され、デ

たとえば、これは _normalized_ NGSI-LD 形式の `Building` です:

```jsonld
```json
{
"id": "urn:ngsi-ld:Building:001",
"type": "Building",
Expand Down Expand Up @@ -649,7 +649,7 @@ datamodels.context.jsonld created

生成されたファイルを開くと、次の構造が見つかります:

```jsonld
```json
{
"@context": {
"type": "@type",
Expand Down Expand Up @@ -741,7 +741,7 @@ datamodels.context.jsonld created
`options=keyValues` パラメータを使用して NGSI-LD リクエストが行われた場合、レスポンスは完全な NGSI-LD
オブジェクトではなく、以下のような、一般的な JSON-LD オブジェクトです:

```jsonld
```json
{
"id": "urn:ngsi-ld:Building:001",
"type": "Building",
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,15 @@ resulting `@context` file will be understandable to the widest number of systems
> Swagger, and indeed you could generate a simple `@context` file without it, but the data held within in has been used
> to help generate a rich [`@graph`](https://w3c.github.io/json-ld-syntax/#dfn-graph-object) and more comprehensive
> documentation.
>

> [!CAUTION]
> The simple NGSI-LD `@context` generator in the tutorial defaults to using `uri.fiware.org` namespaces and updates with
> corrected URIs based on the `x-ngsi.uri` and `x-ngsi.uri-prefix` attributes. The code and defaults found within this
> tutorial can be altered if necessary.
>
> For more complex scenarios, additional `@context` generation tools can be found on
> the [Smart Data Models](https://smartdatamodels.org/) website.
## Amending Models

Expand Down Expand Up @@ -491,7 +496,7 @@ datamodels.context-ngsi.jsonld created

Opening the generated file, the following structure can be found:

```jsonld
```json
{
"@context": {
"type": "@type",
Expand Down Expand Up @@ -554,7 +559,7 @@ the default _normalized_ format. The _normalized_ format includes a structure of

For example this is a `Building` in _normalized_ NGSI-LD format:

```jsonld
```json
{
"id": "urn:ngsi-ld:Building:001",
"type": "Building",
Expand Down Expand Up @@ -639,7 +644,7 @@ datamodels.context.jsonld created

Opening the generated file, the following structure can be found:

```jsonld
```json
{
"@context": {
"type": "@type",
Expand Down Expand Up @@ -729,7 +734,7 @@ Further information about `@graph` can be found in the section on
If NGSI-LD requests are made using the `options=keyValues` parameter, the response a generic JSON-LD object (as shown
below) rather than a full NGSI-LD object:

```jsonld
```json
{
"id": "urn:ngsi-ld:Building:001",
"type": "Building",
Expand Down
10 changes: 8 additions & 2 deletions context-file-generator/bin/jsonld.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ function replaceCommonContextURLs(text) {
}

function addEntry(text, type, key, uri, value, expand) {
if (key.includes(':')){
console.error(`Unable to process file. Attribute contains colons ${key}`)
process.exit(1);
}
if (expand) {
if (type === 'Property' || type === 'GeoProperty') {
if (type === 'Property' || type === 'GeoProperty' || type === 'LanguageProperty') {
let entry;
if (value.type === 'object') {
entry = '"' + key + '": "' + uri + '"';
Expand All @@ -39,13 +43,15 @@ function addEntry(text, type, key, uri, value, expand) {
text.push(entry);
} else if (type === 'Relationship') {
text.push('"' + key + '": {"@id": "' + uri + '", "@type": "@id"}');
} else if (type === 'EnumProperty') {
} else if (type === 'EnumProperty' || type === 'VocabProperty' ) {
text.push('"' + key + '": {"@id": "' + uri + '", "@type": "@vocab"}');
}
} else if (
type === 'Property' ||
type === 'Relationship' ||
type === 'EnumProperty' ||
type === 'VocabProperty' ||
type === 'LanguageProperty' ||
type === 'GeoProperty'
) {
text.push('"' + key + '": "' + uri + '"');
Expand Down

0 comments on commit 576b030

Please sign in to comment.