Как объединить несколько файлов JSON-LD в один файл JSON-LD? - PullRequest
0 голосов
/ 04 июня 2019

У меня есть следующий список, который содержит семантические описания с идентификаторами.

const list = [{
    semanticDescription: {
    "@context": {
      "schema": "https://schema.org/",
      "fno": "https://w3id.org/function/ontology#"
    },
    "@graph": [
      {
        "@id": "Machine001",
        "schema:potentialAction" : {
          "@type": ["schema:PhotographAction", "fno:Function"],
          "@id": "takePhoto"
        }
      },
      {
        "@id": "takePhoto",
        "fno:expects": {
          "@list": [{ "@id": "h" }, { "@id": "w" }]
        },
        "fno:returns": {
          "@list": []
        }
      }]
    },
    identifier: 1
   },
   {
       semanticDescription: {
       "@context": {
         "schema": "https://schema.org/",
         "fno": "https://w3id.org/function/ontology#",
       },
       "@graph": [
         {
           "@id": "Machine001",
           "schema:potentialAction" : {
             "@type": ["schema:Transferaction", "fno:Function"],
             "@id": "takePhoto"
           }
         },
         {
           "@id": "takePhoto",
           "fno:expects": {
             "@list": [{ "@id": "adress" }, { "@id": "postalCode" }]
           },
           "fno:returns": {
             "@list": []
           }
         }]
       },
       identifier: 2
   }
]

Как мне создать один файл JSON-LD, содержащий только описания semantic? Я хочу вернуться в ответ на запрос GET, имеющий mimeType: 'jsonld'.

ожидаемый допустимый вывод JSON-LD

Вот мой недействительный с дубликатами ключей output.jsonld

{
    "@context": {
      "schema": "https://schema.org/",
      "fno": "https://w3id.org/function/ontology#"
    },
    "@graph": [
      {
        "@id": "Machine001",
        "schema:potentialAction" : {
          "@type": ["schema:PhotographAction", "fno:Function"],
          "@id": "takePhoto"
        }
      },
      {
        "@id": "takePhoto",
        "fno:expects": {
          "@list": [{ "@id": "h" }, { "@id": "w" }]
        },
        "fno:returns": {
          "@list": []
        }
      }],
    "@graph": [
        {
        "@id": "Machine001",
        "schema:potentialAction" : {
            "@type": ["schema:Transferaction", "fno:Function"],
            "@id": "takePhoto"
        }
        },
        {
        "@id": "takePhoto",
        "fno:expects": {
            "@list": [{ "@id": "adress" }, { "@id": "postalCode" }]
        },
        "fno:returns": {
            "@list": []
        }
        }]
}

Есть ли способ получить файл JSON-LD, содержащий несколько объектов?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...