⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 creat.java

📁 对jena推理机的文件进行读取
💻 JAVA
字号:

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Selector;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.vocabulary.RDF;


 public class creat {
 
 //static String fullName="Ping Liu";
 //static String email="p.liu@whu.edu.cn";
 //static String personURI="http://sim.whu.edu.cn/teacher/tea_detail.php?tc_id=70";
 
 public static void main(String[] args ){ 
	 OntModel m = ModelFactory.createOntologyModel(); 
	 //File myFile = new File ("D:\\杨惠洁\\workspace\\owl\\com\\animal.owl");
	 //m.read(new FileInputStream(myFile), "");
	// model.read(new FileInputStream("D:\\杨惠洁\\workspace\\owl\\com\\animal.owl"),"");
	 try 
     { 
  	   //File myFile = new File ("D:\\杨惠洁\\workspace\\owl\\com\\animal.owl");
  	  //model.read(new FileInputStream(myFile), "");  
  	    m.read(new FileInputStream("D:\\杨惠洁\\o4oil.owl"),"");
		 //m.read(new FileInputStream("D:\\杨惠洁\\privacy.owl"),"");
     } 
     catch(IOException ioe) 
     { 
            System.err.println(ioe.toString()); 

      } 

	
	 StmtIterator iter =m.listStatements();
	 int j=0;
	
		//m.listSubjectsWithProperty(RDF.type, m.getResource("http://www.zoo.com/ont/Animal")); 
	// ResIterator iter=m.listsu
	while (iter.hasNext()) { 
		j++;
		 Statement stmt =  iter.nextStatement(); 
	     Resource privacy = (Resource) stmt.getSubject(); 
	     Property  predicate = stmt.getPredicate();   // get the predicate
    	  RDFNode   object    = stmt.getObject();  
         String strSP = privacy.getLocalName();
         String strPR = predicate.getLocalName();
         String strOB = object.toString();
	     
	     
	    if (object instanceof Resource) 
	       	{
	    	System.out.println(j+" "+strSP);
		     System.out.println("predicate:"+strPR);
		     System.out.println("object:"+strOB); 
	       	} 
	       	
	       	else 
	       	{
	       		String str="";
	       	 	str = str + ":" + strSP.substring(strSP.indexOf('#')+1);
	           // object is a literal
	       	 System.out.println(j+" "+str);
		     System.out.println("predicate:"+strPR);
		     System.out.println("object:"+strOB);
	      	 	}
	 } 
 }
 }

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -