How to use the rdflib.st 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 / solid-ui / src / pad.js View on Github external
prev = here
        next = kb.any(here, PAD('next'))
        queue = next
        queueProperty = 'newlinesBefore'
      }
      tr1 = ele.parentNode
    } else {
      prev = subject
      next = subject
      tr1 = undefined
    }

    var chunk = UI.widgets.newThing(padDoc)
    var label = chunk.uri.slice(-4)

    var del = [$rdf.st(prev, PAD('next'), next, padDoc)]
    var ins = [
      $rdf.st(prev, PAD('next'), chunk, padDoc),
      $rdf.st(chunk, PAD('next'), next, padDoc),
      $rdf.st(chunk, ns.dc('author'), me, padDoc),
      $rdf.st(chunk, ns.sioc('content'), '', padDoc)
    ]
    if (indent > 0) {
      // Do not inherit
      ins.push($rdf.st(chunk, PAD('indent'), indent, padDoc))
    }

    console.log('    Fresh chunk ' + label + ' proposed')
    updater.update(del, ins, function (uri, ok, errorBody, _xhr) {
      if (!ok) {
        // alert("Error writing new line " + label + ": " + errorBody);
        console.log('    ERROR writing new line ' + label + ': ' + errorBody)
github solid / solid-ui / src / authn / authn.ts View on Github external
widgets.complain(context, msg)
      }
    } // putIndex

    context.index = context.index || {}
    context.index[visibility] = context.index[visibility] || []
    let newIndex
    if (context.index[visibility].length === 0) {
      newIndex = $rdf.sym(`${relevant.dir().uri + visibility}TypeIndex.ttl`)
      console.log(`Linking to new fresh type index ${newIndex}`)
      if (!confirm(`OK to create a new empty index file at ${newIndex}, overwriting anything that is now there?`)) {
        throw new Error('cancelled by user')
      }
      console.log(`Linking to new fresh type index ${newIndex}`)
      const addMe = [
        $rdf.st(context.me, ns.solid(`${visibility}TypeIndex`), newIndex, relevant)
      ]
      try {
        await updatePromise(kb.updater, [], addMe)
      } catch (err) {
        const msg = `Error saving type index link saving back ${newIndex}: ${err}`
        widgets.complain(context, msg)
        return context
      }

      console.log(`Creating new fresh type index file${newIndex}`)
      await putIndex(newIndex)
      context.index[visibility].push(newIndex) // @@ wait
    } else {
      // officially exists
      const ixs = context.index[visibility]
      try {
github solid / solid-panes / scratchpad / data.js View on Github external
function getSetContentsStatements(contents, creationDate, pad, store, user) {
    var lines = contents.split('\n');
    var statementsToAdd = lines.reduce(function (statementsToAdd, lineContents, lineNr) {
        var line = store.sym(pad.uri + ("_line" + lineNr));
        var prevLine = (lineNr === 0) ? pad : statementsToAdd[statementsToAdd.length - 1].subject;
        statementsToAdd.push($rdf.st(prevLine, ns.pad('next'), line, pad.doc()), $rdf.st(line, ns.sioc('content'), lineContents, pad.doc()), $rdf.st(line, ns.dc('created'), creationDate, pad.doc()));
        if (user) {
            statementsToAdd.push($rdf.st(line, ns.dc('author'), user, pad.doc()));
        }
        return statementsToAdd;
    }, []);
    var lastLine = statementsToAdd[statementsToAdd.length - 1].subject;
    statementsToAdd.push($rdf.st(lastLine, ns.pad('next'), pad, pad.doc()));
    var oldLines = store.statementsMatching(null, ns.pad('next'), null, pad.doc(), false)
        .map(function (statement) { return statement.object; })
        .filter(function (line) { return line.value !== pad.value; });
    var statementsPerOldLine = oldLines.map(function (oldLine) {
        return store.statementsMatching(oldLine, null, null, pad.doc(), false);
    });
    var statementsToDelete = statementsPerOldLine.reduce(function (statementsToDelete, oldLineStatements) {
        statementsToDelete.push.apply(statementsToDelete, oldLineStatements);
        return statementsToDelete;
    }, []);
    var startingLink = store.statementsMatching(pad, ns.pad('next'), null, pad.doc(), true)[0];
    if (startingLink) {
        statementsToDelete.push(startingLink);
    }
    return [statementsToDelete, statementsToAdd];
}
github solid / solid-ui / src / widgets / buttons.js View on Github external
var deleteAttachment = function (target) {
    kb.updater.update($rdf.st(subject, predicate, target, doc), [], function (
      uri,
      ok,
      errorBody,
      _xhr
    ) {
      if (ok) {
        refresh()
      } else {
        complain('Error deleting one: ' + errorBody)
      }
    })
  }
  var createNewRow = function (target) {
github solid / solid-panes / scratchpad / data.ts View on Github external
(statementsToAdd, lineContents, lineNr) => {
      const line = store.sym(pad.uri + `_line${lineNr}`)
      const prevLine = (lineNr === 0) ? pad : statementsToAdd[statementsToAdd.length - 1].subject
      statementsToAdd.push(
        $rdf.st(prevLine, ns.pad('next'), line, pad.doc()),
        $rdf.st(line, ns.sioc('content'), lineContents, pad.doc()),
        $rdf.st(line, ns.dc('created'), creationDate, pad.doc())
      )
      if (user) {
        statementsToAdd.push($rdf.st(line, ns.dc('author'), user, pad.doc()))
      }

      return statementsToAdd
    },
    [] as $rdf.Statement[]
github solid / solid-panes / scratchpad / data.ts View on Github external
export function getInitialisationStatements (
  creationDate: Date,
  store: IndexedFormula,
  user?: NamedNode
): [NamedNode, Statement[]] {
  const storeNamespaces = store.namespaces
  const padName = creationDate.getTime()
  const pad = store.sym(storeNamespaces.pub + padName + '/index.ttl#this')

  const statementsToAdd = [
    $rdf.st(pad, ns.rdf('type'), ns.pad('Notepad'), pad.doc()),
    $rdf.st(pad, ns.dc('title'), `Scratchpad (${creationDate.toLocaleDateString()})`, pad.doc()),
    $rdf.st(pad, ns.dc('created'), creationDate, pad.doc())
  ]
  if (user) {
    statementsToAdd.push(
      $rdf.st(pad, ns.dc('author'), user, pad.doc())
    )
  }

  return [pad, statementsToAdd]
}
github solid / solid-panes / scratchpad / data.js View on Github external
function getInitialisationStatements(creationDate, store, user) {
    var storeNamespaces = store.namespaces;
    var padName = creationDate.getTime();
    var pad = store.sym(storeNamespaces.pub + padName + '/index.ttl#this');
    var statementsToAdd = [
        $rdf.st(pad, ns.rdf('type'), ns.pad('Notepad'), pad.doc()),
        $rdf.st(pad, ns.dc('title'), "Scratchpad (" + creationDate.toLocaleDateString() + ")", pad.doc()),
        $rdf.st(pad, ns.dc('created'), creationDate, pad.doc())
    ];
    if (user) {
        statementsToAdd.push($rdf.st(pad, ns.dc('author'), user, pad.doc()));
    }
    return [pad, statementsToAdd];
}
exports.getInitialisationStatements = getInitialisationStatements;
github solid / solid-panes / scratchpad / data.js View on Github external
function getInitialisationStatements(creationDate, store, user) {
    var storeNamespaces = store.namespaces;
    var padName = creationDate.getTime();
    var pad = store.sym(storeNamespaces.pub + padName + '/index.ttl#this');
    var statementsToAdd = [
        $rdf.st(pad, ns.rdf('type'), ns.pad('Notepad'), pad.doc()),
        $rdf.st(pad, ns.dc('title'), "Scratchpad (" + creationDate.toLocaleDateString() + ")", pad.doc()),
        $rdf.st(pad, ns.dc('created'), creationDate, pad.doc())
    ];
    if (user) {
        statementsToAdd.push($rdf.st(pad, ns.dc('author'), user, pad.doc()));
    }
    return [pad, statementsToAdd];
}
exports.getInitialisationStatements = getInitialisationStatements;
github jolocom / smartwallet-app / src / js / lib / agents / chat.js View on Github external
_getParticipantACLTriple(uri, webId) {
    const ACL = $rdf.Namespace('http://www.w3.org/ns/auth/acl#')
    const subject = $rdf.sym(`${uri}#participant`)

    return $rdf.st(subject, ACL('agent'), $rdf.sym(webId))
  }
github solid / solid-panes / scratchpad / data.js View on Github external
var statementsToAdd = lines.reduce(function (statementsToAdd, lineContents, lineNr) {
        var line = store.sym(pad.uri + ("_line" + lineNr));
        var prevLine = (lineNr === 0) ? pad : statementsToAdd[statementsToAdd.length - 1].subject;
        statementsToAdd.push($rdf.st(prevLine, ns.pad('next'), line, pad.doc()), $rdf.st(line, ns.sioc('content'), lineContents, pad.doc()), $rdf.st(line, ns.dc('created'), creationDate, pad.doc()));
        if (user) {
            statementsToAdd.push($rdf.st(line, ns.dc('author'), user, pad.doc()));
        }
        return statementsToAdd;
    }, []);
    var lastLine = statementsToAdd[statementsToAdd.length - 1].subject;