-1

I am having problem during compilation. Can you help to figure out the problem please?

`

public static void main(String[] args) throws IOException {

    File dir = new File("C:data\\test");

    String[] fileNames = dir.list();
    FileWriter outFile = new FileWriter("out.ttl");

    RDFWriter writer = org.eclipse.rdf4j.rio.Rio.createWriter(RDFFormat.TURTLE, outFile );

        writer.startRDF();
    for (String fileName : fileNames) {
        System.out.println("Reading from " + fileName);

        File f = new File(dir, fileName);

        Model data = Rio.parse(new FileInputStream(f), "", RDFFormat.TURTLE);
        for (Statement st: data) {
            if ( "efrbroo:F22_Self-Contained_Expression" != null ) { 
                        writer.handleStatement(st);
            }

        }
    }

    writer.endRDF();

}

`

The initial question with this problem is here: RDF4J data merge

Aram
  • 123
  • 1
  • 8
  • You haven't said what the problem is, exactly. Please [edit] your question to add more details (error messages, stacktraces, etc). – Jeen Broekstra Mar 17 '19 at 22:28
  • Apart from your compilation issue, I can spot some other problems with this code. For example your `if` condition makes no sense: you're checking that a string is not null, which will always be true. – Jeen Broekstra Mar 17 '19 at 22:32
  • @JeenBroekstra I have corrected the 'if' . now the code runs, creates a new file, but the file is empty. ' if ( data.contains("F22_Self-Contained_Expression") ) { writer.handleStatement(st); } ' – Aram Mar 18 '19 at 09:50
  • @JeenBroekstra in fact I cannot figure out how to construct the IF condition. – Aram Mar 18 '19 at 16:31

1 Answers1

0

You are looping over Statement objects, which are the Java representation of an RDF statement, or "triple". It has a subject (available via Statement.getSubject()), a predicate (Statement.getPredicate()) and an object (Statement.getObject()). See https://rdf4j.eclipse.org/documentation/getting-started/ a more detailed introduction to this.

For example, if you wanted to remove all triples that had the IRI http://example.org/F22_Self-Contained_Expression as their object, you'd do something like this:

 IRI f22SelfContainedExpression = SimpleValueFactory.getInstance().createIRI("http://example.org/F22_Self-Contained_Expression"); 

 ... 

 if (!st.getObject().equals(f22SelfContainedExpression)) {
      writer.handleStatement(st);
 }
Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73