Mercurial > hg > AnnotationManager
comparison src/de/mpiwg/itgroup/annotationManager/RDFHandling/Convert.java @ 5:0be9d53a6967
editor for annotations
author | dwinter |
---|---|
date | Tue, 13 Dec 2011 17:43:46 +0100 |
parents | e5f0906c107c |
children | 9393c9c9b916 |
comparison
equal
deleted
inserted
replaced
4:c32080f364c6 | 5:0be9d53a6967 |
---|---|
13 import org.restlet.engine.component.ChildContext; | 13 import org.restlet.engine.component.ChildContext; |
14 | 14 |
15 import de.mpiwg.itgroup.annotationManager.Constants.NS; | 15 import de.mpiwg.itgroup.annotationManager.Constants.NS; |
16 import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreStoreError; | 16 import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreStoreError; |
17 import de.mpiwg.itgroup.annotationManager.Errors.XPointerError; | 17 import de.mpiwg.itgroup.annotationManager.Errors.XPointerError; |
18 import de.mpiwg.itgroup.nimanager.exceptions.TripleStoreHandlerException; | 18 import de.mpiwg.itgroup.triplestoremanager.exceptions.TripleStoreHandlerException; |
19 import de.mpiwg.itgroup.nimanager.owl.TripleStoreHandler; | 19 import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler; |
20 import de.mpiwg.itgroup.nimanager.owl.TripleStoreHandler.Quadruple; | 20 import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler.LiteralQuadruple; |
21 import de.mpiwg.itgroup.nimanager.owl.TripleStoreHandler.LiteralQuadruple; | 21 import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler.Quadruple; |
22 | 22 |
23 /** | 23 /** |
24 * @author dwinter | 24 * @author dwinter |
25 * | 25 * |
26 * Klasse zum Konvertieren von Annotationen zum mpiwg RDF-Format: | 26 * Klasse zum Konvertieren von Annotationen zum mpiwg RDF-Format: |
119 private List<Quadruple> annot2quadruple(String xpointer, String creator, String time, String annot, String type){ | 119 private List<Quadruple> annot2quadruple(String xpointer, String creator, String time, String annot, String type){ |
120 return annot2quadruple(new Annotation(xpointer, creator, time, annot, type)); | 120 return annot2quadruple(new Annotation(xpointer, creator, time, annot, type)); |
121 } | 121 } |
122 | 122 |
123 | 123 |
124 | |
124 /** | 125 /** |
125 * @param annot | 126 * @param annot |
126 * @return | 127 * @return |
127 */ | 128 */ |
128 public List<Quadruple> annot2quadruple(Annotation annot){ | 129 public List<Quadruple> annot2quadruple(Annotation annot){ |
129 List<Quadruple> retQuad = new ArrayList<Quadruple>(); | 130 List<Quadruple> retQuad = new ArrayList<Quadruple>(); |
130 | 131 |
131 String annotation = createRessourceURL("annot:"); | 132 String annotation = createRessourceURL("annot:"); |
132 | 133 |
133 if (annot.time==null){ | 134 if (annot.time==null){ |
134 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'"); | 135 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); |
135 annot.time=format.format(Calendar.getInstance().getTime()); | 136 annot.time=format.format(Calendar.getInstance().getTime()); |
136 | 137 |
137 } | 138 } |
138 | 139 |
139 //TODO: check type | 140 //TODO: check type |
191 return String.format("%s%s%s", urlBase,prefix,time); | 192 return String.format("%s%s%s", urlBase,prefix,time); |
192 | 193 |
193 | 194 |
194 | 195 |
195 } | 196 } |
196 | 197 |
198 /** | |
199 * Hier ist die uri der Annotation angegeben. | |
200 * @param annot | |
201 * @return | |
202 */ | |
203 | |
204 private List<Quadruple> rel2quadruple(Annotation annot) { | |
205 | |
206 List<Quadruple> retQuad = new ArrayList<Quadruple>(); | |
207 | |
208 String annotation = createRessourceURL("annot:"); | |
209 | |
210 if (annot.time==null){ | |
211 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'"); | |
212 annot.time=format.format(Calendar.getInstance().getTime()); | |
213 | |
214 } | |
215 | |
216 //TODO: check type | |
217 retQuad.add(new Quadruple(annotation, NS.RDF+"type", NS.ANNOTATION_TYPE+annot.type, ctx)); | |
218 | |
219 //add author | |
220 | |
221 | |
222 if (annot.creator.startsWith("http")){ | |
223 retQuad.add(new Quadruple(annotation, NS.ANNOTATION_NS+"author", annot.creator, ctx)); | |
224 } else { | |
225 retQuad.add(new LiteralQuadruple(annotation, NS.ANNOTATION_NS+"author", annot.creator, ctx)); | |
226 } | |
227 | |
228 // creation time | |
229 retQuad.add(new LiteralQuadruple(annotation, NS.ANNOTATION_NS+"created", annot.time, ctx)); | |
230 | |
231 String[] xpointerSplitted = annot.xpointer.split("#"); | |
232 | |
233 if (xpointerSplitted.length>2){ | |
234 annotUrl=null; | |
235 throw new XPointerError(); | |
236 } | |
237 | |
238 // now add the xpointers | |
239 retQuad.add(new Quadruple(annotation, NS.MPIWG_annot+"annotatesDocuviewerText", xpointerSplitted[0], ctx)); | |
240 retQuad.add(new Quadruple(annotation, NS.MPIWG_annot+"textSelection", annot.xpointer, ctx)); | |
241 | |
242 //String annotationtext =createRessourceURL("annotText:"); | |
243 | |
244 retQuad.add(new Quadruple(annotation, NS.ANNOTATION_NS+"body", annot.url, ctx)); | |
245 | |
246 retQuad.add(new Quadruple(annot.url, NS.RDF+"type", NS.MPIWG_annot+"ExtendedAnnotation", ctx)); | |
247 | |
248 | |
249 for (Quadruple ret:retQuad){ | |
250 logger.debug(ret.toString()); | |
251 } | |
252 | |
253 annotUrl=annotation; | |
254 return retQuad; | |
255 | |
256 } | |
197 /** | 257 /** |
198 * gibt nach die nach aufruf eines Converters erzeuge aktuelle url der annotation zurueck | 258 * gibt nach die nach aufruf eines Converters erzeuge aktuelle url der annotation zurueck |
199 * @return | 259 * @return |
200 */ | 260 */ |
201 public String getAnnotUrl() { | 261 public String getAnnotUrl() { |
235 | 295 |
236 try { | 296 try { |
237 ChildContext context = (ChildContext)Context.getCurrent(); | 297 ChildContext context = (ChildContext)Context.getCurrent(); |
238 String user = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUser"); | 298 String user = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUser"); |
239 String pw = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUserPassword"); | 299 String pw = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUserPassword"); |
240 | 300 String connectionURL = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreConnectionURL"); |
241 TripleStoreHandler th = new TripleStoreHandler("jdbc:virtuoso://virtuoso.mpiwg-berlin.mpg.de:1111", user, pw); | 301 |
302 //TripleStoreHandler th = new TripleStoreHandler("jdbc:virtuoso://virtuoso.mpiwg-berlin.mpg.de:1111", user, pw); | |
303 TripleStoreHandler th = new TripleStoreHandler(connectionURL, user, pw); | |
242 | 304 |
243 th.write(annots); | 305 th.write(annots); |
244 } catch (RepositoryException e) { | 306 } catch (RepositoryException e) { |
245 // TODO Auto-generated catch block | 307 // TODO Auto-generated catch block |
246 e.printStackTrace(); | 308 e.printStackTrace(); |
255 annot.annotationUri=getAnnotUrl(); | 317 annot.annotationUri=getAnnotUrl(); |
256 return annot; | 318 return annot; |
257 } | 319 } |
258 | 320 |
259 | 321 |
260 private List<Quadruple> rel2quadruple(Annotation annot) { | 322 |
261 // TODO Auto-generated method stub | |
262 return new ArrayList<TripleStoreHandler.Quadruple>(); | |
263 } | |
264 | 323 |
265 } | 324 } |