Code Monkey home page Code Monkey logo

jsonld-to-cypher's Introduction

JSON-LD to Cypher

Compile JSON-LD (Decentralized Identifiers and Verifiable Credentials) to Cypher.

CI Branches Functions Lines Statements Jest coverage NPM

๐Ÿšง Warning Experimental ๐Ÿ”ฅ

Usage

Command Line

npm i -g @transmute/jsonld-to-cypher@latest
jsonld-to-cypher convert ./examples/minimal-vc/minimal-vc.json
jsonld-to-cypher convert ./examples/v1-vc-jwt/v1-vc-jwt.jwt -- --type jwt

Library

npm i @transmute/jsonld-to-cypher@latest --save

Transforming Verifiable Credentials

See minimal-vc.

const { cypher, graph } = await Cypher.fromDocument({
  '@context': ['https://www.w3.org/2018/credentials/v1'],
  type: ['VerifiableCredential'],
  issuer: 'https://example.edu/issuers/565049',
  issuanceDate: '2010-01-01T19:23:24Z',
  credentialSubject: {
    id: 'did:example:ebfeb1f712ebc6f1c276e12ec21',
  },
})

Action

name: Demo
on: [workflow_dispatch]
jobs:
  merge:
    runs-on: ubuntu-latest
    name: Merge
    steps:
      - name: Merge Query from Document
        uses: transmute-industries/[email protected]
        id: merge
        with:
          neo4j-uri: ${{ secrets.NEO4J_URI }}
          neo4j-user: ${{ secrets.NEO4J_USERNAME }}
          neo4j-password: ${{ secrets.NEO4J_PASSWORD }}
          operation: merge
          document: |
            {
              "@context": ["https://www.w3.org/2018/credentials/v1"],
              "type": ["VerifiableCredential"],
              "issuer": "https://example.edu/issuers/565049",
              "issuanceDate": "2010-01-01T19:23:24Z",
              "credentialSubject": {
                "id": "did:example:ebfeb1f712ebc6f1c276e12ec21"
              }
            }

Development

npm i
npm t

Testing CLI

npm run jsonld-to-cypher convert ./examples/minimal-vc/minimal-vc.json

jq -r '.jws' ./examples/v1-vc-jwt/v1-vc-jwt.json > ./examples/v1-vc-jwt/v1-vc-jwt.jwt

npm run jsonld-to-cypher convert ./examples/v1-vc-jwt/v1-vc-jwt.jwt -- --type jwt

Testing GitHub Action with Act

act -j neo4j-merge-documents-local --secret-file .env

Installing Neo4j Desktop

See https://neo4j.com.

jsonld-to-cypher's People

Contributors

acarnagey avatar bluisanatransmute avatar ipbyrne avatar nissimsan avatar or13 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jsonld-to-cypher's Issues

Failing node merge

I'm attempting to import the same resource twice, as part of two separately generated/imported cypher scripts.

I'm getting Node(45) already exists with label Resourceand propertyuri = 'did:key:z6Mkf8r9cUvN48fPhmi13FMgFDg6ccVqmt1spny4f2QoymDP' which seems like unintended behavior. If the URI is the same, then the nodes should merge. But it seems like MERGE doesn't do the trick for some reason.

image

Predicate relationships improvement

image

MERGE ( n0 : DecentralizedIdentifier { id: "did:key:z6MktiSzqF9kqwdU8VkdBKx56EYzXfpgnNPUAGznpicNiWfn" ,  description: "Melting and Pouring Steel", name: "Slovenian Steel" } )
MERGE ( n3 : UniformResourceLocator { id: "https://schema.org/description"  } )
MERGE (n3)-[e1: Predicate { id : "urn:uuid:a8e3cd1f-8e13-4630-b0f9-6dbaf9112471", predicate: "https://vocabulary.transmute.industries/ns/dynamic/#disclosedPredicate" } ]->(n0)

I think the idea of this e1 "Predicate" edge is to include the term definition of n0's description property. However, there isn't a direct relationship to the property (only its node), so in this can you couldn't tell whether "https://schema.org/description" defines description or name.

It also creates a quite cluttered picture with all those nodes and predicate definitions.

A simpler model would to include the term definitions alongside , instead of the above three statements, just:

MERGE ( n0 : DecentralizedIdentifier { id: "did:key:z6MktiSzqF9kqwdU8VkdBKx56EYzXfpgnNPUAGznpicNiWfn" ,  description: "Melting and Pouring Steel", descriptionTerm: "https://schema.org/description", name: "Slovenian Steel", nameTerm: "https://schema.org/name" } )

Introduce `term` keyword to simplify data model

Continuing from #4...

I propose that the following JSON-LD:

{
  "@context": [
    "https://www.w3.org/2018/credentials/v1",
    "https://w3id.org/traceability/v1"
  ],
  "id": "urn:uuid:a8e3cd1f-8e13-4630-b0f9-6dbaf9112471",
  "type": [
    "VerifiableCredential",
    "CommercialInvoiceCredential"
  ],
  "name": "Commercial Invoice Certificate",
  "issuanceDate": "2022-10-08T12:30:00Z",
  "issuer": {
    "type": [
      "Organization"
    ],
    "id": "did:key:z6MktiSzqF9kqwdU8VkdBKx56EYzXfpgnNPUAGznpicNiWfn",
    "name": "Slovenian Steel",
    "description": "Melting and Pouring Steel"
  }
}

Could be both simpler and more precisely represented like this:

MERGE ( n0 : Organization { id: "did:key:z6MktiSzqF9kqwdU8VkdBKx56EYzXfpgnNPUAGznpicNiWfn", description: "Melting and Pouring Steel", descriptionTerm: "https://schema.org/description", name: "Slovenian Steel", nameTerm: "https://schema.org/name" } )
MERGE ( n2 : OrganizationTerm { id: "https://schema.org/Organization"  } )
MERGE ( n5 : CommercialInvoiceCredentialTerm { id: "https://w3id.org/traceability#CommercialInvoiceCredential"  } )
MERGE ( n6 : VerifiableCredentialTerm { id: "https://www.w3.org/2018/credentials#VerifiableCredential"  } )
MERGE ( n9 : VerifiableCredential : CommercialInvoiceCredential { id: "urn:uuid:a8e3cd1f-8e13-4630-b0f9-6dbaf9112471" ,  name: "Commercial Invoice Certificate", nameTerm: "https://schema.org/name", issuanceDate: datetime("2022-10-08T12:30:00Z"), issuanceDateTerm: "https://www.w3.org/2018/credentials#issuanceDate" } )
MERGE (n0)-[e0: Type { id : "urn:uuid:a8e3cd1f-8e13-4630-b0f9-6dbaf9112471", predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" } ]->(n2)
MERGE (n9)-[e5: Type { id : "urn:uuid:a8e3cd1f-8e13-4630-b0f9-6dbaf9112471", predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" } ]->(n5)
MERGE (n9)-[e6: Type { id : "urn:uuid:a8e3cd1f-8e13-4630-b0f9-6dbaf9112471", predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" } ]->(n6)
MERGE (n9)-[e7: Issuer { id : "urn:uuid:a8e3cd1f-8e13-4630-b0f9-6dbaf9112471", predicate: "https://www.w3.org/2018/credentials#issuer" } ]->(n0)
RETURN n0,n2,n5,n6,n9

image

Specifically, I am introducing a term keyword which is used:

  1. For property definitions, for example for name and nameTerm
  2. For class definitions, which the type edges can point at, for example OrganizationTerm.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.