-- 作者: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内容,要如何写呢?..谢谢各位好心人
|