以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 Semantic Web(语义Web)/描述逻辑/本体 』 (http://bbs.xml.org.cn/list.asp?boardid=2) ---- 请教:OntModel::createIndividual() (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=28906) |
-- 作者:xirufeng -- 发布时间:3/20/2006 10:46:00 AM -- 请教:OntModel::createIndividual() 在已经有的文件owl文件的基础上,执行createIndividual()后,为什么只可以保存最新的实例,而且并不能在owl文件中体现? 谢谢! |
-- 作者:jpz6311whu -- 发布时间:3/20/2006 10:49:00 AM -- 你把完整的程序源代码和完整的owl文件贴出来,并说明运行结果。 |
-- 作者:xirufeng -- 发布时间:3/20/2006 10:55:00 AM -- 结果就是只能保存一次的结果 D:\make>javac createInstance.java D:\make>java createInstance import java.util.Vector;
public class createInstance } } } }
|
-- 作者:xirufeng -- 发布时间:3/20/2006 10:58:00 AM -- 下次再这样创建一个之后,上次的http://www.owl-ontologies.com/unnamed.owl#英雄牌 就不显示了 |
-- 作者:jpz6311whu -- 发布时间:3/20/2006 11:21:00 AM -- 你在程序中创建新的本体实例,并对实例添加属性。 但是这些操作都是在内存中进行的,如果要把数据持久化,还需要把本体库写回到文件中: Writing RDF Jena has methods for reading and writing RDF as XML. These can be used to save an RDF model to a file and later read it back in again. Tutorial 3 created a model and wrote it out in triple form. Tutorial 4 modifies tutorial 3 to write the model in RDF XML form to the standard output stream. The code again, is very simple: model.write can take an OutputStream argument. // now write the model in XML form to a file <rdf:RDF RDF is usually embedded in an <rdf:RDF> element. The element is optional if there are other ways of know that some XML is RDF, but it is usually present. The RDF element defines the two namespaces used in the document. There is then an <rdf:Description> element which describes the resource whose URI is "http://somewhere/JohnSmith". If the rdf:about attribute was missing, this element would represent a blank node. The <vcard:FN> element describes a property of the resource. The property name is the "FN" in the vcard namespace. RDF converts this to a URI reference by concatenating the URI reference for the namespace prefix and "FN", the local name part of the name. This gives a URI reference of "http://www.w3.org/2001/vcard-rdf/3.0#FN". The value of the property is the literal "John Smith". The <vcard:N> element is a resource. In this case the resource is represented by a relative URI reference. RDF converts this to an absolute URI reference by concatenating it with the base URI of the current document. There is an error in this RDF XML; it does not exactly represent the Model we created. The blank node in the Model has been given a URI reference. It is no longer blank. The RDF/XML syntax is not capable of representing all RDF Models; for example it cannot represent a blank node which is the object of two statements. The 'dumb' writer we used to write this RDF/XML makes no attempt to write correctly the subset of Models which can be written correctly. It gives a URI to each blank node, making it no longer blank. Jena has an extensible interface which allows new writers for different serialization languages for RDF to be easily plugged in. The above call invoked the standard 'dumb' writer. Jena also includes a more sophisticated RDF/XML writer which can be invoked by specifying another argument to the write() method call: // now write the model in XML form to a file // now write the model in XML form to a file
|
-- 作者:xirufeng -- 发布时间:3/20/2006 3:23:00 PM -- 非常感谢! ![]() |
-- 作者:xirufeng -- 发布时间:3/22/2006 9:38:00 AM -- 我按照上边介绍的做了,还是一样,真不明白是怎么回事
|
-- 作者:jpz6311whu -- 发布时间:3/22/2006 10:12:00 AM -- 你把完整的程序源代码和完整的owl文件贴出来,并说明运行结果。 |
-- 作者:xirufeng -- 发布时间:3/23/2006 8:40:00 AM -- 方法一:下边红色字体另外加的,这样的话,还是只能保存一次。 方法二:如果自己定义outputstream的话,能编译,但不能运行。定义如下: File file=new File("d:/wyh/seller.owl"); FileOutputStream out=new FileOutputStream(file); model.write(out); 异常如下: Exception in thread "main" com.hp.hpl.jena.rdf.arp.ParseException: {E301} Premat ure end of file. at com.hp.hpl.jena.rdf.arp.ARPFilter.parseWarning(ARPFilter.java:559) at com.hp.hpl.jena.rdf.arp.ARPFilter.parseWarning(ARPFilter.java:552) at com.hp.hpl.jena.rdf.arp.ParserSupport.saxException(ParserSupport.java :179) at com.hp.hpl.jena.rdf.arp.RDFParser.saxEx(RDFParser.java:260) at com.hp.hpl.jena.rdf.arp.RDFParser.oneWhite(RDFParser.java:248) at com.hp.hpl.jena.rdf.arp.RDFParser.whiteOrErr(RDFParser.java:196) at com.hp.hpl.jena.rdf.arp.RDFParser.rdfFile(RDFParser.java:98) at com.hp.hpl.jena.rdf.arp.ARPFilter.parse(ARPFilter.java:314) at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:221) at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:209) at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:261) at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:206) at com.hp.hpl.jena.ontology.impl.OntModelImpl.read(OntModelImpl.java:189 4) at com.hp.hpl.jena.ontology.impl.OntModelImpl.read(OntModelImpl.java:184 6) at createInstance.instance(createInstance.java:41) at createInstance.main(createInstance.java:144) com.hp.hpl.jena.shared.JenaException: rethrew: {E301} Premature end of file. at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:226) at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:209) at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:261) at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:206) at com.hp.hpl.jena.ontology.impl.OntModelImpl.read(OntModelImpl.java:189 4) at com.hp.hpl.jena.ontology.impl.OntModelImpl.read(OntModelImpl.java:184 6) at createInstance.instance(createInstance.java:41) at createInstance.main(createInstance.java:144) Caused by: com.hp.hpl.jena.rdf.arp.ParseException: {E301} Premature end of file. at com.hp.hpl.jena.rdf.arp.ARPFilter.parseWarning(ARPFilter.java:559)
|
-- 作者:jpz6311whu -- 发布时间:3/23/2006 2:18:00 PM -- 你看看报错的地方: at createInstance.instance(createInstance.java:41) 并不是write出错了,是在这个之前的read就有错 |
-- 作者:xirufeng -- 发布时间:3/25/2006 7:07:00 PM -- 那为什么我不写的话,就能读出来 还能识别我输入的类概念是不是本体中的类概念,这个不证明我的read是对的么?
|
-- 作者:jpz6311whu -- 发布时间:3/25/2006 7:53:00 PM -- at com.hp.hpl.jena.ontology.impl.OntModelImpl.read(OntModelImpl.java:184 6) at createInstance.instance(createInstance.java:41) at createInstance.main(createInstance.java:144) 很明显,没有能够完成读的操作,在解析的时候就出错了, “识别我输入的类概念”,这个 更是不可能的 |
-- 作者:xirufeng -- 发布时间:3/26/2006 10:42:00 AM -- 这是读操作的代码,当时显示树形式的时候也是这样读的 OntModel model = ModelFactory.createOntologyModel(); OntDocumentManager dm = model.getDocumentManager(); dm.addAltEntry("http://protege.stanford.edu/plugins/owl/protege", "file:/wyh/seller.owl"); model.read("http://protege.stanford.edu/plugins/owl/protege"); 有错吗?
|
-- 作者:jpz6311whu -- 发布时间:3/26/2006 12:35:00 PM -- 有可能不是程序错了,而是owl数据有错 |
-- 作者:fyfunny -- 发布时间:3/26/2006 11:41:00 PM -- 楼上的朋友,能提供owl文件代码吗,我把程序拷下来执行,有错误,是不是owl文件不一样啊,我要用owl做毕设,也和楼主的问题差不多 |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
140.625ms |