Please see below

> On Feb 12, 2021, at 12:38 PM, Dan Segal <dan.segal.w...@gmail.com> wrote:
> 
> Is it possible to dynamically create a new instance based on a query result?

Yes, as long as SPARQL Update is turned on for your server. Go to the Server 
Configuration page in the Admin Console to make sure it is on. By default, it 
is off.

You can also create new instances using GraphQL. See 
https://www.topquadrant.com/querying-topbraid-edg-with-graphql/
> 
> For example, let's say that we assert:
> 
> ?s ?p ?o
> 
> We would then want to dynamically create a new instance ?s1 with a graph such 
> as:
> 
> ?s1 ?p1 ?o
> 
> I have tried a query such as the following, but this does not work without 
> the variable ?s1 being declared in the WHERE clause:
> 
> INSERT {
> ?s1 a class1;
>     ?p1 ?o
> }
> 
> WHERE
> {?s a class;
>   ?p ?o}

All variables in the INSERT must be specified/bound in the WHERE clause. You 
need to create a URI for ?s1 before you can use it in the insert. ?p1 is also 
unbound in your example.

For example, you could base it on a label and prepend the namespace. There are 
a number of SPARQL functions for doing this. For example:


spif:buildURI (spin:Function)

Constructs a new URI resource by inserting the existing variable bindings into 
a template. The template can mention variable names in curly braces, such as 
"my:Instance-{?index}" would create "my:Instance-42" is ?index has the value 
42. As an alternative to variable names, the function can take additional 
arguments after the template, the variables of which can be accessed using 
{?1}, {?2} etc. For example: smf:buildURI("my:Instance-{?1}-{?2}", ?day, 
?month) would insert day and month at places {?1} and {?2}.

Arguments

sp:arg1 (xsd:string): The URI template such as 
"<http://my.com/Instance-{?index}>". If the template contains a full URI, then 
it must be wrapped by <...>, otherwise the system will treat it as a qname.
Return type

Resource
 <>spif:buildUniqueURI (spin:Function)

A variation of smf:buildURI that also makes sure that the created URI is unique 
in the current graph (that is, no triple contains the URI as either subject, 
predicate or object). This function is particularly useful for ontology mapping 
from a legacy data source into an RDF model.

Arguments

sp:arg1 (xsd:string): The URI template such as 
"<http://my.com/Instance-{?index}>". If the template contains a full URI, then 
it must be wrapped by <...>, otherwise the system will treat it as a qname.

Look in the TBC Help under SPARQL Functions Reference.

> INSERT {
>    GRAPH <urn:this_graph>
>       {
> ?s1 a class1;
>     ?p1 ?o
> }
> }
> 
> WHERE
> {?s a class;
>   ?p ?o}
> 
> Is there a way to create these new ?s1 instances automatically based on the 
> query conditions?
> 
> Thank you!
> 
> Dan
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "TopBraid Suite Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to topbraid-users+unsubscr...@googlegroups.com 
> <mailto:topbraid-users+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/topbraid-users/e7312fa7-ee09-41e1-a69f-692dbdefba49n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/topbraid-users/e7312fa7-ee09-41e1-a69f-692dbdefba49n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to topbraid-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/topbraid-users/62B3D6DC-3DD4-4296-9DA2-10CB3D8A433B%40topquadrant.com.

Reply via email to