Permalink
Fetching contributors…
Cannot retrieve contributors at this time
109 lines (91 sloc) 3.07 KB
/* -*- Mode: Prolog -*- */
:- module(owl2_to_progol,
[
write_progol_mode_decls/1,
write_progol_facts/3
]).
:- use_module(owl2_model).
:- use_module(owl2_basic_reasoner).
:- multifile owl2_io:save_axioms_hook/3.
owl2_io:save_axioms_hook(File,progol,Opts) :-
( nonvar(File)
-> tell(File)
; true),
member(mode_decls(Roots),Opts),
write_progol_mode_decls(Roots),
member(head(Head),Opts),
member(goal(Goal),Opts),
member(type(TypeDecl),Opts),
write_progol_facts(Head,Goal,TypeDecl),
told.
%% write_progol_facts(+Head:term,+Goal:callable,+TypeDecl:term)
%
% writes instance data for use as ILP training set. Also generates
% type declarations.
%
% Training set is written as unit clauses using Head. Facts
% are generated using Goal
%
% This is designed to be used in conjunction with a DLP
% program generated by owl2_to_prolog_dlp
%
% classAssertion/2 is treated as a unary predicate
% propertyAssertion/2 is treated as a binary predicate
% (see the Grosof translation in owl2_to_prolog_dlp)
% TODO: combine these?
%
% Example: write_progol_facts(has_disease_type(H,DT), (propertyAssertion(inheres_in,D,H),classAssertion(D,DT)), disease_type(DT))
% writes:
% =|has_disease_type(human1,alzheimers). ... disease_type(alzheimers)|=
write_progol_facts(Head,Goal,TypeDecl) :-
format('% Type declarations:~n'),
setof(TypeDecl,Goal^Goal,TypeDecls),
nl,
format('% Facts:~n'),
forall(member(TypeDecl,TypeDecls),
format('~q.~n',[TypeDecl])),
forall(Goal,format('~q.~n',[Head])).
%% write_progol_mode_decls(+Roots:list)
%
% progol typing system means we have a general type for everything
%
% Roots is a list of classes. A mode declaration is made for
% every class subsumed by each Root in Roots. We use unary class predicates
% for instantiation
%
% Example:
% =|:- modeb(1,brainstem(+object))?|=
write_progol_mode_decls(Roots) :-
forall(class(X),
write_progol_mode_decl(class(X),Roots)).
write_progol_mode_decl(class(X),Roots) :-
entailed(subClassOf(X,Root)),
member(Root,Roots),
format(':- modeb(1,~q(+~q))?~n',[X,Root]),
!.
write_progol_mode_decl(_,_).
/** <module> generates ProGol ILP programs from OWL2 ontologies
---+ Synopsis
==
:- use_module(bio(owl2_to_progol)).
:- use_module(bio(owl2_io)).
%
demo:-
load_axioms('data.rdf'), % classAssertion/2 and propertyAssertion/3
load_axioms('ont.owl'), %
tell('foo.progol'),
use_labels_for_IRIs,
write_progol_mode_decls(['Biomaterial object',quality,'Quality',dependent_continuant,disease,'Disease']),
write_progol_facts(has_disease_type(H,DT),
( propertyAssertion(inheres_in,D,H),
classAssertion(DT,D),
entailed(subClassOf(DT,'Neurodegenerative disease'))),
disease_type(DT)),
told.
==
---+ Details
Alpha/experimental
Depends on owl2_basic_reasoner which is also alpha
---++
TODO - add hooks for owl2_io
*/