Changeset 37105


Ignore:
Timestamp:
2023-01-05T23:53:30+13:00 (3 weeks ago)
Author:
davidb
Message:

A series of changes getting the code and XSLT up to the point where the Mirador annotation viewer can be operated without annotations, with annotaitons from a static manifest, with annotations from the store (editable)

Location:
gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/etc/collectionConfig.xml

    r37088 r37105  
    5252              </xsl:template>
    5353             
    54             <xsl:template name="document-link-miradorORIG">
    55                 <a><xsl:attribute name="href"><xsl:value-of select="$library_name"/><xsl:text>/collection/</xsl:text><xsl:value-of select="/page/pageResponse/collection/@name"/><xsl:text>/document/</xsl:text><xsl:choose><xsl:when test="@OID"><xsl:value-of select="@OID"/></xsl:when><xsl:when test="@OIDmetadata"><xsl:variable name="OIDmeta" select="@OIDmetadata"/><xsl:value-of select="metadataList/metadata[@name='{$OIDmeta}']"/></xsl:when><xsl:otherwise><xsl:value-of select="@nodeID"/></xsl:otherwise></xsl:choose><xsl:text>?book=mirador&amp;ed=1</xsl:text></xsl:attribute><img src="interfaces/{$interface_name}/images/iannotate.png" style="vertical-align:middle;"/> (Annotate)<!--
    56 (<gsf:icon type="document" style="vertical-align:middle;"/> Mirador Annotate)
    57 -->
    58 <!--
    59 <xsl:copy-of select="@value"/>
    60 -->
    61 <!--
    62 <xsl:apply-templates selet="@*|node()"/>
    63 -->
    64 </a>
    65             </xsl:template>
    66 <!--
    67 modify the collection description template to output the "this collection contains X documents and was last built Y days ago" message
    68 -->
     54              <!--
     55                  modify the collection description template to output the "this collection contains X documents and was last built Y days ago" message
     56              -->
    6957            <xsl:template name="coll-description">
    7058                <p>
     
    263251             <gsf:metadata name="GVDocumentOCRJSON"/>
    264252             <gsf:metadata name="Image"/>
    265              
     253
    266254           </gsf:headMetaTags>
    267255
    268256            <gsf:option name="TOC" value="true"/>
    269             <gsf:option name="allowUserComments" value="true"/>
     257            <gsf:option name="allowUserComments"    value="true"/>
    270258            <gsf:option name="allowDocumentEditing" value="true"/>
    271             <gsf:option name="allowMapGPSEditing" value="true"/>
    272 <!--
    273 Overwriting this template allows you to change the heading of the document.
    274 -->
    275 <!--
    276 <gsf:template name="documentHeading">
     259            <gsf:option name="allowMapGPSEditing"   value="true"/>
     260
     261
     262            <gsf:option name="includeFileAssocOpenAnnotations" value="false"/>
     263           
     264            <gsf:option name="includeEditableOpenAnnotations"  value="true" endpointURL="/simpleAnnotationStore/annotation" />
     265            <!--
     266            <gsf:option name="includeEditableOpenAnnotations"  value="true" endpointURL="localStorage" />
     267            -->
     268
     269            <!--
     270            <gsf:variable name="openAnnotationEndpoint">https://intermuse.sowemustthink.space/simpleAnnotationStore/annotation</gsf:variable>
     271            -->
     272
     273            <!--
     274                Overwriting this template allows you to change the heading of the document.
     275            -->
     276            <!--
     277                <gsf:template name="documentHeading">
    277278                <span style="font-weight:italic; font-size: 120%;">
    278279                    <xsl:call-template name="choose-title"/>
    279280                </span>
    280281            </gsf:template>
    281 -->
     282            -->
    282283            <xsl:template name="documentHeadingOLD">
    283284              <!--
  • gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/js/document_viewer.js

    r37075 r37105  
    218218
    219219
    220 /*
    221 
    222 https://stackoverflow.com/questions/57071788/google-vision-api-text-detection-display-words-by-block
    223 
    224 
    225 https://gist.github.com/UBISOFT-1/f00e4d22790f4af378d70b237fa56ca9
    226 
    227     response = client.text_detection(image=image)
    228     # The actual response for the first page of the input file.
    229     breaks = vision.enums.TextAnnotation.DetectedBreak.BreakType
    230     paragraphs = []
    231     lines = []
    232     # extract text by block of detection
    233     for page in response.full_text_annotation.pages:
    234         for block in page.blocks:
    235             for paragraph in block.paragraphs:
    236                 para = ""
    237                 line = ""
    238                 suppose = str(paragraph.bounding_box)
    239                 suppose = suppose.replace('vertices ','')
    240                 print(suppose)
    241                 for word in paragraph.words:
    242                     for symbol in word.symbols:
    243                         line += symbol.text
    244                         if symbol.property.detected_break.type == breaks.SPACE:
    245                             line += ' '
    246                         if symbol.property.detected_break.type == breaks.EOL_SURE_SPACE:
    247                             line += ' '
    248                             lines.append(line)
    249                             para += line
    250                             line = ''
    251                         if symbol.property.detected_break.type == breaks.LINE_BREAK:
    252                             lines.append(line)
    253                             para += line
    254                             line = ''
    255             paragraphs.append(para)
    256 
    257 
    258     return "\n".join(paragraphs)
    259 
    260 
    261 
    262 
    263 https://blog.searce.com/tips-tricks-for-using-google-vision-api-for-text-detection-2d6d1e0c6361
    264 
    265 def draw_boxes(image, bounds, color,width=5):
    266     draw = ImageDraw.Draw(image)
    267     for bound in bounds:
    268         draw.line([
    269             bound.vertices[0].x, bound.vertices[0].y,
    270             bound.vertices[1].x, bound.vertices[1].y,
    271             bound.vertices[2].x, bound.vertices[2].y,
    272             bound.vertices[3].x, bound.vertices[3].y,
    273             bound.vertices[0].x, bound.vertices[0].y],fill=color, width=width)
    274     return image
    275 def get_document_bounds(response, feature):
    276     for i,page in enumerate(document.pages):
    277         for block in page.blocks:
    278             if feature==FeatureType.BLOCK:
    279                 bounds.append(block.bounding_box)
    280             for paragraph in block.paragraphs:
    281                 if feature==FeatureType.PARA:
    282                     bounds.append(paragraph.bounding_box)
    283                 for word in paragraph.words:
    284                     for symbol in word.symbols:
    285                         if (feature == FeatureType.SYMBOL):
    286                             bounds.append(symbol.bounding_box)
    287                     if (feature == FeatureType.WORD):
    288                         bounds.append(word.bounding_box)
    289     return bounds
    290 bounds=get_document_bounds(response, FeatureType.WORD)
    291 draw_boxes(image,bounds, 'yellow')
    292 
    293 */
    294 
    295220
    296221
     
    301226
    302227    var canvas_index = goto_page -1;
     228
     229    var httpDocument = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + gs.cgiParams.d;
     230    var httpDocumentIIIFManifest = httpDocument + "?sa=iiif-manifest&ed=1&excerptid-text=iiif-manifest";
     231
     232    //const endpointUrl = 'https://intermuse.sowemustthink.space/simpleAnnotationStore/annotation';
     233    //const endpointUrl = '/simpleAnnotationStore/annotation';
    303234   
    304235    var mirador3_config = {
    305236    "manifests": {
    306         "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json": {
     237        httpDocumentIIIFManifest: {
    307238        "provider": "InterMusE"
    308239        }
    309240    },
    310     "window" : { "panels": { "annotations": true, "attribution": true },
    311              "defaultSideBarPanel": "annotations",
    312              "sideBarOpenByDefault": true           
    313            },
     241    "window" : { "panels": { "attribution": true, "search": true } },
    314242
    315243    //"annotations": {
     
    317245    //  "filteredMotivations": ['oa:commenting', 'oa:tagging', 'sc:painting', 'commenting', 'tagging'],
    318246    //},
     247    /*
    319248    "requests": {
    320249        "postprocessors": [
     
    330259        }
    331260        ]
    332     },
     261    },*/
    333262   
    334263    "windows": [
    335264        {
    336         "loadedManifest": "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json",
     265        "loadedManifest": httpDocumentIIIFManifest,
    337266        "canvasIndex": canvas_index,
    338267        "thumbnailNavigationPosition": 'far-bottom'
     
    341270    };
    342271
     272    var includeFileAssocOpenAnnotations = gs.variables.optionIncludeFileAssocOpenAnnotations;
     273    var includeEditableOpenAnnotations  = gs.variables.optionIncludeEditableOpenAnnotations;
     274
     275    console.log("**** includeFileAssocOpenAnnotations = " + includeFileAssocOpenAnnotations);
     276    console.log("**** includeEditableOpenAnnotations = " + includeEditableOpenAnnotations);
     277   
     278    if ((includeFileAssocOpenAnnotations == 'true') || (includeEditableOpenAnnotations == 'true')) {
     279    // Activate the annotations plugin
     280
     281    mirador3_config.window.panels.annotations = true;
     282   
     283    mirador3_config.window.defaultSideBarPanel = "annotations";
     284    mirador3_config.window.sideBarOpenByDefault = true;   
     285
     286    if (includeEditableOpenAnnotations == 'true') {
     287
     288        //console.log("**** gs.variables.endpointURL = '" + gs.variables.endpointURL + "'");
     289        //const endpointURL = gs.variables.endpointURL;
     290
     291        var endpointURL  = gs.variables.optionIncludeEditableOpenAnnotationsEndpointURL;
     292        console.log("**** endpointURL = '" + endpointURL + "'");
     293       
     294        mirador3_config.annotation = {};
     295   
     296        if ((endpointURL == "") || (endpointURL == "localStorage")) {
     297        mirador3_config.annotation.adapter = (canvasId) => new mirador3WithAnnotations.LocalStorageAdapter(`localStorage://?canvasId=${canvasId}`)
     298        }
     299        else {
     300        mirador3_config.annotation.adapter = (canvasId) => new mirador3WithAnnotations.SimpleAnnotationServerV2Adapter(canvasId, endpointURL);
     301        }
     302
     303        // **** add in a further options for this ????
     304   
     305        mirador3_config.annotation.exportLocalStorageAnnotations = true;  // display annotation JSON export button
     306   
     307    }
     308    }
    343309   
    344310    var mirador3_viewer = mirador3WithAnnotations.initMirador3Viewer('mirador3-viewer',mirador3_config);
    345 
    346     /*
    347     var mirador3_viewer = Mirador.viewer({
    348     "id": "mirador3-viewer",
    349     "manifests": {
    350         "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json": {
    351         "provider": "IntermusE"
    352         }
    353     },
    354     "window" : { "panels" : { "annotations": true, "attribution": false } },
    355     //"annotations": {
    356     //  "htmlSanitizationRuleSet": 'iiif', // See src/lib/htmlRules.js for acceptable values
    357     //  "filteredMotivations": ['oa:commenting', 'oa:tagging', 'sc:painting', 'commenting', 'tagging'],
    358     //},
    359     "requests": {
    360         "postprocessors": [
    361         (url, action) => {
    362             if (action.type === "mirador/RECEIVE_MANIFEST") {
    363             //console.log(action)
    364             //console.log(iiif_manifest);
    365             return {
    366                 ...action ,
    367                 "manifestJson": iiif_manifest
    368             };
    369             }
    370         }
    371         ]
    372     },
    373    
    374     "windows": [
    375         {
    376         "loadedManifest": "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json",
    377         "canvasIndex": 0,
    378         "thumbnailNavigationPosition": 'far-bottom'
    379         }
    380     ]
    381     });
    382     */
    383311   
    384312    return mirador3_viewer;
  • gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/transform/pages/document.xsl

    r37088 r37105  
    8484
    8585
    86   <xsl:template name="googlevision-ocr-json">
     86  <xsl:template name="opt-googlevision-ocr-json">
    8787    <xsl:param name="assocfilepath"/>
    8888   
     
    9090    <gsf:variable name="docSectionID"><xsl:value-of select="util:replace(@nodeID, '.', '_')"/></gsf:variable>
    9191
    92     <!--
    93     <div style="padding-top: 10px; padding-bottom: 10px;">
    94       Google Vision OCR JSON:
    95       <a>
    96     <xsl:attribute name="href">
    97       <xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name = 'httpPath']"/>
    98       <xsl:text>/index/assoc/</xsl:text><xsl:value-of disable-output-escaping="yes" select="$assocfilepath" /><xsl:text>/</xsl:text><xsl:value-of select="$GVDocumentOCRJSON"/>
    99     </xsl:attribute>
    100     <xsl:value-of select="$GVDocumentOCRJSON"/>
    101       </a>
    102     </div>
    103     -->
    104     <gsf:script>
    105       load_gv_dococr_json(gs.variables.GVDocumentOCRJSON,gs.variables.docSectionID,display_gv_ocr_bounding_boxes);
    106     </gsf:script>
     92    <gsf:switch>
     93      <gsf:metadata name="HasGoogleVisionDocumentOCRJSON"/>
     94      <gsf:when test='equals' test-value="1">
     95
     96    <gsf:script>
     97      // Load in the Google Vision OCR JSON file and display bounding boxes for this document (docType=simple) or page (docType=paged)
     98      load_gv_dococr_json(gs.variables.GVDocumentOCRJSON,gs.variables.docSectionID,display_gv_ocr_bounding_boxes);
     99    </gsf:script>
     100      </gsf:when>
     101    </gsf:switch>
     102   
    107103  </xsl:template>
    108104
     
    117113
    118114    <!-- add in Google Vision OCR JSON link for section image -->
    119     <xsl:call-template name="googlevision-ocr-json">
     115    <xsl:call-template name="opt-googlevision-ocr-json">
    120116      <xsl:with-param name="assocfilepath"><gsf:metadata name="assocfilepath" select="root"/></xsl:with-param>
    121117    </xsl:call-template>   
     
    177173  <xsl:template name="documentPre">
    178174    <xsl:variable name="httpCollection">library/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="/page/pageResponse/collection/@name"/></xsl:variable>
     175
     176    <gsf:variable name="optionIncludeFileAssocOpenAnnotations">
     177      <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeFileAssocOpenAnnotations']/@value"/>
     178    </gsf:variable>
     179    <gsf:variable name="optionIncludeEditableOpenAnnotations">
     180      <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@value"/>
     181    </gsf:variable>
     182    <gsf:variable name="optionIncludeEditableOpenAnnotationsEndpointURL">
     183      <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@endpointURL"/>
     184    </gsf:variable>
     185
     186
    179187    <gsf:variable name="chosenTitle"><xsl:call-template name="choose-title"/></gsf:variable>
    180188    <!-- <gsf:variable name="toplevelTitle"><gsf:metadata name="Title" select="root"/></gsf:variable> -->
     
    259267   
    260268    <xsl:if test="@docType='simple'">
    261 
    262       <!--
    263       <gsf:switch>
    264     <gsf:metadata name='HasGoogleVisionDocumentOCRJSON";'/>
    265       <gsf:when test='equals' test-value="1">
    266       -->
    267 
    268       <!-- add in Google Vision OCR JSON link for simple page image -->     
    269       <xsl:call-template name="googlevision-ocr-json">
    270         <xsl:with-param name="assocfilepath"><gsf:metadata name="assocfilepath" pos="first"/></xsl:with-param>
    271       </xsl:call-template>
    272       <!--
    273     </gsf:when>
    274       </gsf:switch>
    275 -->
    276      
     269      <xsl:call-template name="opt-googlevision-ocr-json">
     270    <xsl:with-param name="assocfilepath"><gsf:metadata name="assocfilepath" pos="first"/></xsl:with-param>
     271      </xsl:call-template>     
    277272    </xsl:if>
    278273  </xsl:template>
     
    282277    <!-- Container element of Mirador whose id should be passed to the instantiating call as "id" -->   
    283278    <div style="position: relative; width: 100%; height: 800px;">
    284       <div id="mirador3-viewer"> <xsl:comment>filler</xsl:comment></div>
    285     </div>
     279      <div id="mirador3-viewer"><xsl:comment>filler</xsl:comment></div>
     280    </div>
     281
     282    <!--
     283    <gsf:variable name="endpointURL">
     284      <xsl:choose>
     285    <xsl:when test="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@value='true'">
     286      <xsl:choose>
     287        <xsl:when test="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@endpointURL">
     288          <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@endpointURL"/>
     289        </xsl:when>
     290        <xsl:otherwise>
     291          <xsl:text>localStorage</xsl:text> < ! - - default - - >
     292        </xsl:otherwise>
     293      </xsl:choose>
     294        </xsl:when>
     295    <xsl:otherwise></xsl:otherwise>
     296      </xsl:choose>
     297    </gsf:variable>
     298    -->
    286299
    287300    <gsf:script>     
Note: See TracChangeset for help on using the changeset viewer.