语义网技术(1):jena的使用——环境以及实例

大四毕设做关于语义网技术的研究,其中需要学习关于protege,jena等工具,以及owl和rdf的技术,网上的资料比较少,在这里给自己做一个学习的记录。


关于jena和protege

简单说,写个式子:(jena→java)    =    (protege→用户)

不难理解,jena对编程来说就像protege对用户的关系一样,这个是网上的资料的普遍说法,另外这个只做了解,这个系列的blog不出意外只做jena的相关研究,说白了,jena的道理都懂,其实大家就是缺API和介绍。

附:Jena官网地址:http://jena.apache.org/


开始

1、第一部分显然是环境问题,jena有相关的资料,下面提供官网下载,同时提供官网下载网址,以方便可以下载最新的jena文件

jena官网下载链接(.zip):apache-jena-2.13.0.zip

官网下载页地址(.zip以及tar.gz):http://jena.apache.org/download/index.cgi


2、之后就不用说了,导包。

解压上述压缩文件后,在lib里面,为方便操作,全部导入即可。


3、例子

解压目录下的\apache-jena-2.13.0\src-examples\jena\examples\rdf会有以下示例,导入即可



4、示例1的运行:

默认大家都有对rdf的基本了解,main里面就三条语句,用ModelFactory里的方法创建model,对该model添加资源,对该model添加属性。

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jena.examples.rdf;

import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.vocabulary.*;

/**
 * Tutorial 1 creating a simple model
 */

public class Tutorial01 extends Object {
	// some definitions
	static String personURI = "http://somewhere/JohnSmith";
	static String fullName = "John Smith";

	public static void main(String args[]) {
		// create an empty model
		Model model = ModelFactory.createDefaultModel();

		// create the resource
		Resource johnSmith = model.createResource(personURI);

		// add the property
		johnSmith.addProperty(VCARD.FN, fullName);
	}
}
运行,咦?没结果,当然没结果,没写输出语句!


在“johnSmith.addProperty(VCARD.FN, fullName);”后添加一句:

model.write(System.out);

运行:

输出rdf格式:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#" > 
  <rdf:Description rdf:about="http://somewhere/JohnSmith">
    <vcard:FN>John Smith</vcard:FN>
  </rdf:Description>
</rdf:RDF>
如上,第一个jena实例运行成功,并得到相应rdf格式的输出。



(本系列未完待续)


  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值