GithubHelp home page GithubHelp logo

rubensworks / rdf-string.js Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 5.0 432 KB

Convenience functions for creating and serializing RDF terms and quads

License: MIT License

TypeScript 100.00%
rdf string linked-data rdfjs ntriples nquads hacktoberfest

rdf-string.js's Introduction

RDF String

Build status Coverage Status npm version

This package contains utility functions to convert between the string-based and RDFJS representations of RDF terms, quads and triples.

If you are looking for a Turtle-based string syntax, have a look at RDF String Turtle

This allows for convenient and compact interaction with RDF terms and quads, as they can be serialized as plain JSON.

This string-based representation is based on the old triple representation of N3.js. Namely, quads are represented as follows:

{
  subject:   'http://example.org/cartoons#Tom',
  predicate: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
  object:    'http://example.org/cartoons#Cat'
  graph:     'http://example.org/myGraph'
}

Different terms types in quads are represented as follows:

  • URLs, URIs and IRIs are simple strings: 'http://example.org/cartoons#Tom'
  • Literals are represented as double quoted strings: '"Tom"', '"Tom"@en-gb', '"1"^^http://www.w3.org/2001/XMLSchema#integer'
  • Variables are prefixed by ?: '?variableName'

Usage

The following examples assume the following imports:

import * as RdfDataModel from "rdf-data-model";
import * as RdfString from "rdf-string";

Term to string

Convert an RDFJS term to the string-based representation.

// Prints http://example.org
console.log(RdfString.termToString(RdfDataModel.namedNode('http://example.org')));

// Prints _:b1
console.log(RdfString.termToString(RdfDataModel.blankNode('b1')));

// Prints "abc"
console.log(RdfString.termToString(RdfDataModel.literal('abc')));

// Prints "abc"@en-us
console.log(RdfString.termToString(RdfDataModel.literal('abc', 'en-us')));

// Prints "abc"^^http://example.org/
console.log(RdfString.termToString(RdfDataModel.literal('abc', namedNode('http://example.org/'))));

// Prints ?v1
console.log(RdfString.termToString(RdfDataModel.variable('v1')));

// Prints empty string
console.log(RdfString.termToString(RdfDataModel.defaultGraph()));

String to term

Convert an string-based term to the RDFJS representation.

Optionally, a custom RDFJS DataFactory can be provided as second argument to create terms instead of the built-in DataFactory.

// Outputs a named node
RdfString.stringToTerm('http://example.org');

// Outputs a blank node
RdfString.stringToTerm('_:b1');

// Outputs a literal
RdfString.stringToTerm('"abc"');

// Outputs a literal with a language tag
RdfString.stringToTerm('"abc"@en-us');

// Outputs a literal with a datatype
RdfString.stringToTerm('"abc"^^http://example.org/');

// Outputs a variable
RdfString.stringToTerm('?v1');

// Outputs a default graph
RdfString.stringToTerm('');

Quad to string-based quad

Convert an RDFJS quad to a string-based quad.

// Prints { subject: 'http://example.org', predicate: 'http://example.org', object: '"abc"', graph: '' }
console.log(RdfString.quadToStringQuad(RdfDataModel.triple(
  namedNode('http://example.org'),
  namedNode('http://example.org'),
  literal('abc'),
)));

String-based quad to quad

Converts a string-based quad to an RDFJS quad.

Optionally, a custom RDFJS DataFactory can be provided as second argument to create quads and terms instead of the built-in DataFactory.

// Outputs a quad
RdfString.stringQuadToQuad({
  subject: 'http://example.org',
  predicate: 'http://example.org',
  object: '"abc"',
  graph: '',
});

License

This software is written by Ruben Taelman. These utility functions are inspired by the implementation of N3.js.

This code is released under the MIT license.

rdf-string.js's People

Contributors

dimitriylol avatar greenkeeper[bot] avatar jeswr avatar renovate-bot avatar renovate[bot] avatar rubensworks avatar thewilkybarkid avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rdf-string.js's Issues

An in-range update of ts-jest is breaking the build 🚨

The devDependency ts-jest was updated from 23.1.4 to 23.10.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ts-jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for 23.10.0

ts-jest, reloaded!

  • lots of new features including full type-checking and internal cache (see changelog)
  • improved performances
  • Babel not required anymore
  • improved (and growing) documentation
  • a ts-jest Slack community where you can find some instant help
  • end-to-end isolated testing over multiple jest, typescript and babel versions
Commits

The new version differs by 293 commits.

  • 0e5ffed chore(release): 23.10.0
  • 3665609 Merge pull request #734 from huafu/appveyor-optimizations
  • 45d44d1 Merge branch 'master' into appveyor-optimizations
  • 76e2fe5 ci(appveyor): cache npm versions as well
  • 191c464 ci(appveyor): try to improve appveyor's config
  • 0f31b42 Merge pull request #733 from huafu/fix-test-snap
  • 661853a Merge branch 'master' into fix-test-snap
  • aa7458a Merge pull request #731 from kulshekhar/dependabot/npm_and_yarn/tslint-plugin-prettier-2.0.0
  • 70775f1 ci(lint): run lint scripts in series instead of parallel
  • a18e919 style(fix): exclude package.json from tslint rules
  • 011b580 test(config): stop using snapshots for pkg versions
  • 7e5a3a1 build(deps-dev): bump tslint-plugin-prettier from 1.3.0 to 2.0.0
  • fbe90a9 Merge pull request #730 from kulshekhar/dependabot/npm_and_yarn/@types/node-10.10.1
  • a88456e build(deps-dev): bump @types/node from 10.9.4 to 10.10.1
  • 54fd239 Merge pull request #729 from kulshekhar/dependabot/npm_and_yarn/prettier-1.14.3

There are 250 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • @rdfjs/types *
  • rdf-data-factory ^1.1.0
  • @types/jest ^27.0.0
  • coveralls ^3.0.0
  • jest ^27.0.0
  • manual-git-changelog ^1.0.0
  • pre-commit ^1.2.2
  • ts-jest ^27.0.0
  • tslint ^6.0.0
  • tslint-eslint-rules ^5.3.1
  • typescript ^5.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

An in-range update of @types/jest is breaking the build 🚨

The devDependency @types/jest was updated from 24.0.9 to 24.0.10.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).
  • βœ… coverage/coveralls: First build on greenkeeper/@types/jest-24.0.10 at 100.0% (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Allow custom DataFactories

Allowing the user to choose which DataFactory is used when translating a string to a Term would allow for more flexibility.

Improve documentation

Now that N3.js has been ported to RDFJS, the README doesn't document its internal string-based term representation anymore, while we still refer to it from our README.

So we should document in full how this string representation works in our README.

stringToTerm does not validate URIs

The methods stringToTermallows you to create a NamedNodewith whatever value, while only IRIs are in fact "possible". See https://github.com/rubensworks/rdf-string.js/blob/master/lib/TermUtil.ts#L100

The fact whether it should do this kind of validation is debatable, because both N3.js and the RDFJS spec don't mention this at object level.
However, it seem literals that literals are being validated (https://github.com/rubensworks/rdf-string.js/blob/master/lib/TermUtil.ts#L77), so IRIs might as well.

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.