Templates, Generics, and Polymorphism in Semantic Web Languages #27
Replies: 6 comments
-
Building on the concepts of client-side preprocessing, the techniques, above, enable named graphs templates which can produce concrete named graph instances for valid sequences of provided arguments. Let us consider that named graph templates, e.g., The named graph template Envisioned is that developers will be able to construct N3-based named graph templates and then add them to datasets so that these could, for each sequence of arguments provided, produce a concrete named graph instance. Some sketches and syntactical possibilities: @prefix list: <http://www.w3.org/2000/10/swap/list#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix ex: <http://example.org/#> .
@prefix graph: <http://www.w3.org/2000/10/swap/graph#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
ex:ng??(?x ?y) :graph
{
?x rdf:type foaf:Person .
?y rdf:type foaf:Person .
?x foaf:knows ?y .
?y foaf:knows ?x .
} .
### example usage of template
{
ex:ng??(ex:alice ex:bob) :graph ?graph .
?graph graph:member ?stmt .
?stmt log:equalTo { ?s ?p ?o } .
}
=>
{
?s ?p ?o .
} . We can also consider adding a named graph parameter, @prefix list: <http://www.w3.org/2000/10/swap/list#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix ex: <http://example.org/#> .
@prefix graph: <http://www.w3.org/2000/10/swap/graph#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
ex:ng??(?kb ?x ?y) :graph
{
@requires ?kb holds { ?x rdf:type foaf:Person } .
@requires ?kb holds { ?y rdf:type foaf:Person } .
@requires ?kb holds { ?x owl:differentFrom ?y } .
?x foaf:knows ?y .
?y foaf:knows ?x .
} .
### example usage of template
{
ex:ng??(:this ex:alice ex:bob) :graph ?graph .
?graph graph:member ?stmt .
?stmt log:equalTo { ?s ?p ?o } .
}
=>
{
?s ?p ?o .
} . The three @prefix list: <http://www.w3.org/2000/10/swap/list#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix ex: <http://example.org/#> .
@prefix graph: <http://www.w3.org/2000/10/swap/graph#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
ex:ng??(?kb ?x ?y) :graph
{
@requires ?kb holds
{
?x rdf:type foaf:Person .
?y rdf:type foaf:Person .
?x owl:differentFrom ?y .
} .
?x foaf:knows ?y .
?y foaf:knows ?x .
} .
### example usage of template
{
ex:ng??(:this ex:alice ex:bob) :graph ?graph .
?graph graph:member ?stmt .
?stmt log:equalTo { ?s ?p ?o } .
}
=>
{
?s ?p ?o .
} . If the |
Beta Was this translation helpful? Give feedback.
-
Brainstorming towards being able to express @prefix list: <http://www.w3.org/2000/10/swap/list#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix ex: <http://example.org/#> .
@prefix graph: <http://www.w3.org/2000/10/swap/graph#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
ex:ng??(?kb ?x ?y) :graph
{
@if ?kb holds
{
?x rdf:type foaf:Person .
?y rdf:type foaf:Person .
?x owl:differentFrom ?y .
}
@then
{
?x foaf:knows ?y .
?y foaf:knows ?x .
}
@else { }
} . the above example intends to express a semantic template which conditionally provides one of two graphs depending on whether a provided graph, Interestingly, with negation for @prefix list: <http://www.w3.org/2000/10/swap/list#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix ex: <http://example.org/#> .
@prefix graph: <http://www.w3.org/2000/10/swap/graph#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
ex:ng1??(?kb ?x ?y) :graph
{
@requires ?kb holds
{
### the condition
?x rdf:type foaf:Person .
?y rdf:type foaf:Person .
?x owl:differentFrom ?y .
} .
### the "then" content
?x foaf:knows ?y .
?y foaf:knows ?x .
} .
ex:ng2??(?kb ?x ?y) :graph
{
@requires ?kb not holds
{
### the condition
?x rdf:type foaf:Person .
?y rdf:type foaf:Person .
?x owl:differentFrom ?y .
} .
### the "else" content (in this case none)
} .
ex:ng3??(?kb ?x ?y) :graph
{
@union
{
ex:ng1??(?kb ?x ?y) .
ex:ng2??(?kb ?x ?y) .
}
} . |
Beta Was this translation helpful? Give feedback.
-
With Templates, generics, and polymorphism are tools with which to enhance languages' expressiveness, convenience, and readability. These language features could equip developers and enhance the development of planning domains, types, operators, predicates, expressions, graphs, constraints, preferences, and so forth. Here is an example sketch of a generic operator,
The preconditions, effects, and implementations of operators, e.g., In addition to using template variables in operators' preconditions, effects, and implementations, resultant operators could be varied more significantly per semantic template processing. That is, the semantic graphs representing operators could be varied based on the processing of template arguments, e.g., Here's a rough-draft sketch in JavaScript to show the concepts: var move = domain.get('move');
if (move.validateTemplateArguments(kb, T))
{
var move_operator = move.createOperator(kb, T);
if (move_operator.preconditionsMet(world, robby, room_1, room_2))
{
var move_action = move_operator.createAction(world, robby, room_1, room_2);
move_action.invoke(world);
}
} In this example, |
Beta Was this translation helpful? Give feedback.
-
In addition to uses of the proposed Utilizing the To stir the imagination, let us consider a computer lexicon scenario involving verbs and sets of thematic relations: @prefix vn : <https://www.verbnet.org/index.php#> .
@prefix ex : <http://example.org/#> .
vn:frame??(("verb" ex:ate) ("agent" ex:bob) ("patient" ex:cheese)) rdf:type vn:VerbNetFrame ;
vn:verb ex:ate ;
vn:agent ex:bob ;
vn:patient ex:cheese . where the subject of that example's graph's triples maps with a URI:
This example URI could also be a URL which, perhaps, provides a Semantic Web resource. Interestingly, we can consider an N3 language feature for fetching or retrieving language-integrated named graphs from URLs. That is, there could be a language-integrated feature, which perhaps resembles invoking a special template, for fetching or retrieving Semantic Web content from URLs and then using the resultant content as first-class named graphs in the language. This "special template invocation" for fetching Semantic Web content from URLs could resemble: special:fetch??( vn:frame??(("verb" ex:ate) ("agent" ex:bob) ("patient" ex:cheese)) ) . |
Beta Was this translation helpful? Give feedback.
-
Per some recent discussions in the Semantic Web Interest Group mailing list (see: here), also possible are the following new syntactic options, utilizing the ex:alice ex:says $"Hello {?world}" . $<http://www.verbnet.org/index.php?verb={?x}&agent={?y}&patient={?z}#frame> rdf:type vn:VerbNetFrame ;
vn:verb ?x ;
vn:agent ?y ;
vn:patient ?z . Also, the running example of @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix ex: <http://example.org/#> .
[] rdf:type $<http://example.org/?T[]={ex:Foo}&T[]={ex:Foo2}&T[]={ex:Foo3}#Widget> . And, using this new syntax option and putting together some pieces, an N3 semantic template definition could resemble: @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix vn : <https://www.verbnet.org/> .
@define ex:template (?kb ?x)
{
@if ?kb holds
{
?x rdf:type vn:Verb .
}
@then
{
@dereference $<https://www.verbnet.org/index.php?verb={?x}#frame> .
}
@else { }
} This example semantic template guards an input parameter, Also possible is using a @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix vn : <https://www.verbnet.org/> .
@define ex:template (?x)
{
@if :world holds
{
?x rdf:type vn:Verb .
}
@then
{
@dereference $<https://www.verbnet.org/index.php?verb={?x}#frame> .
}
@else { }
} |
Beta Was this translation helpful? Give feedback.
-
From a recent email that I wrote to Semantic Web Interest Group mailing list (see: here), here are some use cases for the syntax under discussion: Use Case 1: Templates, Generic Types and PolymorphismFor this interesting use case, we can move the URI pattern to the subject position of a triple in a graph defining an OWL class. @define ex:generateWidget (?n)
{
ex:Widget??(?n) rdf:type owl:Class .
...
} or, if more readable: @define ex:generateWidget (?n)
{
$<http://example.org/?T[]={?n}#Widget> rdf:type owl:Class .
...
} So, for example, for integers, Then, elsewhere, we could create instances of that templated, generic type. ex:somewidget rdf:type ex:Widget??(4) . So, for an example of what a template would produce, the {
ex:Widget??(4) rdf:type owl:Class .
...
} or, if more readable: {
<http://example.org/?T[]=4#Widget> rdf:type owl:Class .
...
} There could be, for example, four Widget types, one for each integer 1 through 4. The feature of semantic templates allows for four generic classes to be defined simply and conveniently in one place, a template. A fuller example could show the resultant graph more significantly varying per the template arguments provided; a cardinality restriction with the OWL class could, for example, differ for each of the four classes using the variable Use Case 2: Parametric URI for DereferencingIn this use case, a @define ex:downloadVerbFrame (?verb)
{
@dereference vn:??(("verb" ?verb)) .
} or, if more readable: @define ex:downloadVerbFrame (?verb)
{
@dereference $<https://www.verbnet.org/index.php?verb={?verb}> .
} This template, when expanded or invoked, returns a graph which, in this case, is one downloaded from a templated URI. With templates and parameters, developers could more conveniently utilize client-side processing, per semantic templates, and server-side processing, per PHP scripts. Use Case 3: Describing Resources which Utilize the URI Query String in a Patterned MannerA templated URI could be such that variables in the URI have semantic meaning, these variables could be book ISSN's, or, in the following example, some event-related data structure parameters: ex2:??(("location" ?loc) ("from" ?f) ("to" ?t)) rdf:type ex:Event ;
ex:location ?loc ;
ex:fromTime ?f ;
ex:untilTime ?t . or, if more readable: $<http://www.example2.org/index.php?location={?loc}&from={?f}&to={?t}> rdf:type ex:Event ;
ex:location ?loc ;
ex:fromTime ?f ;
ex:untilTime ?t . So, one can express that, for every URI like a specified pattern, a resource of or at each URI can be described in a certain way. Use Case 4: String Templates for RDF LiteralsFor this use case, we can see how template parameters could be utilized in string templates for RDF literals. ex:alice ex:says $"Hello {?world}" . |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I recently had an idea pertaining to templates, generics, and polymorphism in Semantic Web languages. Such functionality would be useful for planning domain definition languages and ontologies and for other scenarios such as machine lexicons.
In C# or Java, generic types resemble
Widget<T1, T2, T3>
. Semantic Web generic types might, conceptually, resemble:ex:Widget<ex:Foo, ex:Foo2, ex:Foo3>
. The<>
brackets are utilized for other purposes in Semantic Web languages so some brainstorming was required.For Semantic Web languages, templates and generics could utilize the following syntax:
Utilizing the
prefix:localpart
syntax, this extended syntax also maps with URIs or URLs. It utilizes the query string portion.The syntax in the example, above,
ex:Widget??(ex:Foo ex:Foo2 ex:Foo3)
, would map with a URI or URL resembling:Also, the following example:
shows the syntax
ex:Widget??(("p1" ex:Foo) ("p2" ex:Foo2) ("p3" ex:Foo3))
which would map with a URI or URL utilizing, instead ofT[]
, named query string parameters, e.g,.p1
,p2
, andp3
:Beyond being constrained to URIs for types or classes, template arguments could be other URIs, e.g., those representing individuals, and other built-in datatypes such as strings or numerical datatypes.
Interestingly, this syntax would be utilizable with client-side and server-side processing, e.g., PHP, where output contents could vary depending on the query string arguments. A client-side preprocessor component or a server-side PHP script could vary output content, e.g., content of type
application/trig
, utilizing a provided knowledgebase (e.g., a graph or SPARQL endpoint) and the provided template arguments.What do you think of these ideas and syntax?
Update: I switched the syntax sketch from
^^
to??
to avoid confusion with the^^
syntax for indicating the datatypes of RDF literals and in hopes that the??
syntax reminds developers of URIs' query strings.Beta Was this translation helpful? Give feedback.
All reactions