RDF4j .ttl file filter IF statement

给你一囗甜甜゛ 提交于 2019-12-13 08:41:31

问题


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


回答1:


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);
 }


来源:https://stackoverflow.com/questions/55207723/rdf4j-ttl-file-filter-if-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!