Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
odrlScorer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tetras MARS
odrlScorer
Commits
d90bb4a4
Commit
d90bb4a4
authored
2 years ago
by
Malo Revel
Browse files
Options
Downloads
Patches
Plain Diff
Add stats script
parent
05c9704c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
stats.py
+91
-0
91 additions, 0 deletions
stats.py
with
91 additions
and
0 deletions
stats.py
0 → 100644
+
91
−
0
View file @
d90bb4a4
# Computes some stats about a corpus
import
sys
import
os
def
check_and_incr
(
text
,
token
,
dic
):
if
token
in
text
:
if
token
not
in
dic
:
dic
[
token
]
=
0
dic
[
token
]
+=
1
class
Stats
:
"""
Computes statistics about a corpus, such as the number of modalities and the number of actions
"""
modalities
=
[
"
odrl:permission
"
,
"
odrl:obligation
"
,
"
odrl:prohibition
"
]
actions
=
[
"
cc:Distribution
"
,
"
odrl:play
"
,
"
odrl:run
"
,
"
cc:Reproduction
"
,
"
odrl:use
"
,
"
odrl:display
"
,
"
odrl:copy
"
,
"
odrl:sell
"
,
"
odrl:modify
"
,
"
odrl:derive
"
]
def
__init__
(
self
):
self
.
nb_mods
=
{}
self
.
nb_actions
=
{}
self
.
nb_ands
=
0
self
.
nb_nots
=
0
def
count_modalities
(
self
,
text
):
for
mod
in
self
.
modalities
:
check_and_incr
(
text
,
mod
,
self
.
nb_mods
)
def
count_actions
(
self
,
text
):
for
act
in
self
.
actions
:
check_and_incr
(
text
,
act
,
self
.
nb_actions
)
def
count_and
(
self
,
text
):
count_and
=
{
"
and
"
:
0
}
check_and_incr
(
text
,
"
and
"
,
count_and
)
self
.
nb_ands
+=
count_and
[
"
and
"
]
def
count_not
(
self
,
text
):
count_not
=
{
"
not
"
:
0
,
"
cannot
"
:
0
}
check_and_incr
(
text
,
"
not
"
,
count_not
)
check_and_incr
(
text
,
"
cannot
"
,
count_not
)
self
.
nb_nots
+=
max
(
count_not
[
"
not
"
],
count_not
[
"
cannot
"
])
def
__str__
(
self
):
s
=
"
Number of modalities:
\n
"
for
uri
in
self
.
nb_mods
:
s
+=
f
"
\t
{
uri
}
:
{
self
.
nb_mods
[
uri
]
}
\n
"
s
+=
"
Number of actions:
\n
"
for
uri
in
self
.
nb_actions
:
s
+=
f
"
\t
{
uri
}
:
{
self
.
nb_actions
[
uri
]
}
\n
"
s
+=
f
"
Number of and:
{
self
.
nb_ands
}
\n
Number of not:
{
self
.
nb_nots
}
\n
"
return
s
def
main_stats
(
path_sentences
,
path_odrl
):
stats
=
Stats
()
for
fname
in
os
.
listdir
(
path_odrl
):
if
fname
.
endswith
(
"
.ttl
"
):
with
open
(
path_odrl
+
fname
,
"
r
"
)
as
fodrl
:
odrl_text
=
fodrl
.
read
()
stats
.
count_modalities
(
odrl_text
)
stats
.
count_actions
(
odrl_text
)
for
fname
in
os
.
listdir
(
path_sentences
):
if
fname
.
endswith
(
"
.txt
"
):
with
open
(
path_sentences
+
fname
,
"
r
"
)
as
ftext
:
sent_text
=
ftext
.
read
()
stats
.
count_and
(
sent_text
)
stats
.
count_not
(
sent_text
)
return
stats
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
<
3
:
print
(
f
"
Usage: python3
{
sys
.
argv
[
0
]
}
<path_corpus_sentences> <path_corpus_odrl>
"
)
exit
(
1
)
path_sentences
=
sys
.
argv
[
1
]
path_odrl
=
sys
.
argv
[
2
]
stats
=
main_stats
(
path_sentences
,
path_odrl
)
print
(
stats
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment