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
12540bba
Commit
12540bba
authored
2 years ago
by
Malo Revel
Browse files
Options
Downloads
Patches
Plain Diff
Fix scorer
parent
47b5a23f
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
scorer.py
+25
-13
25 additions, 13 deletions
scorer.py
with
25 additions
and
13 deletions
scorer.py
+
25
−
13
View file @
12540bba
...
@@ -24,9 +24,9 @@ class ODRL:
...
@@ -24,9 +24,9 @@ class ODRL:
graph
.
parse
(
odrl_fname
)
graph
.
parse
(
odrl_fname
)
odrl_ns
=
"
http://www.w3.org/ns/odrl/2/
"
odrl_ns
=
"
http://www.w3.org/ns/odrl/2/
"
ccrel_ns
=
"
http://creativecommons.org/ns#
"
ccrel_ns
=
"
http://creativecommons.org/ns#
"
perm_node
=
None
perm_node
s
=
[]
obl_node
=
None
obl_node
s
=
[]
proh_node
=
None
proh_node
s
=
[]
actions
=
{}
# action listing for every blank node
actions
=
{}
# action listing for every blank node
# List actions and modalities
# List actions and modalities
...
@@ -34,22 +34,22 @@ class ODRL:
...
@@ -34,22 +34,22 @@ class ODRL:
src
,
prop
,
tgt
=
str
(
src
),
str
(
prop
),
str
(
tgt
)
src
,
prop
,
tgt
=
str
(
src
),
str
(
prop
),
str
(
tgt
)
if
prop
==
odrl_ns
+
"
permission
"
:
if
prop
==
odrl_ns
+
"
permission
"
:
self
.
has_perm
=
True
self
.
has_perm
=
True
perm_node
=
tgt
perm_node
s
.
append
(
tgt
)
elif
prop
==
odrl_ns
+
"
obligation
"
:
elif
prop
==
odrl_ns
+
"
obligation
"
:
self
.
has_obl
=
True
self
.
has_obl
=
True
obl_node
=
tgt
obl_node
s
.
append
(
tgt
)
elif
prop
==
odrl_ns
+
"
prohibition
"
:
elif
prop
==
odrl_ns
+
"
prohibition
"
:
self
.
has_proh
=
True
self
.
has_proh
=
True
proh_node
=
tgt
proh_node
s
.
append
(
tgt
)
elif
prop
==
odrl_ns
+
"
action
"
:
elif
prop
==
odrl_ns
+
"
action
"
:
if
src
not
in
actions
:
actions
[
src
]
=
[]
if
src
not
in
actions
:
actions
[
src
]
=
[]
actions
[
src
].
append
(
tgt
)
actions
[
src
].
append
(
tgt
)
# Link modalities with actions
# Link modalities with actions
for
node
in
actions
:
for
node
in
actions
:
if
node
==
perm_node
:
mod
=
self
.
perm
if
node
in
perm_node
s
:
mod
=
self
.
perm
elif
node
==
obl_node
:
mod
=
self
.
obl
elif
node
in
obl_node
s
:
mod
=
self
.
obl
elif
node
==
proh_node
:
mod
=
self
.
proh
elif
node
in
proh_node
s
:
mod
=
self
.
proh
else
:
print
(
"
Warning: ill-formed ODRL
"
)
else
:
print
(
"
Warning: ill-formed ODRL
"
)
for
act
in
actions
[
node
]:
for
act
in
actions
[
node
]:
mod
.
append
(
act
)
mod
.
append
(
act
)
...
@@ -100,10 +100,18 @@ class Scores:
...
@@ -100,10 +100,18 @@ class Scores:
self
.
scores
[
crit
][
"
fn
"
]
+=
1
self
.
scores
[
crit
][
"
fn
"
]
+=
1
def
get_precision
(
self
,
crit
):
def
get_precision
(
self
,
crit
):
return
self
.
scores
[
crit
][
"
tp
"
]
/
(
self
.
scores
[
crit
][
"
tp
"
]
+
self
.
scores
[
crit
][
"
fp
"
])
tp
=
self
.
scores
[
crit
][
"
tp
"
]
fp
=
self
.
scores
[
crit
][
"
fp
"
]
if
tp
+
fp
!=
0
:
return
tp
/
(
tp
+
fp
)
else
:
return
None
def
get_recall
(
self
,
crit
):
def
get_recall
(
self
,
crit
):
return
self
.
scores
[
crit
][
"
tp
"
]
/
(
self
.
scores
[
crit
][
"
tp
"
]
+
self
.
scores
[
crit
][
"
fn
"
])
tp
=
self
.
scores
[
crit
][
"
tp
"
]
fn
=
self
.
scores
[
crit
][
"
fn
"
]
if
tp
+
fn
!=
0
:
return
tp
/
(
tp
+
fn
)
else
:
return
None
def
get_total_precision
(
self
):
def
get_total_precision
(
self
):
tot_tp
=
0
tot_tp
=
0
...
@@ -111,7 +119,9 @@ class Scores:
...
@@ -111,7 +119,9 @@ class Scores:
for
crit
in
self
.
scores
:
for
crit
in
self
.
scores
:
tot_tp
+=
self
.
scores
[
crit
][
"
tp
"
]
tot_tp
+=
self
.
scores
[
crit
][
"
tp
"
]
tot_fp
+=
self
.
scores
[
crit
][
"
fp
"
]
tot_fp
+=
self
.
scores
[
crit
][
"
fp
"
]
if
tot_tp
+
tot_fp
!=
0
:
return
tot_tp
/
(
tot_tp
+
tot_fp
)
return
tot_tp
/
(
tot_tp
+
tot_fp
)
else
:
return
None
def
get_total_recall
(
self
):
def
get_total_recall
(
self
):
tot_tp
=
0
tot_tp
=
0
...
@@ -119,7 +129,9 @@ class Scores:
...
@@ -119,7 +129,9 @@ class Scores:
for
crit
in
self
.
scores
:
for
crit
in
self
.
scores
:
tot_tp
+=
self
.
scores
[
crit
][
"
tp
"
]
tot_tp
+=
self
.
scores
[
crit
][
"
tp
"
]
tot_fn
+=
self
.
scores
[
crit
][
"
fn
"
]
tot_fn
+=
self
.
scores
[
crit
][
"
fn
"
]
if
tot_tp
+
tot_fn
!=
0
:
return
tot_tp
/
(
tot_tp
+
tot_fn
)
return
tot_tp
/
(
tot_tp
+
tot_fn
)
else
:
return
None
def
__str__
(
self
):
def
__str__
(
self
):
s
=
""
s
=
""
...
...
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