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();
}
`
这个问题的初始问题在这里:
您正在遍历 Statement
个对象,它们是 RDF 语句的 Java 表示,或 "triple"。它有一个主语(通过 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);
}
我在编译过程中遇到问题。你能帮忙找出问题所在吗?
`
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();
}
`
这个问题的初始问题在这里:
您正在遍历 Statement
个对象,它们是 RDF 语句的 Java 表示,或 "triple"。它有一个主语(通过 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);
}