Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package lb5;
  7.  
  8. import java.io.InputStream;
  9. import org.apache.jena.rdf.model.Model;
  10. import org.apache.jena.rdf.model.ModelFactory;
  11. import org.apache.jena.rdf.model.Property;
  12. import org.apache.jena.rdf.model.RDFNode;
  13. import org.apache.jena.rdf.model.Resource;
  14. import org.apache.jena.rdf.model.Statement;
  15. import org.apache.jena.rdf.model.StmtIterator;
  16. import org.apache.jena.util.FileManager;
  17.  
  18. /**
  19. *
  20. * @author Sasho
  21. */
  22. public class LB5 {
  23.  
  24. /**
  25. * @param args the command line arguments
  26. */
  27.  
  28. static final String inFile = "https://www.dropbox.com/s/lhlajc03dp51fxl/foaf.ttl?dl=1";
  29.  
  30. public static void main(String[] args) {
  31. // TODO code application logic here
  32. Model model = ModelFactory.createDefaultModel();
  33.  
  34.  
  35. Model temp = ModelFactory.createDefaultModel();
  36. Model suma = ModelFactory.createDefaultModel();
  37.  
  38.  
  39.  
  40. Property pro = model.createProperty("http://xmlns.com/foaf/0.1/knows");
  41. Property pro2 = model.createProperty("http://www.w3.org/2000/01/rdf-schema#seeAlso");
  42. InputStream in = FileManager.get().open(inFile);
  43. if(in == null){
  44. throw new IllegalArgumentException("File: "+ inFile + " not found");
  45. }
  46. model.read(in, inFile, "TTL");
  47. // model.write(System.out, "TURTLE");
  48.  
  49. StmtIterator iter = model.listStatements();
  50.  
  51.  
  52. while(iter.hasNext()){
  53. Statement stmt = iter.nextStatement();
  54. Resource subject = stmt.getSubject();
  55. Property predicate = stmt.getPredicate();
  56. RDFNode object = stmt.getObject();
  57.  
  58. // System.out.println(predicate.toString());
  59. // System.out.println(object.toString());
  60. if(predicate.toString().equals("http://www.w3.org/2000/01/rdf-schema#seeAlso")){
  61. //System.out.println(object.toString());
  62.  
  63. String inFiles = object.toString();
  64. InputStream in2 = FileManager.get().open(inFiles);
  65. if(in2 == null){
  66. throw new IllegalArgumentException("File: "+ inFiles + " not found");
  67. }
  68. temp.read(in2, inFiles, "TTL");
  69. temp.write(System.out, "TURTLE");
  70. ModelFactory.createUnion(temp, suma);
  71.  
  72. }
  73.  
  74. }
  75.  
  76.  
  77.  
  78. // suma.write(System.out, "TURTLE");
  79.  
  80.  
  81. }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement