getinfmodel.java

来自「Jsp写的一个语义检索的Demo」· Java 代码 · 共 80 行

JAVA
80
字号
package cyh;
import com.hp.hpl.jena.rdf.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.reasoner.*;
import com.hp.hpl.jena.vocabulary.*;
import com.hp.hpl.jena.reasoner.rulesys.*;
import com.hp.hpl.jena.util.*;
import java.lang.*;
import java.util.*;
import java.io.*;
public class getInfModel {

   public InfModel getInfModel(){
   InfModel infModel;
      String file = "../../ontology/pub.owl";
      Model data = ModelFactory.createDefaultModel();
      Model model = ModelFactory.createDefaultModel();
      InputStream in ;
     try{
         in = FileManager.get().open( file );
     data.read(in, "");
     }
     catch (Exception e ){
     }
      Resource configuration=model.createResource() ;
      configuration.addProperty(ReasonerVocabulary.PROPruleMode, "forward");
      configuration.addProperty(ReasonerVocabulary.PROPruleSet,  "../../rules/pub.rules");
      Reasoner reasoner = GenericRuleReasonerFactory.theInstance().create(configuration);
      infModel=ModelFactory.createInfModel(reasoner, data);
   return infModel;
   }
     public String itemToProperty(String item){
   String property=null;
     if (item.equals("title")){
           property="http://www.domain2.com#hasTitle";
       }
       else if(item.equals("keywords")){
            property="http://www.domain2.com#keywords";
       }
       else if(item.equals("author")){
            property="http://www.domain2.com#hasAuthor";
       }
       else if(item.equals("content") )   {
        property="http://www.domain2.com#content";
       }
       else if(item.equals("pulished") )   {
        property="http://www.domain2.com#isPublished";
       }
       else if(item.equals("Citing") )   {
               property="http://www.domain2.com#Citing";
           }else if(item.equals("bothCiting") )   {
            property="http://www.domain2.com#bothCiting";
                }
        else if(item.equals("bothCited") )   {
        property="http://www.domain2.com#bothCited";
       }


   return property;
   }
   public String addNameSpace(String value){
         String result=value;
         result="http://www.owl-ontologies.com/unnamed.owl#" + value;
         return result;
   }
     public String removeType(String sou){
       String result=sou;
       if(sou.indexOf("^^")>0){
       result=sou.substring(0,sou.indexOf("^^"));
       }
       return result;
}
   public String addPrefix(String sou){
   String result=null;
   result="http://www.owl-ontologies.com/unnamed.owl#"+sou;
   return result;
   }
}

⌨️ 快捷键说明

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