How to read n-quads file? Jena read n-quads file with model size zero?

Reason : A Jena Model is a single graph and it can't hold named graphs (which are in n-quads file)

Solution : Use DataSet to get the set of all graphs in n-quads file first and use model to get every set.

1:    public static void main(String[] args) {  
2:      // print every Model(Graph) size in n-quads file 
3:      Model model = ModelFactory.createDefaultModel();  
4:      Dataset dataset = RDFDataMgr.loadDataset("sample.nq");  
5:      Iterator it = dataset.listNames();  
6:      while(it.hasNext()){  
7:        String graphName = (String) it.next();  
8:        model = dataset.getNamedModel(graphName);  
9:        System.out.println(graphName+":"+model.size());  
10:      }  
11:    }  

No comments:

Post a Comment