Skip to content

Commit

Permalink
Add flip step for the built-in sssom:superClassOf predicate during OW…
Browse files Browse the repository at this point in the history
…L conversion (#506)

Depends on

- [ ] #505 

This PR adds a preprocessing step to the to_owl_graph() method which
flips "sssom:superClassOf" edges. I should really document
sssom:superClassOf as syntactic sugar, but right now I dont have the
bandwidth. I am certain it will come up.

---------

Co-authored-by: Harshad <hrshdhgd@users.noreply.github.com>
  • Loading branch information
matentzn and hrshdhgd committed Mar 22, 2024
1 parent 5db5296 commit 828a743
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/sssom/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
URI_SSSOM_MAPPINGS,
MappingSetDataFrame,
get_file_extension,
invert_mappings,
sort_df_rows_columns,
)

Expand Down Expand Up @@ -150,6 +151,12 @@ def write_ontoportal_json(

def to_owl_graph(msdf: MappingSetDataFrame) -> Graph:
"""Convert a mapping set dataframe to OWL in an RDF graph."""
msdf.df = invert_mappings(
df=msdf.df,
merge_inverted=False,
update_justification=False,
predicate_invert_dictionary={"sssom:superClassOf": "rdfs:subClassOf"},
)
graph = to_rdf_graph(msdf=msdf)

for _s, _p, o in graph.triples((None, URIRef(URI_SSSOM_MAPPINGS), None)):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ def test_cob_to_owl(self):
size = len(results)
self.assertEqual(size, 60)

results = g.query(
"""SELECT DISTINCT ?e1 ?e2
WHERE {
?e1 <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?e2 .
}"""
)
size = len(results)
self.assertEqual(size, 22)

results = g.query(
"""SELECT DISTINCT ?e1 ?e2
WHERE {
?e1 <https://w3id.org/sssom/superClassOf> ?e2 .
}"""
)
size = len(results)
self.assertEqual(size, 0)

def test_to_rdf(self):
"""Test converting the basic example to a basic RDF graph."""
g = to_rdf_graph(self.msdf)
Expand Down

0 comments on commit 828a743

Please sign in to comment.