root/SPARQLBuilderWWW2016/src/java/org/biohackathon/SPARQLBuilder/OWL/ClassLink.java

リビジョン 271, 11.2 KB (コミッタ: nori, 9 年 前)

graphURI対応のクロールデータに対して、Jenaを使わずJavaインスタンスの操作によって統計データを扱えるように改変

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