def annotationFromSummary(self, summary):
     targetUri = xpathFirst(summary, 'oa:Annotation/oa:hasTarget/@rdf:resource')
     annotationUri = ERFGEO_ENRICHMENT_PROFILE.uriFor(targetUri)
     geoCoordinates = self._geoCoordinatesPresent(summary)
     query, expectedType = self.queryFromSummary(summary) if geoCoordinates is None else (None, None)
     annotation = yield self.annotationFromQuery(query, expectedType=expectedType, targetUri=targetUri, geoCoordinates=geoCoordinates)
     raise StopIteration((annotationUri, annotation))
    def testNoQueryInCaseOfGeoLatLong(self):
        queries = []
        def queryErfGeoApi(query, expectedType=None):
            queries.append(dict(query=query, expectedType=expectedType))
            raise StopIteration(QUERY_RESULTS)
            yield

        def toAnnotation(pit, targetUri, query, geoCoordinates=None):
            return PitToAnnotation().toAnnotation(pit=pit, targetUri=targetUri, query=query, geoCoordinates=geoCoordinates)

        observer = CallTrace('observer', methods={'queryErfGeoApi': queryErfGeoApi, 'toAnnotation': toAnnotation})
        top = be(
            (Observable(),
                (ErfGeoEnrichmentFromSummary(),
                    (observer,)
                )
            )
        )

        summary = makeSummary([], geoLatLong=('51.8', '5.0'))
        result = retval(top.any.annotationFromSummary(summary))
        self.assertEquals([], queries)
        annotationUri, annotation = result
        self.assertEquals(ERFGEO_ENRICHMENT_PROFILE.uriFor('uri:target'), annotationUri)
        self.assertEquals('51.8', xpathFirst(annotation, '/rdf:RDF/oa:Annotation/oa:hasBody/rdf:Description/geo:lat/text()'))
 def testDelete(self):
     summaryToErfGeoEnrichment = SummaryToErfGeoEnrichment()
     observer = CallTrace('observer')
     top = be(
         (Observable(),
             (summaryToErfGeoEnrichment,
                 (observer,)
             )
         )
     )
     targetUri = 'target:uri'
     consume(top.all.delete(identifier=SUMMARY_PROFILE.uriFor(targetUri)))
     self.assertEquals(['delete'], observer.calledMethodNames())
     self.assertEquals(ERFGEO_ENRICHMENT_PROFILE.uriFor(targetUri), observer.calledMethods[0].kwargs['identifier'])
Exemplo n.º 4
0
 def about(self, uri, profile):
     if profile == ERFGEO_ENRICHMENT_PROFILE.prefix:
         data = self.call.getData(identifier=ERFGEO_ENRICHMENT_PROFILE.uriFor(uri), name=profile)
     else:
         arguments = {"uri": [uri], "profile": [profile]}
         if self._digitaleCollectieApiKey:
             arguments["apikey"] = [self._digitaleCollectieApiKey]
         result = yield httpget(
             host=self._digitaleCollectieHost,
             port=self._digitaleCollectiePort,
             request="/about?" + urlencode(arguments, doseq=True),
         )
         header, body = result.split(2 * CRLF, 1)
         if not "HTTP/1.0 200" in header:
             raise ValueError(body)
         data = body
     raise StopIteration(data)
    def testAnnotationFromSummary(self):
        queries = []
        def queryErfGeoApi(query, expectedType=None, exact=None):
            queries.append(dict(query=query, expectedType=expectedType, exact=exact))
            raise StopIteration(QUERY_RESULTS)
            yield

        def toAnnotation(pit, targetUri, query, **kwargs):
            return PitToAnnotation().toAnnotation(pit=pit, targetUri=targetUri, query=query)

        observer = CallTrace('observer', methods={'queryErfGeoApi': queryErfGeoApi, 'toAnnotation': toAnnotation})
        top = be(
            (Observable(),
                (ErfGeoEnrichmentFromSummary(),
                    (observer,)
                )
            )
        )
        summary = makeSummary(['straat: Leunseweg', 'dorp: Leunen', 'gemeente: Venray'])
        result = retval(top.any.annotationFromSummary(summary))
        self.assertEquals([dict(query='"Leunseweg", "Leunen", "Venray"', expectedType='hg:Street', exact=True)], queries)
        annotationUri, annotation = result
        self.assertEquals(ERFGEO_ENRICHMENT_PROFILE.uriFor('uri:target'), annotationUri)
        self.assertEquals('nwb/venray-leunseweg', xpathFirst(annotation, '/rdf:RDF/oa:Annotation/oa:hasBody/rdf:Description/dcterms:spatial/hg:PlaceInTime/@rdf:about'))
 def delete(self, identifier):
     summaryUri = identifier
     targetUri = SUMMARY_PROFILE.targetUriFrom(summaryUri)
     annotationUri = ERFGEO_ENRICHMENT_PROFILE.uriFor(targetUri)
     yield self.all.delete(identifier=annotationUri)