Thank you all for support. I will try to explain it clearer. The  
autoincrementID is a property that will refer to another system - and it 
will be  an ID in another system, therefore this is not a count of current 
instances. So there is an existing system that has some Animal instances 
and each of Animal has this autoincrementID property. Now I built another 
system also with Animals but containing  much more properties that I want 
to connect to the first system based on this autoincrementID property. 
Therefore whenever I add a new Animal to my data graph I also need to add 
the autoincrementID continuing the id count from another system. So let's 
say that I add to my data graph an Animal which will have URI *Animal10254 * 
and 
the last value of autoincrementID from another system is 959. Then my 
*Animal10254* needs to have autoincrementID == 960. Does this makes  more 
sense?

Kind regards,
Maja

torsdag 18. mars 2021 kl. 14:47:44 UTC+1 skrev Irene Polikoff:

> Yes, a good point David.
>
> On Mar 18, 2021, at 8:56 AM, David Price <[email protected]> wrote:
>
>
>
> On 17 Mar 2021, at 21:56, Irene Polikoff <[email protected]> wrote:
>
> Another approach is to use a property value rule to automatically 
> calculate the *autoIncrementID*
>
> It sounds like you want to get a count of all instances plus some number.
>
>
> Hi Maja,
>
> I’m not sure the above is what you mean by “I would like to increment that 
> property each time a new instance of a class is created, starting from a 
> particular number”. 
>
> Either way, everyone should take care to understand the difference between 
> "max of existing value" vs. "count of instances” logic. There is no 
> difference in some scenarios, but they are not identical if your scenario 
> allows people to delete instances. 
>
> Example: 
>
> Create 10 instances - the next Create integer would be 11 if no other 
> change happens and at this moment max and count produce identical result.
>
> Delete 5 instances.
>
> Now:
>
> - “count instances” approach would say 6 is the next available integer
>
> - “max current value” approach could return anything from 6 to 11 
> depending on exactly which instances got deleted
>
> Just suggesting to do a deep analysis of your reuirements before deciding 
> which logic will work in all your user scenarios - and then do a lot of 
> testing.
>
> Cheers,
> David
>
>
> What is *autoIncrementID *a property of? 
>
> Is it a property that each instance of a class has, so that for each 
> instance you can get the count of ll instances of a class plus a number ? 
>
> Then, you would define it for the class Animal and create a property value 
> rule as follows
>
>
>
> <PastedGraphic-65.png>
>
> Select Count number of inverse property values
>
> <PastedGraphic-67.png>
>
> You will get this rule if you look at the source code
>
> g:Animal-autoIncrementID
>   a sh:PropertyShape ;
>   sh:path g:autoIncrementID ;
>   sh:datatype xsd:integer ;
>   sh:name "autoIncrementID" ;
>   sh:nodeKind sh:Literal ;
>   sh:values [
>       sh:count [
>           sh:path [
>               sh:inversePath rdf:type ;
>             ] ;
>         ] ;
>     ] ;
> .
>
> Update it because the path you want to use for the count is from an 
> instance to the class and then from the class to all instances via inverse 
>  i.e., rdf:type/^rdf:type
>
> g:Animal-autoIncrementID
>   a sh:PropertyShape ;
>   sh:path g:autoIncrementID ;
>   sh:datatype xsd:integer ;
>   sh:name "autoIncrementID" ;
>   sh:nodeKind sh:Literal ;
>   sh:values [
>       sh:count [
>           sh:path (
>               rdf:type
>               [
>                 sh:inversePath rdf:type ;
>               ]
>             ) ;
>         ] ;
>     ] ;
> .
>
> Now, when you access any instance of Animal, you can get a count of all 
> Animals
>
> <PastedGraphic-70.png>
>
>
> If you want to add some number to the count, use sparql:add function in 
> your rule - http://datashapes.org/sparql
>
> You can also associate the property with the class itself, then you do not 
> need to change the rule that will be generated by the template. 
>
> To associate a property with a class, switch the class hierarchy root to 
> Resource, find owl:Class in the tree and define the property and a rule for 
> it.
>
> <PastedGraphic-68.png>
>
> Then, you will get the generated autoIncrementID value for every class in 
> your ontology
>
> <PastedGraphic-69.png>
>
>
> You can also define a property for all classes to store the number you 
> want to add to the count. The value of this property could be different for 
> different classes.
>
> The above approach for adding a property to a class is for 7.0. If you are 
> using 6.4, use the following approach to add properties directly to a 
> class: 
>
>
> https://doc.topquadrant.com/6.4/ontologies/#Customizing_Forms_for_Classes_and_Properties
>  
>
> On Mar 17, 2021, at 8:49 AM, David Price <[email protected]> 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]> 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].
> 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 <+44%207788%20561308>
> US +1 (336) 283-0808 <(336)%20283-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].
> 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/26067D09-E4E1-4C22-908D-814BDB0E23D7%40topquadrant.com
>  
> <https://groups.google.com/d/msgid/topbraid-users/26067D09-E4E1-4C22-908D-814BDB0E23D7%40topquadrant.com?utm_medium=email&utm_source=footer>
> .
>
>
> UK +44 (0) 7788 561308 <+44%207788%20561308>
> US +1 (336) 283-0808 <(336)%20283-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].
>
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/topbraid-users/FB3F08CF-85E9-49B8-B3A7-5F272C0AE3C7%40topquadrant.com
>  
> <https://groups.google.com/d/msgid/topbraid-users/FB3F08CF-85E9-49B8-B3A7-5F272C0AE3C7%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/d968627f-a6cd-4089-b0e4-6c320b423bd6n%40googlegroups.com.

Reply via email to