How to use the rdflib.namedNode function in rdflib

To help you get started, we’ve selected a few rdflib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github solid / node-solid-server / test / allow.js View on Github external
const assert = require('chai').assert
const { getRequestingWebId, verifyDelegator } = require('../lib/handlers/allow')
const rdf = require('rdflib')
const ns = require('solid-namespace')(rdf)

const alice = 'https://alice.com'  // principal
const agentWebId = 'https://agent.example.com'  // secretary

const verifiedSecretaryGraph = rdf.graph()
verifiedSecretaryGraph.add(
    rdf.namedNode(alice),
    ns.acl('delegates'),
    rdf.namedNode(agentWebId)
  )
const notVerifiedSecretaryGraph = rdf.graph()

describe('handlers/allow.js', () => {
  describe('getRequestingWebId()', () => {
    const emptyFetchDocument = () => {}

    it('should return null if no webId and no onBehalfOf present', () => {
      let webId  // no secretary
      let onBehalfOf  // no principal

      return getRequestingWebId(webId, onBehalfOf, emptyFetchDocument)
        .then(userId => {
          assert.equal(userId, null,
github TopQuadrant / shacl / js / src / rdflib-graph.js View on Github external
var errorHandler = require("debug")("rdflib-graph::error");


// Monkey Patching rdflib, Literals, BlankNodes and NamedNodes
var exLiteral = $rdf.literal("a", "de");
Object.defineProperty(Object.getPrototypeOf(exLiteral), "lex", { get: function () { return this.value } });
Object.getPrototypeOf(exLiteral).isBlankNode = function () { return false };
Object.getPrototypeOf(exLiteral).isLiteral = function () { return true };
Object.getPrototypeOf(exLiteral).isURI = function () { return false };

var exBlankNode = $rdf.blankNode();
Object.getPrototypeOf(exBlankNode).isBlankNode = function () { return true };
Object.getPrototypeOf(exBlankNode).isLiteral = function () { return false };
Object.getPrototypeOf(exBlankNode).isURI = function () { return false };

var exNamedNode = $rdf.namedNode("urn:x-dummy");
Object.getPrototypeOf(exNamedNode).isBlankNode = function () { return false };
Object.getPrototypeOf(exNamedNode).isLiteral = function () { return false };
Object.getPrototypeOf(exNamedNode).isURI = function () { return true };



var RDFLibGraph = function (store) {
    this.store = store;
};

RDFLibGraph.prototype.find = function (s, p, o) {
    return new RDFLibGraphIterator(this.store, s, p, o);
};

RDFLibGraph.prototype.query = function () {
    return rdfquery(this);
github solid / solid-ui / src / authn / authn.ts View on Github external
export function saveUser (
  webId: $rdf.NamedNode | string | null,
  context?: AuthenticationContext
): $rdf.NamedNode | null {
  // @@ TODO Remove the need for having context as output argument
  let webIdUri: string
  if (webId) {
    webIdUri = (typeof webId === 'string') ? webId : webId.uri
    const me = $rdf.namedNode(webIdUri)
    if (context) {
      context.me = me
    }
    return me
  }
  return null
}
github solid / solid-ui / src / widgets / peoplePicker.js View on Github external
kb.fetcher.nowOrWhenFetched(webId, (ok, err) => {
        if (!ok) {
          this.onGroupChanged(err)
          return reject(err)
        }
        // make sure it's a valid person, group, or entity (for now just handle
        // webId)
        const webIdNode = rdf.namedNode(webId)
        const rdfClass = kb.any(webIdNode, ns.rdf('type'))
        if (!rdfClass || !rdfClass.equals(ns.foaf('Person'))) {
          return reject(
            new Error(
              `Only people supported right now. (tried to add something of type ${
                rdfClass.value
              })`
            )
          )
        }
        return resolve(webIdNode)
      })
    }).then(webIdNode => {
github solid / node-solid-server / test / unit / account-manager.js View on Github external
it('parses and returns the agent mailto from the root acl', () => {
      let userAccount = UserAccount.from({ username: 'alice' })

      let rootAclGraph = rdf.graph()
      rootAclGraph.add(
        rdf.namedNode('https://alice.example.com/.acl#owner'),
        ns.acl('agent'),
        rdf.namedNode('mailto:alice@example.com')
      )

      let store = {
        suffixAcl: '.acl',
        getGraph: sinon.stub().resolves(rootAclGraph)
      }

      let options = { host, multiUser: true, store }
      let accountManager = AccountManager.from(options)

      return accountManager.loadAccountRecoveryEmail(userAccount)
        .then(recoveryEmail => {
          expect(recoveryEmail).to.equal('alice@example.com')
        })
github solid / node-solid-server / test / unit / add-cert-request.js View on Github external
.then(graph => {
          let webId = rdf.namedNode(certificate.webId)
          let key = rdf.namedNode(certificate.keyUri)

          expect(graph.anyStatementMatching(webId, ns.cert('key'), key))
            .to.exist
          expect(graph.anyStatementMatching(key, ns.rdf('type'), ns.cert('RSAPublicKey')))
            .to.exist
          expect(graph.anyStatementMatching(key, ns.cert('modulus')))
            .to.exist
          expect(graph.anyStatementMatching(key, ns.cert('exponent')))
            .to.exist
        })
    }).timeout(3000)
github solid / node-solid-server / test / unit / add-cert-request.js View on Github external
.then(graph => {
          let webId = rdf.namedNode(certificate.webId)
          let key = rdf.namedNode(certificate.keyUri)

          expect(graph.anyStatementMatching(webId, ns.cert('key'), key))
            .to.exist
          expect(graph.anyStatementMatching(key, ns.rdf('type'), ns.cert('RSAPublicKey')))
            .to.exist
          expect(graph.anyStatementMatching(key, ns.cert('modulus')))
            .to.exist
          expect(graph.anyStatementMatching(key, ns.cert('exponent')))
            .to.exist
        })
    }).timeout(3000)
github solid / node-solid-server / test / integration / ldp.js View on Github external
.then(graph => {
          assert.ok(graph)
          let fullname = $rdf.namedNode('http://example.org/stuff/1.0/fullname')
          let match = graph.match(null, fullname)
          assert.equal(match[0].object.value, 'Dave Beckett')
        })
    })
github solid / node-solid-server / lib / models / account-manager.js View on Github external
addCertKeyToGraph (certificate, graph) {
    let webId = rdf.namedNode(certificate.webId)
    let key = rdf.namedNode(certificate.keyUri)
    let timeCreated = rdf.literal(certificate.date.toISOString(), ns.xsd('dateTime'))
    let modulus = rdf.literal(certificate.modulus, ns.xsd('hexBinary'))
    let exponent = rdf.literal(certificate.exponent, ns.xsd('int'))
    let title = rdf.literal('Created by solid-server')
    let label = rdf.literal(certificate.commonName)

    graph.add(webId, ns.cert('key'), key)
    graph.add(key, ns.rdf('type'), ns.cert('RSAPublicKey'))
    graph.add(key, ns.dct('title'), title)
    graph.add(key, ns.rdfs('label'), label)
    graph.add(key, ns.dct('created'), timeCreated)
    graph.add(key, ns.cert('modulus'), modulus)
    graph.add(key, ns.cert('exponent'), exponent)

    return graph
github solid / oidc-auth-manager / src / preferred-provider.js View on Github external
.then(response => {
      let providerTerm = rdf.namedNode('http://www.w3.org/ns/solid/terms#oidcIssuer')
      let providerUri = store.anyValue(rdf.namedNode(webId), providerTerm)
      return providerUri
    }, err => {
      let error = new Error(`Could not reach Web ID ${webId} to discover provider`)