comparison src/main/java/de/mpiwg/itgroup/annotationManager/RDFHandling/Convert.java @ 30:b37487b756ac

still working on new annotations...
author casties
date Wed, 09 May 2012 11:26:54 +0200
parents cf8166ee8918
children e5f5848892a2
comparison
equal deleted inserted replaced
29:cf8166ee8918 30:b37487b756ac
62 annotationUrl = createRessourceURL("annot:"); 62 annotationUrl = createRessourceURL("annot:");
63 } 63 }
64 64
65 // annotation class 65 // annotation class
66 retQuad.add(new Quadruple(annotationUrl, NS.RDF_NS + "type", NS.OAC_NS + "Annotation", context)); 66 retQuad.add(new Quadruple(annotationUrl, NS.RDF_NS + "type", NS.OAC_NS + "Annotation", context));
67 67 /*
68 // author 68 * author
69 */
69 if (annot.creator.startsWith("http")) { 70 if (annot.creator.startsWith("http")) {
70 retQuad.add(new Quadruple(annotationUrl, NS.DCTERMS_NS + "creator", annot.creator, context)); 71 retQuad.add(new Quadruple(annotationUrl, NS.DCTERMS_NS + "creator", annot.creator, context));
71 } else { 72 } else {
72 // TODO: this should not happen 73 // TODO: this should not happen
73 retQuad.add(new LiteralQuadruple(annotationUrl, NS.DCTERMS_NS + "creator", annot.creator, context)); 74 retQuad.add(new LiteralQuadruple(annotationUrl, NS.DCTERMS_NS + "creator", annot.creator, context));
74 } 75 }
75 // creation time 76 /*
77 * creation time
78 */
76 if (annot.time == null) { 79 if (annot.time == null) {
77 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); 80 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
78 annot.time = format.format(Calendar.getInstance().getTime()); 81 annot.time = format.format(Calendar.getInstance().getTime());
79 } 82 }
80 retQuad.add(new LiteralQuadruple(annotationUrl, NS.DCTERMS_NS + "created", annot.time, context)); 83 retQuad.add(new LiteralQuadruple(annotationUrl, NS.DCTERMS_NS + "created", annot.time, context));
81 84
82 if (annot.page == null || annot.page == "") { 85 if (annot.page == null || annot.page == "") {
83 // target without page number (full URL) 86 /*
87 * target without page number (full URL)
88 */
84 retQuad.add(new Quadruple(annot.xpointer, NS.RDF_NS + "type", NS.OAC_NS + "Target", context)); 89 retQuad.add(new Quadruple(annot.xpointer, NS.RDF_NS + "type", NS.OAC_NS + "Target", context));
85 // is target of annotation 90 // is target of annotation
86 retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasTarget", annot.xpointer, context)); 91 retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasTarget", annot.xpointer, context));
87 } else { 92 } else {
88 // ConstrainedTarget with page number (full URL) 93 /*
89 retQuad.add(new Quadruple(annot.xpointer, NS.RDF_NS + "type", NS.OAC_NS + "ConstrainedTarget", context)); 94 * ConstrainedTarget with page number
95 */
96 String ctUrl = createRessourceURL("annotCT:");
97 // is ConstrainedTarget
98 retQuad.add(new Quadruple(ctUrl, NS.RDF_NS + "type", NS.OAC_NS + "ConstrainedTarget", context));
90 // is target of annotation 99 // is target of annotation
91 retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasTarget", annot.xpointer, context)); 100 retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasTarget", ctUrl, context));
92 // constrains Target 101 // constrains Target (full URL)
93 //retQuad.add(new Quadruple(constraint, NS.OAC_NS + "constrains", annot.xpointer, context)); 102 retQuad.add(new Quadruple(ctUrl, NS.OAC_NS + "constrains", annot.xpointer, context));
94 // TextPageConstraint 103 // TextPageConstraint
95 String constraint = createRessourceURL("annotC:"); 104 String tpcUrl = createRessourceURL("annotC:");
96 retQuad.add(new Quadruple(constraint, NS.RDF_NS + "type", NS.MPIWG_ANNOT_NS + "TextPageConstraint", context)); 105 // is TextPageConstraint
97 retQuad.add(new LiteralQuadruple(constraint, NS.MPIWG_ANNOT_NS + "textPage", annot.page, context)); 106 retQuad.add(new Quadruple(tpcUrl, NS.RDF_NS + "type", NS.MPIWG_ANNOT_NS + "TextPageConstraint", context));
98 // constrains Target 107 // page number
99 retQuad.add(new Quadruple(constraint, NS.OAC_NS + "constrains", annot.xpointer, context)); 108 retQuad.add(new LiteralQuadruple(tpcUrl, NS.MPIWG_ANNOT_NS + "textPage", annot.page, context));
100 109 // textPageDisplay
110 if (annot.displayUrl != null && annot.displayUrl != "") {
111 retQuad.add(new LiteralQuadruple(tpcUrl, NS.MPIWG_ANNOT_NS + "textPageDisplay", annot.displayUrl, context));
112 }
113 // ConstrainedTarget has this Constraint
114 retQuad.add(new Quadruple(ctUrl, NS.OAC_NS + "hasConstraint", tpcUrl, context));
115 //TODO: displayUrl
101 } 116 }
102 117
103 // annotation body 118 // annotation body
104 if (annot.url != null && annot.url.startsWith("http://")) { 119 if (annot.url != null && annot.url.startsWith("http://")) {
105 // body is resource 120 /*
121 * body is resource
122 */
106 retQuad.add(new Quadruple(annot.url, NS.RDF_NS + "type", NS.OAC_NS + "Body", context)); 123 retQuad.add(new Quadruple(annot.url, NS.RDF_NS + "type", NS.OAC_NS + "Body", context));
107 // is body of annotation 124 // is body of annotation
108 retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasBody", annot.url, context)); 125 retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasBody", annot.url, context));
109 } else { 126 } else {
110 // body is literal text 127 /*
111 String annotationtext = createRessourceURL("annotB:"); 128 * body is literal text
112 retQuad.add(new Quadruple(annotationtext, NS.RDF_NS + "type", NS.OAC_NS + "Body", context)); 129 */
113 retQuad.add(new Quadruple(annotationtext, NS.RDF_NS + "type", NS.CNT_NS + "ContentAsText", context)); 130 String abUrl = createRessourceURL("annotB:");
114 retQuad.add(new LiteralQuadruple(annotationtext, NS.CNT_NS + "chars", annot.text, context)); 131 // is Body and ContentAsText
132 retQuad.add(new Quadruple(abUrl, NS.RDF_NS + "type", NS.OAC_NS + "Body", context));
133 retQuad.add(new Quadruple(abUrl, NS.RDF_NS + "type", NS.CNT_NS + "ContentAsText", context));
134 // has text
135 retQuad.add(new LiteralQuadruple(abUrl, NS.CNT_NS + "chars", annot.text, context));
115 // is body of annotation 136 // is body of annotation
116 retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasBody", annotationtext, context)); 137 retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasBody", abUrl, context));
117 } 138 }
118 139
119 for (Quadruple ret : retQuad) { 140 for (Quadruple ret : retQuad) {
120 logger.debug(ret.toString()); 141 logger.debug(ret.toString());
121 } 142 }
123 annot.setAnnotationUri(annotationUrl); 144 annot.setAnnotationUri(annotationUrl);
124 return retQuad; 145 return retQuad;
125 } 146 }
126 147
127 /** 148 /**
128 * Erzeuge eine urn aus der aktullen Zeit in millis 149 * Erzeuge eine urn aus der aktuellen Zeit in millis
129 * 150 *
130 * @return 151 * @return
131 */ 152 */
132 private String createRessourceURL(String prefix) { 153 private String createRessourceURL(String prefix) {
133 154
165 throw new TripleStoreStoreError(); 186 throw new TripleStoreStoreError();
166 } 187 }
167 return annot; 188 return annot;
168 } 189 }
169 190
170 /**
171 * @param args
172 */
173 public static void main(String[] args) {
174 Convert myConvert = new Convert("http://annotations.rdf");
175 List<Quadruple> rets = myConvert
176 .annot2quadruple(
177 "http://mpdl-dev.mpiwg-berlin.mpg.de/ECHOdocuViewfullTest?url=/mpiwg/online/permanent/library/163127KK&amp;viewMode=text&amp;pn=7#xpointer(string-range(id(&quot;s1&quot;), &quot;&quot;, 66, 12))",
178 "mbuchman", null, "myannot", "Example");
179 for (Quadruple ret : rets) {
180 System.out.println(ret.toString());
181 }
182 }
183
184 } 191 }