Click here to view Assignment 4 - WordPress.com

taupesalmonInternet και Εφαρμογές Web

21 Οκτ 2013 (πριν από 3 χρόνια και 9 μήνες)

96 εμφανίσεις

Assignment 4

Explore whether you can use Protégé to do everything that was done in Jena in Chapter 2
example. Can you create model (s), and query and align them, reason with them, and print
results (perhaps in different visual formats)? Blog with
attachments on results/Protégé
code/tutorial.

Here I am trying to explore whether Protégé can do everything like Eclipse and Jena for
HelloSemanticWeb example (Chapter 2).

My answer is
“YES”
, that Protégé can do everything that Eclipse and Jena does. Let’
s see step
by step.

Find the attachment for HelloSemanticWeb.java code


Model Creation:

Jena:

You can create a model in Jena with Model class.

Model _friends = null;

The populateFOAFFriends() method from code is used to load the ontology in Eclipse/Jena.

private void populateFOAFFriends()

{


_
friends = ModelFactory.createOntologyModel();


InputStream inFoafInstance =

FileManager.get().open("Ontologies/FOAFFriends.rdf");


_friends.read(inFoafInstance,defaultNameSpace);


//inFoafInstance.close();

}


Protégé:

In protégé above process is same as loading the ontology file using option open
ontology.


Defining default Namespace:

In Jena default namespace is defined by declaring a variable as a string.

static String defaultNameSpace

= “http://org.semwebprogramming/chapter2/people#”;

Here the defaultNameSpace is defined as static variable.
A
static variable

is a
variable

that has
been
allocated statically



whose
lifetime

extends across the entire run of the
program.

In protégé however, the default namespace is defined for you.

http://www.semanticweb.org/ontologies/2011/8/Ontology1317678220959.owl#

Query:

In Jena you can pe
rform queries as shown below. Given is an example for how to define query in
Jena and Eclipse environment.

// Say Hello to my FOAF Friends

System.out.println("
\
nSay Hello to my FOAF Friends");


hello.myFriends(hello._friends);


private void myFriends
(Model model)

{

//Hello to just my friends
-

navigation

runQuery(" select DISTINCT ?myname ?name where{ people:me foaf:knows ?friend.
?friend foaf:name ?name } ", model); //add the query string

}

Below is the screenshot for querying in protégé.



Only
protégé 3.4.7 will support SPARQ
L query.



Align
ing

Two Schemas
:


In Jena we use addAlignment function to align two ontology schemas.

private void addAlignment(){






// State that :individual is equivalentClass of foaf:Person



Resource resource = schem
a.createResource(defaultNameSpace + "Individual");



Property prop =
schema.createProperty("http://www.w3.org/2002/07/owl#equivalentClass");



Resource obj = schema.createResource("http://xmlns.com/foaf/0.1/Person");



schema.add(resource,prop,obj);






/
/State that :hasName is an equivalentProperty of foaf:name



resource = schema.createResource(defaultNameSpace + "hasName");



//prop = schema.createProperty("http://www.w3.org/2000/01/rdf
-
schema#subPropertyOf");



prop =
schema.createProperty("http://www.
w3.org/2002/07/owl#equivalentProperty");



obj = schema.createResource("http://xmlns.com/foaf/0.1/name");



schema.add(resource,prop,obj);






//State that :hasFriend is a subproperty of foaf:knows



resource = schema.createResource(defaultNameSpace + "ha
sFriend");



prop = schema.createProperty("http://www.w3.org/2000/01/rdf
-
schema#subPropertyOf");



obj = schema.createResource("http://xmlns.com/foaf/0.1/knows");



schema.add(resource,prop,obj);









//State that sem

web is the same person as Semantic Web



resource =
schema.createResource("http://org.semwebprogramming/chapter2/people#me");



prop = schema.createProperty("http://www.w3.org/2002/07/owl#sameAs");



obj =
schema.createResource("http://org.semwebprogrammi
ng/chapter2/people#Individual_5");



schema.add(resource,prop,obj);


}

In protégé a
fter loading additionalFriends.owl
import the other ontology through direct import
option in protégé and merge them.


Reasoner:

In protégé to enable

“Reasoner”
,

select
Reasoner then “Start Reasoner”. Very simple, and then
the inferred model is generated automatically.

In Jena we defined a method called blindReasoner.

private void bindReasoner(){



Reasoner reasoner = ReasonerRegistry.getOWLReasoner();



reasoner =

reasoner.bindSchema(schema);



inferredFriends = ModelFactory.createInfModel(reasoner,
_friends);



}


S
ett
ing a rule:


In Jena we will set the Jena rule as shown below.

private void runJenaRule(Model model){



String rules = "[emailChange: (?person
<
http://xmlns.com/foaf/0.1/mbox> ?email), strConcat(?email, ?lit),
regex( ?lit, '(.*@gmail.com)')
-
> (?person
<http://www.w3.org/1999/02/22
-
rdf
-
syntax
-
ns#type>
<http://org.semwebprogramming/chapter2/people#GmailPerson>)]";




Reasoner ruleReasoner = new
GenericRuleReasoner(Rule.parseRules(rules));



ruleReasoner = ruleReasoner.bindSchema(schema);



inferredFriends = ModelFactory.createInfModel(ruleReasoner,
model);




}

In protégé we can do using SWRL.

V
isual formats: