def get_context_data(self, request, **kwargs): context = super(AttributeWordView, self).get_context_data(request, **kwargs) dataset = context['dataset'] analysis = context['analysis'] attribute = context['attribute'] value = context['value'] word = Word.objects.get(dataset=dataset, type=kwargs['word']) documents = word.document_set.filter(attribute=attribute, attributevaluedocument__value=value) words = [] for document in documents: w = WordSummary(word.type) set_word_context(w, document, analysis) words.append(w) w.url = '%s/%s/values/%s/documents/%d?kwic=%s' \ % (context['attributes_url'], attribute.name, value.value, document.id, word.type) w.doc_name = document.filename w.doc_id = document.id context['words'] = words context['breadcrumb'].word(word) context['attribute_post_link'] = '/words/%s' % word.type return context
def get_context_data(self, request, **kwargs): dataset_name = kwargs['dataset'] analysis_name = kwargs['analysis'] word = Word.objects.get(dataset__name=dataset_name, type=kwargs['word']) filter = TopicFilterByWord(Analysis.objects.get(dataset__name=dataset_name, name=analysis_name), 0) filter.current_word = word context = super(TopicWordView, self).get_context_data(request, extra_filters=[filter], **kwargs) analysis = context['analysis'] topic = context['topic'] context['word'] = word documents = word.documenttopicword_set.filter(topic=topic).order_by( 'document__filename') docs = [] for dtw in documents: d = dtw.document w = WordSummary(word.type) set_word_context(w, d, analysis, topic.number) docs.append(w) w.url = "%s/%d/documents/%d?kwic=%s" % (context['topics_url'], topic.number, d.id, word.type) w.doc_name = d.filename w.doc_id = d.id context['documents'] = docs context['breadcrumb'].word(word) context['topic_post_link'] = '/words/%s' % word.type word_url = '%s/%d/words/' % (context['topics_url'], topic.number) context['tabs'] = [self._topic_word_tab(analysis, word, word_url, context['IMAGES'])] return context
def word_in_context(request, dataset, analysis, word, topic=None): analysis = Analysis.objects.get(name=analysis, dataset__name=dataset) w = Word.objects.get(dataset__name=dataset, type=word) word_context = WordSummary(word) if topic is None: docset = w.documentword_set.all() else: topic = Topic.objects.get(analysis=analysis, number=topic) docset = topic.documenttopicword_set.filter(word=w) num_docs = len(docset) d = docset[random.randint(0, num_docs - 1)] word_context.left_context, word_context.word, word_context.right_context \ = d.document.get_context_for_word(word, analysis, topic.number if topic else None) word_context.doc_name = d.document.filename word_context.doc_id = d.document.id return HttpResponse(anyjson.dumps(vars(word_context)))