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
65840e35
Commit
65840e35
authored
2 years ago
by
Malo Revel
Browse files
Options
Downloads
Patches
Plain Diff
Add F-measure
parent
262e2c94
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scorer.py
+14
-5
14 additions, 5 deletions
scorer.py
with
14 additions
and
5 deletions
scorer.py
+
14
−
5
View file @
65840e35
...
@@ -8,6 +8,10 @@ import os
...
@@ -8,6 +8,10 @@ import os
import
sys
import
sys
from
rdflib
import
Graph
from
rdflib
import
Graph
def
f_measure
(
precision
,
recall
):
if
precision
==
0
or
recall
==
0
:
return
None
else
:
return
2
/
(
1
/
precision
+
1
/
recall
)
class
ODRL
:
class
ODRL
:
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -136,11 +140,16 @@ class Scores:
...
@@ -136,11 +140,16 @@ class Scores:
def
__str__
(
self
):
def
__str__
(
self
):
s
=
""
s
=
""
for
crit
in
self
.
scores
:
for
crit
in
self
.
scores
:
precision
=
self
.
get_precision
(
crit
)
recall
=
self
.
get_recall
(
crit
)
s
+=
f
"
{
crit
}
:
\n
"
s
+=
f
"
{
crit
}
:
\n
"
s
+=
f
'
\t
TP =
{
self
.
scores
[
crit
][
"
tp
"
]
}
, FP =
{
self
.
scores
[
crit
][
"
fp
"
]
}
, FN =
{
self
.
scores
[
crit
][
"
fn
"
]
}
\n
'
s
+=
f
'
\t
TP =
{
self
.
scores
[
crit
][
"
tp
"
]
}
, FP =
{
self
.
scores
[
crit
][
"
fp
"
]
}
, FN =
{
self
.
scores
[
crit
][
"
fn
"
]
}
\n
'
s
+=
f
'
\t
Precision =
{
self
.
get_precision
(
crit
)
}
, Recall =
{
self
.
get_recall
(
crit
)
}
\n
'
s
+=
f
'
\t
Precision =
{
precision
}
, Recall =
{
recall
}
, F-measure =
{
f_measure
(
precision
,
recall
)
}
\n
'
s
+=
f
'
Total precision =
{
self
.
get_total_precision
()
}
\n
'
precision
=
self
.
get_total_precision
()
s
+=
f
'
Total recall =
{
self
.
get_total_recall
()
}
\n
'
recall
=
self
.
get_total_recall
()
s
+=
f
'
Total precision =
{
precision
}
\n
'
s
+=
f
'
Total recall =
{
recall
}
\n
'
s
+=
f
'
Total F-measure =
{
f_measure
(
precision
,
recall
)
}
\n
'
return
s
return
s
...
@@ -177,7 +186,7 @@ def main_scorer(path_target, path_output):
...
@@ -177,7 +186,7 @@ def main_scorer(path_target, path_output):
for
fname
in
os
.
listdir
(
path_target
):
for
fname
in
os
.
listdir
(
path_target
):
if
fname
.
endswith
(
"
.ttl
"
):
if
fname
.
endswith
(
"
.ttl
"
):
print
(
fname
)
odrl_target
=
ODRL
()
odrl_target
=
ODRL
()
odrl_target
.
parse
(
path_target
+
fname
)
odrl_target
.
parse
(
path_target
+
fname
)
odrl_output
=
ODRL
()
odrl_output
=
ODRL
()
...
@@ -194,7 +203,7 @@ def main_scorer(path_target, path_output):
...
@@ -194,7 +203,7 @@ def main_scorer(path_target, path_output):
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
<
3
:
if
len
(
sys
.
argv
)
<
3
:
print
(
f
"
Usage: python3
{
sys
.
argv
[
0
]
}
<path_corpus_odrl> <path_output_odrl
"
)
print
(
f
"
Usage: python3
{
sys
.
argv
[
0
]
}
<path_corpus_odrl> <path_output_odrl
>
"
)
exit
(
1
)
exit
(
1
)
path_target
=
sys
.
argv
[
1
]
path_target
=
sys
.
argv
[
1
]
...
...
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