Tim; Looking down this thread, I see that someone, perhaps me,
suggested using a DELETE statement in a constructor.  I'm not sure how
this makes sense, or why this was stated.  But a constructor by
definition starts with no data.  So {?this ?p ?o} will fail, but the
BIND statement is executed outside of the basic graph pattern (bgp) -
BIND translates to a select projection.

So, in the following query, the only variables that can be bound are ?
this and ?uri, and neither the DELETE nor the INSERT clause will
execute anything:

DELETE  {
    ?this ?p ?o .
    ?s1 ?p1 ?this .
}
INSERT  {
    ?uri ?p ?o .
    ?s1 ?p1 ?uri .
}
WHERE {
    ?this ?p ?o .
    ?s1 ?p1 ?this .
        BIND (spif:buildURI("
http://ontologies.pg.com/test#PROJECT_RESOURCE_{?1}";,
spif:generateUUID())
AS ?uri) .
}

Apologies for the confusion that may have created.  So let's go back
to a couple of key points in the original statement:

> This requires the use of the same "rules" to
> create the URI.  Currently, I must copy & paste and maintain these rules in
> every SM module that needs to create the URIs.

In this case, you can create a SPIN function an place it in a file
with a .spin extension - for example myRules.spin.ttl.  The function
will then be available to all project in the workspace and you can
call this rule in any of the SPARQLMotion module queries.  For
example, if you had a SPIN function named
globals:createProjectResource with the spin:body

SELECT ?uri
WHERE
{  BIND (spif:buildURI("http://ontologies.pg.com/
test#PROJECT_RESOURCE_{?1}", spif:generateUUID()) AS ?uri) .
}

..then this can be called anywhere in the workspace as
  BIND (globals:createProjectResource() AS ?myuri)

> It would be nice if there was a way to create the URI automatically using a
> pre-defined template that is applied when the new instance is created as
> part of a CONSTRUCT query.

This is what bnodes do. But I understand being hesitant about using
bnodes.  Given that, spif:generateUUID() will give you a unique id and
i believe the aforementioned SPIN function will address your issues
with generating unique uri's.

-- Scott

On Apr 17, 7:50 pm, Holger Knublauch <[email protected]> wrote:
> On 4/18/2012 8:29, Tim Smith wrote:
>
>
>
>
>
>
>
>
>
>
>
> > To continue this thread a bit...
>
> > I ran into a case where I wanted to use this constructor inside TBC/E
> > to set the URI for an instance when the instance is created.  The
> > objective is to create useful, yet standardized URIs so that users do
> > not have to think about those details when creating new instances.
>
> > I placed the following into spin:constructor for a class (this was
> > just a test)
>
> > DELETE  {
> >     ?this ?p ?o .
> >     ?s1 ?p1 ?this .
> > }
> > INSERT  {
> >     ?uri ?p ?o .
> >     ?s1 ?p1 ?uri .
> > }
> > WHERE {
> >     ?this ?p ?o .
> >     ?s1 ?p1 ?this .
> >         BIND
> > (spif:buildURI("http://ontologies.pg.com/test#PROJECT_RESOURCE_{?1}
> > <http://ontologies.pg.com/test#PROJECT_RESOURCE_%7B?1%7D>",
> > spif:generateUUID()) AS ?uri) .
> > }
>
> > However, TBC fails with very odd behavior.
>
> > This is due  to the use of the spif:generateUUID() function.
>
> > In some cases you have to use a function like this to avoid naming
> > collisions.  I really need to use blank nodes here but I can't use
> > them because they won't work in a linked data scenario.
>
> > Is there any way to bind the output of generateUUID() once and avoid
> > multiple executions of the function?
>
> Would it work to place the BIND into a sub-select or { } block before
> the basic graph pattern? This should execute this block first and you
> can use a single value even if the rest of the query iterates multiple
> times.
>
> Holger
>
>
>
>
>
>
>
>
>
> > Or is there another way to create unique URIs as users enter them?
> > spif:buildUniqueURI() does not say what it does when it encounters a
> > duplicate URI.
>
> > Thanks,
>
> > Tim
>
> > The attached file has an example that I'll describe.
>
> > Two classes - Project and ProjectResource and one property - hasResource.
>
> > hasResource is part of an AllValuesFrom restriction on Project that
> > points to ProjectResource.
>
> > The constructor shown above is the constructor for ProjectResource.
>
> > I then created an instance of Project, clicked on "hasResource" on the
> > new project instance (Project_1) and selected "Create and Add".
>
> > TBC attempts to add the instance, however it quickly fails with the
> > following error:
>
> > Operation failed.
>
> > On: Apr 17, 2012 5:52:49 PM
>
> > Reason:
> > java.lang.StackOverflowError
>
> > Once I close this window, I'm back to TBC and no new instance of
> > ProjectResource has been created, or so I think.
>
> > Now click on hasResource for Project_1 again and this time select
> > "Create blank node".  This will run to completion.
>
> > Once it returns, I see the new blank node instance as well as two
> > additional ProjectResource instances - one has an rdf:type the other
> > has an rdfs:label.
>
> > Shortened stack trace below.  The last line was repeated hundreds of
> > times.
>
> > Operation failed.
>
> > On: Apr 17, 2012 5:52:49 PM
>
> > Reason:
> > java.lang.StackOverflowError
>
> >     at com.hp.hpl.jena.graph.Node_URI.same(Node_URI.java:51)
>
> >     at com.hp.hpl.jena.graph.Node_URI.equals(Node_URI.java:46)
>
> >     at
> > com.hp.hpl.jena.graph.impl.SimpleReifier.matchesReification(SimpleReifier.java:222)
>
> >     at
> > com.hp.hpl.jena.graph.impl.SimpleReifier.find(SimpleReifier.java:211)
>
> >     at
> > com.hp.hpl.jena.graph.impl.SimpleReifier.findEither(SimpleReifier.java:238)
>
> >     at
> > com.hp.hpl.jena.graph.impl.SimpleReifier.findExposed(SimpleReifier.java:235)
>
> >     at
> > com.hp.hpl.jena.graph.impl.GraphBase.reifierTriples(GraphBase.java:318)
>
> >     at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240)
>
> >     at
> > com.hp.hpl.jena.graph.impl.GraphBase.containsByFind(GraphBase.java:308)
>
> >     at
> > com.hp.hpl.jena.graph.impl.GraphBase.graphBaseContains(GraphBase.java:288)
>
> >     at
> > com.hp.hpl.jena.mem.faster.GraphMemFaster.graphBaseContains(GraphMemFaster.java:183)
>
> >     at com.hp.hpl.jena.graph.impl.GraphBase.contains(GraphBase.java:270)
>
> >     at
> > com.hp.hpl.jena.graph.compose.MultiUnion.graphBaseContains(MultiUnion.java:144)
>
> >     at com.hp.hpl.jena.graph.impl.GraphBase.contains(GraphBase.java:270)
>
> >     at com.hp.hpl.jena.graph.impl.GraphBase.contains(GraphBase.java:296)
>
> >     at com.hp.hpl.jena.rdf.model.impl.ModelCom.contains(ModelCom.java:994)
>
> >     at org.topbraid.spin.vocabulary.SP.exists(SP.java:420)
>
> >     at
> > org.topbraid.spintb.modules.SPINSessionPropertyFunctionRegistry.get(SPINSessionPropertyFunctionRegistry.java:46)
>
> >     at
> > org.topbraid.spintb.modules.SPINSessionPropertyFunctionRegistry.manages(SPINSessionPropertyFunctionRegistry.java:62)
>
> >     at
> > org.topbraid.spin.arq.SPINThreadPropertyFunctionRegistry.manages(SPINThreadPropertyFunctionRegistry.java:67)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.PropertyFunctionGenerator.isMagicProperty(PropertyFunctionGenerator.java:201)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.PropertyFunctionGenerator.findPropertyFunctions(PropertyFunctionGenerator.java:82)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.PropertyFunctionGenerator.compilePattern(PropertyFunctionGenerator.java:58)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.PropertyFunctionGenerator.buildPropertyFunctions(PropertyFunctionGenerator.java:37)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.optimize.TransformPropertyFunction.transform(TransformPropertyFunction.java:51)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.TransformWrapper.transform(TransformWrapper.java:24)
>
> >     at com.hp.hpl.jena.sparql.algebra.op.OpBGP.apply(OpBGP.java:34)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.Transformer$ApplyTransformVisitor.visit0(Transformer.java:261)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.OpVisitorByType.visit(OpVisitorByType.java:28)
>
> >     at com.hp.hpl.jena.sparql.algebra.op.OpBGP.visit(OpBGP.java:35)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.OpWalker$WalkerVisitor.visit0(OpWalker.java:76)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.OpVisitorByType.visit(OpVisitorByType.java:28)
>
> >     at com.hp.hpl.jena.sparql.algebra.op.OpBGP.visit(OpBGP.java:35)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.OpWalker$WalkerVisitor.visit1(OpWalker.java:84)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.OpVisitorByType.visit(OpVisitorByType.java:97)
>
> >     at com.hp.hpl.jena.sparql.algebra.op.OpExtend.visit(OpExtend.java:107)
>
> >     at com.hp.hpl.jena.sparql.algebra.OpWalker.walk(OpWalker.java:40)
>
> >     at com.hp.hpl.jena.sparql.algebra.OpWalker.walk(OpWalker.java:30)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.Transformer.applyTransformation(Transformer.java:99)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.Transformer.transformation(Transformer.java:92)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.Transformer.transformation(Transformer.java:81)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.Transformer.transform(Transformer.java:46)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.Transformer.transformSkipService(Transformer.java:64)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.Transformer.transformSkipService(Transformer.java:52)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.optimize.Optimize.apply(Optimize.java:187)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.optimize.Optimize.rewrite(Optimize.java:143)
>
> >     at
> > com.hp.hpl.jena.sparql.algebra.optimize.Optimize.optimize(Optimize.java:67)
>
> >     at com.hp.hpl.jena.sparql.algebra.Algebra.optimize(Algebra.java:53)
>
> >     at
> > com.hp.hpl.jena.sparql.engine.main.QueryEngineMain.modifyOp(QueryEngineMain.java:72)
>
> >     at
> > com.hp.hpl.jena.sparql.engine.QueryEngineBase.createPlan(QueryEngineBase.java:104)
>
> >     at
> > com.hp.hpl.jena.sparql.engine.QueryEngineBase.getPlan(QueryEngineBase.java:97)
>
> >     at
> > com.hp.hpl.jena.sparql.engine.main.QueryEngineMain$1.create(QueryEngineMain.java:91)
>
> >     at
> > com.hp.hpl.jena.query.QueryExecutionFactory.makePlan(QueryExecutionFactory.java:498)
>
> >     at
> > com.hp.hpl.jena.query.QueryExecutionFactory.createPlan(QueryExecutionFactory.java:462)
>
> >     at
> > com.hp.hpl.jena.sparql.modify.UpdateEngineWorker.evalBindings(UpdateEngineWorker.java:463)
>
> >     at
> > com.hp.hpl.jena.sparql.modify.UpdateEngineWorker.visit(UpdateEngineWorker.java:243)
>
> >     at
> > com.hp.hpl.jena.sparql.modify.request.UpdateModify.visit(UpdateModify.java:85)
>
> >     at
> > com.hp.hpl.jena.sparql.modify.UpdateEngineMain.execute(UpdateEngineMain.java:39)
>
> >     at
> > com.hp.hpl.jena.sparql.modify.UpdateProcessorBase.execute(UpdateProcessorBase.java:48)
>
> >     at
> > org.topbraid.spin.inference.SPINConstructors.constructInstance(SPINConstructors.java:295)
>
> >     at
> > org.topbraid.spin.inference.SPINConstructors.constructInstance(SPINConstructors.java:145)
>
> >     at
> > org.topbraid.spin.inference.SPINConstructors.construct(SPINConstructors.java:117)
>
> >     at
> > org.topbraid.spin.inference.SPINConstructors.construct(SPINConstructors.java:120)
>
> >     at
> > org.topbraid.spin.inference.SPINConstructors.construct(SPINConstructors.java:120)
>
> >     at
> > org.topbraid.spin.inference.SPINConstructors.construct(SPINConstructors.java:120)
>
> >     at
> > org.topbraid.spin.inference.SPINConstructors.construct(SPINConstructors.java:120)
>
> >     at
> > org.topbraid.spin.inference.SPINConstructors.construct(SPINConstructors.java:120)
>
> > On Fri, Mar 30, 2012 at 7:27 PM, Scott Henninger
> > <[email protected] <mailto:[email protected]>> wrote:
>
> >     See some responses inline:
>
> >     On Mar 30, 3:33 pm, Tim Smith <[email protected]
> >     <mailto:[email protected]>> wrote:
> >     > Sorry about the last one - Gmail sent it too soon...
>
> >     > Thanks for the help.  To clarify the scenario, consider the
> >     following where
> >     > each line is from a different spreadsheet:
>
> >     > From file #1 with two columns - Car and Color:
>
> >     > Car   Color
> >     > Car1 Blue
>
> >     > From file #2 with two columns - Car and # of Doors
>
> >     > Car   # of Doors
> >     > Car1  2
>
> >     > Assume each file is processed in its own SM script.
>
> >     > Also assume Car1 could
>
> ...
>
> read more »

-- 
You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary 
Network (EVN), TopBraid Composer,
TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en

Reply via email to