Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
BabelZoo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PLN
BabelZoo
Commits
5a4f5208
Unverified
Commit
5a4f5208
authored
Nov 24, 2019
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(parles): stats words/lines, clean input
parent
c36b9f70
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
7 deletions
+43
-7
parles.py
CommentTuParles/parles.py
+43
-7
No files found.
CommentTuParles/parles.py
View file @
5a4f5208
...
...
@@ -3,11 +3,34 @@ import os
from
collections
import
defaultdict
def
are_invalid
(
lyrics
:
str
):
placeholders
=
[
"Please check back once the song has been released"
,
"Lyrics for this song have yet"
,
"Tell us that you would like to have the lyrics of this song"
]
for
placeholder
in
placeholders
:
if
lyrics
.
find
(
placeholder
)
!=
-
1
:
return
True
return
False
def
cleanup
(
lyrics
):
lines
=
lyrics
.
split
(
"
\n
"
)
filtered
=
[
l
for
l
in
lines
if
l
is
not
None
and
len
(
l
)
and
l
[
0
]
not
in
[
"#"
,
"["
]
and
"Paroles de la chanson"
not
in
l
and
"Paroles de Même"
not
in
l
]
return
"
\n
"
.
join
(
filtered
)
def
analyse
():
path
=
"../data/"
files
=
os
.
listdir
(
path
)
stats
=
{
"avg_length"
:
defaultdict
(
lambda
:
0
),
"avg_lines"
:
defaultdict
(
lambda
:
0
),
"avg_newlines"
:
defaultdict
(
lambda
:
0
),
"missing"
:
defaultdict
(
lambda
:
0
)
}
...
...
@@ -20,16 +43,29 @@ def analyse():
print
(
"
\n
##
%
s ##"
%
artist
)
for
song
in
songs
:
title
=
song
[
"title"
]
#
title = song["title"]
if
song
[
"lyrics"
]
is
not
None
:
lyrics
=
song
[
"lyrics"
]
stats
[
"avg_length"
][
artist
]
+=
len
(
lyrics
)
lyrics
:
str
=
song
[
"lyrics"
]
if
are_invalid
(
lyrics
):
stats
[
"missing"
][
artist
]
+=
1
else
:
lyrics
=
cleanup
(
lyrics
)
stats
[
"avg_lines"
][
artist
]
+=
len
(
lyrics
)
stats
[
"avg_newlines"
][
artist
]
+=
lyrics
.
count
(
"
\n
"
)
else
:
stats
[
"missing"
][
artist
]
+=
1
stats
[
"avg_length"
][
artist
]
/=
len
(
songs
)
print
(
"
%
s: Average song is
%
i long (
%
i missing)."
%
(
artist
,
stats
[
"avg_length"
][
artist
],
stats
[
"missing"
][
artist
]))
final_missing
=
stats
[
"missing"
][
artist
]
final_songs
=
len
(
songs
)
-
final_missing
stats
[
"avg_lines"
][
artist
]
/=
final_songs
stats
[
"avg_newlines"
][
artist
]
/=
final_songs
print
(
"
%
s:
%
i songs, on average
%
i/
%
i long (
%
i missing)."
%
(
artist
,
final_songs
,
stats
[
"avg_lines"
][
artist
],
stats
[
"avg_newlines"
][
artist
],
final_missing
))
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment