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

Add F-measure

parent 262e2c94
No related branches found
No related tags found
No related merge requests found
...@@ -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'\tTP = {self.scores[crit]["tp"]}, FP = {self.scores[crit]["fp"]}, FN = {self.scores[crit]["fn"]}\n' s += f'\tTP = {self.scores[crit]["tp"]}, FP = {self.scores[crit]["fp"]}, FN = {self.scores[crit]["fn"]}\n'
s += f'\tPrecision = {self.get_precision(crit)}, Recall = {self.get_recall(crit)}\n' s += f'\tPrecision = {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]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment