Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package lb5;
- import java.io.InputStream;
- import org.apache.jena.rdf.model.Model;
- import org.apache.jena.rdf.model.ModelFactory;
- import org.apache.jena.rdf.model.Property;
- 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;
- /**
- *
- * @author Sasho
- */
- public class LB5 {
- /**
- * @param args the command line arguments
- */
- static final String inFile = "https://www.dropbox.com/s/lhlajc03dp51fxl/foaf.ttl?dl=1";
- public static void main(String[] args) {
- // TODO code application logic here
- Model model = ModelFactory.createDefaultModel();
- Model temp = ModelFactory.createDefaultModel();
- Model suma = ModelFactory.createDefaultModel();
- Property pro = model.createProperty("http://xmlns.com/foaf/0.1/knows");
- Property pro2 = model.createProperty("http://www.w3.org/2000/01/rdf-schema#seeAlso");
- InputStream in = FileManager.get().open(inFile);
- if(in == null){
- throw new IllegalArgumentException("File: "+ inFile + " not found");
- }
- model.read(in, inFile, "TTL");
- // model.write(System.out, "TURTLE");
- StmtIterator iter = model.listStatements();
- while(iter.hasNext()){
- Statement stmt = iter.nextStatement();
- Resource subject = stmt.getSubject();
- Property predicate = stmt.getPredicate();
- RDFNode object = stmt.getObject();
- // System.out.println(predicate.toString());
- // System.out.println(object.toString());
- if(predicate.toString().equals("http://www.w3.org/2000/01/rdf-schema#seeAlso")){
- //System.out.println(object.toString());
- String inFiles = object.toString();
- InputStream in2 = FileManager.get().open(inFiles);
- if(in2 == null){
- throw new IllegalArgumentException("File: "+ inFiles + " not found");
- }
- temp.read(in2, inFiles, "TTL");
- temp.write(System.out, "TURTLE");
- ModelFactory.createUnion(temp, suma);
- }
- }
- // suma.write(System.out, "TURTLE");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement