




如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
创建RDF语言本体: staticStringpersonURI="http://somewhere/JohnSmith"; staticStringfullName="JohnSmith"; //createanemptyModel Modelmodel=ModelFactory.createDefaultModel();eq\o\ac(○,1) //createtheresource ResourcejohnSmith=model.createResource(personURI);eq\o\ac(○,2) //addtheproperty johnSmith.addProperty(VCARD.FN,fullName);eq\o\ac(○,3) eq\o\ac(○,1)处是用模型工程创建一个空的本体模型 eq\o\ac(○,2)处是创建一个资源,主体是johnSmith,其对应URI为"http://somewhere/JohnSmith"。 eq\o\ac(○,3)处是给eq\o\ac(○,2)出创建的资源增加属性和客体(即属性的值),属性为VCARD.FN,其中VCARD是RDFS中定义好的,客体为fullName,是字符串,也就是literal。 eq\o\ac(○,2)和eq\o\ac(○,3)合起来就是创建了一个三元组,是组成本体的基本单元,可以简写成如下:ResourcejohnSmith= model.createResource(personURI) .addProperty(VCARD.FN,fullName); 对本体中的陈述(即三元组)的操作 StmtIteratoriter=model.listStatements();eq\o\ac(○,1) //printoutthepredicate,subjectandobjectofeachstatement while(iter.hasNext()){eq\o\ac(○,2) Statementstmt=iter.nextStatement();//getnextstatement Resourcesubject=stmt.getSubject();//getthesubject Propertypredicate=stmt.getPredicate();//getthepredicate eq\o\ac(○,4)RDFNodeobject=stmt.getObject();//gettheobject System.out.print(subject.toString());eq\o\ac(○,3) System.out.print(""+predicate.toString()+""); if(objectinstanceofResource){ System.out.print(object.toString()); }else{ //objectisaliteral System.out.print("\""+object.toString()+"\""); } System.out.println("."); } eq\o\ac(○,1)处是列出model本体模型中的所有的陈述。 eq\o\ac(○,2)处是对所有陈述逐个进行操作,stmt是得到该陈述,subject是得到陈述主题,predicate是得到陈述的属性,object是得到陈述的属性值,记住各个函数的用法功能。还有打印三元组的各个部分时,.toString函数是打印出完整的URI,而.getlocalname则是URI的最后的本地名字部分。例如eq\o\ac(○,3)处打印为:HYPERLINK"http://somewhere/JohnSmith"http://somewhere/JohnSmith,若eq\o\ac(○,3)处改为subject.localname(),则打印为:JohnSmith。 eq\o\ac(○,4)处,因为属性值可以为resource和literal,所以用其父类RDFNode做返回值,其后再用objectinstanceofResource语句判断到底是资源,还是literal。 写RDF本体 model.write(System.out); model.write(System.out,"RDF/XML-ABBREV"); model.write(newFileOutputStream(newFile(文件路径))); 第一句是默认本体表示语言的写,默认是用intripleform,用三元组形式的RDF表示法。 第二句是用RDF/

xf****65
实名认证
内容提供者


最近下载