بتاريخ الجمعة، 24 يناير، 2020 7:22:23 م UTC+3، كتب Lim Kai Wey:
> Greetings everyone,
> 
> 
> I would like to ask if anyone knows how to convert my  queryset into string 
> or if there is a better approach to what I am trying to accomplish. In 
> theory, I am trying to assign all the text into a variable and tokenize the 
> whole string so that I can find the top 10 most common word.
> 
> 
> Following is the snippet of my code:
> 
> Models.py
> 
> 
> class Tweet(models.Model):
>     tweet_id = models.BigIntegerField()
>     text = models.TextField()
>     polarity = models.DecimalField(decimal_places=5,max_digits=6,null=True)
>     keyword = models.ForeignKey(Keyword, on_delete=models.CASCADE)
>     country = models.CharField(max_length=255,null=True)
>     stored_at = models.DateTimeField(editable= False)
> 
>     def __str__(self):
>         return self.text
> 
> 
> 
> Views.py
> 
> 
> def tweet_visualizer(request, word = None):
>     if(word == None):
>         num_comments = Tweet.objects.all().count()
>         latest_comments = Tweet.objects.all().order_by('-stored_at')[:6]
>         all_tweets = Tweet.objects.all()
> 
>         all_comments = all_tweets.__str__()
>         tokenized_text = word_tokenize(all_comments)
>         fdist = FreqDist(tokenized_text)
>         top_10_common = fdist.most_common(10)
>     else:
>         num_comments = Tweet.objects.filter(keyword__keyword=word).count()
>         latest_comments = 
> Tweet.objects.filter(keyword__keyword=word).order_by('-stored_at')[:6]
>         all_tweets = Tweet.objects.filter(keyword__keyword=word)
> 
>         all_comments= all_tweets.__str__()
>         tokenized_text = word_tokenize(all_comments)
>         fdist = FreqDist(tokenized_text)
>         top_10_common = fdist.most_common(10)
> 
> 
> 
> My Current Output:
> <QuerySet [<Tweet: Just each machine team recognize.>, <Tweet: Card shoulder 
> option majority with green conference.>, <Tweet: Sometimes feel news chance 
> either.>, <Tweet: Second pull so across drug term.>, <Tweet: Result wife my 
> sport without.>, <Tweet: Modern pick indeed wall north.>, <Tweet: Standard 
> sense each might loss.>, <Tweet: Wish sport small.>, <Tweet: Feel shoulder 
> two go.>, <Tweet: Social state just perhaps.>, <Tweet: Daughter son although 
> development house.>, <Tweet: Before political Democrat during pass.>, <Tweet: 
> Natural development story music and eye water.>, <Tweet: Yourself agency 
> school since what benefit force or.>, <Tweet: Join floor gun do.>, <Tweet: 
> Scientist here very at risk computer.>, <Tweet: Maybe leave seek on big 
> policy.>, <Tweet: Activity close defense should personal.>
> 
> 
> My Desired Output:
> Just each machine team recognize Card shoulder option majority with green 
> conference Sometimes feel news chance either ... etc
> 
> 
> Thank you in advance for anyone who can help me. I really do appreciate it! 
> 
> 
> Sincerely,
> Kai Wey

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7102f293-d861-404b-a1c6-16cb5ed5aed1%40googlegroups.com.

Reply via email to