2016-05-06 11 views
0

私はプロジェクトのためにいくつかのオントロジを読み込もうとしています。今は私は生物臓器からのオントロジを使っていますが、それらのうちのいくつかは本当に重いです、200MBまたは400MBです。そして、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を使用してください。また、2番目の呼び出しでin.close()をコメント化しないでください。

関連する問題