以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 Semantic Web(语义Web)/描述逻辑/本体 』  (http://bbs.xml.org.cn/list.asp?boardid=2)
----  [求助]ontology存入HashMap的问题?附代码  (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=60325)


--  作者:dasotkb
--  发布时间:3/23/2008 5:59:00 PM

--  [求助]ontology存入HashMap的问题?附代码
import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.model.*;
import java.util.*;

public  class  QueryClasses {
 public static void main(String[] args) throws Exception  {
  Map<String, String> map = new HashMap<String, String>();
  String uri = "http://homepage19.seed.net.tw/web@5/humor7207/Person.owl";
        OWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri);
       
        // Print all classes and their instances        
        Collection classes = owlModel.getUserDefinedOWLNamedClasses();
        for (Iterator it = classes.iterator(); it.hasNext();) {
            OWLNamedClass cls = (OWLNamedClass) it.next();
            //System.out.println("Class " + cls.getBrowserText() ); 印出类别名称
            int a = Math.abs(cls.getBrowserText().substring(1,3).hashCode()%1000);//产生hashCode
            String key = String.valueOf(a);   
            String Value = cls.getBrowserText            
            map.put(key, Value); //存入key及Value
            System.out.println(map.get(key)); //输出key,不知为何输出的内容却是Value
            //System.out.println("键:"+ key + "  值:" + Value); //这里输出key及Value都正常
     }
      
        // Print all resources that have owl:Thing as their rdfs:subClassOf value
        RDFProperty subClassOfProperty = owlModel.getRDFProperty(RDFSNames.Slot.SUB_CLASS_OF);
        OWLNamedClass owlThingClass = owlModel.getOWLThingClass();
        Collection results = owlModel.getRDFResourcesWithPropertyValue(subClassOfProperty, owlThingClass);
        //System.out.println("Subclasses of owl:Thing:");
        for (Iterator it = results.iterator(); it.hasNext();) {
            RDFResource resource = (RDFResource) it.next();
            System.out.println(" - " + resource.getBrowserText());
   
        }     

       }

   }

我有问题的是这两行
System.out.println(map.get(key)); //输出key,不知为何输出的内容却是Value
//System.out.println("键:"+ key + "  值:" + Value); //这里输出key及Value都正常

如果我要印出hashmap的key及value内容,要如何写呢?..谢谢各位好心人


--  作者:jpz6311whu
--  发布时间:3/23/2008 6:15:00 PM

--  
System.out.println(map.get(key)); //输出key,不知为何输出的内容却是Value

get指的是得到key的value值,楼主看看java doc就知道了


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
78.125ms