2016-05-06 21 views
0

我正在尝试为项目加载一些本体。现在我使用bioportal的本体,其中一些非常重,200 mb或400 mb,并且java需要花费大量的时间来加载它们。如何使用jena快速加载ontolgy?

我不知道我是否以正确的方式加载文件或有任何解决方法,使加载时间更小。

这是我的代码,我在那里装载本体的一部分:

System.out.println("loading the model..."); 
    model = ModelFactory.createOntologyModel(OntModelSpec.OWL_LITE_MEM); 
    listPaths = new LinkedList(); 
    //sc = new Scanner(System.in); 

    try{ 

     if(args[0].equals("0")){ 

      InputStream in = new FileInputStream("ontologies/camera.owl"); 
      model.read(in, null); 
      NS = NS0; 
      in.close(); 

     }else if(args[0].equals("1")){ 

      InputStream in = new FileInputStream("ontologies/NCITNCBO.owl"); 
      model.read(in, null); 
      NS = NS1; 
      //in.close(); 

     }else if(args[0].equals("2")){ 

      InputStream in = new FileInputStream("ontologies/HL7.ttl"); 
      model.read(in,null, "TTL"); 
      NS = "http://purl.bioontology.org/ontology/HL7/"; 
      in.close(); 

     }else if(args[0].equals("3")){ 

      InputStream in = new FileInputStream("ontologies/LOINC.ttl"); 
      model.read(in,null, "TTL"); 
      NS = "http://purl.bioontology.org/ontology/LNC/"; 
      in.close(); 

     } 
    }catch(Exception e){ 
     System.out.println("erro: " + e.getMessage()); 
    } 
    System.out.println("Ontology loaded!"); 

    //some info about the ontology 
    int maxChildcount = 0; 
    int numClasses = 0; 
    int numChilds = 0; 
    int numChildsClass = 0; 
    Iterator i = model.listClasses(); 

    while(i.hasNext()){ 
     numClasses++; 
     OntClass c = (OntClass) i.next(); 

     //get num childs 
     if(c.hasSubClass()){ 
      Iterator i2 = c.listSubClasses(); 
        while(i2.hasNext()){ 
         i2.next(); 
         numChilds++; 
         numChildsClass++; 

        } 

      if(numChildsClass > maxChildcount) 
       maxChildcount = numChildsClass; 
     } 

     numChildsClass = 0; 
    } 

    System.out.println("NumChilds: " + numChilds + " MaxChildCLass: " + maxChildcount + " numClasses: " + numClasses); 
    System.out.println("Paths for class: " + NS + args[1]); 

回答

0

使用FileInputStream围绕BufferedInputStream,以确保内容适当缓冲。另外,请不要在第二个电话中注释掉in.close()