On 17/01/14 01:44, Wang Dongsheng wrote:
Thank you for ur answering, but andy, even I did not use model.add(); it
was added into the model.
Anyway, the key point is that I can not get reification that I
created/added it before, I will paste the whole test code:

Each call of createReifiedStatement() creates a new blank resource and that is what is returned by the call. if you want to find it again you can:

1/ Use createReifiedStatement(String uri) to have a URI for the reificiation (same uri). If you change your code you'll see you get one entry now.

2/ Search for it - either by SPARQL to look for a reification by type and also the label property, or API with Model. listSubjectsWithProperty.

3/ Find all reifications with one of the Model.listReifiedStatements() methods.

        Andy

----------------------------------------
public static void main(String[] args) {
// TODO Auto-generated method stub
  Model model = ModelFactory.createDefaultModel();
Resource sub = model.createResource(ns+"A");
  Resource obj = model.createResource(ns+"B");
Property relate = model.createProperty(ns, "relatedTo");
  sub.addProperty(relate, obj);
  Statement stmt = model.createStatement(sub, relate, obj);
  model.add(stmt);
ReifiedStatement  reiStmt = stmt.createReifiedStatement();
reiStmt.addLiteral(RDFS.label, "customized reification");
  ReifiedStatement reiStmt2 = model.createStatement(sub, relate,
obj).createReifiedStatement();
StmtIterator stmtItor = reiStmt2.listProperties();
  while(stmtItor.hasNext()){
System.out.println("property: "+stmtItor.next());
}
  System.out.println("------- graph ---------");
model.write(System.out, "TTL");
}
---------------------------------------------------------------
Output of this method,
----------------------------------------------------------------------
property: [26045f75:1439dd6f41c:-7ffe,
http://www.w3.org/1999/02/22-rdf-syntax-ns#subject, http://test/A]
property: [26045f75:1439dd6f41c:-7ffe,
http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate, http://test/relatedTo]
property: [26045f75:1439dd6f41c:-7ffe,
http://www.w3.org/1999/02/22-rdf-syntax-ns#object, http://test/B]
property: [26045f75:1439dd6f41c:-7ffe,
http://www.w3.org/1999/02/22-rdf-syntax-ns#type,
http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement]
------- graph ---------
[]    a       <http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement> ;
       <http://www.w3.org/1999/02/22-rdf-syntax-ns#object>
               <http://test/B> ;
       <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate>
               <http://test/relatedTo> ;
       <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject>
               <http://test/A> ;
       <http://www.w3.org/2000/01/rdf-schema#label>
               "customized reification"^^<
http://www.w3.org/2001/XMLSchema#string> .

[]    a       <http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement> ;
       <http://www.w3.org/1999/02/22-rdf-syntax-ns#object>
               <http://test/B> ;
       <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate>
               <http://test/relatedTo> ;
       <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject>
               <http://test/A> .

<http://test/A>
       <http://test/relatedTo>
               <http://test/B> .
----------------------------------------------------------
As a result:

1) I can not get reiStmt using the newly created reiStmt2;  (printed
property do not include the added label message)
2) In the graph, there are two reification that refer to the same s,p,o;




On Wed, Jan 15, 2014 at 5:26 PM, Andy Seaborne <[email protected]> wrote:

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" .




Reply via email to