1 | package org.biohackathon.SPARQLBuilder.OWL;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import org.json.JSONArray;
|
---|
6 | import org.json.JSONException;
|
---|
7 | import org.json.JSONObject;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * 襍キ轤ケ縺ィ縺ェ繧九Μ繧ス繝シ繧ケ縺九i騾先ャ。逧�↓隍�焚繝ェ繝ウ繧ッ縺ァ邨らせ繝ェ繧ス繝シ繧ケ縺セ縺ァ謗・邯壹&繧後k荳縺、縺ョ繝代せ繧定ィ倩ソー縺吶k
|
---|
11 | *
|
---|
12 | * @author Yamaguchi
|
---|
13 | * @since 28.01.2014
|
---|
14 | * @version 29.01.2014
|
---|
15 | */
|
---|
16 | public 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.getClassLabel(startClass, classes)+"\",";
|
---|
77 | if (classLinks != null && classLinks.size() != 0) {
|
---|
78 | json_str+="\"classLinks\":[";
|
---|
79 |
|
---|
80 | JSONObject[] classLinkObjs = new JSONObject[classLinks.size()];
|
---|
81 | for (int i = 0; i < classLinks.size(); i++) {
|
---|
82 | if(i>0){json_str += "," ;}
|
---|
83 | json_str+= classLinks.get(i).toJSONString3(classes);
|
---|
84 | }
|
---|
85 | json_str+="]";
|
---|
86 | }
|
---|
87 | json_str+="}";
|
---|
88 |
|
---|
89 | return json_str;
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | public String getStartClass() {
|
---|
94 | return startClass;
|
---|
95 | }
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * public String[] getProperties(){ return properties; }
|
---|
99 | *
|
---|
100 | * public String[] getObjectClasses(){ return objectClasses; }
|
---|
101 | *
|
---|
102 | * public Direction[] getDirections(){ return directions; }
|
---|
103 | */
|
---|
104 | public List<ClassLink> getClassLinks() {
|
---|
105 | return classLinks;
|
---|
106 | }
|
---|
107 |
|
---|
108 | public int getWidth() {
|
---|
109 | return width;
|
---|
110 | }
|
---|
111 |
|
---|
112 | public Path() {
|
---|
113 | }
|
---|
114 |
|
---|
115 | public Path(String startClass, List<ClassLink> classLinks, int width) {
|
---|
116 | this.startClass = startClass;
|
---|
117 | this.classLinks = classLinks;
|
---|
118 | this.width = width;
|
---|
119 | }
|
---|
120 |
|
---|
121 | public void setStartClass(String startClass) {
|
---|
122 | this.startClass = startClass;
|
---|
123 | }
|
---|
124 |
|
---|
125 | public void setClassLinks(List<ClassLink> classLinks) {
|
---|
126 | this.classLinks = classLinks;
|
---|
127 | }
|
---|
128 |
|
---|
129 | public void setWidth(int width) {
|
---|
130 | this.width = width;
|
---|
131 | }
|
---|
132 |
|
---|
133 | @Override
|
---|
134 | public int compareTo(Path path) {
|
---|
135 | return this.width - path.getWidth();
|
---|
136 | //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
---|
137 | }
|
---|
138 |
|
---|
139 | } |
---|