root/SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/Path.java

リビジョン 281, 5.8 KB (コミッタ: atsuko, 8 年 前)

新ランキング関数でソート機能追加

  • 属性 svn:mime-type の設定値 text/plain
行番号 
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        private float width;
24        private int min;
25        private boolean chk;
26
27        /**
28         * 繝代せ縺ョ襍キ轤ケ縺九i邨らせ縺ォ蜷代°縺」縺ヲ騾先ャ。逧�↓縺、縺ェ縺後k繧ッ繝ゥ繧ケ髢薙Μ繝ウ繧ッ縺ョ繝ェ繧ケ繝�
29         */
30        private List<ClassLink> classLinks;
31
32        public JSONObject toJSON() {
33                JSONObject obj = new JSONObject();
34                try {
35                        obj.put("startClassURI", startClass);
36                obj.put("width", width);
37                if (classLinks != null && classLinks.size() != 0) {
38                        JSONArray array = new JSONArray();
39                        for (int i = 0; i < classLinks.size(); i++) {
40                                array.put(classLinks.get(i).toJSON());
41                        }
42                        obj.put("classLinks", array);
43                }
44                } catch (JSONException e) {
45                        // TODO Auto-generated catch block
46                        e.printStackTrace();
47                        System.out.println(e.toString());
48                }
49                return obj;
50        }
51       
52        public String toJSONString(){
53                return toJSON().toString();
54        }
55
56        public String toJSONString2(){
57                String json_str="";
58                json_str+="{\"startClassURI\":\""+ startClass+"\",";
59                //json_str+="\"width\":"+width+",";
60               
61                if (classLinks != null && classLinks.size() != 0) {
62                        json_str+="\"classLinks\":[";
63                       
64                        JSONObject[] classLinkObjs = new JSONObject[classLinks.size()];
65                        for (int i = 0; i < classLinks.size(); i++) {
66                                if(i>0){json_str += "," ;}
67                                json_str+= classLinks.get(i).toJSONString2();
68                        }
69                        json_str+="]";
70                }
71                json_str+="}";
72               
73                return json_str;
74        }
75
76        public String toJSONString3(SClass[] classes){
77                String json_str="";
78                //json_str+="{\"startClassURI\":\""+ startClass+"\",";
79                //json_str+="\"startClassLabel\":\""+QueryPathGenerator.getClassLabelfromList(startClass, classes)+"\",";
80                json_str+="{\"startClass\":\""+ startClass+"\",";
81                // label
82                json_str+="\"label\":\""+QueryPathGenerator.getClassLabelfromList(startClass, classes)+"\",";
83                if (classLinks != null && classLinks.size() != 0) {
84                        json_str+="\"classLinks\":[";
85                       
86                        JSONObject[] classLinkObjs = new JSONObject[classLinks.size()];
87                        for (int i = 0; i < classLinks.size(); i++) {
88                                if(i>0){json_str += "," ;}
89                                json_str+= classLinks.get(i).toJSONString3(classes);
90                        }
91                        json_str+="]";                       
92                }
93                json_str += ",";
94                json_str +="\"score\":\""+width+"\"";
95                json_str +="}";
96               
97                return json_str;
98        }
99
100        public String toJSONString4(QueryPathGenerator qpg){
101                String json_str="";
102                json_str+="{\"startClass\":\""+ startClass+"\",";
103                // label
104                json_str+="\"label\":\""+qpg.getClassLabel(startClass)+"\",";
105                if (classLinks != null && classLinks.size() != 0) {
106                        json_str+="\"classLinks\":[";
107                       
108                        JSONObject[] classLinkObjs = new JSONObject[classLinks.size()];
109                        for (int i = 0; i < classLinks.size(); i++) {
110                                if(i>0){json_str += "," ;}
111                                json_str+= classLinks.get(i).toJSONString4(qpg);
112                        }
113                        json_str+="]";                       
114                }
115                json_str += ",";
116                //json_str +="\"score\":\""+width+"\"";
117                json_str +="\"score\":\""+""+"\"";
118                json_str +="}";
119               
120                return json_str;
121        }
122       
123        public String getStartClass() {
124                return startClass;
125        }
126
127        /*
128         * public String[] getProperties(){ return properties; }
129         *
130         * public String[] getObjectClasses(){ return objectClasses; }
131         *
132         * public Direction[] getDirections(){ return directions; }
133         */
134        public List<ClassLink> getClassLinks() {
135                return classLinks;
136        }
137
138        public float getWidth() {
139                return width;
140        }
141
142        public Path() {
143        }
144
145        public Path(String startClass, List<ClassLink> classLinks, int width) {
146                this.startClass = startClass;
147                this.classLinks = classLinks;
148                this.width = width;
149        }
150
151        public void setStartClass(String startClass) {
152                this.startClass = startClass;
153        }
154
155        public void setClassLinks(List<ClassLink> classLinks) {
156                this.classLinks = classLinks;
157        }
158
159        public void setWidth(int width) {
160                this.width = width;
161        }
162
163        public void setWidth(double width) {
164                this.width = (float) width;
165        }
166       
167        public void setMin(int min){
168            this.min = min;
169        }
170       
171        public int getMin(){
172            return min;
173        }
174       
175        public void setChk(boolean chk){
176            this.chk = chk;
177        }
178       
179        public boolean getChk(){
180            return chk;
181        }
182               
183    @Override
184    public int compareTo(Path path) {
185        if ( this.width - path.getWidth() > 0 ){ return 1; }
186        else if ( this.width - path.getWidth() < 0 ){ return -1; }
187        else {
188            if ( this.chk == true && path.getChk() == false ){ return 1; }
189            if ( this.chk == false && path.getChk() == true ){ return -1; }
190            else {
191                if ( path.classLinks.size() - this.classLinks.size() > 0 ){ return 1;}
192                else if ( path.classLinks.size() - this.classLinks.size() < 0 ){ return -1;}
193                else{
194                    if ( this.min - path.getMin() > 0 ){ return 1; }
195                    else if ( this.min - path.getMin() < 0 ){ return -1;}
196                    return 0;
197                }
198            }
199        }
200        //return this.width - path.getWidth() ;
201        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
202    }
203}
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。