root/SPARQLBuilderWWW2016/src/java/org/biohackathon/SPARQLBuilder/OWL/Path.java @ 267

リビジョン 267, 4.5 KB (コミッタ: atsuko, 9 年 前)

メタデータ仕様変更,フェデレートサーチ対応向け

行番号 
1package org.biohackathon.SPARQLBuilder.OWL;
2
3import java.util.*;
4
5import org.json.JSONArray;
6import org.json.JSONException;
7import org.json.JSONObject;
8
9/**
10 * 襍キ轤ケ縺ィ縺ェ繧九Μ繧ス繝シ繧ケ縺九i騾先ャ。逧�↓隍�焚繝ェ繝ウ繧ッ縺ァ邨らせ繝ェ繧ス繝シ繧ケ縺セ縺ァ謗・邯壹&繧後k荳€縺、縺ョ繝代せ繧定ィ倩ソー縺吶k
11 *
12 * @author Yamaguchi
13 * @since 28.01.2014
14 * @version 29.01.2014
15 */
16public class Path implements Comparable<Path>{
17
18        /**
19         * 繝代せ縺ョ襍キ轤ケ縺ィ縺ェ繧九け繝ゥ繧ケ縺ョURI
20         */
21        private String startClass;
22        private int width;
23
24        /**
25         * 繝代せ縺ョ襍キ轤ケ縺九i邨らせ縺ォ蜷代°縺」縺ヲ騾先ャ。逧�↓縺、縺ェ縺後k繧ッ繝ゥ繧ケ髢薙Μ繝ウ繧ッ縺ョ繝ェ繧ケ繝�
26         */
27        private List<ClassLink> classLinks;
28
29        public JSONObject toJSON() {
30                JSONObject obj = new JSONObject();
31                try {
32                        obj.put("startClassURI", startClass);
33                obj.put("width", width);
34                if (classLinks != null && classLinks.size() != 0) {
35                        JSONArray array = new JSONArray();
36                        for (int i = 0; i < classLinks.size(); i++) {
37                                array.put(classLinks.get(i).toJSON());
38                        }
39                        obj.put("classLinks", array);
40                }
41                } catch (JSONException e) {
42                        // TODO Auto-generated catch block
43                        e.printStackTrace();
44                        System.out.println(e.toString());
45                }
46                return obj;
47        }
48       
49        public String toJSONString(){
50                return toJSON().toString();
51        }
52
53        public String toJSONString2(){
54                String json_str="";
55                json_str+="{\"startClassURI\":\""+ startClass+"\",";
56                //json_str+="\"width\":"+width+",";
57               
58                if (classLinks != null && classLinks.size() != 0) {
59                        json_str+="\"classLinks\":[";
60                       
61                        JSONObject[] classLinkObjs = new JSONObject[classLinks.size()];
62                        for (int i = 0; i < classLinks.size(); i++) {
63                                if(i>0){json_str += "," ;}
64                                json_str+= classLinks.get(i).toJSONString2();
65                        }
66                        json_str+="]";
67                }
68                json_str+="}";
69               
70                return json_str;
71        }
72
73        public String toJSONString3(SClass[] classes){
74                String json_str="";
75                //json_str+="{\"startClassURI\":\""+ startClass+"\",";
76                //json_str+="\"startClassLabel\":\""+QueryPathGenerator.getClassLabelfromList(startClass, classes)+"\",";
77                json_str+="{\"startClass\":\""+ startClass+"\",";
78                // label
79                json_str+="\"label\":\""+QueryPathGenerator.getClassLabelfromList(startClass, classes)+"\",";
80                if (classLinks != null && classLinks.size() != 0) {
81                        json_str+="\"classLinks\":[";
82                       
83                        JSONObject[] classLinkObjs = new JSONObject[classLinks.size()];
84                        for (int i = 0; i < classLinks.size(); i++) {
85                                if(i>0){json_str += "," ;}
86                                json_str+= classLinks.get(i).toJSONString3(classes);
87                        }
88                        json_str+="]";                       
89                }
90                json_str += ",";
91                json_str +="\"score\":\""+width+"\"";
92                json_str +="}";
93               
94                return json_str;
95        }
96
97        public String toJSONString4(QueryPathGenerator qpg){
98                String json_str="";
99                json_str+="{\"startClass\":\""+ startClass+"\",";
100                // label
101                json_str+="\"label\":\""+qpg.getClassLabel(startClass)+"\",";
102                if (classLinks != null && classLinks.size() != 0) {
103                        json_str+="\"classLinks\":[";
104                       
105                        JSONObject[] classLinkObjs = new JSONObject[classLinks.size()];
106                        for (int i = 0; i < classLinks.size(); i++) {
107                                if(i>0){json_str += "," ;}
108                                json_str+= classLinks.get(i).toJSONString4(qpg);
109                        }
110                        json_str+="]";                       
111                }
112                json_str += ",";
113                json_str +="\"score\":\""+width+"\"";
114                json_str +="}";
115               
116                return json_str;
117        }
118       
119        public String getStartClass() {
120                return startClass;
121        }
122
123        /*
124         * public String[] getProperties(){ return properties; }
125         *
126         * public String[] getObjectClasses(){ return objectClasses; }
127         *
128         * public Direction[] getDirections(){ return directions; }
129         */
130        public List<ClassLink> getClassLinks() {
131                return classLinks;
132        }
133
134        public int getWidth() {
135                return width;
136        }
137
138        public Path() {
139        }
140
141        public Path(String startClass, List<ClassLink> classLinks, int width) {
142                this.startClass = startClass;
143                this.classLinks = classLinks;
144                this.width = width;
145        }
146
147        public void setStartClass(String startClass) {
148                this.startClass = startClass;
149        }
150
151        public void setClassLinks(List<ClassLink> classLinks) {
152                this.classLinks = classLinks;
153        }
154
155        public void setWidth(int width) {
156                this.width = width;
157        }
158
159    @Override
160    public int compareTo(Path path) {
161        return this.width - path.getWidth() ;
162        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
163    }
164}
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。