RDF4j .ttl 文件过滤器 IF 语句 [英] RDF4j .ttl file filter IF statement

查看:86
本文介绍了RDF4j .ttl 文件过滤器 IF 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

}

`

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

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

推荐答案

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

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.

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

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

这篇关于RDF4j .ttl 文件过滤器 IF 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆