changeset 27:b4a798d417fe

on the way to new annotations...
author casties
date Fri, 27 Apr 2012 09:55:39 +0200
parents 235b91ba8dff
children 185db3cac82c
files src/main/java/de/mpiwg/itgroup/annotationManager/Constants/NS.java src/main/java/de/mpiwg/itgroup/annotationManager/RDFHandling/Convert.java
diffstat 2 files changed, 24 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotationManager/Constants/NS.java	Thu Apr 26 11:44:57 2012 +0200
+++ b/src/main/java/de/mpiwg/itgroup/annotationManager/Constants/NS.java	Fri Apr 27 09:55:39 2012 +0200
@@ -5,6 +5,7 @@
     // public static String
     // ANNOTATION_TYPE="http://www.w3.org/2000/10/annotationType#";
     public static final String OAC_NS = "http://www.openannotation.org/ns/";
+    public static final String CNT_NS = "http://www.w3.org/2011/content#";
     public static final String DCTERMS_NS = "http://www.purl.org/dc/terms/";
     public static final String RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
     public static final String MPIWG_ANNOT_URL = "http://entities.mpiwg-berlin.mpg.de/annotations/";
--- a/src/main/java/de/mpiwg/itgroup/annotationManager/RDFHandling/Convert.java	Thu Apr 26 11:44:57 2012 +0200
+++ b/src/main/java/de/mpiwg/itgroup/annotationManager/RDFHandling/Convert.java	Fri Apr 27 09:55:39 2012 +0200
@@ -1,20 +1,15 @@
 package de.mpiwg.itgroup.annotationManager.RDFHandling;
 
-import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
-import java.util.Date;
 import java.util.List;
 
 import org.apache.log4j.Logger;
 import org.openrdf.repository.RepositoryException;
-import org.restlet.Context;
-import org.restlet.engine.component.ChildContext;
 
 import de.mpiwg.itgroup.annotationManager.Constants.NS;
 import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreStoreError;
-import de.mpiwg.itgroup.annotationManager.Errors.XPointerError;
 import de.mpiwg.itgroup.triplestoremanager.exceptions.TripleStoreHandlerException;
 import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler;
 import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler.LiteralQuadruple;
@@ -70,7 +65,7 @@
         // annotation class
         retQuad.add(new Quadruple(annotationUrl, NS.RDF_NS + "type", NS.OAC_NS + "Annotation", context));
         // TODO: what types?
-        //retQuad.add(new LiteralQuadruple(annotationUrl, NS.RDF + "type", annot.type, context));
+        // retQuad.add(new LiteralQuadruple(annotationUrl, NS.RDF + "type", annot.type, context));
 
         // author
         if (annot.creator.startsWith("http")) {
@@ -90,24 +85,29 @@
         retQuad.add(new Quadruple(annot.xpointer, NS.RDF_NS + "type", NS.OAC_NS + "Target", context));
         // is target of annotation
         retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasTarget", annot.xpointer, context));
-        
+
         // now add the xpointers
-        /* String[] xpointerSplitted = annot.xpointer.split("#");
-        if (xpointerSplitted.length > 2) {
-            throw new XPointerError();
-        }
-        retQuad.add(new Quadruple(annotationUrl, NS.MPIWG_ANNOT_URL + "annotatesDocuviewerText", xpointerSplitted[0], context));
-        retQuad.add(new Quadruple(annotationUrl, NS.MPIWG_ANNOT_URL + "textSelection", annot.xpointer, context));
-        */
+        /*
+         * String[] xpointerSplitted = annot.xpointer.split("#"); if (xpointerSplitted.length > 2) { throw new XPointerError(); }
+         * retQuad.add(new Quadruple(annotationUrl, NS.MPIWG_ANNOT_URL + "annotatesDocuviewerText", xpointerSplitted[0], context));
+         * retQuad.add(new Quadruple(annotationUrl, NS.MPIWG_ANNOT_URL + "textSelection", annot.xpointer, context));
+         */
 
         // annotation body
-        String annotationtext = createRessourceURL("annotationBody:");
-        
-        retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "Body", annotationtext, context));
-
-        retQuad.add(new Quadruple(annotationtext, NS.RDF_NS + "type", NS.MPIWG_ANNOT_URL + "StandardTextNote", context));
-
-        retQuad.add(new LiteralQuadruple(annotationtext, NS.MPIWG_ANNOT_URL + "containsText", annot.text, context));
+        if (annot.url != null && annot.url.startsWith("http://")) {
+            // body is resource
+            retQuad.add(new Quadruple(annot.url, NS.RDF_NS + "type", NS.OAC_NS + "Body", context));            
+            // is body of annotation
+            retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasBody", annot.url, context));
+        } else {
+            // body is literal text
+            String annotationtext = createRessourceURL("annotationBody:");
+            retQuad.add(new Quadruple(annotationtext, NS.RDF_NS + "type", NS.OAC_NS + "Body", context));
+            retQuad.add(new Quadruple(annotationtext, NS.RDF_NS + "type", NS.CNT_NS + "ContentAsText", context));
+            retQuad.add(new LiteralQuadruple(annotationtext, NS.CNT_NS + "chars", annot.text, context));
+            // is body of annotation
+            retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasBody", annotationtext, context));
+        }
 
         for (Quadruple ret : retQuad) {
             logger.debug(ret.toString());
@@ -132,65 +132,8 @@
 
     }
 
+
     /**
-     * Hier ist die uri der Annotation angegeben.
-     * 
-     * @param annot
-     * @return
-     */
-
-    private List<Quadruple> rel2quadruple(Annotation annot) {
-
-        List<Quadruple> retQuad = new ArrayList<Quadruple>();
-
-        String annotation = createRessourceURL("annot:");
-
-        if (annot.time == null) {
-            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
-            annot.time = format.format(Calendar.getInstance().getTime());
-
-        }
-
-        // TODO: check type
-        retQuad.add(new Quadruple(annotation, NS.RDF_NS + "type", NS.ANNOTATION_TYPE + annot.type, context));
-
-        // add author
-        if (annot.creator.startsWith("http")) {
-            retQuad.add(new Quadruple(annotation, NS.OAC_NS + "author", annot.creator, context));
-        } else {
-            retQuad.add(new LiteralQuadruple(annotation, NS.OAC_NS + "author", annot.creator, context));
-        }
-
-        // creation time
-        retQuad.add(new LiteralQuadruple(annotation, NS.OAC_NS + "created", annot.time, context));
-
-        String[] xpointerSplitted = annot.xpointer.split("#");
-
-        if (xpointerSplitted.length > 2) {
-            throw new XPointerError();
-        }
-
-        // now add the xpointers
-        retQuad.add(new Quadruple(annotation, NS.MPIWG_ANNOT_URL + "annotatesDocuviewerText", xpointerSplitted[0], context));
-        retQuad.add(new Quadruple(annotation, NS.MPIWG_ANNOT_URL + "textSelection", annot.xpointer, context));
-
-        // String annotationtext =createRessourceURL("annotText:");
-
-        retQuad.add(new Quadruple(annotation, NS.OAC_NS + "body", annot.url, context));
-
-        retQuad.add(new Quadruple(annot.url, NS.RDF_NS + "type", NS.MPIWG_ANNOT_URL + "ExtendedAnnotation", context));
-
-        for (Quadruple ret : retQuad) {
-            logger.debug(ret.toString());
-        }
-
-        // save new annotation url in annotation object
-        annot.setAnnotationUri(annotation);
-        return retQuad;
-
-    }
-
-    /** 
      * Stores the Annotation in the TripleStore.
      * 
      * @param annot
@@ -202,12 +145,7 @@
         if ((annot.type == null) || annot.type.equals("")) {
             annot.type = "Comment";
         }
-        if (annot.text != null && !annot.text.equals("")) {
-            annotationRdf = annot2quadruple(annot);
-        }
-        if (annot.url != null && !annot.url.equals("")) {
-            annotationRdf.addAll(rel2quadruple(annot));
-        }
+        annotationRdf = annot2quadruple(annot);
         try {
             TripleStoreHandler th = TripleStoreConnection.newTripleStoreHandler();
             th.write(annotationRdf);