changeset 30:b37487b756ac

still working on new annotations...
author casties
date Wed, 09 May 2012 11:26:54 +0200
parents cf8166ee8918
children 38465b158de6
files src/main/java/de/mpiwg/itgroup/annotationManager/RDFHandling/Convert.java src/main/java/de/mpiwg/itgroup/annotationManager/RDFHandling/RDFSearcher.java
diffstat 2 files changed, 54 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotationManager/RDFHandling/Convert.java	Mon May 07 19:50:39 2012 +0200
+++ b/src/main/java/de/mpiwg/itgroup/annotationManager/RDFHandling/Convert.java	Wed May 09 11:26:54 2012 +0200
@@ -64,15 +64,18 @@
 
         // annotation class
         retQuad.add(new Quadruple(annotationUrl, NS.RDF_NS + "type", NS.OAC_NS + "Annotation", context));
-
-        // author
+        /*
+         * author
+         */
         if (annot.creator.startsWith("http")) {
             retQuad.add(new Quadruple(annotationUrl, NS.DCTERMS_NS + "creator", annot.creator, context));
         } else {
             // TODO: this should not happen
             retQuad.add(new LiteralQuadruple(annotationUrl, NS.DCTERMS_NS + "creator", annot.creator, context));
         }
-        // creation time
+        /*
+         * creation time
+         */
         if (annot.time == null) {
             SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
             annot.time = format.format(Calendar.getInstance().getTime());
@@ -80,40 +83,58 @@
         retQuad.add(new LiteralQuadruple(annotationUrl, NS.DCTERMS_NS + "created", annot.time, context));
 
         if (annot.page == null || annot.page == "") {
-            // target without page number (full URL)
+            /*
+             *  target without page number (full URL)
+             */
             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));
         } else {
-            // ConstrainedTarget with page number (full URL)
-            retQuad.add(new Quadruple(annot.xpointer, NS.RDF_NS + "type", NS.OAC_NS + "ConstrainedTarget", context));
+            /* 
+             * ConstrainedTarget with page number
+             */
+            String ctUrl = createRessourceURL("annotCT:");
+            // is ConstrainedTarget
+            retQuad.add(new Quadruple(ctUrl, NS.RDF_NS + "type", NS.OAC_NS + "ConstrainedTarget", context));
             // is target of annotation
-            retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasTarget", annot.xpointer, context));
-            // constrains Target
-            //retQuad.add(new Quadruple(constraint, NS.OAC_NS + "constrains", annot.xpointer, context));
+            retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasTarget", ctUrl, context));
+            // constrains Target (full URL)
+            retQuad.add(new Quadruple(ctUrl, NS.OAC_NS + "constrains", annot.xpointer, context));
             // TextPageConstraint
-            String constraint = createRessourceURL("annotC:");
-            retQuad.add(new Quadruple(constraint, NS.RDF_NS + "type", NS.MPIWG_ANNOT_NS + "TextPageConstraint", context));
-            retQuad.add(new LiteralQuadruple(constraint, NS.MPIWG_ANNOT_NS + "textPage", annot.page, context));
-            // constrains Target
-            retQuad.add(new Quadruple(constraint, NS.OAC_NS + "constrains", annot.xpointer, context));
-            
+            String tpcUrl = createRessourceURL("annotC:");
+            // is TextPageConstraint
+            retQuad.add(new Quadruple(tpcUrl, NS.RDF_NS + "type", NS.MPIWG_ANNOT_NS + "TextPageConstraint", context));
+            // page number
+            retQuad.add(new LiteralQuadruple(tpcUrl, NS.MPIWG_ANNOT_NS + "textPage", annot.page, context));
+            // textPageDisplay
+            if (annot.displayUrl != null && annot.displayUrl != "") {
+                retQuad.add(new LiteralQuadruple(tpcUrl, NS.MPIWG_ANNOT_NS + "textPageDisplay", annot.displayUrl, context));
+            }
+            // ConstrainedTarget has this Constraint
+            retQuad.add(new Quadruple(ctUrl, NS.OAC_NS + "hasConstraint", tpcUrl, context));  
+            //TODO: displayUrl
         }
 
         // annotation body
         if (annot.url != null && annot.url.startsWith("http://")) {
-            // body is resource
+            /*
+             *  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("annotB:");
-            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));
+            /*
+             *  body is literal text
+             */
+            String abUrl = createRessourceURL("annotB:");
+            // is Body and ContentAsText
+            retQuad.add(new Quadruple(abUrl, NS.RDF_NS + "type", NS.OAC_NS + "Body", context));
+            retQuad.add(new Quadruple(abUrl, NS.RDF_NS + "type", NS.CNT_NS + "ContentAsText", context));
+            // has text
+            retQuad.add(new LiteralQuadruple(abUrl, NS.CNT_NS + "chars", annot.text, context));
             // is body of annotation
-            retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasBody", annotationtext, context));
+            retQuad.add(new Quadruple(annotationUrl, NS.OAC_NS + "hasBody", abUrl, context));
         }
 
         for (Quadruple ret : retQuad) {
@@ -125,7 +146,7 @@
     }
 
     /**
-     * Erzeuge eine urn aus der aktullen Zeit in millis
+     * Erzeuge eine urn aus der aktuellen Zeit in millis
      * 
      * @return
      */
@@ -167,18 +188,4 @@
         return annot;
     }
 
-    /**
-     * @param args
-     */
-    public static void main(String[] args) {
-        Convert myConvert = new Convert("http://annotations.rdf");
-        List<Quadruple> rets = myConvert
-                .annot2quadruple(
-                        "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))",
-                        "mbuchman", null, "myannot", "Example");
-        for (Quadruple ret : rets) {
-            System.out.println(ret.toString());
-        }
-    }
-
 }
--- a/src/main/java/de/mpiwg/itgroup/annotationManager/RDFHandling/RDFSearcher.java	Mon May 07 19:50:39 2012 +0200
+++ b/src/main/java/de/mpiwg/itgroup/annotationManager/RDFHandling/RDFSearcher.java	Wed May 09 11:26:54 2012 +0200
@@ -13,8 +13,6 @@
 
 public class RDFSearcher {
 
-    private String urlBase = "http://ontologies.mpiwg-berlin.mpg.de/annotations/"; // TODO should go into config
-
     private String context;
 
     private Logger logger = Logger.getRootLogger();
@@ -24,10 +22,10 @@
     }
 
     /**
-     * Sucht im Triplestore nach Annotationen.
+     * Retrieves Annotations by ID.
      * 
      * @param id
-     *            id der Annotation
+     *            id of the Annotation
      * @return
      * @throws TripleStoreHandlerException
      * @throws TripleStoreSearchError
@@ -48,6 +46,14 @@
         whereString.append(String.format("<%s> <http://www.w3.org/2000/10/annotation-ns#created> ?created.", id));
         whereString.append(" OPTIONAL {?annotText <http://ontologies.mpiwg-berlin.mpg.de/annotations/containsText> ?text.}");
 
+        /* StringBuilder whereString = new StringBuilder(String.format("<%s> ?p <http://www.w3.org/2000/10/annotationType#Comment>.", id));
+        whereString.append(String.format("<%s> <http://ontologies.mpiwg-berlin.mpg.de/annotations/annotatesDocuviewerText> ?uri.", id));
+        whereString.append(String.format("<%s> <http://ontologies.mpiwg-berlin.mpg.de/annotations/textSelection> ?xpointer.", id));
+        whereString.append(String.format("<%s> <http://www.w3.org/2000/10/annotation-ns#body> ?annotText.", id));
+        whereString.append(String.format("<%s> <http://www.w3.org/2000/10/annotation-ns#author> ?author.", id));
+        whereString.append(String.format("<%s> <http://www.w3.org/2000/10/annotation-ns#created> ?created.", id));
+        whereString.append(" OPTIONAL {?annotText <http://ontologies.mpiwg-berlin.mpg.de/annotations/containsText> ?text.}"); */
+
         queryString = String.format("select distinct * where {%s}", whereString);
 
         logger.debug("RDFSearcher:" + queryString);