Skip to content
Snippets Groups Projects
Commit 12540bba authored by Malo Revel's avatar Malo Revel
Browse files

Fix scorer

parent 47b5a23f
Branches
No related tags found
No related merge requests found
...@@ -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_nodes = []
obl_node = None obl_nodes = []
proh_node = None proh_nodes = []
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_nodes.append(tgt)
elif prop == odrl_ns + "obligation": elif prop == odrl_ns + "obligation":
self.has_obl = True self.has_obl = True
obl_node = tgt obl_nodes.append(tgt)
elif prop == odrl_ns + "prohibition": elif prop == odrl_ns + "prohibition":
self.has_proh = True self.has_proh = True
proh_node = tgt proh_nodes.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_nodes: mod = self.perm
elif node == obl_node: mod = self.obl elif node in obl_nodes: mod = self.obl
elif node == proh_node: mod = self.proh elif node in proh_nodes: 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 = ""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment