counting the same words within a song added by a user using Django

67 views
Skip to first unread message

DJANGO DEVELOPER

unread,
Jul 5, 2021, 7:36:52 AM7/5/21
to Django users
Hi there.
I am developing a project based on adding songs to the user's library and to the home page.
other users can also purchase the songs like wise people do shopping on eCommerce stores.
Problem:(Question)
The problem that I want to discuss here is that when a user adds a sing through django forms, and now that song is added to the user's personal library.
now what I want to do is :
When the lyrics of a song are added as a record to the "Song" table, the individual words in that song should be added to a 2nd table with their frequency of usage within that song (so the words need to be counted and a signal needs to be created).

Also, when a user adds the song to his/her personal library, all of the words from the song and their frequencies within that song should be added to another table and associated with that user.


how to count same word within a song? 

can anyone help me here?
your help would be appreciated.

Lalit Suthar

unread,
Jul 5, 2021, 8:44:29 AM7/5/21
to django...@googlegroups.com

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bc7bc37b-6f26-465c-b330-d275ab86b76an%40googlegroups.com.

DJANGO DEVELOPER

unread,
Jul 5, 2021, 1:51:48 PM7/5/21
to Django users
Thank you Lalit bhai.
it seems to be a solution.
but what if I want to get the result for each single word rather than single letter?


Simon Charette

unread,
Jul 5, 2021, 4:54:08 PM7/5/21
to Django users
If you're using a PostgreSQL you might want to look at using a tsvector column instead which will ignore stop words (the, or, of, ...) and map lexemes to their number of occurrence and position in the lyrics[0]. Assuming you were to index this column you'd be able to efficiently query it for existence of a particular lexeme or multiple of them.

You could then a union of all a user's song lyrics tsvector and even apply weights based on their listening frequency or their favorite songs.

Cheers,
Simon

DJANGO DEVELOPER

unread,
Jul 5, 2021, 10:26:53 PM7/5/21
to Django users
thanks Simon but I am not using postgresql. I am using sqlite3 database. so I want a global solution, that work in all the databases.

Lalit Suthar

unread,
Jul 6, 2021, 12:22:41 AM7/6/21
to django...@googlegroups.com
Screen Shot 2021-07-06 at 9.50.12 AM.png
Counter works with words also

nice one Simon Charette learned something new :) 

DJANGO DEVELOPER

unread,
Jul 6, 2021, 12:55:06 AM7/6/21
to Django users
I found this as well. and I think  I want the result this way.

wordcounter.PNG
result.PNG

lalit suthar

unread,
Jul 6, 2021, 3:08:51 AM7/6/21
to Django users
cool :D 

sum abiut

unread,
Jul 6, 2021, 12:40:56 PM7/6/21
to django...@googlegroups.com
You can to something like this

def count_songs(request):
#get the field that you want to count the words in it
field_name = model._meta.get_field('your_field)
word_count =Counter(field_name)
for key, value in word_count.items():
      key = key
      value=value
context={
'key':key,
'value':value,
}

return render(request, 'template.html', context)


DJANGO DEVELOPER

unread,
Jul 6, 2021, 8:31:26 PM7/6/21
to Django users
so will it run smoothly?
I mean there is no filter function there so will it filter a specific field and will give me count for the words?

DJANGO DEVELOPER

unread,
Jul 9, 2021, 1:57:52 AM7/9/21
to Django users
sum it is giving me error of TextField is not iterable

DJANGO DEVELOPER

unread,
Jul 9, 2021, 3:41:21 AM7/9/21
to Django users
https://stackoverflow.com/questions/41689274/split-multiple-selections-into-separate-records-in-a-django-model

I also want the same result as it is mentioned here in the stackoverflow question

sum abiut

unread,
Jul 11, 2021, 5:44:37 PM7/11/21
to django...@googlegroups.com
I might not fully understand your question. Can you show me what you have done? show us your models and what you want to achieve.



DJANGO DEVELOPER

unread,
Jul 11, 2021, 6:40:21 PM7/11/21
to Django users
Sum thanks for your interest.
these are the screenshots of my requirements and of models.

DJANGO DEVELOPER

unread,
Jul 11, 2021, 6:40:46 PM7/11/21
to Django users
models1.PNG
models2.PNG
req.PNG

RaviKiran Kk

unread,
Jul 12, 2021, 11:23:38 AM7/12/21
to django...@googlegroups.com
We are looking for django developer
Plz contact 6309620745

--
Reply all
Reply to author
Forward
0 new messages