|
1
|
|
|
/* |
|
2
|
|
|
* |
|
3
|
|
|
* Copyright (C) 2009-2017 Julian Mendez |
|
4
|
|
|
* |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of jcel. |
|
7
|
|
|
* |
|
8
|
|
|
* |
|
9
|
|
|
* The contents of this file are subject to the GNU Lesser General Public License |
|
10
|
|
|
* version 3 |
|
11
|
|
|
* |
|
12
|
|
|
* |
|
13
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
14
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
15
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
16
|
|
|
* (at your option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, |
|
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21
|
|
|
* GNU Lesser General Public License for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
25
|
|
|
* |
|
26
|
|
|
* |
|
27
|
|
|
* Alternatively, the contents of this file may be used under the terms |
|
28
|
|
|
* of the Apache License, Version 2.0, in which case the |
|
29
|
|
|
* provisions of the Apache License, Version 2.0 are applicable instead of those |
|
30
|
|
|
* above. |
|
31
|
|
|
* |
|
32
|
|
|
* |
|
33
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
34
|
|
|
* you may not use this file except in compliance with the License. |
|
35
|
|
|
* You may obtain a copy of the License at |
|
36
|
|
|
* |
|
37
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
38
|
|
|
* |
|
39
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
40
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
41
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
42
|
|
|
* See the License for the specific language governing permissions and |
|
43
|
|
|
* limitations under the License. |
|
44
|
|
|
* |
|
45
|
|
|
*/ |
|
46
|
|
|
|
|
47
|
|
|
package de.tudresden.inf.lat.jcel.core.completion.ext; |
|
48
|
|
|
|
|
49
|
|
|
import java.util.Objects; |
|
50
|
|
|
import java.util.Optional; |
|
51
|
|
|
|
|
52
|
|
|
import de.tudresden.inf.lat.jcel.core.completion.common.ClassifierStatus; |
|
53
|
|
|
import de.tudresden.inf.lat.jcel.core.completion.common.CompletionRuleMonitor; |
|
54
|
|
|
import de.tudresden.inf.lat.jcel.core.completion.common.RObserverRule; |
|
55
|
|
|
import de.tudresden.inf.lat.jcel.core.graph.VNode; |
|
56
|
|
|
import de.tudresden.inf.lat.jcel.core.graph.VNodeImpl; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* |
|
60
|
|
|
* <ul> |
|
61
|
|
|
* <li>CR-7 : <b>if</b> ∃ s<sup>-</sup> <i>.</i> A \u2291 B ∈ |
|
62
|
|
|
* <i>T</i> , <u>(r<sub>2</sub>, x, y) ∈ R</u>, x = (A', φ) , y = (B', |
|
63
|
|
|
* ψ), <br> |
|
64
|
|
|
* r \u2218 r \u2291 r ∈ <i>T</i>, r<sub>1</sub> \u2291<sub><i>T</i></sub> |
|
65
|
|
|
* r, r<sub>2</sub> \u2291<sub><i>T</i></sub> r, ∃ r<sub>1</sub> |
|
66
|
|
|
* <sup>-</sup> <i>.</i> A ∈ φ, r \u2291<sub><i>T</i></sub> s <br> |
|
67
|
|
|
* <b>then</b> v := (B', ψ ∪ {∃ r<sup>-</sup> <i>.</i> A}) <br> |
|
68
|
|
|
* <b>if</b> v ∉ V <b>then</b> V := V ∪ {v} , |
|
69
|
|
|
* S := S ∪ {(v, k) | (y, k) ∈ S} <br> |
|
70
|
|
|
* S := S ∪ {(v, B)} <br> |
|
71
|
|
|
* R := R ∪ {(r<sub>2</sub>, x, v)}</li> |
|
72
|
|
|
* </ul> |
|
73
|
|
|
* <br> |
|
74
|
|
|
* |
|
75
|
|
|
* @author Julian Mendez |
|
76
|
|
|
*/ |
|
77
|
|
|
public class CR7RExtRule implements RObserverRule { |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Constructs a new completion rule CR-7. |
|
81
|
|
|
*/ |
|
82
|
|
|
public CR7RExtRule() { |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
@Override |
|
86
|
|
|
public boolean apply(ClassifierStatus status, int property, int leftClass, int rightClass) { |
|
87
|
|
|
Objects.requireNonNull(status); |
|
88
|
|
|
return applyRule(status, property, leftClass, rightClass); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
private boolean applyRule(ClassifierStatus status, int r2, int x, int y) { |
|
92
|
|
|
CompletionRuleMonitor ret = new CompletionRuleMonitor(); |
|
93
|
|
|
Optional<VNode> optPhiNode = status.getNode(x); |
|
94
|
|
|
if (!optPhiNode.isPresent()) { |
|
95
|
|
|
throw new IllegalStateException("Node not found in internal structure '" + x + "'."); |
|
96
|
|
|
} |
|
97
|
|
|
Optional<VNode> optPsiNode = status.getNode(y); |
|
98
|
|
|
if (!optPsiNode.isPresent()) { |
|
99
|
|
|
throw new IllegalStateException("Node not found in internal structure '" + y + "'."); |
|
100
|
|
|
} |
|
101
|
|
|
status.getSuperObjectProperties(r2).forEach(r -> { |
|
102
|
|
|
if (status.getExtendedOntology().getTransitiveObjectProperties().contains(r)) { |
|
103
|
|
|
int rMinus = status.getInverseObjectPropertyOf(r); |
|
104
|
|
|
status.getSuperObjectProperties(r).forEach(s -> { |
|
105
|
|
|
int sMinus = status.getInverseObjectPropertyOf(s); |
|
106
|
|
|
status.getExtendedOntology().getGCI3rAxioms(sMinus).forEach(axiom -> { |
|
107
|
|
|
int a = axiom.getClassInSubClass(); |
|
108
|
|
|
int b = axiom.getSuperClass(); |
|
109
|
|
|
status.getSubObjectProperties(r).forEach(r1 -> { |
|
110
|
|
|
int r1Minus = status.getInverseObjectPropertyOf(r1); |
|
111
|
|
|
if (optPhiNode.get().containsExistential(r1Minus, a)) { |
|
112
|
|
|
VNodeImpl newNode = new VNodeImpl(optPsiNode.get().getClassId()); |
|
113
|
|
|
newNode.addExistentialsOf(optPsiNode.get()); |
|
114
|
|
|
newNode.addExistential(rMinus, a); |
|
115
|
|
|
boolean inV = status.contains(newNode); |
|
116
|
|
|
int v = status.createOrGetNodeId(newNode); |
|
117
|
|
|
if (!inV) { |
|
118
|
|
|
status.getSubsumers(y).forEach(p -> { |
|
119
|
|
|
ret.or(status.addNewSEntry(v, p)); |
|
120
|
|
|
}); |
|
121
|
|
|
} |
|
122
|
|
|
ret.or(status.addNewSEntry(v, b)); |
|
123
|
|
|
ret.or(status.addNewREntry(r2, x, v)); |
|
124
|
|
|
} |
|
125
|
|
|
}); |
|
126
|
|
|
}); |
|
127
|
|
|
}); |
|
128
|
|
|
} |
|
129
|
|
|
}); |
|
130
|
|
|
return ret.get(); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
@Override |
|
134
|
|
|
public boolean equals(Object o) { |
|
135
|
|
|
return (Objects.nonNull(o)) && getClass().equals(o.getClass()); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
@Override |
|
139
|
|
|
public int hashCode() { |
|
140
|
|
|
return getClass().hashCode(); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
@Override |
|
144
|
|
|
public String toString() { |
|
145
|
|
|
return getClass().getSimpleName(); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|