1 | package org.biohackathon.SPARQLBuilder.OWL;
|
---|
2 |
|
---|
3 | import org.json.JSONException;
|
---|
4 | import org.json.JSONObject;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * 繧ッ繝ゥ繧ケ縺ク縲√≠繧九>縺ッ繧ッ繝ゥ繧ケ縺九i縺ョ1繧ケ繝�ャ繝励Μ繝ウ繧ッ繧定ィ倩ソー縺吶k
|
---|
8 | * @author Norio KOBAYASHI
|
---|
9 | * @since 28.01.2014
|
---|
10 | * @version 29.01.2014
|
---|
11 | */
|
---|
12 | public class ClassLink {
|
---|
13 |
|
---|
14 | private String propertyURI = null;
|
---|
15 | private String linkedClassURI = null;
|
---|
16 | private String linkedLiteralDatatypeURI = null;
|
---|
17 | private Direction direction = null;
|
---|
18 | private int numOfLinks = 0;
|
---|
19 | private int numOfLinkedInstances = 0;
|
---|
20 | private int numOfOriginInstances = 0;
|
---|
21 | private int numOfOriginClassInstances = 0;
|
---|
22 | private int numOfLinkedClassInstances = 0;
|
---|
23 | private boolean domainClassLimitedQ = false;
|
---|
24 | private boolean rangeClassLimitedQ = false;
|
---|
25 |
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * 繝励Ο繝代ユ繧」URI縲√Μ繝ウ繧ッ蜈茨シ亥��峨け繝ゥ繧ケ縲√Μ繝ウ繧ッ縺ョ蜷代″繧剃ク弱∴繧区ァ区�蟄� |
---|
29 | *
|
---|
30 | * @param propertyURI縲繝励Ο繝代ユ繧」縺ョURI
|
---|
31 | * @param linkedClassURI縲繝ェ繝ウ繧ッ縺ョ荳サ隱槭√√≠繧九>縺ッ繝ェ繝ウ繧ッ縺ョ逶ョ逧�ェ槭→縺ェ縺」縺ヲ縺�k繧ッ繝ゥ繧ケ縺ョURI
|
---|
32 | * @param direction 繝励Ο繝代ユ繧」縺ョ蜷代″縲〕inkedClassURI縺ョ繧ッ繝ゥ繧ケ縺後Μ繝ウ繧ッ蜈医↓縺ェ縺」縺ヲ縺�k縺ィ縺阪�Direction.forward,繝ェ繝ウ繧ッ蜈�↓縺ェ縺」縺ヲ縺�k縺ィ縺阪�Direction.reverse, 縺昴l繧我ク。譁ケ縺ョ譎ゅ�Direction.both繧呈欠螳壹☆繧�
|
---|
33 | * @param numOfLinks 蠖楢ゥイ繝励Ο繝代ユ繧」縺ァ荳。遶ッ繧ッ繝ゥ繧ケ縺ョ繧、繝ウ繧ケ繧ソ繝ウ繧ケ蜷悟」ォ繧偵▽縺ェ縺�〒縺�k繝ェ繝ウ繧ッ謨ー�医ヨ繝ェ繝励Ν謨ー�� |
---|
34 | * @throws Exception
|
---|
35 | * @since 28.01.2014
|
---|
36 | */
|
---|
37 | public ClassLink(String propertyURI, String linkedClassURI, String linkedLiteralDatatypeURI, Direction direction,
|
---|
38 | int numLinks, int numOfOriginInstances, int numOfLinkedInstances,
|
---|
39 | int numOfOriginClassInstances, int numofLinkedClassInstances,
|
---|
40 | boolean domainClassLimitedQ, boolean rangeClassLimitedQ){
|
---|
41 | this.propertyURI = propertyURI;
|
---|
42 | this.linkedClassURI = linkedClassURI;
|
---|
43 | this.linkedLiteralDatatypeURI = linkedLiteralDatatypeURI;
|
---|
44 | this.direction = direction;
|
---|
45 | this.numOfLinks = numLinks;
|
---|
46 | this.numOfLinkedInstances = numOfLinkedInstances;
|
---|
47 | this.numOfOriginInstances = numOfOriginInstances;
|
---|
48 | this.numOfOriginClassInstances = numOfOriginClassInstances;
|
---|
49 | this.numOfLinkedClassInstances = numofLinkedClassInstances;
|
---|
50 | this.domainClassLimitedQ = domainClassLimitedQ;
|
---|
51 | this.rangeClassLimitedQ = rangeClassLimitedQ;
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | public JSONObject toJSON() throws JSONException{
|
---|
56 | JSONObject obj = new JSONObject();
|
---|
57 | if( propertyURI != null ) {
|
---|
58 | obj.put("propertyURI", propertyURI);
|
---|
59 | }
|
---|
60 | if( linkedClassURI != null ){
|
---|
61 | obj.put("linkedClassURI", linkedClassURI);
|
---|
62 | }
|
---|
63 | if( linkedLiteralDatatypeURI != null ){
|
---|
64 | obj.put("linkedLiteralDatatypeURI", linkedLiteralDatatypeURI);
|
---|
65 | }
|
---|
66 | if( direction != null ){
|
---|
67 | obj.put("direction", direction);
|
---|
68 | }
|
---|
69 | //obj.put("numOfLinks", numOfLinks);
|
---|
70 | //obj.put("numOfLinkedInstances", numOfLinkedInstances);
|
---|
71 | //obj.put("numOfOriginInstances", numOfOriginInstances);
|
---|
72 | //obj.put("numOfOriginClassInstances", numOfOriginClassInstances);
|
---|
73 | //obj.put("numOfLinkedClassInstances", numOfLinkedClassInstances);
|
---|
74 | return obj;
|
---|
75 | }
|
---|
76 | // add direction and other variations
|
---|
77 | public String toJSONString2() {
|
---|
78 | String json_str ="{";
|
---|
79 |
|
---|
80 | if( propertyURI != null ) {
|
---|
81 | json_str+="\"propertyURI\":"+"\""+propertyURI+"\",";
|
---|
82 | }
|
---|
83 | else{
|
---|
84 | json_str+="\"propertyURI\":"+"\"propertyURI\",";
|
---|
85 | }
|
---|
86 | if( linkedClassURI != null ){
|
---|
87 | json_str+="\"linkedClassURI\":"+"\""+linkedClassURI+"\",";
|
---|
88 | }
|
---|
89 | else{
|
---|
90 | json_str+="\"linkedClassURI\":"+"\"linkedClassURI\",";
|
---|
91 | }
|
---|
92 | if( linkedLiteralDatatypeURI != null ){
|
---|
93 | json_str+="\"linkedLiteralDatatypeURI\":"+"\""+linkedLiteralDatatypeURI+"\",";
|
---|
94 | }
|
---|
95 | else{
|
---|
96 | json_str+="\"linkedLiteralDatatypeURI\":"+"\"linkedLiteralDatatypeURI\",";
|
---|
97 | }
|
---|
98 | if( direction != null ){
|
---|
99 | json_str+="\"direction\":"+"\""+direction.toString()+"\"";
|
---|
100 | }
|
---|
101 | else{
|
---|
102 | json_str+="\"direction\":"+"\"direction\"";
|
---|
103 | }
|
---|
104 |
|
---|
105 | // json_str+="\"numOfLinks\":"+"\""+numOfLinks+"\",";
|
---|
106 | // json_str+="\"numOfLinkedInstances\":"+"\""+numOfLinkedInstances+"\",";
|
---|
107 | // json_str+="\"numOfOriginInstances\":"+"\""+numOfOriginInstances+"\",";
|
---|
108 | // json_str+="\"numOfOriginClassInstances\":"+"\""+numOfOriginClassInstances+"\",";
|
---|
109 | // json_str+="\"numOfLinkedClassInstances\":"+"\""+numOfLinkedClassInstances+"\"";
|
---|
110 |
|
---|
111 | json_str+="}";
|
---|
112 |
|
---|
113 | return json_str;
|
---|
114 | }
|
---|
115 |
|
---|
116 | public String toJSONString3(SClass[] classes) {
|
---|
117 | String json_str ="{";
|
---|
118 |
|
---|
119 | if( propertyURI != null ) {
|
---|
120 | json_str+="\"propertyURI\":"+"\""+propertyURI+"\",";
|
---|
121 | }
|
---|
122 | else{
|
---|
123 | json_str+="\"propertyURI\":"+"\"propertyURI\",";
|
---|
124 | }
|
---|
125 | if( linkedClassURI != null ){
|
---|
126 | json_str+="\"linkedClassURI\":"+"\""+linkedClassURI+"\",";
|
---|
127 | }
|
---|
128 | else{
|
---|
129 | json_str+="\"linkedClassURI\":"+"\"linkedClassURI\",";
|
---|
130 | }
|
---|
131 | if( linkedLiteralDatatypeURI != null ){
|
---|
132 | json_str+="\"linkedLiteralDatatypeURI\":"+"\""+linkedLiteralDatatypeURI+"\",";
|
---|
133 | }
|
---|
134 | else{
|
---|
135 | json_str+="\"linkedLiteralDatatypeURI\":"+"\"linkedLiteralDatatypeURI\",";
|
---|
136 | }
|
---|
137 | if( direction != null ){
|
---|
138 | json_str+="\"direction\":"+"\""+direction.toString()+"\",";
|
---|
139 | }
|
---|
140 | else{
|
---|
141 | json_str+="\"direction\":"+"\"direction\",";
|
---|
142 | }
|
---|
143 | //if ( linkedClassURI != null ){
|
---|
144 | String label = getLinkedClassLabel(classes);
|
---|
145 | json_str+="\"nodelabel\":"+"\""+label+"\"";
|
---|
146 | //}
|
---|
147 | // json_str+="\"numOfLinks\":"+"\""+numOfLinks+"\",";
|
---|
148 | // json_str+="\"numOfLinkedInstances\":"+"\""+numOfLinkedInstances+"\",";
|
---|
149 | // json_str+="\"numOfOriginInstances\":"+"\""+numOfOriginInstances+"\",";
|
---|
150 | // json_str+="\"numOfOriginClassInstances\":"+"\""+numOfOriginClassInstances+"\",";
|
---|
151 | // json_str+="\"numOfLinkedClassInstances\":"+"\""+numOfLinkedClassInstances+"\"";
|
---|
152 |
|
---|
153 | json_str+="}";
|
---|
154 |
|
---|
155 | return json_str;
|
---|
156 | }
|
---|
157 |
|
---|
158 | public int getNumOfLinks() {
|
---|
159 | return numOfLinks;
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 |
|
---|
165 | public void setNumOfLinks(int numOfLinks) {
|
---|
166 | this.numOfLinks = numOfLinks;
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 |
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * 譁�ュ怜�陦ィ險倥r蜿門セ励☆繧� |
---|
174 | *
|
---|
175 | * @since 28.01.2014
|
---|
176 | */
|
---|
177 | public String toString(){
|
---|
178 | StringBuffer sb = new StringBuffer();
|
---|
179 | sb.append(propertyURI);
|
---|
180 | if( direction == Direction.forward ){
|
---|
181 | sb.append(" --> ");
|
---|
182 | }else{
|
---|
183 | if( direction == Direction.reverse ){
|
---|
184 | sb.append(" <-- ");
|
---|
185 | }else{
|
---|
186 | sb.append(" <-> ");
|
---|
187 | }
|
---|
188 | }
|
---|
189 | sb.append(linkedClassURI);
|
---|
190 | sb.append(" [");
|
---|
191 | sb.append(numOfOriginClassInstances);
|
---|
192 | sb.append("/");
|
---|
193 | sb.append(numOfOriginInstances);
|
---|
194 | sb.append("]縲---");
|
---|
195 |
|
---|
196 |
|
---|
197 | sb.append(" [");
|
---|
198 | sb.append(numOfLinks);
|
---|
199 | sb.append("] --->");
|
---|
200 |
|
---|
201 | sb.append(" [");
|
---|
202 | sb.append(numOfLinkedClassInstances);
|
---|
203 | sb.append("/");
|
---|
204 | sb.append(numOfLinkedInstances);
|
---|
205 | sb.append("]");
|
---|
206 | return sb.toString();
|
---|
207 | }
|
---|
208 |
|
---|
209 | public String getPropertyURI() {
|
---|
210 | return propertyURI;
|
---|
211 | }
|
---|
212 | public void setPropertyURI(String propertyURI) {
|
---|
213 | this.propertyURI = propertyURI;
|
---|
214 | }
|
---|
215 | public String getLinkedClassURI() {
|
---|
216 | return linkedClassURI;
|
---|
217 | }
|
---|
218 | public void setLinkedClassURI(String linkedClassURI) {
|
---|
219 | this.linkedClassURI = linkedClassURI;
|
---|
220 | }
|
---|
221 | public Direction getDirection() {
|
---|
222 | return direction;
|
---|
223 | }
|
---|
224 | public void setDirection(Direction direction) {
|
---|
225 | this.direction = direction;
|
---|
226 | }
|
---|
227 |
|
---|
228 | public final int getNumOfLinkedInstances() {
|
---|
229 | return numOfLinkedInstances;
|
---|
230 | }
|
---|
231 |
|
---|
232 | public final void setNumOfLinkedInstances(int numOfLinkedInstances) {
|
---|
233 | this.numOfLinkedInstances = numOfLinkedInstances;
|
---|
234 | }
|
---|
235 |
|
---|
236 |
|
---|
237 |
|
---|
238 |
|
---|
239 | public final boolean isDomainClassLimitedQ() {
|
---|
240 | return domainClassLimitedQ;
|
---|
241 | }
|
---|
242 |
|
---|
243 |
|
---|
244 | public final boolean isRangeClassLimitedQ() {
|
---|
245 | return rangeClassLimitedQ;
|
---|
246 | }
|
---|
247 |
|
---|
248 |
|
---|
249 | public final int getNumOfOriginInstances() {
|
---|
250 | return numOfOriginInstances;
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | public final void setNumOfOriginInstances(int numOfOriginInstances) {
|
---|
255 | this.numOfOriginInstances = numOfOriginInstances;
|
---|
256 | }
|
---|
257 |
|
---|
258 |
|
---|
259 | public final int getNumOfOriginClassInstances() {
|
---|
260 | return numOfOriginClassInstances;
|
---|
261 | }
|
---|
262 |
|
---|
263 |
|
---|
264 | public final void setNumOfOriginClassInstances(int numOfOriginClassInstances) {
|
---|
265 | this.numOfOriginClassInstances = numOfOriginClassInstances;
|
---|
266 | }
|
---|
267 |
|
---|
268 |
|
---|
269 | public final int getNumOfLinkedClassInstances() {
|
---|
270 | return numOfLinkedClassInstances;
|
---|
271 | }
|
---|
272 |
|
---|
273 |
|
---|
274 | public final void setNumOfLinkedClassInstances(int numOfLinkedClassInstances) {
|
---|
275 | this.numOfLinkedClassInstances = numOfLinkedClassInstances;
|
---|
276 | }
|
---|
277 |
|
---|
278 |
|
---|
279 | public final String getLinkedLiteralDatatypeURI() {
|
---|
280 | return linkedLiteralDatatypeURI;
|
---|
281 | }
|
---|
282 |
|
---|
283 |
|
---|
284 | public final void setLinkedLiteralDatatypeURI(String linkedLiteralDatatypeURI) {
|
---|
285 | this.linkedLiteralDatatypeURI = linkedLiteralDatatypeURI;
|
---|
286 | }
|
---|
287 |
|
---|
288 |
|
---|
289 | public final void setDomainClassLimitedQ(boolean domainClassLimitedQ) {
|
---|
290 | this.domainClassLimitedQ = domainClassLimitedQ;
|
---|
291 | }
|
---|
292 |
|
---|
293 |
|
---|
294 | public final void setRangeClassLimitedQ(boolean rangeClassLimitedQ) {
|
---|
295 | this.rangeClassLimitedQ = rangeClassLimitedQ;
|
---|
296 | }
|
---|
297 |
|
---|
298 | private String getLinkedClassLabel(SClass[] classes){
|
---|
299 | return QueryPathGenerator.getClassLabel(linkedClassURI, classes);
|
---|
300 | }
|
---|
301 |
|
---|
302 | // private String[] propertyDomainClassURIs = null;
|
---|
303 | // private String[] propertyRangeClassURIs = null;
|
---|
304 |
|
---|
305 |
|
---|
306 |
|
---|
307 | }
|
---|