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 endpointURI = null;
|
---|
15 | private String graphURI = null;
|
---|
16 | private String propertyURI = null;
|
---|
17 | private String linkedClassURI = null;
|
---|
18 | private String linkedLiteralDatatypeURI = null;
|
---|
19 | private Direction direction = null;
|
---|
20 | private int numOfLinks = 0;
|
---|
21 | private int numOfLinkedInstances = 0;
|
---|
22 | private int numOfOriginInstances = 0;
|
---|
23 | private int numOfOriginClassInstances = 0;
|
---|
24 | private int numOfLinkedClassInstances = 0;
|
---|
25 | private boolean domainClassLimitedQ = false;
|
---|
26 | private boolean rangeClassLimitedQ = false;
|
---|
27 |
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * 繝励Ο繝代ユ繧」URI縲√Μ繝ウ繧ッ蜈茨シ亥��峨け繝ゥ繧ケ縲√Μ繝ウ繧ッ縺ョ蜷代″繧剃ク弱∴繧区ァ区�蟄� |
---|
31 | *
|
---|
32 | * @param propertyURI縲繝励Ο繝代ユ繧」縺ョURI
|
---|
33 | * @param linkedClassURI縲繝ェ繝ウ繧ッ縺ョ荳サ隱槭√√≠繧九>縺ッ繝ェ繝ウ繧ッ縺ョ逶ョ逧�ェ槭→縺ェ縺」縺ヲ縺�k繧ッ繝ゥ繧ケ縺ョURI
|
---|
34 | * @param direction 繝励Ο繝代ユ繧」縺ョ蜷代″縲〕inkedClassURI縺ョ繧ッ繝ゥ繧ケ縺後Μ繝ウ繧ッ蜈医↓縺ェ縺」縺ヲ縺�k縺ィ縺阪�Direction.forward,繝ェ繝ウ繧ッ蜈�↓縺ェ縺」縺ヲ縺�k縺ィ縺阪�Direction.reverse, 縺昴l繧我ク。譁ケ縺ョ譎ゅ�Direction.both繧呈欠螳壹☆繧�
|
---|
35 | * @param numOfLinks 蠖楢ゥイ繝励Ο繝代ユ繧」縺ァ荳。遶ッ繧ッ繝ゥ繧ケ縺ョ繧、繝ウ繧ケ繧ソ繝ウ繧ケ蜷悟」ォ繧偵▽縺ェ縺�〒縺�k繝ェ繝ウ繧ッ謨ー�医ヨ繝ェ繝励Ν謨ー�� |
---|
36 | * @throws Exception
|
---|
37 | * @since 28.01.2014
|
---|
38 | */
|
---|
39 | public ClassLink(String propertyURI, String linkedClassURI, String linkedLiteralDatatypeURI, Direction direction,
|
---|
40 | int numLinks, int numOfOriginInstances, int numOfLinkedInstances,
|
---|
41 | int numOfOriginClassInstances, int numofLinkedClassInstances,
|
---|
42 | boolean domainClassLimitedQ, boolean rangeClassLimitedQ){
|
---|
43 | this.propertyURI = propertyURI;
|
---|
44 | this.linkedClassURI = linkedClassURI;
|
---|
45 | this.linkedLiteralDatatypeURI = linkedLiteralDatatypeURI;
|
---|
46 | this.direction = direction;
|
---|
47 | this.numOfLinks = numLinks;
|
---|
48 | this.numOfLinkedInstances = numOfLinkedInstances;
|
---|
49 | this.numOfOriginInstances = numOfOriginInstances;
|
---|
50 | this.numOfOriginClassInstances = numOfOriginClassInstances;
|
---|
51 | this.numOfLinkedClassInstances = numofLinkedClassInstances;
|
---|
52 | this.domainClassLimitedQ = domainClassLimitedQ;
|
---|
53 | this.rangeClassLimitedQ = rangeClassLimitedQ;
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | public JSONObject toJSON() throws JSONException{
|
---|
58 | JSONObject obj = new JSONObject();
|
---|
59 | if( propertyURI != null ) {
|
---|
60 | obj.put("propertyURI", propertyURI);
|
---|
61 | }
|
---|
62 | if( linkedClassURI != null ){
|
---|
63 | obj.put("linkedClassURI", linkedClassURI);
|
---|
64 | }
|
---|
65 | if( linkedLiteralDatatypeURI != null ){
|
---|
66 | obj.put("linkedLiteralDatatypeURI", linkedLiteralDatatypeURI);
|
---|
67 | }
|
---|
68 | if( direction != null ){
|
---|
69 | obj.put("direction", direction);
|
---|
70 | }
|
---|
71 | //obj.put("numOfLinks", numOfLinks);
|
---|
72 | //obj.put("numOfLinkedInstances", numOfLinkedInstances);
|
---|
73 | //obj.put("numOfOriginInstances", numOfOriginInstances);
|
---|
74 | //obj.put("numOfOriginClassInstances", numOfOriginClassInstances);
|
---|
75 | //obj.put("numOfLinkedClassInstances", numOfLinkedClassInstances);
|
---|
76 | return obj;
|
---|
77 | }
|
---|
78 | // add direction and other variations
|
---|
79 | public String toJSONString2() {
|
---|
80 | String json_str ="{";
|
---|
81 |
|
---|
82 | if( propertyURI != null ) {
|
---|
83 | json_str+="\"propertyURI\":"+"\""+propertyURI+"\",";
|
---|
84 | }
|
---|
85 | else{
|
---|
86 | json_str+="\"propertyURI\":"+"\"propertyURI\",";
|
---|
87 | }
|
---|
88 | if( linkedClassURI != null ){
|
---|
89 | json_str+="\"linkedClassURI\":"+"\""+linkedClassURI+"\",";
|
---|
90 | }
|
---|
91 | else{
|
---|
92 | json_str+="\"linkedClassURI\":"+"\"linkedClassURI\",";
|
---|
93 | }
|
---|
94 | if( linkedLiteralDatatypeURI != null ){
|
---|
95 | json_str+="\"linkedLiteralDatatypeURI\":"+"\""+linkedLiteralDatatypeURI+"\",";
|
---|
96 | }
|
---|
97 | else{
|
---|
98 | json_str+="\"linkedLiteralDatatypeURI\":"+"\"linkedLiteralDatatypeURI\",";
|
---|
99 | }
|
---|
100 | if( direction != null ){
|
---|
101 | json_str+="\"direction\":"+"\""+direction.toString()+"\"";
|
---|
102 | }
|
---|
103 | else{
|
---|
104 | json_str+="\"direction\":"+"\"direction\"";
|
---|
105 | }
|
---|
106 |
|
---|
107 | // json_str+="\"numOfLinks\":"+"\""+numOfLinks+"\",";
|
---|
108 | // json_str+="\"numOfLinkedInstances\":"+"\""+numOfLinkedInstances+"\",";
|
---|
109 | // json_str+="\"numOfOriginInstances\":"+"\""+numOfOriginInstances+"\",";
|
---|
110 | // json_str+="\"numOfOriginClassInstances\":"+"\""+numOfOriginClassInstances+"\",";
|
---|
111 | // json_str+="\"numOfLinkedClassInstances\":"+"\""+numOfLinkedClassInstances+"\"";
|
---|
112 |
|
---|
113 | json_str+="}";
|
---|
114 |
|
---|
115 | return json_str;
|
---|
116 | }
|
---|
117 |
|
---|
118 | public String toJSONString3(SClass[] classes) {
|
---|
119 | String json_str ="{";
|
---|
120 |
|
---|
121 | if( propertyURI != null ) {
|
---|
122 | //json_str+="\"propertyURI\":"+"\""+propertyURI+"\",";
|
---|
123 | json_str+="\"predicate\":"+"\""+propertyURI+"\",";
|
---|
124 | }
|
---|
125 | else{
|
---|
126 | json_str+="\"predicate\":"+"\"propertyURI\",";
|
---|
127 | }
|
---|
128 | if( linkedClassURI != null ){
|
---|
129 | //json_str+="\"linkedClassURI\":"+"\""+linkedClassURI+"\",";
|
---|
130 | json_str+="\"linkedClass\":"+"\""+linkedClassURI+"\",";
|
---|
131 | }
|
---|
132 | else{
|
---|
133 | //json_str+="\"linkedClassURI\":"+"\"linkedClassURI\",";
|
---|
134 | json_str+="\"linkedClass\":"+"\""+linkedClassURI+"\",";
|
---|
135 | }
|
---|
136 | if( linkedLiteralDatatypeURI != null ){
|
---|
137 | json_str+="\"linkedLiteralDatatypeURI\":"+"\""+linkedLiteralDatatypeURI+"\",";
|
---|
138 | }
|
---|
139 | else{
|
---|
140 | json_str+="\"linkedLiteralDatatypeURI\":"+"\"linkedLiteralDatatypeURI\",";
|
---|
141 | }
|
---|
142 | if( direction != null ){
|
---|
143 | json_str+="\"direction\":"+"\""+direction.toString()+"\",";
|
---|
144 | }
|
---|
145 | else{
|
---|
146 | json_str+="\"direction\":"+"\"direction\",";
|
---|
147 | }
|
---|
148 | if ( linkedClassURI != null ){
|
---|
149 | String label = getLinkedClassLabel(classes);
|
---|
150 | json_str+="\"label\":"+"\""+label+"\"";
|
---|
151 | }else if ( linkedLiteralDatatypeURI != null ){
|
---|
152 | String url[] = linkedLiteralDatatypeURI.split("/");
|
---|
153 | String tmplabel = url[url.length-1];
|
---|
154 | String[] tmplabel2 = tmplabel.split("#");
|
---|
155 | String label = tmplabel2[tmplabel2.length-1];
|
---|
156 | json_str+="\"label\":"+"\""+label+"\"";
|
---|
157 | }else{
|
---|
158 | json_str+="\"label\":"+"\""+"\"No Label\""+"\"";
|
---|
159 | }
|
---|
160 | // json_str+="\"numOfLinks\":"+"\""+numOfLinks+"\",";
|
---|
161 | // json_str+="\"numOfLinkedInstances\":"+"\""+numOfLinkedInstances+"\",";
|
---|
162 | // json_str+="\"numOfOriginInstances\":"+"\""+numOfOriginInstances+"\",";
|
---|
163 | // json_str+="\"numOfOriginClassInstances\":"+"\""+numOfOriginClassInstances+"\",";
|
---|
164 | // json_str+="\"numOfLinkedClassInstances\":"+"\""+numOfLinkedClassInstances+"\"";
|
---|
165 |
|
---|
166 | json_str+="}";
|
---|
167 |
|
---|
168 | return json_str;
|
---|
169 | }
|
---|
170 |
|
---|
171 | public String toJSONString4(QueryPathGenerator qpg) {
|
---|
172 | String json_str ="{";
|
---|
173 |
|
---|
174 | if( propertyURI != null ) {
|
---|
175 | //json_str+="\"propertyURI\":"+"\""+propertyURI+"\",";
|
---|
176 | json_str+="\"predicate\":"+"\""+propertyURI+"\",";
|
---|
177 | }
|
---|
178 | else{
|
---|
179 | json_str+="\"predicate\":"+"\"propertyURI\",";
|
---|
180 | }
|
---|
181 | if( linkedClassURI != null ){
|
---|
182 | //json_str+="\"linkedClassURI\":"+"\""+linkedClassURI+"\",";
|
---|
183 | json_str+="\"linkedClass\":"+"\""+linkedClassURI+"\",";
|
---|
184 | }
|
---|
185 | else{
|
---|
186 | //json_str+="\"linkedClassURI\":"+"\"linkedClassURI\",";
|
---|
187 | json_str+="\"linkedClass\":"+"\""+linkedClassURI+"\",";
|
---|
188 | }
|
---|
189 | if( linkedLiteralDatatypeURI != null ){
|
---|
190 | json_str+="\"linkedLiteralDatatypeURI\":"+"\""+linkedLiteralDatatypeURI+"\",";
|
---|
191 | }
|
---|
192 | else{
|
---|
193 | json_str+="\"linkedLiteralDatatypeURI\":"+"\"linkedLiteralDatatypeURI\",";
|
---|
194 | }
|
---|
195 | if( direction != null ){
|
---|
196 | json_str+="\"direction\":"+"\""+direction.toString()+"\",";
|
---|
197 | }
|
---|
198 | else{
|
---|
199 | json_str+="\"direction\":"+"\"direction\",";
|
---|
200 | }
|
---|
201 | if ( linkedClassURI != null ){
|
---|
202 | String label = qpg.getClassLabel(linkedClassURI);
|
---|
203 | json_str+="\"label\":"+"\""+label+"\"";
|
---|
204 | }else if ( linkedLiteralDatatypeURI != null ){
|
---|
205 | String url[] = linkedLiteralDatatypeURI.split("/");
|
---|
206 | String tmplabel = url[url.length-1];
|
---|
207 | String[] tmplabel2 = tmplabel.split("#");
|
---|
208 | String label = tmplabel2[tmplabel2.length-1];
|
---|
209 | json_str+="\"label\":"+"\""+label+"\"";
|
---|
210 | }else{
|
---|
211 | json_str+="\"label\":"+"\""+"\"No Label\""+"\"";
|
---|
212 | }
|
---|
213 | json_str+="}";
|
---|
214 |
|
---|
215 | return json_str;
|
---|
216 | }
|
---|
217 |
|
---|
218 |
|
---|
219 | public int getNumOfLinks() {
|
---|
220 | return numOfLinks;
|
---|
221 | }
|
---|
222 |
|
---|
223 |
|
---|
224 |
|
---|
225 |
|
---|
226 | public void setNumOfLinks(int numOfLinks) {
|
---|
227 | this.numOfLinks = numOfLinks;
|
---|
228 | }
|
---|
229 |
|
---|
230 |
|
---|
231 |
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * 譁�ュ怜�陦ィ險倥r蜿門セ励☆繧� |
---|
235 | *
|
---|
236 | * @since 28.01.2014
|
---|
237 | */
|
---|
238 | public String toString(){
|
---|
239 | StringBuffer sb = new StringBuffer();
|
---|
240 | sb.append(propertyURI);
|
---|
241 | if( direction == Direction.forward ){
|
---|
242 | sb.append(" --> ");
|
---|
243 | }else{
|
---|
244 | if( direction == Direction.reverse ){
|
---|
245 | sb.append(" <-- ");
|
---|
246 | }else{
|
---|
247 | sb.append(" <-> ");
|
---|
248 | }
|
---|
249 | }
|
---|
250 | sb.append(linkedClassURI);
|
---|
251 | sb.append(" [");
|
---|
252 | sb.append(numOfOriginClassInstances);
|
---|
253 | sb.append("/");
|
---|
254 | sb.append(numOfOriginInstances);
|
---|
255 | sb.append("]縲---");
|
---|
256 |
|
---|
257 |
|
---|
258 | sb.append(" [");
|
---|
259 | sb.append(numOfLinks);
|
---|
260 | sb.append("] --->");
|
---|
261 |
|
---|
262 | sb.append(" [");
|
---|
263 | sb.append(numOfLinkedClassInstances);
|
---|
264 | sb.append("/");
|
---|
265 | sb.append(numOfLinkedInstances);
|
---|
266 | sb.append("]");
|
---|
267 | return sb.toString();
|
---|
268 | }
|
---|
269 |
|
---|
270 | public String getPropertyURI() {
|
---|
271 | return propertyURI;
|
---|
272 | }
|
---|
273 | public void setPropertyURI(String propertyURI) {
|
---|
274 | this.propertyURI = propertyURI;
|
---|
275 | }
|
---|
276 | public String getLinkedClassURI() {
|
---|
277 | return linkedClassURI;
|
---|
278 | }
|
---|
279 | public void setLinkedClassURI(String linkedClassURI) {
|
---|
280 | this.linkedClassURI = linkedClassURI;
|
---|
281 | }
|
---|
282 | public Direction getDirection() {
|
---|
283 | return direction;
|
---|
284 | }
|
---|
285 | public void setDirection(Direction direction) {
|
---|
286 | this.direction = direction;
|
---|
287 | }
|
---|
288 |
|
---|
289 | public final int getNumOfLinkedInstances() {
|
---|
290 | return numOfLinkedInstances;
|
---|
291 | }
|
---|
292 |
|
---|
293 | public final void setNumOfLinkedInstances(int numOfLinkedInstances) {
|
---|
294 | this.numOfLinkedInstances = numOfLinkedInstances;
|
---|
295 | }
|
---|
296 |
|
---|
297 |
|
---|
298 |
|
---|
299 |
|
---|
300 | public final boolean isDomainClassLimitedQ() {
|
---|
301 | return domainClassLimitedQ;
|
---|
302 | }
|
---|
303 |
|
---|
304 |
|
---|
305 | public final boolean isRangeClassLimitedQ() {
|
---|
306 | return rangeClassLimitedQ;
|
---|
307 | }
|
---|
308 |
|
---|
309 |
|
---|
310 | public final int getNumOfOriginInstances() {
|
---|
311 | return numOfOriginInstances;
|
---|
312 | }
|
---|
313 |
|
---|
314 |
|
---|
315 | public final void setNumOfOriginInstances(int numOfOriginInstances) {
|
---|
316 | this.numOfOriginInstances = numOfOriginInstances;
|
---|
317 | }
|
---|
318 |
|
---|
319 |
|
---|
320 | public final int getNumOfOriginClassInstances() {
|
---|
321 | return numOfOriginClassInstances;
|
---|
322 | }
|
---|
323 |
|
---|
324 |
|
---|
325 | public final void setNumOfOriginClassInstances(int numOfOriginClassInstances) {
|
---|
326 | this.numOfOriginClassInstances = numOfOriginClassInstances;
|
---|
327 | }
|
---|
328 |
|
---|
329 |
|
---|
330 | public final int getNumOfLinkedClassInstances() {
|
---|
331 | return numOfLinkedClassInstances;
|
---|
332 | }
|
---|
333 |
|
---|
334 |
|
---|
335 | public final void setNumOfLinkedClassInstances(int numOfLinkedClassInstances) {
|
---|
336 | this.numOfLinkedClassInstances = numOfLinkedClassInstances;
|
---|
337 | }
|
---|
338 |
|
---|
339 |
|
---|
340 | public final String getLinkedLiteralDatatypeURI() {
|
---|
341 | return linkedLiteralDatatypeURI;
|
---|
342 | }
|
---|
343 |
|
---|
344 |
|
---|
345 | public final void setLinkedLiteralDatatypeURI(String linkedLiteralDatatypeURI) {
|
---|
346 | this.linkedLiteralDatatypeURI = linkedLiteralDatatypeURI;
|
---|
347 | }
|
---|
348 |
|
---|
349 |
|
---|
350 | public final void setDomainClassLimitedQ(boolean domainClassLimitedQ) {
|
---|
351 | this.domainClassLimitedQ = domainClassLimitedQ;
|
---|
352 | }
|
---|
353 |
|
---|
354 |
|
---|
355 | public final void setRangeClassLimitedQ(boolean rangeClassLimitedQ) {
|
---|
356 | this.rangeClassLimitedQ = rangeClassLimitedQ;
|
---|
357 | }
|
---|
358 |
|
---|
359 | private String getLinkedClassLabel(SClass[] classes){
|
---|
360 | return QueryPathGenerator.getClassLabelfromList(linkedClassURI, classes);
|
---|
361 | }
|
---|
362 |
|
---|
363 |
|
---|
364 | public final String getEndpointURI() {
|
---|
365 | return endpointURI;
|
---|
366 | }
|
---|
367 |
|
---|
368 |
|
---|
369 | public final void setEndpointURI(String endpointURI) {
|
---|
370 | this.endpointURI = endpointURI;
|
---|
371 | }
|
---|
372 |
|
---|
373 |
|
---|
374 | public final String getGraphURI() {
|
---|
375 | return graphURI;
|
---|
376 | }
|
---|
377 |
|
---|
378 |
|
---|
379 | public final void setGraphURI(String graphURI) {
|
---|
380 | this.graphURI = graphURI;
|
---|
381 | }
|
---|
382 |
|
---|
383 | // private String[] propertyDomainClassURIs = null;
|
---|
384 | // private String[] propertyRangeClassURIs = null;
|
---|
385 |
|
---|
386 |
|
---|
387 |
|
---|
388 | }
|
---|