def __call__(self, params): uristr = params.pop('uri', None) if uristr is None: return None scopes = [uri.normalize(u) for u in uri.expand(uristr)] return {"terms": {"target.scope": scopes}}
def __call__(self, params): uristr = params.pop('uri', None) if uristr is None: return None scopes = [uri.normalize(u) for u in storage.expand_uri(uristr)] return {"terms": {"target.scope": scopes}}
def _read_group(request, group): """Return the rendered "Share this group" page. This is the page that's shown when a user who is already a member of a group visits the group's URL. """ url = request.route_url('group_read', pubid=group.pubid, slug=group.slug) result = search.search(request, private=False, params={ "group": group.pubid, "limit": 1000}) annotations = [presenters.AnnotationHTMLPresenter(a) for a in result['rows']] # Group the annotations by URI. # Create a dict mapping the (normalized) URIs of the annotated documents # to the most recent annotation of each document. annotations_by_uri = collections.OrderedDict() for annotation in annotations: normalized_uri = uri.normalize(annotation.uri) if normalized_uri not in annotations_by_uri: annotations_by_uri[normalized_uri] = annotation if len(annotations_by_uri) >= 25: break document_links = [annotation.document_link for annotation in annotations_by_uri.values()] template_data = { 'group': group, 'group_url': url, 'document_links': document_links} return renderers.render_to_response( renderer_name='h:groups/templates/share.html.jinja2', value=template_data, request=request)
def __call__(self, params): uristr = params.pop('uri', None) if uristr is None: return None uris = storage.expand_uri(self.request, uristr) scopes = [uri.normalize(u) for u in uris] return {"terms": {"target.scope": scopes}}
def __call__(self, params): uristr = params.pop('uri', None) if uristr is None: return None uris = storage.expand_uri(self.request.db, uristr) scopes = [uri.normalize(u) for u in uris] return {"terms": {"target.scope": scopes}}
def _term_clause_for_uri(uristr): """Return an Elasticsearch term clause for the given URI.""" uristrs = uri.expand(uristr) filters = [{"term": {"target.scope": uri.normalize(u)}} for u in uristrs] if len(filters) == 1: return filters[0] return { "or": filters }
def _term_clause_for_uri(uristr): """Return an Elasticsearch term clause for the given URI.""" uristrs = uri.expand(uristr) filters = [{ "term": { "target.source_normalized": uri.normalize(u) } } for u in uristrs] if len(filters) == 1: return filters[0] return {"or": filters}
def find_by_uris(cls, session, uris): """Find documents by a list of uris.""" query_uris = [text_type(uri.normalize(u), 'utf-8') for u in uris] matching_claims = ( session.query(DocumentURI) .filter(DocumentURI.uri_normalized.in_(query_uris)) .distinct(DocumentURI.document_id) .subquery() ) return session.query(Document).join(matching_claims)
def __call__(self, params): if 'uri' not in params: return None query_uris = [v for k, v in params.items() if k == 'uri'] del params['uri'] uris = set() for query_uri in query_uris: us = [uri.normalize(u) for u in storage.expand_uri(self.request.db, query_uri)] uris.update(us) return {"terms": {"target.scope": list(uris)}}
def _normalize_annotation_target_uris(annotation): if 'target' not in annotation: return if not isinstance(annotation['target'], list): return for target in annotation['target']: if not isinstance(target, dict): continue if 'source' not in target: continue if not isinstance(target['source'], string_types): continue target['scope'] = [uri.normalize(target['source'])]
def _normalize_annotation_target_uris(annotation): if 'target' not in annotation: return if not isinstance(annotation['target'], list): return for target in annotation['target']: if not isinstance(target, dict): continue if 'source' not in target: continue if not isinstance(target['source'], basestring): continue target['source_normalized'] = uri.normalize(target['source'])
def _normalize_annotation_target_uris(annotation): if "target" not in annotation: return if not isinstance(annotation["target"], list): return for target in annotation["target"]: if not isinstance(target, dict): continue if "source" not in target: continue if not isinstance(target["source"], basestring): continue target["source_normalized"] = uri.normalize(target["source"])
def normalize_annotation_target_uris(annotation): if 'target' not in annotation: return if not isinstance(annotation['target'], list): return for target in annotation['target']: if not isinstance(target, dict): continue if 'source' not in target: continue if not isinstance(target['source'], string_types): continue target['scope'] = [uri.normalize(target['source'])]
def _read_group(request, group): """Return the rendered "Share this group" page. This is the page that's shown when a user who is already a member of a group visits the group's URL. """ url = request.route_url('group_read', pubid=group.pubid, slug=group.slug) result = search.search(request, private=False, params={ "group": group.pubid, "limit": 1000 }) annotations = [ presenters.AnnotationHTMLPresenter(storage.annotation_from_dict(a)) for a in result['rows'] ] # Group the annotations by URI. # Create a dict mapping the (normalized) URIs of the annotated documents # to the most recent annotation of each document. annotations_by_uri = collections.OrderedDict() for annotation in annotations: normalized_uri = uri.normalize(annotation.uri) if normalized_uri not in annotations_by_uri: annotations_by_uri[normalized_uri] = annotation if len(annotations_by_uri) >= 25: break document_links = [ annotation.document_link for annotation in annotations_by_uri.values() ] template_data = { 'group': group, 'group_url': url, 'document_links': document_links } return renderers.render_to_response( renderer_name='h:templates/groups/share.html.jinja2', value=template_data, request=request)
def target_uri(self, value): self._target_uri = value self._target_uri_normalized = text_type(uri.normalize(value), 'utf-8')
def _fetch_document_uri_claimants(session, uri_): return session.query(models.DocumentURI).filter( models.DocumentURI.claimant_normalized == uri.normalize(uri_)).all()
def claimant(self, value): self._claimant = value self._claimant_normalized = text_type(uri.normalize(value), 'utf-8')
def test_normalize(url_in, url_out): assert uri.normalize(url_in) == url_out
def uri_normalized(self): uri_ = self.uri if uri_: return text_type(uri.normalize(uri_), 'utf-8')
def target_uri(self, value): self._target_uri = value self._target_uri_normalized = uri.normalize(value)
def _fetch_annotations(session, uri_): return session.query(models.Annotation).filter( models.Annotation.target_uri_normalized == uri.normalize(uri_)).all()
def claimant_normalized(self): claimant = self.claimant if claimant: return uri.normalize(claimant)
def uri_normalized(self): uri_ = self.uri if uri_: return uri.normalize(uri_)
def read_group(request, group, language=None, search_url=None, user=None, render=True): """ Return the rendered "Share this group" page. This is the page that's shown when a user who is already a member of a group visits the group's URL. :param request: a request object :param group: a group object :param language: a language object to search or None :param search_url: the URL to search or None :param user: the user object to search or None :param render: whether or not to return a context object :return: if render, a context object for a template. If render is false, a list of annotations """ if group is None: public_group_id = "__world__" slug = "Public" else: public_group_id = group.pubid slug = group.slug url = request.route_url('group_read', pubid=public_group_id, slug=slug) parameters = {"group": public_group_id, "limit": 1000} if language: parameters['language'] = language.pubid if search_url: parameters['uri'] = search_url if user: parameters['user'] = user result = search.search(request, private=False, params=parameters) annotations = [presenters.AnnotationHTMLPresenter(h.models.Annotation(a)) for a in result['rows']] if render: # Group the annotations by URI. # Create a dict mapping the (normalized) URIs of the annotated documents # to the most recent annotation of each document. annotations_by_uri = collections.OrderedDict() for annotation in annotations: normalized_uri = uri.normalize(annotation.uri) if normalized_uri not in annotations_by_uri: annotations_by_uri[normalized_uri] = annotation if len(annotations_by_uri) >= 25: break document_links = [annotation.document_link for annotation in annotations_by_uri.values()] template_data = { 'group': group, 'group_url': url, 'document_links': document_links} return renderers.render_to_response( renderer_name='h:templates/groups/share.html.jinja2', value=template_data, request=request) else: return annotations
def test_normalize_returns_unicode(url, _): assert isinstance(uri.normalize(url), text_type)
def _fetch_document_uri_canonical_self_claim(session, uri_): return session.query(models.DocumentURI).filter( models.DocumentURI.uri_normalized == uri.normalize(uri_), models.DocumentURI.type.in_([u'self-claim', u'rel-canonical'])).all()
def claimant_normalized(self): claimant = self.claimant if claimant: return text_type(uri.normalize(claimant), 'utf-8')
def term_filter(self, uristr): scopes = [uri.normalize(u) for u in uri.expand(uristr)] return {"terms": {"target.scope": scopes}}
def uri(self, value): self._uri = value self._uri_normalized = text_type(uri.normalize(value), 'utf-8')
def target_uri_normalized(self): target_uri = self.target_uri if target_uri: return uri.normalize(target_uri)