在 Sparql 更新中使用 Javascript 变量
Using a Javascript Variable in Sparql update
我正在使用我的 Nodejs 应用程序在我的 Ontology 模型上 运行(发送 HTTP Post)Sparql 更新。现在我的代码中有一个存储整数值的变量 'seconds'。现在如何将该变量包含到我的查询中。
var request = require('request');
var querystring = require('querystring');
var seconds = ROB_8_StopSeconds-ROB_8_StartSeconds;
var myquery2 = querystring.stringify({
update: "PREFIX test:<http://www.semanticweb.org/muhammad/ontologies/2017/2/untitled-ontology-14#> insert {[] test:Actual_Production_Time ?s; test:hasValue_ROB1 ?p; test:hasTime ?now.} where {values (?s ?p ) {(test:Actual_Production_Time 2000)} bind (now() as ?now)}"
});
request.post({headers: {'content-type': 'application/x-www-form-urlencoded'},
url: 'http://localhost:3030/DS-1/?' + myquery2},
function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log('successful update');
//console.log(body);
} else {
console.log(response.statusCode)
console.warn(error);
}
});
现在在我的查询中,如您所见,我正在发送 2000,但我想发送变量 'seconds' 而不是 2000。我该如何实现?其次,我的模型是否能够从变量 'seconds'.
中提取整数值
P.s: 我已经在 dotNetRDF 文档中搜索了答案(https://github.com/dotnetrdf/dotnetrdf/wiki),但我找不到它。
我通过简单地连接 querystring.stringify() 之外的字符串之间的变量解决了这个问题。
var seconds = ROB_8_StopSeconds - ROB_8_StartSeconds;
abc = "PREFIX test:<http://www.semanticweb.org/muhammad/ontologies/2017/2/untitled-ontology-14#> insert {[] test:Actual_Production_Time ?s; test:hasValue_ROB1 ?p; test:hasTime ?now.} where {values (?s ?p ) {(test:Actual_Production_Time "+seconds+")} bind (now() as ?now)}";
var myquery2 = querystring.stringify({
update: abc
});
我试图在 querystring.stringify() 中进行连接,但这是错误的。
我正在使用我的 Nodejs 应用程序在我的 Ontology 模型上 运行(发送 HTTP Post)Sparql 更新。现在我的代码中有一个存储整数值的变量 'seconds'。现在如何将该变量包含到我的查询中。
var request = require('request');
var querystring = require('querystring');
var seconds = ROB_8_StopSeconds-ROB_8_StartSeconds;
var myquery2 = querystring.stringify({
update: "PREFIX test:<http://www.semanticweb.org/muhammad/ontologies/2017/2/untitled-ontology-14#> insert {[] test:Actual_Production_Time ?s; test:hasValue_ROB1 ?p; test:hasTime ?now.} where {values (?s ?p ) {(test:Actual_Production_Time 2000)} bind (now() as ?now)}"
});
request.post({headers: {'content-type': 'application/x-www-form-urlencoded'},
url: 'http://localhost:3030/DS-1/?' + myquery2},
function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log('successful update');
//console.log(body);
} else {
console.log(response.statusCode)
console.warn(error);
}
});
现在在我的查询中,如您所见,我正在发送 2000,但我想发送变量 'seconds' 而不是 2000。我该如何实现?其次,我的模型是否能够从变量 'seconds'.
中提取整数值P.s: 我已经在 dotNetRDF 文档中搜索了答案(https://github.com/dotnetrdf/dotnetrdf/wiki),但我找不到它。
我通过简单地连接 querystring.stringify() 之外的字符串之间的变量解决了这个问题。
var seconds = ROB_8_StopSeconds - ROB_8_StartSeconds;
abc = "PREFIX test:<http://www.semanticweb.org/muhammad/ontologies/2017/2/untitled-ontology-14#> insert {[] test:Actual_Production_Time ?s; test:hasValue_ROB1 ?p; test:hasTime ?now.} where {values (?s ?p ) {(test:Actual_Production_Time "+seconds+")} bind (now() as ?now)}";
var myquery2 = querystring.stringify({
update: abc
});
我试图在 querystring.stringify() 中进行连接,但这是错误的。