当前位置:网站首页>Ontology Development Diary 03-Understanding Code
Ontology Development Diary 03-Understanding Code
2022-08-09 09:29:00 【"Cancelled"】
1.Recommend a Treasure Blogger
https://blog.csdn.net/javafreely
(natives of earth).
2.代码:https://blog.csdn.net/javafreely/article/details/8432522
3.博主的RDF专栏:https://blog.csdn.net/javafreely/category_1311840.html?spm=1001.2014.3001.5482
if there is aOWL的就好了!Found everyone is written this project!我OWL完全没搞懂!!!!
1.According to the previous reference code the content inside,My own understanding about this code about some what!因为好记性不如烂笔头,Although typing,But I still think I should remember,I guess that's a little firmer!
(1)第一个类IntroductionAccording to the original blog, it is simplejena应用!
参考教材
https://max.book118.com/html/2017/0717/122715588.shtm
(This version is a bit low,It should now be possible toOWLof read and write operations!)
Page4:jena的用途:a)以RDF/XML,Read and write in triple formRDF;b)RDFS,OWL,DAML+OILThe operation of the other body;c)Using the database to store data;d)查询模型;e)基于规则的推理.
ModelFactory 类是一个Model 工厂,用于创建model 对象.我们可以使用 Model 的createResource 方法在model 中创建一个资源,And can use the resources addProperty 方法添加属性.
(2)StatementDemo类:Jena API 解析RDF 的Statement
StmtIterator iter = model.listStatements(); | Model 类的listStatements 返回 Statement | Iterator |
---|---|---|
Statement stmt = iter.nextStatement(); | 遍历Statement | |
Resource subject = stmt.getSubject(); | 主语 getSubject | Resource |
Property predicate = stmt.getPredicate(); | 谓语 getPredicate | Property |
RDFNode object = stmt.getObject(); | 客体 getObject | RDFNode |
(3)RDFWriting类:输出RDF, Model 的write 方法将其model write the content to an output stream
model.write(System.out); | model.write(OutputStream) | 默认的输出格式 |
---|---|---|
model.write(System.out, "RDF/XML-ABBREV"); | model.write(OutputStream, “RDF/XML-ABBREV”) | 使用XML The thumbnail grammar outputRDF |
model.write(System.out, "N-TRIPLE"); | model.write(OutputStream, “N-TRIPLE”) | 输出n 元组的格式 |
PS:This part of paste the contents of the original blogger!I can't understand it with my IQ.!
(4)RDFReading类:读取已有的RDF文件
InputStream in = FileManager.get().open( inputFileName ); | 使用 FileManager 查找文件 | import org.apache.jena.util.FileManager |
---|---|---|
model.read(in, null); | 读取RDF/XML 文件 | Model 的read 方法可以读取RDF 输入到model 中.The second parameter can specify the format. |
model.write(System.out); |
(5)NSPrefix类:设置Namespace 前缀
String nsA = "http://somewhere/else#"; | ||
---|---|---|
Resource root = m.createResource( nsA + "root" ); | 调用 Model 的createProperty 和createResource Generate properties and resources | |
Property P = m.createProperty( nsA + "P" ); | ||
m.add( root, P, x ).add( root, P, y ).add( y, Q, z ); | 调用Model.add 向model 中增加3个Statement | add The three parameters are the subject of the triplet、谓语和客体 |
m.write( System.out ); | ||
m.setNsPrefix( "nsA", nsA ); | Model的setNsPrefix Function to set the namespace prefix | 没有为RDF指定namespace前缀,则jenawill automatically generate a name for it j.0, j.1的名字空间 |
(6)ModelAccess类:访问RDF Model的信息
Resource vcard = model.getResource(personURI); | 从 Model 获取资源 | Model 的 getResource 方法:The method according to the parameter returns a resource object. |
---|---|---|
Resource name = (Resource) vcard.getProperty(VCARD.N).getObject(); | 获取N 属性的值(用属性的 getObject()方法) | Resource 的 getProperty 方法:According to the parameter is a properties object.Property 的 getObject 方法:返回属性值.When used according to the actual type is Resource 还是 literal 进行强制转换. |
Resource name = vcard.getProperty(VCARD.N).getResource(); | If you know the value of the property is a resource,可以使用属性的getResource 方法 | Property 的 getResource 方法:A resource that returns a property value.If the property value is notResource,则报错. |
fullName = vcard.getProperty(VCARD.FN).getString(); | The value of the property is if literal,则使用 getString 方法 | Property 的 getString 方法:Returns the text content of the property value.If the property value is not text,则报错. |
vcard.addProperty(VCARD.NICKNAME, "Smithy").addProperty(VCARD.NICKNAME, "Adman"); | 增加两个 NICKNAME 属性 | |
StmtIterator iter = vcard.listProperties(VCARD.NICKNAME); | 列出两个NICKNAME 属性,使用资源的 listProperties 方法 | Resource 的 listProperties 方法:List found properties that match the criteria. |
(7)RDFQuery类&RDFQuery1类
model.read(in, null); | 读 |
---|---|
ResIterator iter = model.listResourcesWithProperty(VCARD.FN); | Model.listSubjectsWithProperty(Property p, RDFNode o): list all propertiesp且其值为o的资源. |
System.out.println(" "+iter.nextResource().getProperty(VCARD.FN).getString()); | |
StmtIterator iter = model.listStatements(new SimpleSelector(null, VCARD.FN, (RDFNode)null)); | Model.listStatements(): 列出Model 所有的Statements. |
System.out.println(" "+iter.nextStatement().getString()); | |
Model.listSubjects(): List all resources with properties. | |
Model.listStatements(Selector s) | Selector selector = new SimpleSelector(subject, predicate, object).This selector selects all subjects matching subject、predicate conforms predicate、object conforms object 的Statement. |
PS:没看懂!
(8)AddDelete类:对model的增删操作!(I suddenly realized that I forgot what wasmodel了!)
model.remove(model.listStatements(null, VCARD.N, (RDFNode)null)); | Model.remove 方法可以实现statement 的删除操作 |
---|---|
model.removeAll(null, VCARD.Given, (RDFNode)null); | |
model.add(johnSmith, VCARD.N, model.createResource().addProperty(VCARD.Given, givenName).addProperty(VCARD.Family, familyName)); | Model.add 可以实现statement 的增加 |
Model 中的Resource(资源)或Property(属性,actually inherited fromResource)进行增删操作 |
2.https://max.book118.com/html/2017/0717/122715588.shtm
的解读
The version of this textbook isJena2.4.
1)JenaThe framework consists of a subsystem of ontology(Ontology Subsystem),它提供的APIAllow processing based onRDFThe ontology of data,支持?OWL DAML+OIL RDFS.本体APICombined with inference subsystems can extract information from a particular ontology,Provides a document manager to support document management of imported ontology.
2)Allow data to be stored to hard disk,或者是OWL文件中!(??可以导入到OWL文件中!!)
3)ARQ查询引擎,实现SPARQL查询语言,后面那个RDQLI don't think I can use it either,就不写了!(写给我自己的!I won't write anymore if I don't use it!)
4)How did go wrong before!Isn't it already written?!全部加入CLASSPATH中去!
5)Eclipse的方法
6)I suddenly saw something goodhttp://jena.apache.org/documentation/ontology/
,但是还不行,I have to read this document!
7)java类或者接口
- 本体模型OntModel:Jena通过model包中的ModelFactoryCreate an ontology model,This class can create various models,The class defines the members that implement the model and more than twenty methods to create the model.
OntModel ontModel = ModelFactory.createOntologyModel();
使用OWL语言,基于内存,支持RDFS推理;Model classes can be applied by creatingOntModelSpecparameters to create different models;OntMode ontModel = ModelFactory.createOntologyModel(OntModelSpec.DAML_MEM);
创建了一个使用DAMLLanguage Memory Ontology Model;The memory model is the model that exists only when the program is running.- 读取OWL文件的方法:调用jena OntoModel提供的Read方法;
ontModel.read("file:D:/temp/Creature/Creature.owl");
(如果这样的话,I want to readowl文件,Don't get a2.4来用了!);read(String url); read(Reader reader,String base); read(InputStream reader,String base); read(String url,String lang); read(Reader reader,String base,String lang); read(InputStream reader,String base,String lang);
. - Ontology Document ManagerOntDocumentManager;Each ontology model has an associated document manager;
OntModel m = ModelFactory.createOntologyModel();OntDocumentManager dm = m.getDocumentMananger();
Created a document manager and associated it with the created ontology model;
8)Web Ontology Language或OWL:Articulate the meaning of words in the vocabulary and the relationships between those words.与RDF Schema一起,OWLprovides a formal descriptionRDF模型的机制;Defines the hierarchical classes that a resource can belong to,Attribute characteristics that allow expressing resources.Jena中,Be regarded as a special type of ontologyRDF模型OntModel,This interface allows programmatically to ontology,Create classes with convenience methods、property restrictions, etc..
9)ontology can be considered as specialRDF模型,Add only the statement that defines its semantic rules,Ontology statements can also be added to an existing data model,或使用Model.union()Merge the ontology model with the data model.
//创建一个新的model,创建WordNet的OWL本体模型
OntModel wnOntology = ModelFactory.createOntologyModel();
//使用OntModel的方法
wnOntology.createTransitiveProperty(WordnetVocab.hyponymOf.getURI());
wnOntolgy.add(WordnetVocab.hyponymOf,RDF.type,OWL.TransitiveProperyt);
10)使用Jena推理:After the ontology and model are given,jenaThe inference engine can derive additional statements not explicitly expressed by the model;jena提供了多个Reasonertypes to use different types of ontologies.
11)将OWL本体与WordNet模型一起使用,所以为OWLReasoner.首先从ReasonerRegistry中获得OWLReasoner---->ReasonerRegistry.getOWLReasoner()
;下一步将reasoner与WordNetOntology binding,The returned results are those for which ontology rules can be applied.reasoner;然后,使用绑定的reasoner从WordNet模型创建InfModel.
//WordNet的推理模型
ModelMaker maker = ModelFactory.createModelRDBMaker(connection);
Model model = maker.openModel("wordnet-plants",true);
//创建OWL reasoner
Reasoner owlReasoner = ReasonerRegistry.getOWLReasoner();
//绑定reasoner到WordNet本体模型
Reasoner wnReasoner = owlReasoner.bindSchema(wnOntology);
//使用该reasonerCreate the inference model
InfModel infModel = ModelFactory.createInfModel(wnReasoner,model);
//Set up an inference model
query query.setSource(infModel);
//指定查询
QueryEngine qe = new QueryEngine(query);
QueryResults results = qe.exec(initialBinding);
12)Screenshot of code listing
PS:This seems outdated!因为是2.4版本,我现在都用4的版本了!Something happened suddenly,put me in a bad mood!
边栏推荐
猜你喜欢
随机推荐
RPC服务远程漏洞
[Environmental Construction] tensorrt
如何用数组实现环形队列
本体开发日记04-努力理解protege的某个方面
Redis基础
【面试体系知识点总结】---JVM
MySQL Leak Check (4) Stored Procedures and Cursors
on duplicate key update
div模拟textarea文本框,输入文字高度自适应,且实现字数统计和限制
本体开发日记05-努力理解SWRL(中)
web测试之功能测试常用的方法有哪几种?有什么要点要注意?
Teach you how to get a 0.1-meter high-precision satellite map for free
Swap swap partition
可以写进简历的软件测试项目实战经验(包含电商、银行、app等)
使用Protege4和CO-ODE工具构建OWL本体的实用指南-1.3版本(4.Building An OWL Ontology)
白盒测试的概念、目的是什么?及主要方法有哪些?
swap交换分区
软件测试面试思路技巧和方法分享,学到就是赚到
Domestic with Google earth software, see the download 19th level high-resolution satellite images so easy!
static_assert报错为什么?