-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathowl2_to_progol.pl
108 lines (91 loc) · 3.07 KB
/
owl2_to_progol.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* -*- 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
*/