| 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.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 |
|
|---|
| 98 | public String getStartClass() {
|
|---|
| 99 | return startClass;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | /*
|
|---|
| 103 | * public String[] getProperties(){ return properties; }
|
|---|
| 104 | *
|
|---|
| 105 | * public String[] getObjectClasses(){ return objectClasses; }
|
|---|
| 106 | *
|
|---|
| 107 | * public Direction[] getDirections(){ return directions; }
|
|---|
| 108 | */
|
|---|
| 109 | public List<ClassLink> getClassLinks() {
|
|---|
| 110 | return classLinks;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | public int getWidth() {
|
|---|
| 114 | return width;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | public Path() {
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | public Path(String startClass, List<ClassLink> classLinks, int width) {
|
|---|
| 121 | this.startClass = startClass;
|
|---|
| 122 | this.classLinks = classLinks;
|
|---|
| 123 | this.width = width;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | public void setStartClass(String startClass) {
|
|---|
| 127 | this.startClass = startClass;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | public void setClassLinks(List<ClassLink> classLinks) {
|
|---|
| 131 | this.classLinks = classLinks;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | public void setWidth(int width) {
|
|---|
| 135 | this.width = width;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | @Override
|
|---|
| 139 | public int compareTo(Path path) {
|
|---|
| 140 | return this.width - path.getWidth() ;
|
|---|
| 141 | //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|---|
| 142 | }
|
|---|
| 143 | } |
|---|