2017-04-27 26 views
1

我有一个本体模型。我通过Sparql更新将整型数据插入到其中一个类实例中。该模型以任意顺序随机存储数据。现在,当我想通过Sparql Query提取这些数据时,我想按照插入时间的顺序。我怎么能做到这一点?任何想法?根据本体模型中的时间对插入的数据进行排序

P.S:我的本体模型是用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 
+0

你可以编辑你的问题吗?这样人们可以看到你的努力并帮助你。 – user730611

+0

编辑的问题。查询已添加 –

+0

如何运行INSERT查询?在Protege中?如果是这样,通过哪个插件? – AKSW

回答

4

数据在RDF简直是三倍。没有的概念,当三元组添加到图形。如果你需要这种信息,你需要在你的数据模型中明确表达出来。 SPARQL确实包含现在的函数,可以让您获取运行查询时的时间戳。这意味着,你可以做这样的事情:

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 

一旦你在不同的时间插入了一些东西,你会有不同的时间值,所以排序会很有意义。我建议你不要像我那样把三元组化(如果你打算用一种直接的物化方式,你应该使用标准词汇表),而是有一些有意义的结构,它们实际上有时间戳作为它的一部分。

相关问题