How to use the rdflib.serialize 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 / lib / utils.js View on Github external
function serialize (graph, baseUri, contentType, callback) {
  try {
                // target, kb, base, contentType, callback
    $rdf.serialize(null, graph, baseUri, contentType, function (err, result) {
      if (err) {
        console.log(err)
        return callback(err)
      }
      if (result === undefined) {
        return callback(new Error('Error serializing the graph to ' +
          contentType))
      }

      return callback(null, result)
    })
  } catch (err) {
    console.log(err)
    callback(err)
  }
}
github redaktor / owl2jsonschema.js / lib / index.js View on Github external
var h = (res && res.hasOwnProperty('headers')) ? res.headers : null;
	var b = (h && h.hasOwnProperty('location')) ? h['location'] : this.uri;
	if (this.options.baseUrl === '') this.options.baseUrl = b;
	if (err) return this.parseFile(); 
	// console.log( res.headers, res.statusCode );
	
	if (res.statusCode == 200) {
		var xmlData = '';
		this.options.contentType = this.getType(this.uri, res, this.options.contentType);
		if (this.options.contentType === 'application/rdf+xml') {
			xmlData = body;
		} else {
			var graph = new rdflib.IndexedFormula();
			// TODO - base parameter
			var rawData = rdflib.parse(body, graph, this.uri, this.options.contentType);
			xmlData = rdflib.serialize(rawData, graph, this.uri, 'application/rdf+xml');
		}
		
		var json = this.parseOWL(xmlData, this.options);
		return this.cb(null, json);
	}
}
github solid / solid-panes / src / pad / padPane.ts View on Github external
g.add(a, auth('accessTo'), doc, acl)
      g.add(a, auth('agent'), me, acl)
      g.add(a, auth('mode'), auth('Read'), acl)
      g.add(a, auth('mode'), auth('Write'), acl)
      g.add(a, auth('mode'), auth('Control'), acl)

      a = g.sym(aclURI + '#a2')
      g.add(a, ns.rdf('type'), auth('Authorization'), acl)
      g.add(a, auth('accessTo'), doc, acl)
      g.add(a, auth('agentClass'), ns.foaf('Agent'), acl)
      g.add(a, auth('mode'), auth('Read'), acl)
      if (allWrite) {
        g.add(a, auth('mode'), auth('Write'), acl)
      }
      // TODO: Figure out why `serialize` isn't on the type definition according to TypeScript:
      return serialize(acl, g, aclURI, 'text/turtle')
    }
github jolocom / smartwallet-app / src / js / lib / agents / solid-wallet.js View on Github external
g.add(ownerUrl, PRED.countryOfBirth, entryValue.birthCountry.value)
      g.add(ownerUrl, PRED.address, addrBNode)

      // Owner address info
      g.add(
        addrBNode,
        PRED.street,
        entryValue.physicalAddress.streetWithNumber.value
      )
      g.add(addrBNode, PRED.zip, entryValue.physicalAddress.zip.value)
      g.add(addrBNode, PRED.city, entryValue.physicalAddress.city.value)
      g.add(addrBNode, PRED.state, entryValue.physicalAddress.state.value)
      g.add(addrBNode, PRED.country, entryValue.physicalAddress.country.value)
    }

    return rdf.serialize(undefined, g, entryFileUrl, 'text/turtle')
  },
github inrupt / wac-ldp / src / lib / rdf / RdfLibStoreManager.ts View on Github external
// 1. check the cache
    if (this.stores[url.toString()]) {
      return this.getRepresentationFromStore(url)
    }

    // 2. check remote
    debug('getResourceData - local?', url.host, this.serverRootDomain)
    if (!url.host.endsWith(this.serverRootDomain)) {
      return this.getRepresentationFromRemote(url)
    }

    // 3. container
    const resourceData = await this.storage.read(url)
    if (resourceData.resourceType === ResourceType.LdpBc) {
      const quadStream = (resourceData as ResourceDataLdpBc).getQuads((options && options.preferMinimalContainer))
      const data = rdflib.serialize(undefined, rdflib.graph(), url, 'text/turtle')
      return makeResourceData('text/turtle', data)
    }

    // 4. translate
    if (requiresTranslation(resourceData, options)) {
      await this.load(url)
      return this.getRepresentationFromStore(url)
    }

    // 5. stream
    debug('streaming', resourceData)
    return makeResourceData(resourceData.contentType as string, (await streamToBuffer((resourceData as ResourceDataLdpNr).getBody())).toString())
  }
  setRepresentation (url: URL, resourceData: ResourceData) {
github solid / node-solid-server / lib / handlers / patch.js View on Github external
targetKB.applyPatch(patchObject, target, function (err) {
          if (err) {
            var message = err.message || err // returns string at the moment
            debug('PATCH FAILED. Returning 409. Message: \'' + message + '\'')
            return cb(error(409, 'Error when applying the patch'))
          }
          debug('PATCH -- Patched. Writeback URI base ' + targetURI)
          var data = $rdf.serialize(target, targetKB, targetURI, targetContentType)
          // debug('Writeback data: ' + data)

          fs.writeFile(filename, data, {encoding: 'utf8'}, function (err, data) {
            if (err) {
              return cb(error(500, 'Failed to write file back after patch: ' + err))
            }
            debug('PATCH -- applied OK (sync)')
            return cb(null, patchKB)
          })
        })
      })
github inrupt / wac-ldp / src / lib / rdf / RdfLibStoreManager.ts View on Github external
getRepresentationFromStore (url: URL): ResourceData {
    const body = rdflib.serialize(undefined, this.stores[url.toString()], url, 'text/turtle')
    // const body = this.stores[url.toString()].toNT()
    return makeResourceData('text/turtle', body)
  }
github inrupt / wac-ldp / src / lib / rdf / StoreManager.ts View on Github external
debug('patchObject', patchObject)
    if (appendOnly && typeof patchObject.delete !== 'undefined') {
      debug('appendOnly and patch contains deletes')
      throw new ErrorResult(ResultType.AccessDenied)
    }
    await new Promise((resolve, reject) => {
      this.stores[url.toString()].applyPatch(patchObject, this.stores[url.toString()].sym(url.toString()), (err: Error) => {
        if (err) {
          reject(err)
        } else {
          resolve()
        }
      })
    })
    debug('after patch', this.stores[url.toString()].toNT())
    return rdflib.serialize(undefined, this.stores[url.toString()], url.toString(), 'text/turtle')
  }
github cwrc / CWRC-WriterBase / src / js / entities / annotationsManager.js View on Github external
rdflib.parse(JSON.stringify(annotation), store, doc.uri, 'application/ld+json', (err, kb) => {
                    try {
                        var result = rdflib.serialize(doc, kb, doc.uri, 'application/rdf+xml');
                        if (result !== undefined) {
                            var xml = me.w.utilities.stringToXML(result);
                            resolve(xml);
                        } else {
                            reject(err);
                        }
                    } catch (e2) {
                        reject(e2);
                    }
                });
            } catch (e1) {
github solid / node-solid-server / lib / requests / sharing-request.js View on Github external
async saveProfileGraph (ldp, store, webId) {
    const text = $rdf.serialize(undefined, store, this.getWebIdFile(webId), 'text/turtle')
    await ldp.put(webId, intoStream(text), 'text/turtle')
  }