Operator Sketches #25
Replies: 4 comments 3 replies
-
Also, could templates, additionally, be expressed as @prefix aps: <http://www.w3.org/community/planning/> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://example.org/#template123>
rdf:type aps:OperatorTemplate ;
rdf:value [ rdf:type aps:Data ;
dc:format "application/trig" ;
dc:source [ rdf:type aps:Data ;
rdf:value "... php ..." ;
dc:format "text/php"
]
] ;
aps:templateParameters [ rdf:type aps:ParameterList ;
rdf:value ( [ rdf:type aps:Parameter ;
aps:name "T1"
]
[ rdf:type aps:Parameter ;
aps:name "T2"
]
) ;
aps:requires [ rdf:type aps:Data ;
rdf:value "function guard(world, t1, t2) { ... javascript ... }" ;
dc:format "text/javascript"
]
] . Such templates could also provide additional JavaScript: @prefix aps: <http://www.w3.org/community/planning/> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://example.org/#template123>
rdf:type aps:OperatorTemplate ;
rdf:value [ rdf:type aps:Data ;
dc:format "application/trig" ;
dc:source [ rdf:type aps:Data ;
rdf:value "... php ..." ;
dc:format "text/php"
]
] ;
aps:script [ rdf:type aps:Data ;
dc:format "text/javascript" ;
dc:source [ rdf:type aps:Data ;
rdf:value "... php ..." ;
dc:format "text/php"
]
] ;
aps:templateParameters [ rdf:type aps:ParameterList ;
rdf:value ( [ rdf:type aps:Parameter ;
aps:name "T1"
]
[ rdf:type aps:Parameter ;
aps:name "T2"
]
) ;
aps:requires [ rdf:type aps:Data ;
rdf:value "function guard(world, t1, t2) { ... javascript ... }" ;
dc:format "text/javascript"
]
] . |
Beta Was this translation helpful? Give feedback.
-
@AdamSobieski have you looked into using The Function Ontology to describe these operators? I don't think it would cover all your requirements (such as pre-conditions) but much of it seems covered. |
Beta Was this translation helpful? Give feedback.
-
@william-vw, thank you. I’m presently looking at the Function Ontology. I agree that it could be useful for these purposes; in particular, if we extend it. One conceptual matter involves guards on input parameters or design by contract expressiveness pertaining to both input and output parameters. The Function Ontology appears to resemble modern programming languages in that it allows type information on parameters and other per-parameter annotations. Beyond per-parameter information and annotations (e.g., those pertaining to optionality/requiredness or those pertaining to nullability), I’m thinking about guard logic where multiple parameters can be used simultaneously in expressions. I'm also thinking about implicit (e.g., global) or explicit first parameters for knowledgebases with which to explore other parameters. For example: function(kb, p1, p2)
{
if(kb.isa(p1, 'http://example.org/#type1') && kb.isa(p2, 'http://example.org/#type1') && kb.neq(p1, p2))
{
/* ... */
}
} Looking at Example 8 from the Function Ontology: ex:sumFunction
a fno:Function ;
fno:name "The sum function"^^xsd:string ;
dcterms:description "This function can do the sum of two integers."^^xsd:string ;
fno:solves ex:sumProblem ;
fno:implements ex:sumAlgorithm ;
fno:expects ( ex: intParameterA ex:intParameterB ) ;
fno:returns ( ex:sumOutput ) .
ex:intParameterA
a fno:Parameter ;
fno:predicate ex:startValue ;
fno:type xsd:integer ;
fno:required "true"^^xsd:boolean .
ex:intParameterB
a fno:Parameter ;
fno:predicate ex:sumValue ;
fno:type xsd:integer ;
fno:required "true"^^xsd:boolean .
ex:sumOutput
a fno:Output ;
fno:predicate ex:sumResult ;
fno:type xsd:integer ;
fno:required "true"^^xsd:boolean .
ex:sumProblem
a fno:Problem ;
fno:name "The sum problem"^^xsd:string ;
dcterms:description "This handles the problem of adding two integers to each other."^^xsd:string ;
skos:broader ex:mathProblem .
ex:sumAlgorithm
a fno:Algorithm ;
fno:name "The sum algorithm"^^xsd:string ;
dcterms:description "About how to add two integers to each other."^^xsd:string .
ex:sumExecution
a fno:Execution ;
fno:executes ex:sumFunction ;
ex:startValue "2"^^xsd:integer ;
ex:sumValue "4"^^xsd:integer . Resembling design by contract, we could extend the Function Ontology to be able to attach simple functions with provided, inspectable implementations to functions. This might resemble adding ex:sumFunction
a fno:Function ;
fno:name "The sum function"^^xsd:string ;
dcterms:description "This function can do the sum of two integers."^^xsd:string ;
fno:solves ex:sumProblem ;
fno:implements ex:sumAlgorithm ;
fno:expects ( ex: intParameterA ex:intParameterB ) ;
ext:guard ex:sumFunctionGuard ;
fno:returns ( ex:sumOutput ) . Or, it could be the case, from design by contract, that the matter is one of requirements on the input parameters, adding ex:sumFunction
a fno:Function ;
fno:name "The sum function"^^xsd:string ;
dcterms:description "This function can do the sum of two integers."^^xsd:string ;
fno:solves ex:sumProblem ;
fno:implements ex:sumAlgorithm ;
fno:expects ( ex: intParameterA ex:intParameterB ) ;
ext:requires ex:sumFunctionRequires ;
fno:returns ( ex:sumOutput ) . and we could, then, also add ex:sumFunction
a fno:Function ;
fno:name "The sum function"^^xsd:string ;
dcterms:description "This function can do the sum of two integers."^^xsd:string ;
fno:solves ex:sumProblem ;
fno:implements ex:sumAlgorithm ;
fno:expects ( ex: intParameterA ex:intParameterB ) ;
ext:requires ex:sumFunctionRequires ;
ext:ensures ex:sumFunctionEnsures ;
fno:returns ( ex:sumOutput ) . I agree that the Function Ontology could be useful, in particular if extended, e.g., to include guards and/or design by contract requires and ensures for input and output parameters respectively. What do you think about attaching to function definitions other, simple functions with inspectable implementations, the implementations of which describe input or output parameters beyond per-parameter information and annotations? |
Beta Was this translation helpful? Give feedback.
-
In addition to the applicability of FnO, some other topics for consideration include:
Here is a rough-draft sketch which explores FnO for a case where an abstract function, @prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix example: <http://example.org/#> .
@prefix fno: <http://w3id.org/function/ontology#> .
@prefix fnoc: <http://w3id.org/function/vocabulary/composition#> .
@prefix fnoi: <http://w3id.org/function/vocabulary/implementation#> .
@prefix fnom: <http://w3id.org/function/vocabulary/mapping#> .
@prefix plan: <http://www.w3.org/community/planning/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
example:foo rdf:type fno:Function ;
fno:expects ( example:foo_p1 example:foo_p2 ) ;
fno:returns ( example:foo_return ) .
example:foo_implementation
rdf:type fnoi:JavaScriptFunction , plan:Data ;
rdf:value "function foo(p1, p2) { ... javascript ... }" ;
dc:format "text/javascript" .
example:foo_mapping rdf:type fno:Mapping ;
fno:function example:foo ;
fno:implementation example:foo_implementation ;
fno:methodMapping [ rdf:type fnom:StringMethodMapping ;
fnom:method-name "foo"
] ;
fno:parameterMapping [ rdf:type fnom:PositionParameterMapping ;
fnom:functionParameter example:foo_p1 ;
fnom:implementationParameterPosition
"1"^^xsd:int
] ;
fno:parameterMapping [ rdf:type fnom:PositionParameterMapping ;
fnom:functionParameter example:foo_p2 ;
fnom:implementationParameterPosition
"2"^^xsd:int
] ;
fno:returnMapping [ rdf:type fnom:DefaultReturnMapping ;
fnom:functionOutput example:foo_return
] .
example:foo_p1 rdf:type fno:Parameter ;
fno:predicate example:foo_p1_predicate ;
fno:required true .
example:foo_p2 rdf:type fno:Parameter ;
fno:predicate example:foo_p2_predicate ;
fno:required true .
example:foo_return rdf:type fno:Output ;
fno:required true ;
fno:type xsd:boolean . |
Beta Was this translation helpful? Give feedback.
-
Transitioning from markup-language-based sketches (see: #21, #22) to ontology-based sketches, here is a Turtle/TriG sketch of a definition of an operator,
operator123
, with two generic template parameters,T1
andT2
and two parameters,p1
andp2
:For clarity, a related JavaScript example might resemble:
The above Turtle/TriG sketch intends to show:
T1
andT2
, have a guard in the form of a JavaScript function,guard
.p1
andp2
, have a guard in the form of a JavaScript function,guard
.aps:Data
resources andrdf:Alt
. Throughout this sketch, extensibleaps:Data
resources are utilized, even where RDF literals could be used instead, even when the format istext/plain
. In this way, algorithms for selecting, preprocessing, and loading content fromaps:Data
resource alternatives could be consistently reused during deserialization.dc:source
, to nestaps:Data
resources when data is to be preprocessed from other described data (see: Client-side Preprocessing #21). In these regards, it could be that the provenance ontology (PROV-O) could additionally, or instead, be of use.The above Turtle/TriG sketch doesn't yet include:
guard
, might have multiple knowledgebase parameters, parameters in addition toworld
, or arguments for that first parameter could be or hold an array of, a map of, or an object-based map of knowledgebases.guard
is the one to use from itsaps:Data
resource.onload
oroninterrupt
, which would reference functions in theaps:script
aps:Data
resource.duration
, which would reference functions in theaps:script
aps:Data
resource.aps:Data
resources, either in or preprocessed into a Semantic Web format, to be referenceable as named graphs from otheraps:Data
resources, either in or preprocessed into a Semantic Web format. Note: TriG (application/trig
) can express content in named graphs. A matter would then be cross-referencing named graphs acrossaps:Data
resources. If templated semantic contents are to be put into datasets together, then the URI’s for named graphs should somehow contain the template arguments (URL-encoded query string parameters and arguments?) so thatWidget<t1>
andWidget<t2>
could both be in a dataset.Any thoughts on these initial sketches? Is Turtle/TriG good to use for examples and sketches?
Beta Was this translation helpful? Give feedback.
All reactions