import java.io.InputStream;import java.util.*;import org.apache.jena.rdf.model.Model;import org.apache.jena.rdf.model.ModelFactory;import org.apache.jena.rdf.model.RDFNode;import org.apache.jena.rdf.model.Resource;import org.apache.jena.rdf.model.Statement;import org.apache.jena.rdf.model.StmtIterator;import org.apache.jena.util.FileManager;public class parseTTL { public static void parsettl(String fileName){ Model model = ModelFactory.createDefaultModel(); InputStream in = FileManager.get().open(fileName); if (in == null) { throw new IllegalArgumentException("File: " + fileName + " not found"); } model.read(in, "","TTL"); StmtIterator iter = model.listStatements(); while (iter.hasNext()) { Statement stmt = iter.nextStatement(); String subject = stmt.getSubject().toString(); String predicate = stmt.getPredicate().toString(); RDFNode object = stmt.getObject(); if (object instanceof Resource) //宾语为新的实体 { System.out.print(" 宾语 " + object); } else { // 宾语为字面量 System.out.print("宾语 \"" + object.toString() + "\""); } } } public static void main(String[] args){ String fileName = "F:\\DataSet\\dbpedia\\anchor_text_en.ttl"; parsettl(fileName); }}