문제

I am working on Java sesame. I started with a very little example following a tutorial. I am trying to build a simple statement as shown in the code. My problem is I do not know how to print out, for example, the subject or object of that statement. Could anyone please help me with this? Here is my code:

public static void main(String[] args)
{
    ValueFactory factory = ValueFactoryImpl.getInstance();
    URI bob = factory.createURI("http://example.org/bob");
    URI name = factory.createURI("http://example.org/name");
    Literal bobsName = factory.createLiteral("Bob");
    Statement nameStatement = factory.createStatement(bob, name, bobsName);
    Statement typeStatement = factory.createStatement(bob, RDF.TYPE,FOAF.PERSON); 
}

I should use the following line:

model.filter(null, RDF.TYPE, FOAF.PERSON).subjects();

I should use a code like the one above but do not know how to define model and how to print out the statement or at least the subject. Your help is very much appreciated.

도움이 되었습니까?

해결책

According to the javadoc for org.openrdf.Statement, you'd use getSubject(), getPredicate(), and getObject(). As pointed out in the comments, the common implementation of Statement, StatementImpl, provides an implementation of toString() method so that you can even just print the Statement:

Statement s = /* ... */;
System.out.println( s );
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top