在 Ontology 模型中根据时间对插入的数据进行排序
Sort the Inserted data on basis of Time in Ontology Model
我有一个 ontology 模型。我通过 Sparql 更新在 class 实例之一中插入整数数据。该模型随机存储数据,没有任何顺序。现在,当我想通过 Sparql Query 提取这些数据时,我希望它按插入时间的顺序排列。我怎么能做到这一点?有什么想法吗?
P.S: 我的 ontology 模型是用 Protege 软件制作的。
我的插入数据查询低于一个。
PREFIX test:<http://www.semanticweb.org/muhammad/ontologies/2017/2/untitled-ontology-14#>
INSERT {
?KPI_Variables test:hasValue_ROB1 10
} WHERE {
?KPI_Variables test:hasValue_ROB1 ?Newvalue
FILTER(?KPI_Variables= test:Actual_Production_Time)
}
为了获取数据,我使用以下查询:
PREFIX test:<http://www.semanticweb.org/muhammad/ontologies/2017/2/untitled-ontology-14#>
SELECT ?KPI_Variables ?Newvalue WHERE {
?KPI_Variables test:hasValue_ROB1 ?Newvalue
FILTER(?KPI_Variables = test:Actual_Production_Time)
} LIMIT 25
RDF 中的数据只是三元组。没有 when 将三元组添加到图中的概念。如果您需要此类信息,则需要在您的数据模型中将其显式化。 SPARQL 确实包含一个 now 函数,可让您获取查询为 运行 时的时间戳。这意味着您可以这样做:
prefix : <urn:ex:>
insert {
[] :hasSubject ?s ;
:hasPredicate ?p ;
:hasObject ?o ;
:hasTime ?now .
}
where {
#-- Fake a couple of triples
values (?s ?p ?o) {
(:a :p :b)
(:c :q :d)
}
#-- Get the current time
bind (now() as ?now)
}
现在您的图表包含如下数据:
@prefix : <urn:ex:> .
[ :hasObject :d ;
:hasPredicate :q ;
:hasSubject :c ;
:hasTime "2017-04-28T13:32:11.482+00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime>
] .
[ :hasObject :b ;
:hasPredicate :p ;
:hasSubject :a ;
:hasTime "2017-04-28T13:32:11.482+00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime>
] .
你可以这样查询:
prefix : <urn:ex:>
select ?s ?p ?o ?time {
[] :hasSubject ?s ;
:hasPredicate ?p ;
:hasObject ?o ;
:hasTime ?time
}
order by ?time
s,p,o,time
urn:ex:c,urn:ex:q,urn:ex:d,2017-04-28T13:32:11.482+00:00
urn:ex:a,urn:ex:p,urn:ex:b,2017-04-28T13:32:11.482+00:00
一旦你在不同的时间插入了一些东西,你就会有不同的时间值,所以排序就有意义了。我建议你不要像我那样只是具体化三元组(如果你打算直接具体化,你可能应该使用标准词汇表),而是有一些有意义的结构,实际上有时间戳作为其中的一部分。
我有一个 ontology 模型。我通过 Sparql 更新在 class 实例之一中插入整数数据。该模型随机存储数据,没有任何顺序。现在,当我想通过 Sparql Query 提取这些数据时,我希望它按插入时间的顺序排列。我怎么能做到这一点?有什么想法吗?
P.S: 我的 ontology 模型是用 Protege 软件制作的。 我的插入数据查询低于一个。
PREFIX test:<http://www.semanticweb.org/muhammad/ontologies/2017/2/untitled-ontology-14#>
INSERT {
?KPI_Variables test:hasValue_ROB1 10
} WHERE {
?KPI_Variables test:hasValue_ROB1 ?Newvalue
FILTER(?KPI_Variables= test:Actual_Production_Time)
}
为了获取数据,我使用以下查询:
PREFIX test:<http://www.semanticweb.org/muhammad/ontologies/2017/2/untitled-ontology-14#>
SELECT ?KPI_Variables ?Newvalue WHERE {
?KPI_Variables test:hasValue_ROB1 ?Newvalue
FILTER(?KPI_Variables = test:Actual_Production_Time)
} LIMIT 25
RDF 中的数据只是三元组。没有 when 将三元组添加到图中的概念。如果您需要此类信息,则需要在您的数据模型中将其显式化。 SPARQL 确实包含一个 now 函数,可让您获取查询为 运行 时的时间戳。这意味着您可以这样做:
prefix : <urn:ex:>
insert {
[] :hasSubject ?s ;
:hasPredicate ?p ;
:hasObject ?o ;
:hasTime ?now .
}
where {
#-- Fake a couple of triples
values (?s ?p ?o) {
(:a :p :b)
(:c :q :d)
}
#-- Get the current time
bind (now() as ?now)
}
现在您的图表包含如下数据:
@prefix : <urn:ex:> .
[ :hasObject :d ;
:hasPredicate :q ;
:hasSubject :c ;
:hasTime "2017-04-28T13:32:11.482+00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime>
] .
[ :hasObject :b ;
:hasPredicate :p ;
:hasSubject :a ;
:hasTime "2017-04-28T13:32:11.482+00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime>
] .
你可以这样查询:
prefix : <urn:ex:>
select ?s ?p ?o ?time {
[] :hasSubject ?s ;
:hasPredicate ?p ;
:hasObject ?o ;
:hasTime ?time
}
order by ?time
s,p,o,time
urn:ex:c,urn:ex:q,urn:ex:d,2017-04-28T13:32:11.482+00:00
urn:ex:a,urn:ex:p,urn:ex:b,2017-04-28T13:32:11.482+00:00
一旦你在不同的时间插入了一些东西,你就会有不同的时间值,所以排序就有意义了。我建议你不要像我那样只是具体化三元组(如果你打算直接具体化,你可能应该使用标准词汇表),而是有一些有意义的结构,实际上有时间戳作为其中的一部分。