0

More specifically, this is to represent a situation such as "John said the car is blue," without necessarily having "the car is blue" in the current ontology. My code would have to check it afterward. I may have an idea on how to do it with OWL2 Annotation Axiom. However, I'm confused about how to do it in Jena, with RDF Statement.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127
  • IRIs aren't in a model; statements are. You can create a reified statement about any IRIs that you like; the reified statements don't need to be in the model. – Joshua Taylor Oct 22 '13 at 21:34

1 Answers1

1

The reification of a statement is a resource that has a subject, property, and object, and has the type statement. You can use a Model to create a Statement (using createStatement) without adding that statement to the model. You can then get a ReifiedStatement (using createReifiedStatement) based on that statement. Here's Jena code that creates the necessary resources, then creates a statement

car hasColor blue

without adding it to the model, creates the reification x of that statement (which does add triples to the model), and finally adds the statement

john says x

to the Model.

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.ReifiedStatement;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;


public class ReificationExample {
    public static void main(String[] args) {
        final String NS = "http://stackoverflow.com/questions/19526223/";
        final Model model = ModelFactory.createDefaultModel();

        final Resource john = model.createResource( NS+"john" );
        final Resource car = model.createResource( NS+"car" );
        final Property hasColor = model.createProperty( NS+"hasColor" );
        final Property says = model.createProperty( NS+"says" );
        final Resource blue = model.createResource( NS+"blue" );

        // creating a statement doesn't add it to the model
        final Statement stmt = model.createStatement( car, hasColor, blue );

        // creating a reified statement does add some triples to the model, but
        // not the triple [car hasColor blue].
        final ReifiedStatement rstmt = model.createReifiedStatement( stmt );

        // john says rstmt
        model.add( john, says, rstmt );

        model.write( System.out, "TTL", null ); // or "RDF/XML", etc.
    }
}

Output in Turtle:

<http://stackoverflow.com/questions/19526223/john>
      <http://stackoverflow.com/questions/19526223/says>
              [ a       <http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement> ;
                <http://www.w3.org/1999/02/22-rdf-syntax-ns#object>
                        <http://stackoverflow.com/questions/19526223/blue> ;
                <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate>
                        <http://stackoverflow.com/questions/19526223/hasColor> ;
                <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject>
                        <http://stackoverflow.com/questions/19526223/car>
              ] .

Output in RDF/XML:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:j.0="http://stackoverflow.com/questions/19526223/">
  <rdf:Description rdf:about="http://stackoverflow.com/questions/19526223/john">
    <j.0:says>
      <rdf:Statement>
        <rdf:object rdf:resource="http://stackoverflow.com/questions/19526223/blue"/>
        <rdf:predicate rdf:resource="http://stackoverflow.com/questions/19526223/hasColor"/>
        <rdf:subject rdf:resource="http://stackoverflow.com/questions/19526223/car"/>
      </rdf:Statement>
    </j.0:says>
  </rdf:Description>
</rdf:RDF>
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353