Coder Social home page Coder Social logo

shex-methods's Introduction

shex-methods

A library to read, create, update or delete rdf nodes that fit a given shape expression.

Examples | Usage | Features | Contributing

Examples

To create a shape object you can use the generated context and types from shex-codegen.

import { Shape } from "shex-methods";
import {
  chatShex,
  ChatShape,
  ChatShapeType,
  ChatShapeContext,
} from "../resources/shex"; // generated by shex-codegen

const chat = new Shape<ChatShape>({
  id: "https://shaperepo.com/schemas/longChat#ChatShape",
  shape: chatShex,
  context: ChatShapeContext,
  type: ChatShapeType,
});

Then you can use the shape object to create nodes of this shape using plain javascript-objects for specifying data. The id of the input data will be used as the node iri of the shape so make sure to pass a valid url.

const newChat = await chat.create({
  doc: testDoc,
  data: {
    id: firstChatIri,
    type: ChatShapeType.LongChat,
    title: "Test Chat",
    author: webId,
    created: new Date(),
  },
});
const { data, errors } = newChat;

Usage

Install the package via your preferred node package manager: npm i shex-methods or yarn add shex-methods

See the auto-generated documentation to learn about all methods.

Features

Current features:

  • Can read, create, update and delete a single shape in remote resources
  • Can read multiple shapes in remote resources
  • User can specify data as primitive type or rdf node

Planned features:

  • Can do all operations on a local graph
  • Can create, update and delete many nodes at once
  • Can publish a shape to an index of shapes
  • Can subscribe to an index of shapes

Contributing

Run yarn to install dependencies and generate shape types.

Configure Environment

Make a copy of example.env and add the required environment variables for running tests that involve authentication/authorization.

Use yarn develop to start the build process in watch mode and run the tests on file changes.

shex-methods's People

Contributors

dependabot[bot] avatar l0vecraft avatar renovate-bot avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

yucukof

shex-methods's Issues

Bug: Empty langString causes ["Invalid URL: value"] error

(This is consequent to this change in shex-codegen)

Whenever a TTL file contains a rdfs:langString with an empty character sequence, such as the following

@prefix : <http://www.w3.org/ns/shapetrees#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .

:describesInstance
  a owl:ObjectProperty ;
  rdfs:domain :Description ;
  rdfs:comment ""@en ; // <- empty string
  rdfs:isDefinedBy <> ;
  rdfs:label "Describes Instance"@en .

then, the following error is thrown

    TypeError: Invalid URL: value
        at new URLImpl (/home/hba/Documents/Git/SOLID/src/node_modules/whatwg-url/dist/URL-impl.js:21:13)
        at Object.exports.setup (/home/hba/Documents/Git/SOLID/src/node_modules/whatwg-url/dist/URL.js:54:12)
        at new URL (/home/hba/Documents/Git/SOLID/src/node_modules/whatwg-url/dist/URL.js:107:22)
        at normalizeUrl (/home/hba/Documents/Git/shex-methods/lib/transform/rdfToData.js:86:23)
        at getNormalizedKeyFromContextOrSchemaPrefixes (/home/hba/Documents/Git/shex-methods/lib/transform/rdfToData.js:74:38)
        at /home/hba/Documents/Git/shex-methods/lib/transform/rdfToData.js:38:28
        at Array.map (<anonymous>)
        at absoluteToNormalized (/home/hba/Documents/Git/shex-methods/lib/transform/rdfToData.js:34:51)
        at /home/hba/Documents/Git/shex-methods/lib/transform/rdfToData.js:48:35
        at Array.map (<anonymous>)

      at ../../shex-methods/lib/validate.js:65:17

I have not been able to track the exact source of the issue, though.

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.