# baseURI: http://qudt.org/2.1/schema/extensions/functions
# imports: http://spinrdf.org/spl
# prefix: functions

@prefix arg: <http://spinrdf.org/arg#> .
@prefix functions: <http://qudt.org/2.1/schema/extensions/functions#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix qudt: <http://qudt.org/schema/qudt/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix sp: <http://spinrdf.org/sp#> .
@prefix spin: <http://spinrdf.org/spin#> .
@prefix spl: <http://spinrdf.org/spl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://qudt.org/2.1/schema/extensions/functions>
  a owl:Ontology ;
  owl:imports <http://spinrdf.org/spl> ;
  owl:versionInfo "Created with TopBraid Composer" ;
.
qudt:inferredApplicableUnit
  a spin:MagicProperty ;
  spin:body [
      a sp:Select ;
      sp:distinct true ;
      sp:resultVariables (
          [
            sp:varName "unit" ;
          ]
        ) ;
      sp:where (
          [
            a sp:Union ;
            sp:elements (
                (
                  [
                    sp:object spin:_arg1 ;
                    sp:predicate qudt:hasQuantityKind ;
                    sp:subject [
                        sp:varName "unit" ;
                      ] ;
                  ]
                  [
                    sp:object qudt:Unit ;
                    sp:predicate rdf:type ;
                    sp:subject [
                        sp:varName "unit" ;
                      ] ;
                  ]
                )
                (
                  [
                    a sp:NotExists ;
                    sp:elements (
                        [
                          sp:object spin:_arg1 ;
                          sp:predicate qudt:hasQuantityKind ;
                          sp:subject [
                              sp:varName "unit" ;
                            ] ;
                        ]
                        [
                          sp:object qudt:Unit ;
                          sp:predicate rdf:type ;
                          sp:subject [
                              sp:varName "unit" ;
                            ] ;
                        ]
                      ) ;
                  ]
                  [
                    sp:object [
                        sp:varName "parent1" ;
                      ] ;
                    sp:predicate skos:broader ;
                    sp:subject spin:_arg1 ;
                  ]
                  [
                    sp:object [
                        sp:varName "unit" ;
                      ] ;
                    sp:predicate qudt:inferredApplicableUnit ;
                    sp:subject [
                        sp:varName "parent1" ;
                      ] ;
                  ]
                )
              ) ;
          ]
        ) ;
    ] ;
  spin:constraint [
      a spl:Argument ;
      spl:predicate sp:arg1 ;
      spl:valueType qudt:QuantityKind ;
      rdfs:comment "The QuantityKind instance" ;
    ] ;
  spin:returnType rdfs:Class ;
  rdfs:comment """A magic property that returns all units that are \"applicable\" to a given QuantityKind, found by examining the incoming qudt:hasQuantityKind property for the provided QuantityKind. If there are none found, recurse up the skos:broader relation until such a QuantityKind is found.

Example use:
quantitykind:Power qudt:inferredApplicableUnit ?unit . """ ;
  rdfs:label "applicable units for a QuantityKind instance" ;
  rdfs:subClassOf spin:MagicProperties ;
.
