On 14/01/14 09:43, Wang Dongsheng wrote:
In terms of a triple, such as "S P O". I created a Reification, and want
to create another triple for it;
The example is to record the appearance time of the triple:
------------------------------
It's a lot easier if you provide a complete, minimal example.
Property apearAmount = model.CreateProperty(NS+"apearTimes");
ReifiedStatement reiStmt = model.createStatement(sub, pro,
obj).createReifiedStatement();
reiStmt.addProperty(appearAmount, "23");
-----------------------------
Next time, when I create the same reiStmt, I can not get the corresponding
property.
Can anyone help me? Thanks in advance~
That code does not add the statement to the model - it simply creates it:
Statement stmt = model.createStatement(sub, pro, obj) ;
model.add(stmt) ;
ReifiedStatement reiStmt = stmt.createReifiedStatement();
Andy
public class DevMain {
public static void main(String... argv) throws Exception {
String NS = "http://example/" ;
Model model = ModelFactory.createDefaultModel() ;
model.setNsPrefix("rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#") ;
model.setNsPrefix("", NS) ;
Resource sub = model.createResource(NS+"s") ;
Property pro = model.createProperty(NS+"p") ;
Literal obj = model.createLiteral("X") ;
Property appearAmount = model.createProperty(NS+"apearTimes");
Statement stmt = model.createStatement(sub, pro, obj) ;
model.add(stmt) ;
ReifiedStatement reiStmt = stmt.createReifiedStatement();
reiStmt.addProperty(appearAmount, "23");
RDFDataMgr.write(System.out, model, Lang.TTL) ;
System.exit(0);
}
}
------------------
@prefix : <http://example/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
[ a rdf:Statement ;
rdf:object "X" ;
rdf:predicate :p ;
rdf:subject :s ;
:apearTimes "23"
] .
:s :p "X" .