语义网简明教程SW6-OWL-JenaPPT文件格式下载.pptx
《语义网简明教程SW6-OWL-JenaPPT文件格式下载.pptx》由会员分享,可在线阅读,更多相关《语义网简明教程SW6-OWL-JenaPPT文件格式下载.pptx(69页珍藏版)》请在冰豆网上搜索。
![语义网简明教程SW6-OWL-JenaPPT文件格式下载.pptx](https://file1.bdocx.com/fileroot1/2022-10/7/1f8989fd-6638-434a-a03d-4e7fea826e3e/1f8989fd-6638-434a-a03d-4e7fea826e3e1.gif)
Modelmodel=ModelFactory.createDefaultModel();
6,2、创建属性,使用Model.createProperty创建属性PropertycreateProperty(StringnameSpace,StringlocalName)nameSpace:
命名空间localName:
属性局部名称/NamespacedeclarationsStringfamilyUri=http:
/family/;
StringrelationshipUri=http:
/purl.org/vocab/relationship/;
/CreatethetypesofPropertytodescriberelationshipsinthemodelPropertychildOf=model.createProperty(relationshipUri,childOf);
PropertyparentOf=model.createProperty(relationshipUri,parentOf);
PropertysiblingOf=model.createProperty(relationshipUri,siblingOf);
PropertyspouseOf=model.createProperty(relationshipUri,spouseOf);
7,3、创建资源,使用Model.createResource创建资源ResourcecreateResource(Stringuri)uri:
资源的URI/CreateresourcesrepresentingthepeopleinourmodelResourceadam=model.createResource(familyUri+adam);
Resourcebeth=model.createResource(familyUri+beth);
Resourcechuck=model.createResource(familyUri+chuck);
Resourcedotty=model.createResource(familyUri+dotty);
Resourceedward=model.createResource(familyUri+edward);
Resourcefran=model.createResource(familyUri+fran);
Resourcegreg=model.createResource(familyUri+greg);
Resourceharriet=model.createResource(familyUri+harriet);
8,4、添加陈述,使用Resource.addProperty添加关于资源的陈述到模型ResourceaddProperty(Propertyp,RDFNodeo)p:
陈述的谓词,o:
陈述的客体,本资源为主体/Addpropertiestodescribingtherelationshipsbetweenthemadam.addProperty(siblingOf,beth);
adam.addProperty(spouseOf,dotty);
adam.addProperty(parentOf,edward);
adam.addProperty(parentOf,fran);
beth.addProperty(siblingOf,adam);
beth.addProperty(spouseOf,chuck);
chuck.addProperty(spouseOf,beth);
dotty.addProperty(spouseOf,adam);
dotty.addProperty(parentOf,edward);
dotty.addProperty(parentOf,fran);
9,4、添加陈述(续),也可使用Model.createStatement创建陈述StatementcreateStatement(Resources,Propertyp,RDFNodeo)Modeladd(Statementstmt)/Statementscanalsobedirectlycreated.Statementstatement1=model.createStatement(edward,childOf,adam);
Statementstatement2=model.createStatement(edward,childOf,dotty);
Statementstatement3=model.createStatement(edward,siblingOf,fran);
/.thenaddedtothemodel:
model.add(statement1);
model.add(statement2);
model.add(statement3);
10,4、添加陈述(续),/ArraysofStatementscanalsobeaddedtoaModel:
Statementstatements=newStatement5;
statements0=model.createStatement(fran,childOf,adam);
statements1=model.createStatement(fran,childOf,dotty);
statements2=model.createStatement(fran,siblingOf,edward);
statements3=model.createStatement(fran,spouseOf,greg);
statements4=model.createStatement(fran,parentOf,harriet);
model.add(statements);
/AListofStatementscanalsobeaddedListlist=newArrayList();
list.add(model.createStatement(greg,spouseOf,fran);
list.add(model.createStatement(greg,parentOf,harriet);
list.add(model.createStatement(harriet,childOf,fran);
list.add(model.createStatement(harriet,childOf,greg);
model.add(list);
11,5、查询RDF模型,Model接口提供对模型中的资源、属性、陈述等的查询listStatements():
ListallstatementslistStatements(Resources,Propertyp,RDFNodeo):
Findallthestatementsmatchingapattern.listSubjects():
Listallresourceswhicharesubjectsofstatements.listSubjectsWithProperty(Propertyp):
ListallsubjectswithagivenpropertylistObjects():
Listallobjectsinamodel.listObjectsOfProperty(Propertyp):
Listallobjectsofagivenproperty,12,5、查询RDF模型(续),列出陈述StmtIteratorlistStatements()列出所有陈述结果存放在陈述迭代器中StmtIteratorlistStatements(Resources,Propertyp,RDFNodeo)查找满足给定模式的陈述s:
查找的资源,p:
查找的谓词,o:
查找的客体参数可为null,表示匹配任何值例如:
/Findtheexactstatementadamisaspouseofdottymodel.listStatements(adam,spouseOf,dotty);
13,5、查询RDF模型(续),例:
/FindanystatementsmadeaboutadamStmtIteratoriter=model.listStatements(adam,null,(RDFNode)null);
/printoutthepredicate,subjectandobjectofeachstatementwhile(iter.hasNext(),14,/getnextstatement/getthesubject/getthepredicate/gettheobject,Statementstmt=iter.nextStatement();
Resourcesubject=stmt.getSubject();
Propertypredicate=stmt.getPredicate();
RDFNodeobject=stmt.getObject();
System.out.print(subject.toString();
System.out.print(+predicate.toString()+);
if(objectinstanceofResource)System.out.print(object.toString();
else/objectisaliteralSystem.out.print(+object.toString()+);
System.out.println(.);
5、查