Skip to content

Commit

Permalink
test(py-rules): add rectangle test
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleycaselli committed May 28, 2024
1 parent 39f05c3 commit d962cee
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/test/resources/py/tests/rules/rectangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ns = "http://datashapes.org/py/tests/rules/rectangle.test#"


def compute_area(_this):
width = get_property(_this, "width")
height = get_property(_this, "height")
area = py_tf.literal(int(width.getLex()) * int(height.getLex()), width.getDatatype())
area_property = py_tf.namedNode(ns + "area")
return [ [_this, area_property, area] ]


def get_property(_this, name):
it = _data.find(_this, py_tf.namedNode(ns + name), None)
result = it.next().getObject()
it.close()
return result
45 changes: 45 additions & 0 deletions src/test/resources/py/tests/rules/rectangle.test.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# baseURI: http://datashapes.org/py/tests/rules/rectangle.test
# imports: http://datashapes.org/dash
# prefix: ex

@prefix dash: <http://datashapes.org/dash#> .
@prefix ex: <http://datashapes.org/py/tests/rules/rectangle.test#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://datashapes.org/py/tests/rules/rectangle.test>
rdf:type owl:Ontology ;
rdfs:label "Test of rectangle" ;
owl:imports <http://datashapes.org/dash> ;
.
ex:ExampleRectangle
rdf:type ex:Rectangle ;
ex:height 8 ;
ex:width 7 ;
.
ex:InferencingTestCase
rdf:type dash:InferencingTestCase ;
dash:expectedResult [
rdf:object 56 ;
rdf:predicate ex:area ;
rdf:subject ex:ExampleRectangle ;
] ;
.
ex:Rectangle
rdf:type rdfs:Class ;
rdfs:subClassOf rdfs:Resource ;
.
ex:RectangleShape
rdf:type sh:NodeShape ;
sh:rule [
rdf:type sh:PyRule ;
sh:pyFunctionName "compute_area" ;
sh:pyLibrary [
sh:pyLibraryURL "http://datashapes.org/py/tests/rules/rectangle.py"^^xsd:anyURI ;
] ;
] ;
sh:targetClass ex:Rectangle ;
.

0 comments on commit d962cee

Please sign in to comment.