How to use the rdflib.quad 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 dan-f / modelld / test / field.spec.js View on Github external
it('returns a quad with no graph URI for quads without a source', () => {
      const quad = rdf.quad(
        rdf.NamedNode.fromValue('https://example.com/profile#me'),
        vocab.foaf('name'),
        rdf.Literal.fromValue('dan')
      )
      expect(name.fromQuad(quad).originalQuad(rdf, quad.subject)).toEqual(
        rdf.quad(
          rdf.NamedNode.fromValue('https://example.com/profile#me'),
          vocab.foaf('name'),
          rdf.Literal.fromValue('dan')
        )
      )
    })
github dan-f / modelld / test / model.spec.js View on Github external
it(`does not add ${type} fields to the diff`, () => {
          const phoneQuad = rdf.quad(
            rdf.NamedNode.fromValue(webId),
            vocab.foaf('phone'),
            rdf.Literal.fromValue('tel:444-444-4444'),
            rdf.NamedNode.fromValue(source)
          )
          expect(model.addQuad(phoneQuad).diff(rdf))
            .toEqual({})
        })
      })
github dan-f / modelld / test / field.spec.js View on Github external
it(`converts ${type} both ways`, () => {
          const subject = rdf.NamedNode.fromValue('https://example.com/profile#me')
          const originalResource = rdf.NamedNode.fromValue(
            'https://example.com/another-private-resource'
          )
          const quad = rdf.quad(
            subject,
            vocab.foaf('age'),
            rdf.Literal.fromValue(firstVal),
            originalResource
          )
          const firstField = age.fromQuad(quad)
          expect(firstField.value).toBe(firstVal)
          expect(firstField.toQuad(rdf, subject)).toEqual(quad)
          const newField = firstField.set({value: nextVal})
          expect(newField.value).toBe(nextVal)
          expect(newField.toQuad(rdf, subject))
            .toEqual(
              rdf.quad(
                subject,
                vocab.foaf('age'),
                rdf.Literal.fromValue(nextVal),
github dan-f / modelld / test / field.spec.js View on Github external
it('parses unknown datatypes as strings', () => {
      const object = new rdf.Literal(
        'foo', null, rdf.NamedNode.fromValue('https://example.com/datatypes#unknown')
      )
      const quad = rdf.quad(
        rdf.NamedNode.fromValue('https://example.com/profile/#me'),
        vocab.foaf('name'),
        object
      )
      const field = name.fromQuad(quad)
      expect(field.value).toBe('foo')
    })
  })
github dan-f / modelld / test / field.spec.js View on Github external
it('rejects values that are mis-matched with their type', () => {
      const subject = rdf.NamedNode.fromValue('https://example.com/profile#me')
      const predicate = rdf.NamedNode.fromValue('http://www.w3.org/ns/solid/terms#read')
      const datatype = rdf.NamedNode.fromValue('http://www.w3.org/2001/XMLSchema#boolean')
      const object = new rdf.Literal('foo', null, datatype)
      const quad = rdf.quad(subject, predicate, object)
      expect(() => {
        hasRead.fromQuad(quad)
      }).toThrow(/Cannot parse/)
    })
github dan-f / modelld / test / field.spec.js View on Github external
it('constructs a namedNode when the field is specified as a NamedNode', () => {
      const storage = fieldFactory(vocab.pim('storage'))
      const storageField = storage('https://example.databox.me/storage/', namedGraph, {namedNode: true})
      expect(storageField.toQuad(rdf, rdf.NamedNode.fromValue('https://example.com/storage#this')))
        .toEqual(
          rdf.quad(
            rdf.NamedNode.fromValue('https://example.com/storage#this'),
            vocab.pim('storage'),
            rdf.NamedNode.fromValue('https://example.databox.me/storage/'),
            rdf.NamedNode.fromValue(namedGraph)
          )
        )
    })
  })
github dan-f / modelld / test / field.spec.js View on Github external
it('converts datetimes both ways', () => {
      const subject = rdf.NamedNode.fromValue('https://example.com/profile#me')
      const predicate = rdf.NamedNode.fromValue('http://purl.org/dc/terms/date')
      const originalResource = rdf.NamedNode.fromValue(
        'https://example.com/another-private-resource'
      )
      const d = new Date('2016-1-1')
      const quad = rdf.quad(
        subject,
        predicate,
        rdf.Literal.fromValue(d),
        originalResource
      )
      const firstField = date.fromQuad(quad)
      expect(firstField.value.toString()).toBe(d.toString())
      expect(firstField.toQuad(rdf, subject)).toEqual(quad)
      const d2 = new Date('2020-1-1')
      const newField = firstField.set({value: d2})
      expect(newField.value.toString()).toBe(d2.toString())
      expect(newField.toQuad(rdf, subject))
        .toEqual(
          rdf.quad(
            subject,
            predicate,
github dan-f / modelld / test / field.spec.js View on Github external
it('returns the original quad for a quad-constructed field', () => {
        const quad = rdf.quad(
          rdf.NamedNode.fromValue('https://example.com/profile#me'),
          vocab.foaf('name'),
          rdf.Literal.fromValue('dan'),
          rdf.NamedNode.fromValue('https://unknown-server.com/resource')
        )
        expect(name.fromQuad(quad).toQuad(rdf, quad.subject)).toEqual(quad)
      })
    })
github dan-f / modelld / test / field.spec.js View on Github external
'https://example.com/another-private-resource'
          )
          const quad = rdf.quad(
            subject,
            vocab.foaf('age'),
            rdf.Literal.fromValue(firstVal),
            originalResource
          )
          const firstField = age.fromQuad(quad)
          expect(firstField.value).toBe(firstVal)
          expect(firstField.toQuad(rdf, subject)).toEqual(quad)
          const newField = firstField.set({value: nextVal})
          expect(newField.value).toBe(nextVal)
          expect(newField.toQuad(rdf, subject))
            .toEqual(
              rdf.quad(
                subject,
                vocab.foaf('age'),
                rdf.Literal.fromValue(nextVal),
                originalResource
              )
            )
        })
      })
github dan-f / modelld / test / field.spec.js View on Github external
const d = new Date('2016-1-1')
      const quad = rdf.quad(
        subject,
        predicate,
        rdf.Literal.fromValue(d),
        originalResource
      )
      const firstField = date.fromQuad(quad)
      expect(firstField.value.toString()).toBe(d.toString())
      expect(firstField.toQuad(rdf, subject)).toEqual(quad)
      const d2 = new Date('2020-1-1')
      const newField = firstField.set({value: d2})
      expect(newField.value.toString()).toBe(d2.toString())
      expect(newField.toQuad(rdf, subject))
        .toEqual(
          rdf.quad(
            subject,
            predicate,
            rdf.Literal.fromValue(d2),
            originalResource
          )
        )
    })