How to use the rdf-ext.createLiteral function in rdf-ext

To help you get started, we’ve selected a few rdf-ext 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 simplerdf / simplerdf / lib / core.js View on Github external
// don't cache array values, because we cache the complete array
          if (!options.array) {
            this.objects[predicate] = value
          }
        }
      } else if (typeof value === 'boolean') {
        this.graph.add(rdf.createTriple(
          this.iri,
          predicate,
          rdf.createLiteral(value, null, 'http://www.w3.org/2001/XMLSchema#boolean')))
      } else if (typeof value === 'number') {
        this.graph.add(rdf.createTriple(
          this.iri,
          predicate,
          rdf.createLiteral(value, null, rdf.createNamedNode('http://www.w3.org/2001/XMLSchema#double'))))
      } else {
        console.warn('unsupported type: ' + typeof value)
      }
    })
  }
github simplerdf / simplerdf / lib / core.js View on Github external
} else if (typeof value === 'object') {
        if (value.interfaceName) {
          this.graph.add(rdf.createTriple(this.iri, predicate, value))
        } else {
          this.graph.add(rdf.createTriple(this.iri, predicate, value._core.iri))

          // don't cache array values, because we cache the complete array
          if (!options.array) {
            this.objects[predicate] = value
          }
        }
      } else if (typeof value === 'boolean') {
        this.graph.add(rdf.createTriple(
          this.iri,
          predicate,
          rdf.createLiteral(value, null, 'http://www.w3.org/2001/XMLSchema#boolean')))
      } else if (typeof value === 'number') {
        this.graph.add(rdf.createTriple(
          this.iri,
          predicate,
          rdf.createLiteral(value, null, rdf.createNamedNode('http://www.w3.org/2001/XMLSchema#double'))))
      } else {
        console.warn('unsupported type: ' + typeof value)
      }
    })
  }
github simplerdf / simplerdf / examples / get-save.js View on Github external
var blogPostNode = rdf.createBlankNode()

var blogGraph = rdf.createGraph([
  rdf.createTriple(
    rdf.createNamedNode(blogIri),
    rdf.createNamedNode('http://schema.org/name'),
    rdf.createLiteral('simple blog')),
  rdf.createTriple(
    rdf.createNamedNode(blogIri),
    rdf.createNamedNode('http://schema.org/post'),
    blogPostNode),
  rdf.createTriple(
    blogPostNode,
    rdf.createNamedNode('http://schema.org/headline'),
    rdf.createLiteral('first blog post'))
])

var blogStore = rdf.createStore()

blogStore.add('http://example.org/blog', blogGraph).then(function () {
  return simple(blogContext, blogIri, null, blogStore).get()
}).then(function (blog) {
  console.log('fetched blog from: ' + blog._iri.toString())
  console.log(blog.name)
  console.log(blog.post.shift().headline)

  // move blog to new location
  blog.iri('http://example.org/new-blog')

  return blog.save()
}).then(function (blog) {
github simplerdf / simplerdf / lib / core.js View on Github external
values.forEach((value) => {
      if (typeof value === 'string') {
        if (options.namedNode) {
          this.graph.add(rdf.createTriple(this.iri, predicate, rdf.createNamedNode(value)))
        } else {
          this.graph.add(rdf.createTriple(this.iri, predicate, rdf.createLiteral(value)))
        }
      } else if (typeof value === 'object') {
        if (value.interfaceName) {
          this.graph.add(rdf.createTriple(this.iri, predicate, value))
        } else {
          this.graph.add(rdf.createTriple(this.iri, predicate, value._core.iri))

          // don't cache array values, because we cache the complete array
          if (!options.array) {
            this.objects[predicate] = value
          }
        }
      } else if (typeof value === 'boolean') {
        this.graph.add(rdf.createTriple(
          this.iri,
          predicate,
github rdf2h / rdf2h / dist / rdf2h.js View on Github external
if (Array.isArray(value)) {
    return value.map(function (item) {
      return node(item)
    })
  }

  if (typeof value === 'object' && value.interfaceName) {
    return value
  }

  if (typeof value === 'string') {
    if (clownface.options.detectNamedNodes && clownface.options.namedNodeRegEx.test(value)) {
      return rdf.createNamedNode(value)
    } else {
      return rdf.createLiteral(value)
    }
  } else if (typeof value === 'number') {
    return rdf.createLiteral(value + '')
  } else {
    throw new Error('unknown type')
  }
}
github rdf2h / rdf2h / dist / rdf2h.js View on Github external
return node(item)
    })
  }

  if (typeof value === 'object' && value.interfaceName) {
    return value
  }

  if (typeof value === 'string') {
    if (clownface.options.detectNamedNodes && clownface.options.namedNodeRegEx.test(value)) {
      return rdf.createNamedNode(value)
    } else {
      return rdf.createLiteral(value)
    }
  } else if (typeof value === 'number') {
    return rdf.createLiteral(value + '')
  } else {
    throw new Error('unknown type')
  }
}
github rdf2h / rdf2h / dist / rdf2h.js View on Github external
if (section.startsWith("^")) {
                                return node.in(RDF2h.resolveCurie(section.substring(1)));
                            } else {
                                return node.out(RDF2h.resolveCurie(section));
                            }
                            }
                        }
                    }
                    subNode = resolveSection(pathSections[0]);
                    if (pathSections.length === 1) {
                        var resultNodes = subNode.nodes();
                        if (resultNodes.length === 0) {
                            //handling pseudo properties of literals
                            if (node.nodes()[0].language) {
                                if (RDF2h.resolveCurie(pathSections[0]) === "http://purl.org/dc/terms/language") {
                                    return [rdf.createLiteral(node.nodes()[0].language)];
                                }
                            }
                            if (node.nodes()[0].datatype) {
                                if (RDF2h.resolveCurie(pathSections[0]) === RDF2h.resolveCurie("rdf:type")) {
                                    return [node.nodes()[0].datatype];
                                }
                            }
                        }
                        return resultNodes;
                    }
                    return resolveSubPath(subNode,pathSections.slice(1))    
                }
                var pathSections = path.split("/").filter(function(e) { return e.length > 0})
github simplerdf / simplerdf / examples / get-save.js View on Github external
'@id': 'http://schema.org/post',
    '@container': '@set'
  },
  headline: 'http://schema.org/headline',
  content: 'http://schema.org/content'
}

var blogIri = 'http://example.org/blog'

var blogPostNode = rdf.createBlankNode()

var blogGraph = rdf.createGraph([
  rdf.createTriple(
    rdf.createNamedNode(blogIri),
    rdf.createNamedNode('http://schema.org/name'),
    rdf.createLiteral('simple blog')),
  rdf.createTriple(
    rdf.createNamedNode(blogIri),
    rdf.createNamedNode('http://schema.org/post'),
    blogPostNode),
  rdf.createTriple(
    blogPostNode,
    rdf.createNamedNode('http://schema.org/headline'),
    rdf.createLiteral('first blog post'))
])

var blogStore = rdf.createStore()

blogStore.add('http://example.org/blog', blogGraph).then(function () {
  return simple(blogContext, blogIri, null, blogStore).get()
}).then(function (blog) {
  console.log('fetched blog from: ' + blog._iri.toString())