On 18/09/14 01:31, Deyan Chen wrote:
Hi Dave,

Thank you for your reply.

I know the means of the error, but I want to know why the second
case(model created by Model.union()) doesn't report the error.

Presumably because in that case you are using TDB instead of an in-memory data structure.

And about the way to associate a triple with a weight value, have you a
better one or any other suggestions?

Apart from reification at the RDF level the alternative is to consider explicit n-ary relations. The implementation of n-ary relations boils down to something much the same as reification - create resources, typically b-nodes, to represent each instance of the relation with separate properties to link that instance to the relation components (such as subject, object, weight).

It depends on whether you really are trying to annotate every RDF statement or whether you want to build on top of RDF some way of representing certain weighted property values.

Dave

Thank you very much.

Deyan Chen

在 2014年09月17日 17:13, Dave Reynolds 写道:

On 17/09/14 10:01, Deyan Chen wrote:
Hi all,

I want to associate a triple with a weight value, for example:

s1 p1 v1 with 20,
s1 p1 v2 with 11,
s1 p2 v3 with 30,
......
s2 p1 v1 with 15,
s2 p2 v3 with 20,
......

The way I have tested is to make a anonymous ReifiedStatement object
from the triple/statement.
The example code is as following:

// list the statements in the graph
StmtIterator stmtIter = model.listStatements(res, prop, (RDFNode) null);

Property certaintyFactor = model.createProperty(fuzzyOntNameSpace,
"certainty_factor");

// print out the predicate, subject and object of each statement
Statement stmt = null;

while (stmtIter.hasNext()) {
     // get next statement
     stmt = stmtIter.nextStatement();
     System.out.println(stmt.toString());

     if (stmt.isReified()) {
         stmt.removeReification();
     } else {
         ReifiedStatement reifStmt = stmt.createReifiedStatement();
         reifStmt.addLiteral(certaintyFactor, Math.random());

N.B. This modifies the model you are iterating over.

System.out.println(reifStmt.toString());
     }
}

The output is as following:

[http://www.example.com/ontologies/2013/6/medicine.owl#m.029k_,
http://www.example.com/ontologies/2013/6/medicine.owl#disease.symptoms,
http://www.example.com/ontologies/2013/6/medicine.owl#m.014wq_]
(273851cd:146eb73208f:-7fea rdf:type rdf:Statement)
(273851cd:146eb73208f:-7fea rdf:subject medicine:m.029k_)
(273851cd:146eb73208f:-7fea rdf:predicate medicine:disease.symptoms)
(273851cd:146eb73208f:-7fea rdf:object medicine:m.014wq_)
(273851cd:146eb73208f:-7fea fuzzy:certainty_factor
'0.6892811680228655'^^http://www.w3.org/2001/XMLSchema#double)
Exception in thread "main" java.util.ConcurrentModificationException:

As the error says, you are modifying a data structure while still
iterating over it.

Depending on the reification style the reification statements
themselves may be visible but in any case the step noted above
definitely adds statements to the model you are scanning.

The thing to do is the build up a separate list of modification
actions during the iteration and then afterwards perform all those
modifications.

Dave



---------------------------------------------------------------------------------------------------

Confidentiality Notice: The information contained in this e-mail and any
accompanying attachment(s) is intended only for the use of the intended
recipient and may be confidential and/or privileged of Neusoft
Corporation, its subsidiaries and/or its affiliates. If any reader of
this communication is not the intended recipient, unauthorized use,
forwarding, printing,  storing, disclosure or copying is strictly
prohibited, and may be unlawful.If you have received this communication
in error,please immediately notify the sender by return e-mail, and
delete the original message and all copies from your system. Thank you.
---------------------------------------------------------------------------------------------------


Reply via email to