This is in fact how the built-in URI generation policy "counter" is implemented. Open teamwork.ui.ttlx and go to

teamwork:IncrementCounterEditRule

The main difference is that we store this "counter" in the TCH graphs.

Holger


On 2021-03-17 10:49 pm, David Price wrote:
Hi Maja,

There may be other ways, but you can do this kind of thing with an EDG Edit Rule as code. An Edit Rule can access the changes graph via a special graph called ui:addedGraph (ui:deletedGraph is also available) and find new instances being created and then search the current graph data for the max existing value and just add one. Something like this should be close and search for that property in any new instance of any class:

property-rules:Set_autoIncrementID
  a teamwork:EditRule ;
  teamwork:ruleMayUpdate true ;
  ui:prototype """
<ui:forEach ui:resultSet=\"{#
        SELECT DISTINCT ?i ?class
        WHERE {
            GRAPH ui:addedGraph {
                ?i a ?class .
                FILTER NOT EXISTS {
                    ?i myschema:autoIncrementID ?currentvalue .
                } .
            } .
        } }\">
    <ui:update ui:updateQuery=\"{!
            INSERT {
                ?i myschema:autoIncrementID ?nextvalue .
            }
            WHERE {
                GRAPH ui:addedGraph {
                    ?i a ?class .
                } .
                {
                    SELECT (MAX(?num) AS ?maxvalue)
                    WHERE {
                        ?noti a ?class .
                        ?noti myschema:autoIncrementID ?id .
                        BIND (ceil(xsd:decimal(?id)) AS ?num) .
                        FILTER bound(?num) .
                    }
                } .
                BIND (COALESCE((xsd:integer(?maxvalue) + 1), 1) AS ?nextvalue) .
            } }\"/>
</ui:forEach>
"""^^ui:Literal ;
  rdfs:comment "When creating a new thing set the autoIncrementID property value to be the next highest interger value" ;
  rdfs:label "Default autoIncrementID" ;
  rdfs:subClassOf teamwork:EditRules ;
.

Cheers,
David


On 17 Mar 2021, at 12:09, majaCap <[email protected] <mailto:[email protected]>> wrote:

Hi,

I have an int property in my ontology. Now, I would like to increment that property each time a new instance of a class is created, starting from a particular number. How would I approach this in EDG? Let's say the class instance is Animal with property *autoIncrementID*. Each time I create a new Animal I would like the *autoIncrementID *to be incremented by 1.

Br,
Maja

--
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 [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/01759423-765a-4084-a991-2caa46eb49e8n%40googlegroups.com <https://groups.google.com/d/msgid/topbraid-users/01759423-765a-4084-a991-2caa46eb49e8n%40googlegroups.com?utm_medium=email&utm_source=footer>.

UK +44 (0) 7788 561308
US +1 (336) 283-0808‬

--
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 [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/6CE83445-5B78-424E-A92F-7E5FDE25E275%40topquadrant.com <https://groups.google.com/d/msgid/topbraid-users/6CE83445-5B78-424E-A92F-7E5FDE25E275%40topquadrant.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/topbraid-users/26f63566-797c-6dc9-51bf-dcdac00c9763%40topquadrant.com.

Reply via email to