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 | json_str+="\"predicate\":"+"\""+propertyURI+"\",";
|
---|
122 | }
|
---|
123 | else{
|
---|
124 | json_str+="\"predicate\":"+"\"propertyURI\",";
|
---|
125 | }
|
---|
126 | if( linkedClassURI != null ){
|
---|
127 | //json_str+="\"linkedClassURI\":"+"\""+linkedClassURI+"\",";
|
---|
128 | json_str+="\"linkedClass\":"+"\""+linkedClassURI+"\",";
|
---|
129 | }
|
---|
130 | else{
|
---|
131 | //json_str+="\"linkedClassURI\":"+"\"linkedClassURI\",";
|
---|
132 | json_str+="\"linkedClass\":"+"\""+linkedClassURI+"\",";
|
---|
133 | }
|
---|
134 | if( linkedLiteralDatatypeURI != null ){
|
---|
135 | json_str+="\"linkedLiteralDatatypeURI\":"+"\""+linkedLiteralDatatypeURI+"\",";
|
---|
136 | }
|
---|
137 | else{
|
---|
138 | json_str+="\"linkedLiteralDatatypeURI\":"+"\"linkedLiteralDatatypeURI\",";
|
---|
139 | }
|
---|
140 | if( direction != null ){
|
---|
141 | json_str+="\"direction\":"+"\""+direction.toString()+"\",";
|
---|
142 | }
|
---|
143 | else{
|
---|
144 | json_str+="\"direction\":"+"\"direction\",";
|
---|
145 | }
|
---|
146 | if ( linkedClassURI != null ){
|
---|
147 | String label = getLinkedClassLabel(classes);
|
---|
148 | json_str+="\"label\":"+"\""+label+"\"";
|
---|
149 | }else if ( linkedLiteralDatatypeURI != null ){
|
---|
150 | String url[] = linkedLiteralDatatypeURI.split("/");
|
---|
151 | String tmplabel = url[url.length-1];
|
---|
152 | String[] tmplabel2 = tmplabel.split("#");
|
---|
153 | String label = tmplabel2[tmplabel2.length-1];
|
---|
154 | json_str+="\"label\":"+"\""+label+"\"";
|
---|
155 | }else{
|
---|
156 | json_str+="\"label\":"+"\""+"\"No Label\""+"\"";
|
---|
157 | }
|
---|
158 | // json_str+="\"numOfLinks\":"+"\""+numOfLinks+"\",";
|
---|
159 | // json_str+="\"numOfLinkedInstances\":"+"\""+numOfLinkedInstances+"\",";
|
---|
160 | // json_str+="\"numOfOriginInstances\":"+"\""+numOfOriginInstances+"\",";
|
---|
161 | // json_str+="\"numOfOriginClassInstances\":"+"\""+numOfOriginClassInstances+"\",";
|
---|
162 | // json_str+="\"numOfLinkedClassInstances\":"+"\""+numOfLinkedClassInstances+"\"";
|
---|
163 |
|
---|
164 | json_str+="}";
|
---|
165 |
|
---|
166 | return json_str;
|
---|
167 | }
|
---|
168 |
|
---|
169 | public String toJSONString4(QueryPathGenerator qpg) {
|
---|
170 | String json_str ="{";
|
---|
171 |
|
---|
172 | if( propertyURI != null ) {
|
---|
173 | //json_str+="\"propertyURI\":"+"\""+propertyURI+"\",";
|
---|
174 | json_str+="\"predicate\":"+"\""+propertyURI+"\",";
|
---|
175 | }
|
---|
176 | else{
|
---|
177 | json_str+="\"predicate\":"+"\"propertyURI\",";
|
---|
178 | }
|
---|
179 | if( linkedClassURI != null ){
|
---|
180 | //json_str+="\"linkedClassURI\":"+"\""+linkedClassURI+"\",";
|
---|
181 | json_str+="\"linkedClass\":"+"\""+linkedClassURI+"\",";
|
---|
182 | }
|
---|
183 | else{
|
---|
184 | //json_str+="\"linkedClassURI\":"+"\"linkedClassURI\",";
|
---|
185 | json_str+="\"linkedClass\":"+"\""+linkedClassURI+"\",";
|
---|
186 | }
|
---|
187 | if( linkedLiteralDatatypeURI != null ){
|
---|
188 | json_str+="\"linkedLiteralDatatypeURI\":"+"\""+linkedLiteralDatatypeURI+"\",";
|
---|
189 | }
|
---|
190 | else{
|
---|
191 | json_str+="\"linkedLiteralDatatypeURI\":"+"\"linkedLiteralDatatypeURI\",";
|
---|
192 | }
|
---|
193 | if( direction != null ){
|
---|
194 | json_str+="\"direction\":"+"\""+direction.toString()+"\",";
|
---|
195 | }
|
---|
196 | else{
|
---|
197 | json_str+="\"direction\":"+"\"direction\",";
|
---|
198 | }
|
---|
199 | if ( linkedClassURI != null ){
|
---|
200 | String label = qpg.getClassLabel(linkedClassURI);
|
---|
201 | json_str+="\"label\":"+"\""+label+"\"";
|
---|
202 | }else if ( linkedLiteralDatatypeURI != null ){
|
---|
203 | String url[] = linkedLiteralDatatypeURI.split("/");
|
---|
204 | String tmplabel = url[url.length-1];
|
---|
205 | String[] tmplabel2 = tmplabel.split("#");
|
---|
206 | String label = tmplabel2[tmplabel2.length-1];
|
---|
207 | json_str+="\"label\":"+"\""+label+"\"";
|
---|
208 | }else{
|
---|
209 | json_str+="\"label\":"+"\""+"\"No Label\""+"\"";
|
---|
210 | }
|
---|
211 | json_str+="}";
|
---|
212 |
|
---|
213 | return json_str;
|
---|
214 | }
|
---|
215 |
|
---|
216 |
|
---|
217 | public int getNumOfLinks() {
|
---|
218 | return numOfLinks;
|
---|
219 | }
|
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 |
|
---|
224 | public void setNumOfLinks(int numOfLinks) {
|
---|
225 | this.numOfLinks = numOfLinks;
|
---|
226 | }
|
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * 譁�ュ怜�陦ィ險倥r蜿門セ励☆繧� |
---|
233 | *
|
---|
234 | * @since 28.01.2014
|
---|
235 | */
|
---|
236 | public String toString(){
|
---|
237 | StringBuffer sb = new StringBuffer();
|
---|
238 | sb.append(propertyURI);
|
---|
239 | if( direction == Direction.forward ){
|
---|
240 | sb.append(" --> ");
|
---|
241 | }else{
|
---|
242 | if( direction == Direction.reverse ){
|
---|
243 | sb.append(" <-- ");
|
---|
244 | }else{
|
---|
245 | sb.append(" <-> ");
|
---|
246 | }
|
---|
247 | }
|
---|
248 | sb.append(linkedClassURI);
|
---|
249 | sb.append(" [");
|
---|
250 | sb.append(numOfOriginClassInstances);
|
---|
251 | sb.append("/");
|
---|
252 | sb.append(numOfOriginInstances);
|
---|
253 | sb.append("]縲---");
|
---|
254 |
|
---|
255 |
|
---|
256 | sb.append(" [");
|
---|
257 | sb.append(numOfLinks);
|
---|
258 | sb.append("] --->");
|
---|
259 |
|
---|
260 | sb.append(" [");
|
---|
261 | sb.append(numOfLinkedClassInstances);
|
---|
262 | sb.append("/");
|
---|
263 | sb.append(numOfLinkedInstances);
|
---|
264 | sb.append("]");
|
---|
265 | return sb.toString();
|
---|
266 | }
|
---|
267 |
|
---|
268 | public String getPropertyURI() {
|
---|
269 | return propertyURI;
|
---|
270 | }
|
---|
271 | public void setPropertyURI(String propertyURI) {
|
---|
272 | this.propertyURI = propertyURI;
|
---|
273 | }
|
---|
274 | public String getLinkedClassURI() {
|
---|
275 | return linkedClassURI;
|
---|
276 | }
|
---|
277 | public void setLinkedClassURI(String linkedClassURI) {
|
---|
278 | this.linkedClassURI = linkedClassURI;
|
---|
279 | }
|
---|
280 | public Direction getDirection() {
|
---|
281 | return direction;
|
---|
282 | }
|
---|
283 | public void setDirection(Direction direction) {
|
---|
284 | this.direction = direction;
|
---|
285 | }
|
---|
286 |
|
---|
287 | public final int getNumOfLinkedInstances() {
|
---|
288 | return numOfLinkedInstances;
|
---|
289 | }
|
---|
290 |
|
---|
291 | public final void setNumOfLinkedInstances(int numOfLinkedInstances) {
|
---|
292 | this.numOfLinkedInstances = numOfLinkedInstances;
|
---|
293 | }
|
---|
294 |
|
---|
295 |
|
---|
296 |
|
---|
297 |
|
---|
298 | public final boolean isDomainClassLimitedQ() {
|
---|
299 | return domainClassLimitedQ;
|
---|
300 | }
|
---|
301 |
|
---|
302 |
|
---|
303 | public final boolean isRangeClassLimitedQ() {
|
---|
304 | return rangeClassLimitedQ;
|
---|
305 | }
|
---|
306 |
|
---|
307 |
|
---|
308 | public final int getNumOfOriginInstances() {
|
---|
309 | return numOfOriginInstances;
|
---|
310 | }
|
---|
311 |
|
---|
312 |
|
---|
313 | public final void setNumOfOriginInstances(int numOfOriginInstances) {
|
---|
314 | this.numOfOriginInstances = numOfOriginInstances;
|
---|
315 | }
|
---|
316 |
|
---|
317 |
|
---|
318 | public final int getNumOfOriginClassInstances() {
|
---|
319 | return numOfOriginClassInstances;
|
---|
320 | }
|
---|
321 |
|
---|
322 |
|
---|
323 | public final void setNumOfOriginClassInstances(int numOfOriginClassInstances) {
|
---|
324 | this.numOfOriginClassInstances = numOfOriginClassInstances;
|
---|
325 | }
|
---|
326 |
|
---|
327 |
|
---|
328 | public final int getNumOfLinkedClassInstances() {
|
---|
329 | return numOfLinkedClassInstances;
|
---|
330 | }
|
---|
331 |
|
---|
332 |
|
---|
333 | public final void setNumOfLinkedClassInstances(int numOfLinkedClassInstances) {
|
---|
334 | this.numOfLinkedClassInstances = numOfLinkedClassInstances;
|
---|
335 | }
|
---|
336 |
|
---|
337 |
|
---|
338 | public final String getLinkedLiteralDatatypeURI() {
|
---|
339 | return linkedLiteralDatatypeURI;
|
---|
340 | }
|
---|
341 |
|
---|
342 |
|
---|
343 | public final void setLinkedLiteralDatatypeURI(String linkedLiteralDatatypeURI) {
|
---|
344 | this.linkedLiteralDatatypeURI = linkedLiteralDatatypeURI;
|
---|
345 | }
|
---|
346 |
|
---|
347 |
|
---|
348 | public final void setDomainClassLimitedQ(boolean domainClassLimitedQ) {
|
---|
349 | this.domainClassLimitedQ = domainClassLimitedQ;
|
---|
350 | }
|
---|
351 |
|
---|
352 |
|
---|
353 | public final void setRangeClassLimitedQ(boolean rangeClassLimitedQ) {
|
---|
354 | this.rangeClassLimitedQ = rangeClassLimitedQ;
|
---|
355 | }
|
---|
356 |
|
---|
357 | private String getLinkedClassLabel(SClass[] classes){
|
---|
358 | return QueryPathGenerator.getClassLabelfromList(linkedClassURI, classes);
|
---|
359 | }
|
---|
360 |
|
---|
361 | // private String[] propertyDomainClassURIs = null;
|
---|
362 | // private String[] propertyRangeClassURIs = null;
|
---|
363 |
|
---|
364 |
|
---|
365 |
|
---|
366 | }
|
---|