root/tags/lgt2305/library/class_hierarchy.lgt

Revision 3687, 4.0 KB (checked in by pmoura, 21 months ago)

Code reformating.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- category(class_hierarchy,
3    implements(class_hierarchyp)).
4
5    :- info([
6        version is 1.1,
7        author is 'Paulo Moura',
8        date is 2006/2/20,
9        comment is 'Class hierarchy predicates.']).
10
11    class(Class) :-
12        self(Self),
13        instantiates_class(Self, Class).
14
15    classes(Classes) :-
16        self(Self),
17        findall(Class, instantiates_class(Self, Class), Classes).
18
19    ancestor(Ancestor) :-
20        self(Self),
21        ancestor(Self, Ancestor).
22
23    ancestor(Self, Ancestor) :-
24        instantiates_class(Self, Ancestor).
25    ancestor(Self, Ancestor) :-
26        instantiates_class(Self, Class),
27        superclass(Class, Ancestor).
28 
29    ancestors(Ancestors) :-
30        self(Self),
31        findall(Ancestor, ancestor(Self, Ancestor), Ancestors).
32
33    instance(Instance) :-
34        self(Self),
35        instantiates_class(Instance, Self).
36
37    instances(Instances) :-
38        self(Self),
39        findall(Instance, instantiates_class(Instance, Self), Instances).
40
41    subclass(Subclass) :-
42        self(Self),
43        specializes_class(Subclass, Self).
44
45    subclasses(Subclasses) :-
46        self(Self),
47        findall(Subclass, specializes_class(Subclass, Self), Subclasses).
48
49    superclass(Superclass) :-
50        self(Self),
51        superclass(Self, Superclass).
52
53    superclass(Self, Superclass) :-
54        specializes_class(Self, Superclass).
55    superclass(Self, Superclass) :-
56        specializes_class(Self, Class),
57        superclass(Class, Superclass).
58
59    superclasses(Superclasses) :-
60        self(Self),
61        findall(Superclass, specializes_class(Self, Superclass), Superclasses).
62
63    leaf(Leaf) :-
64        self(Self),
65        leaf(Self, Leaf).
66
67    leaf(Self, Leaf) :-
68        instantiates_class(Leaf, Self),
69        \+ instantiates_class(_, Leaf),
70        \+ specializes_class(_, Leaf).
71    leaf(Self, Leaf) :-
72        specializes_class(Leaf, Self),
73        \+ instantiates_class(_, Leaf),
74        \+ specializes_class(_, Leaf).
75    leaf(Self, Leaf) :-
76        specializes_class(Subclass, Self),
77        leaf(Subclass, Leaf).
78
79    leaves(Leaves) :-
80        self(Self),
81        (   setof(Leaf, leaf(Self, Leaf), Leaves) ->
82            true
83        ;   Leaves = []
84        ).
85
86    leaf_instance(Leaf) :-
87        self(Self),
88        leaf_instance(Self, Leaf).
89
90    leaf_instance(Self, Leaf) :-
91        instantiates_class(Leaf, Self),
92        \+ instantiates_class(_, Leaf).
93    leaf_instance(Self, Leaf) :-
94        specializes_class(Subclass, Self),
95        leaf_instance(Subclass, Leaf).
96
97    leaf_instances(Leaves) :-
98        self(Self),
99        (   setof(Leaf, leaf_instance(Self, Leaf), Leaves) ->
100            true
101        ;   Leaves = []
102        ).
103
104    leaf_class(Leaf) :-
105        self(Self),
106        leaf_class(Self, Leaf).
107       
108    leaf_class(Self, Leaf) :-
109        specializes_class(Leaf, Self),
110        \+ specializes_class(_, Leaf).
111    leaf_class(Self, Leaf) :-
112        specializes_class(Subclass, Self),
113        leaf_class(Subclass, Leaf).
114
115    leaf_classes(Leaves) :-
116        self(Self),
117        (   setof(Leaf, leaf_class(Self, Leaf), Leaves) ->
118            true
119        ;   Leaves = []
120        ).
121
122    descendant(Descendant) :-
123        self(Self),
124        descendant(Self, Descendant).
125
126    descendant(Self, Descendant) :-
127        instantiates_class(Descendant, Self).
128    descendant(Self, Descendant) :-
129        specializes_class(Descendant, Self),
130        \+ instantiates_class(Descendant, Self).
131    descendant(Self, Descendant) :-
132        specializes_class(Subclass, Self),
133        descendant(Subclass, Descendant).
134
135    descendants(Descendants) :-
136        self(Self),
137        (   setof(Descendant, descendant(Self, Descendant), Descendants) ->
138            true
139        ;   Descendants = []
140        ).
141
142    descendant_class(Descendant) :-
143        self(Self),
144        descendant_class(Self, Descendant).
145       
146    descendant_class(Self, Descendant) :-
147        specializes_class(Descendant, Self).
148    descendant_class(Self, Descendant) :-
149        specializes_class(Subclass, Self),
150        descendant_class(Subclass, Descendant).
151
152    descendant_classes(Descendants) :-
153        self(Self),
154        (   setof(Descendant, descendant_class(Self, Descendant), Descendants) ->
155            true
156        ;   Descendants = []
157        ).
158
159    descendant_instance(Descendant) :-
160        self(Self),
161        descendant_instance(Self, Descendant).
162
163    descendant_instance(Self, Descendant) :-
164        instantiates_class(Descendant, Self).
165    descendant_instance(Self, Descendant) :-
166        specializes_class(Subclass, Self),
167        descendant_instance(Subclass, Descendant).
168
169    descendant_instances(Descendants) :-
170        self(Self),
171        (   setof(Descendant, descendant_instance(Self, Descendant), Descendants) ->
172            true
173        ;   Descendants = []
174        ).
175
176:- end_category.
Note: See TracBrowser for help on using the browser.