Skip to content

Commit

Permalink
Merge pull request #85 from dice-group/improve-confusion-matrix
Browse files Browse the repository at this point in the history
Confusion matrix query improvements
  • Loading branch information
Demirrr authored Oct 17, 2024
2 parents 49f41b9 + bf36d30 commit c4e42f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions owlapy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,13 @@ def as_confusion_matrix_query(self,
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT * WHERE {{
{{
SELECT (xsd:double(COUNT(DISTINCT {root_variable})) as ?tp) (xsd:double(({number_of_positive_examples} - COUNT(DISTINCT {root_variable}))) as ?fn) WHERE {{
SELECT (COUNT(DISTINCT {root_variable}) as ?tp) (({number_of_positive_examples} - COUNT(DISTINCT {root_variable})) as ?fn) WHERE {{
VALUES {root_variable} {{ {positive_examples_as_str} }}
{graph_pattern_str}
}}
}}
{{
SELECT DISTINCT (xsd:double(COUNT(DISTINCT {root_variable})) as ?fp) (xsd:double(({number_of_negative_examples} - COUNT(DISTINCT {root_variable}))) as ?tn) WHERE {{
SELECT (COUNT(DISTINCT {root_variable}) as ?fp) (({number_of_negative_examples} - COUNT(DISTINCT {root_variable})) as ?tn) WHERE {{
VALUES {root_variable} {{ {negative_examples_as_str} }}
{graph_pattern_str}
}}
Expand Down
9 changes: 5 additions & 4 deletions tests/test_owlapy_owl2sparql_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,11 @@ def test_ConfusionMatrixQuery(self):
named_individuals=True)

sparql_results = family_rdf_graph.query(query_with_confusion_matrix)
self.assertEqual(float(sparql_results.bindings[0]["tp"]), 2.0)
self.assertEqual(float(sparql_results.bindings[0]["fn"]), 0.0)
self.assertEqual(float(sparql_results.bindings[0]["fp"]), 1.0)
self.assertEqual(float(sparql_results.bindings[0]["tn"]), 1.0)
print(str(sparql_results.bindings))
self.assertEqual(int(sparql_results.bindings[0]["tp"]), 2)
self.assertEqual(int(sparql_results.bindings[0]["fn"]), 0)
self.assertEqual(int(sparql_results.bindings[0]["fp"]), 1)
self.assertEqual(int(sparql_results.bindings[0]["tn"]), 1)

if __name__ == '__main__':
unittest.main()

0 comments on commit c4e42f3

Please sign in to comment.