annotate src/main/java/de/mpiwg/itgroup/annotationManager/RDFHandling/Convert.java @ 26:235b91ba8dff

on the way to new annotations...
author casties
date Thu, 26 Apr 2012 11:44:57 +0200
parents 52dff477e45f
children b4a798d417fe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dwinter
parents:
diff changeset
1 package de.mpiwg.itgroup.annotationManager.RDFHandling;
dwinter
parents:
diff changeset
2
dwinter
parents:
diff changeset
3 import java.text.DateFormat;
dwinter
parents:
diff changeset
4 import java.text.SimpleDateFormat;
dwinter
parents:
diff changeset
5 import java.util.ArrayList;
dwinter
parents:
diff changeset
6 import java.util.Calendar;
dwinter
parents:
diff changeset
7 import java.util.Date;
dwinter
parents:
diff changeset
8 import java.util.List;
dwinter
parents:
diff changeset
9
dwinter
parents:
diff changeset
10 import org.apache.log4j.Logger;
dwinter
parents:
diff changeset
11 import org.openrdf.repository.RepositoryException;
dwinter
parents:
diff changeset
12 import org.restlet.Context;
dwinter
parents:
diff changeset
13 import org.restlet.engine.component.ChildContext;
dwinter
parents:
diff changeset
14
dwinter
parents:
diff changeset
15 import de.mpiwg.itgroup.annotationManager.Constants.NS;
dwinter
parents:
diff changeset
16 import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreStoreError;
dwinter
parents:
diff changeset
17 import de.mpiwg.itgroup.annotationManager.Errors.XPointerError;
5
0be9d53a6967 editor for annotations
dwinter
parents: 3
diff changeset
18 import de.mpiwg.itgroup.triplestoremanager.exceptions.TripleStoreHandlerException;
0be9d53a6967 editor for annotations
dwinter
parents: 3
diff changeset
19 import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler;
0be9d53a6967 editor for annotations
dwinter
parents: 3
diff changeset
20 import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler.LiteralQuadruple;
0be9d53a6967 editor for annotations
dwinter
parents: 3
diff changeset
21 import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler.Quadruple;
0
dwinter
parents:
diff changeset
22
dwinter
parents:
diff changeset
23 /**
dwinter
parents:
diff changeset
24 * @author dwinter
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
25 *
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
26 * Klasse zum Konvertieren von Annotationen zum mpiwg RDF-Format: http://ontologies.mpiwg-berlin.mpg.de/annotations/
0
dwinter
parents:
diff changeset
27 */
dwinter
parents:
diff changeset
28
dwinter
parents:
diff changeset
29 public class Convert {
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
30 private String context = "file:///annotations";
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
31 private static Logger logger = Logger.getRootLogger();
25
52dff477e45f on the way to a new ontology...
casties
parents: 23
diff changeset
32 private String urlBase = "http://entities.mpiwg-berlin.mpg.de/annotations/"; // TODO should go into config
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
33
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
34 public Convert(String context) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
35 this.context = context;
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
36 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
37
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
38 /**
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
39 *
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
40 * @param xpointer
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
41 * Beschreibt die Annotation
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
42 * @param creator
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
43 * Username des Creators
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
44 * @param time
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
45 * Erstellungszeit, wenn null wird das aktuelle Datum verwenden beim Konvertieren
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
46 * @param text
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
47 * der Annotation
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
48 * @param type
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
49 * Annotationstype (Entsprechend den in http://www.w3.org/2000/10/annotationType# definierten.)
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
50 * @return
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
51 */
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
52
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
53 private List<Quadruple> annot2quadruple(String xpointer, String creator, String time, String annot, String type) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
54 return annot2quadruple(new Annotation(xpointer, creator, time, annot, type));
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
55 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
56
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
57 /**
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
58 * @param annot
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
59 * @return
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
60 */
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
61 public List<Quadruple> annot2quadruple(Annotation annot) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
62 List<Quadruple> retQuad = new ArrayList<Quadruple>();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
63
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
64 // create new URL if annot has no annotationUrl
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
65 String annotationUrl = annot.getAnnotationUri();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
66 if (annotationUrl == null) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
67 annotationUrl = createRessourceURL("annot:");
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
68 }
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
69
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
70 // annotation class
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
71 retQuad.add(new Quadruple(annotationUrl, NS.RDF_NS + "type", NS.OAC_NS + "Annotation", context));
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
72 // TODO: what types?
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
73 //retQuad.add(new LiteralQuadruple(annotationUrl, NS.RDF + "type", annot.type, context));
25
52dff477e45f on the way to a new ontology...
casties
parents: 23
diff changeset
74
52dff477e45f on the way to a new ontology...
casties
parents: 23
diff changeset
75 // author
52dff477e45f on the way to a new ontology...
casties
parents: 23
diff changeset
76 if (annot.creator.startsWith("http")) {
52dff477e45f on the way to a new ontology...
casties
parents: 23
diff changeset
77 retQuad.add(new Quadruple(annotationUrl, NS.DCTERMS_NS + "creator", annot.creator, context));
52dff477e45f on the way to a new ontology...
casties
parents: 23
diff changeset
78 } else {
52dff477e45f on the way to a new ontology...
casties
parents: 23
diff changeset
79 // TODO: this should not happen
52dff477e45f on the way to a new ontology...
casties
parents: 23
diff changeset
80 retQuad.add(new LiteralQuadruple(annotationUrl, NS.DCTERMS_NS + "creator", annot.creator, context));
52dff477e45f on the way to a new ontology...
casties
parents: 23
diff changeset
81 }
52dff477e45f on the way to a new ontology...
casties
parents: 23
diff changeset
82 // creation time
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
83 if (annot.time == null) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
84 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
85 annot.time = format.format(Calendar.getInstance().getTime());
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
86 }
25
52dff477e45f on the way to a new ontology...
casties
parents: 23
diff changeset
87 retQuad.add(new LiteralQuadruple(annotationUrl, NS.DCTERMS_NS + "created", annot.time, context));
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
88
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
89 // target (full URL)
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
90 retQuad.add(new Quadruple(annot.xpointer, NS.RDF_NS + "type", NS.OAC_NS + "Target", context));
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
91 // is target of annotation
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
92 retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasTarget", annot.xpointer, context));
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
93
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
94 // now add the xpointers
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
95 /* String[] xpointerSplitted = annot.xpointer.split("#");
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
96 if (xpointerSplitted.length > 2) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
97 throw new XPointerError();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
98 }
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
99 retQuad.add(new Quadruple(annotationUrl, NS.MPIWG_ANNOT_URL + "annotatesDocuviewerText", xpointerSplitted[0], context));
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
100 retQuad.add(new Quadruple(annotationUrl, NS.MPIWG_ANNOT_URL + "textSelection", annot.xpointer, context));
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
101 */
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
102
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
103 // annotation body
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
104 String annotationtext = createRessourceURL("annotationBody:");
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
105
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
106 retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "Body", annotationtext, context));
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
107
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
108 retQuad.add(new Quadruple(annotationtext, NS.RDF_NS + "type", NS.MPIWG_ANNOT_URL + "StandardTextNote", context));
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
109
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
110 retQuad.add(new LiteralQuadruple(annotationtext, NS.MPIWG_ANNOT_URL + "containsText", annot.text, context));
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
111
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
112 for (Quadruple ret : retQuad) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
113 logger.debug(ret.toString());
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
114 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
115
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
116 annot.setAnnotationUri(annotationUrl);
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
117 return retQuad;
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
118 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
119
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
120 /**
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
121 * Erzeuge eine urn aus der aktullen Zeit in millis
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
122 *
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
123 * @return
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
124 */
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
125 private String createRessourceURL(String prefix) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
126
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
127 Calendar cal = Calendar.getInstance();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
128
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
129 long time = cal.getTimeInMillis();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
130
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
131 return String.format("%s%s%s", urlBase, prefix, time);
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
132
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
133 }
0
dwinter
parents:
diff changeset
134
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
135 /**
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
136 * Hier ist die uri der Annotation angegeben.
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
137 *
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
138 * @param annot
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
139 * @return
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
140 */
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
141
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
142 private List<Quadruple> rel2quadruple(Annotation annot) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
143
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
144 List<Quadruple> retQuad = new ArrayList<Quadruple>();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
145
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
146 String annotation = createRessourceURL("annot:");
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
147
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
148 if (annot.time == null) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
149 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
150 annot.time = format.format(Calendar.getInstance().getTime());
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
151
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
152 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
153
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
154 // TODO: check type
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
155 retQuad.add(new Quadruple(annotation, NS.RDF_NS + "type", NS.ANNOTATION_TYPE + annot.type, context));
0
dwinter
parents:
diff changeset
156
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
157 // add author
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
158 if (annot.creator.startsWith("http")) {
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
159 retQuad.add(new Quadruple(annotation, NS.OAC_NS + "author", annot.creator, context));
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
160 } else {
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
161 retQuad.add(new LiteralQuadruple(annotation, NS.OAC_NS + "author", annot.creator, context));
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
162 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
163
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
164 // creation time
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
165 retQuad.add(new LiteralQuadruple(annotation, NS.OAC_NS + "created", annot.time, context));
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
166
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
167 String[] xpointerSplitted = annot.xpointer.split("#");
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
168
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
169 if (xpointerSplitted.length > 2) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
170 throw new XPointerError();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
171 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
172
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
173 // now add the xpointers
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
174 retQuad.add(new Quadruple(annotation, NS.MPIWG_ANNOT_URL + "annotatesDocuviewerText", xpointerSplitted[0], context));
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
175 retQuad.add(new Quadruple(annotation, NS.MPIWG_ANNOT_URL + "textSelection", annot.xpointer, context));
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
176
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
177 // String annotationtext =createRessourceURL("annotText:");
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
178
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
179 retQuad.add(new Quadruple(annotation, NS.OAC_NS + "body", annot.url, context));
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
180
26
235b91ba8dff on the way to new annotations...
casties
parents: 25
diff changeset
181 retQuad.add(new Quadruple(annot.url, NS.RDF_NS + "type", NS.MPIWG_ANNOT_URL + "ExtendedAnnotation", context));
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
182
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
183 for (Quadruple ret : retQuad) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
184 logger.debug(ret.toString());
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
185 }
0
dwinter
parents:
diff changeset
186
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
187 // save new annotation url in annotation object
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
188 annot.setAnnotationUri(annotation);
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
189 return retQuad;
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
190
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
191 }
0
dwinter
parents:
diff changeset
192
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
193 /**
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
194 * Stores the Annotation in the TripleStore.
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
195 *
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
196 * @param annot
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
197 * @return
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
198 * @throws TripleStoreStoreError
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
199 */
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
200 public Annotation storeAnnotation(Annotation annot) throws TripleStoreStoreError {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
201 List<Quadruple> annotationRdf = new ArrayList<Quadruple>();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
202 if ((annot.type == null) || annot.type.equals("")) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
203 annot.type = "Comment";
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
204 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
205 if (annot.text != null && !annot.text.equals("")) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
206 annotationRdf = annot2quadruple(annot);
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
207 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
208 if (annot.url != null && !annot.url.equals("")) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
209 annotationRdf.addAll(rel2quadruple(annot));
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
210 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
211 try {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
212 TripleStoreHandler th = TripleStoreConnection.newTripleStoreHandler();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
213 th.write(annotationRdf);
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
214 } catch (RepositoryException e) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
215 // TODO Auto-generated catch block
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
216 e.printStackTrace();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
217 throw new TripleStoreStoreError();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
218 } catch (TripleStoreHandlerException e) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
219 // TODO Auto-generated catch block
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
220 e.printStackTrace();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
221 throw new TripleStoreStoreError();
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
222 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
223 return annot;
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
224 }
0
dwinter
parents:
diff changeset
225
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
226 /**
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
227 * @param args
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
228 */
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
229 public static void main(String[] args) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
230 Convert myConvert = new Convert("http://annotations.rdf");
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
231 List<Quadruple> rets = myConvert
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
232 .annot2quadruple(
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
233 "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))",
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
234 "mbuchman", null, "myannot", "Example");
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
235 for (Quadruple ret : rets) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
236 System.out.println(ret.toString());
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
237 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents: 13
diff changeset
238 }
0
dwinter
parents:
diff changeset
239
dwinter
parents:
diff changeset
240 }