Query OWL File

111 views
Skip to first unread message

LuisPHP

unread,
Sep 11, 2011, 3:16:05 PM9/11/11
to thea-owl-lib
Hello, I know how to load a owl file
consultations and make it through the rules in Prolog.

For example:

family.owl have a file and want to load it and create a rule in Prolog
as:

grandfather (X, Y): - father (X, Z), father (Z, Y)

When calling this rule will bring me her grandparents who are in the
file family.owl

Thank you very much

Chris Mungall

unread,
Sep 12, 2011, 10:42:29 AM9/12/11
to thea-o...@googlegroups.com

You can convert the ontology to a logic program like this:

thea testfiles/family.owl --to dlp --save-opts "no_base(_)" > family.pl

which is short for

load_axioms(...),
save_axioms('family.pl',dlp,[no_base(_)]).

LuisPHP

unread,
Sep 12, 2011, 8:01:07 PM9/12/11
to thea-owl-lib
I can not run this command, it might be stupid of me.

thea testfiles / family.owl - to dlp - save-opts "no_base (_)">
family.pl

I tried to run from the command line of windows, what I'm missing?

help me?

Thank you very much

Chris Mungall

unread,
Sep 12, 2011, 8:49:09 PM9/12/11
to thea-o...@googlegroups.com

The command line probably only works from linux and os x.

Try:

load_module(library(thea/owl2_io)).
load_axioms('family.owl).
save_axioms('family.pl',dlp).

LuisPHP

unread,
Sep 14, 2011, 11:53:33 PM9/14/11
to thea-owl-lib
thanks, it worked!

One more thing, after conversion the facts were as follows:

% propertyAssertion('http://www.owl-ontologies.com/
family.owl#name','http://www.owl-ontologies.com/
family.owl#Person_1',literal(type('http://www.w3.org/2001/
XMLSchema#string',Paul)))

It is possible that they would be already in default, this way:

name(Person_1,Paul).

Chris Mungall

unread,
Sep 15, 2011, 12:19:52 AM9/15/11
to thea-o...@googlegroups.com

On Sep 14, 2011, at 8:53 PM, LuisPHP wrote:

> thanks, it worked!
>
> One more thing, after conversion the facts were as follows:
>
> % propertyAssertion('http://www.owl-ontologies.com/
> family.owl#name','http://www.owl-ontologies.com/
> family.owl#Person_1',literal(type('http://www.w3.org/2001/
> XMLSchema#string',Paul)))
>
> It is possible that they would be already in default, this way:
>
> name(Person_1,Paul).

note that these would need to be enclosed in quotes in prolog

try

save_axioms('my.pl',dlp,[no_base(_)]).

LuisPHP

unread,
Sep 20, 2011, 9:54:11 PM9/20/11
to thea-owl-lib
thank you for help, were very helpful.

I wonder if you know of any rule language for semantic web that uses
backward chaining, as prolog. the SWRL looks good, but uses forward
chaining.

Chris Mungall

unread,
Sep 20, 2011, 10:04:00 PM9/20/11
to thea-o...@googlegroups.com

SWRL doesn't "use" anything. A SWRL *engine* might use backward or forward chaining - although most SWRL engines targeted at OWL-DL + SWRL will probably use some of tableaux-based algorithm (I'm not an expert here).

Luis Eduardo Santos

unread,
Sep 20, 2011, 10:54:09 PM9/20/11
to thea-o...@googlegroups.com
SWRL uses the JESS inference engine, which uses two types of chaining rules, however, when you create the rules in SWRL in the protected environment, the rules are always forward chaining.

example, father (?x,?y) ^ father (?y,?z) -> grandfather (?x,?z)

I would like to find some way to create rules below, with some language for the semantic web.

  grandfather(?x,?z)-> father (?x,?y) ^ father (?y,?z)


2011/9/20 Chris Mungall <cjmu...@lbl.gov>

Chris Mungall

unread,
Sep 21, 2011, 3:02:18 AM9/21/11
to thea-o...@googlegroups.com
On Sep 20, 2011, at 7:54 PM, Luis Eduardo Santos wrote:

SWRL uses the JESS inference engine

Hi Luis

SWRL doesn't use JESS. There is nothing here that mentions JESS:


It may be the case that the JESS environment allows you to reason with some subset of SWRL - I imagine it does, but I'm not an expert on JESS.

SWRL extends OWL-DL with rules

, which uses two types of chaining rules, however, when you create the rules in SWRL in the protected environment, the rules are always forward chaining.

example, father (?x,?y) ^ father (?y,?z) -> grandfather (?x,?z)

I would like to find some way to create rules below, with some language for the semantic web.

  grandfather(?x,?z)-> father (?x,?y) ^ father (?y,?z)


Read:

What you want has nothing to do with forward or backward chaining. 

It sounds like you want to say is:

if x is the grandfather of z, then there exists some y such that x is the father of y and y is the father of z.

If so, you might want to look at using full FOL and a theorem prover like prover 9.

In prover 9 syntax:

grandfather_of(x,z) -> exists y : father_of(x,y) & father_of(y,z).

(tip: always make the directionality of relations explicit)

It may help to take a step back - is this really what you want to do? Why? Does it need to be in a "semantic web" language?

You may be better off asking the question on a more general mailing list

Cheers
Chris

LuisPHP

unread,
Sep 23, 2011, 11:14:52 PM9/23/11
to thea-owl-lib
In all this our discussion, my goal is to run the Prolog rules, and
facts come from an owl file.

For example:

have this rule in Prolog

grandfather (X, Y):-father (X, Z), father (Z, Y).

facts "father" would come from an owl file, other words, it consulting
the an OWL file

I'm sorry to make you question so much, that really needs to do this

Thanks again

On Sep 21, 4:02 am, Chris Mungall <cjmung...@lbl.gov> wrote:
> On Sep 20, 2011, at 7:54 PM, Luis Eduardo Santos wrote:
>
> > SWRL uses the JESS inference engine
>
> Hi Luis
>
> SWRL doesn't use JESS. There is nothing here that mentions JESS:
>
>        http://www.w3.org/Submission/SWRL/
>
> It may be the case that the JESS environment allows you to reason with some subset of SWRL - I imagine it does, but I'm not an expert on JESS.
>
> SWRL extends OWL-DL with rules
>
> > , which uses two types of chaining rules, however, when you create the rules in SWRL in the protected environment, the rules are always forward chaining.
>
> > example, father (?x,?y) ^ father (?y,?z) -> grandfather (?x,?z)
>
> > I would like to find some way to create rules below, with some language for the semantic web.
>
> >   grandfather(?x,?z)-> father (?x,?y) ^ father (?y,?z)
>
> Read:http://en.wikipedia.org/wiki/Forward_chaining
>
> What you want has nothing to do with forward or backward chaining.
>
> It sounds like you want to say is:
>
>         if x is the grandfather of z, then there exists some y such that x is the father of y and y is the father of z.
>
> If so, you might want to look at using full FOL and a theorem prover like prover 9.
>
> In prover 9 syntax:
>
> grandfather_of(x,z) -> exists y : father_of(x,y) & father_of(y,z).
>
> (tip: always make the directionality of relations explicit)
>
> It may help to take a step back - is this really what you want to do? Why? Does it need to be in a "semantic web" language?
>
> You may be better off asking the question on a more general mailing list
>
> Cheers
> Chris
>
>
>
>
>
>
>
> > 2011/9/20 Chris Mungall <cjmung...@lbl.gov>

Jochem Liem

unread,
Sep 24, 2011, 3:34:58 AM9/24/11
to thea-o...@googlegroups.com
Hi Luis,

When you load an OWL file using Thea, it asserts the contents of the
OWL file as "facts" (closely resembling OWL abstract syntax). Look in
the file 'owl2_model.pl' to see what this looks like.You can directly
use these facts in prolog rules.

You probably want something like:

:- rdf_db:rdf_register_ns('namespacename',
'http://www.uriofyourontology.com/family.owl#').

grandfather (X, Y):-
rdf_global_id(namespacename:has_father, HasFatherURI),
propertyAssertion(HasFatherURI, X, Z),
propertyAssertion(HasFatherURI, Z, Y).

Cheers,
Jochem

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Jochem Liem, MSc.
Informatics Institute
Faculty of Science
University of Amsterdam
http://www.science.uva.nl/~jliem/

Phone:  +31 (0)20 525 6801
Mobile: +31 (0)6  4321 9992
Fax:     +31 (0)20 525 7490

Visitor address:
Science Park 904, C2.248
1098 XH Amsterdam

Mailing address:
Postbus 94323
1090 GH Amsterdam
The Netherlands
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Luis Eduardo Santos

unread,
Sep 27, 2011, 9:22:31 PM9/27/11
to thea-o...@googlegroups.com
Thank you for your help, I managed to make it work! one more question

the code looked like this:

grandfather(NameX,NameY):-
    propertyAssertion(HasFatherURI, X, Z),
    propertyAssertion(HasFatherURI, Z, Y),
    propertyAssertion(Name, X, NameX),
    propertyAssertion(Name, Y, NameY).

 

When I do a query below, he correctly returns

?- grandfather(X,Y).

X = literal(type('http://www.w3.org/2001/XMLSchema#string', paul)),
Y = literal(type('http://www.w3.org/2001/XMLSchema#string', mary))


But when I do a query specifies:

?- grandfather(paul,Y).
false.


he returns "false". How do I get it correctly returns me to the variable Y only "mary"?


Thank you!


2011/9/24 Jochem Liem <joche...@gmail.com>

Jochem Liem

unread,
Sep 28, 2011, 6:48:10 AM9/28/11
to thea-o...@googlegroups.com
You should take care when working with literals. They can have
different forms depending on whether you indicate the datatype (such
as you have now), and whether you indicate that the literal is in a
particular language. See the following documentation:
http://www.swi-prolog.org/pldoc/doc_for?object=section(3,'3.1',swi('/doc/packages/rdf2pl.html'))

Also note that your properties are not instantiated, so then can match
with any property.

In your code, you can construct the complete literal from NameX:
NameXLiteral =
literal(type('http://www.w3.org/2001/XMLSchema#string', NameX)

Then use NameXLiteral instead of NameX in your propertyAssertion line.
propertyAssertion(Name, X, NameX),

You should do the same for NameY.

~ Jochem

Reply all
Reply to author
Forward
0 new messages