繁体   English   中英

RDF4j .ttl 文件过滤器 IF 语句

[英]RDF4j .ttl file filter IF statement

我在编译过程中遇到问题。 你能帮忙找出问题吗?

`

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

}

`

这个问题的最初问题在这里: RDF4J数据合并

您正在循环Statement对象,它们是 RDF 语句或“三重”的 Java 表示。 它有一个主题(可通过Statement.getSubject() )、一个谓词( Statement.getPredicate() )和一个对象( Statement.getObject() )。 请参阅https://rdf4j.eclipse.org/documentation/getting-started/更详细的介绍。

例如,如果您想删除所有以 IRI http://example.org/F22_Self-Contained_Expression作为对象的三元组,您可以执行以下操作:

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

 ... 

 if (!st.getObject().equals(f22SelfContainedExpression)) {
      writer.handleStatement(st);
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM