Querying the TCH for the last changed date of a resource

54 views
Skip to first unread message

cbur...@healthwise.org

unread,
May 14, 2021, 4:57:40 PM5/14/21
to TopBraid Suite Users
Suppose I want to write a query for the last changed date of every concept in my taxonomy. Further suppose that in the case of changes made in working copies, I'm only interested in the date the change was committed to production.

How can I write these kinds of queries? Is there someplace where all the classes and properties in the teamwork: namespace are documented? I don't really see much here: https://doc.topquadrant.com/7.0/teamwork/

By searching the archives of this message board, I discovered that the property <http://topbraid.org/teamwork#lastChange> exists, but it seems to apply only to entire knowledge graphs, not to individual resources like concepts. Is that right?

Irene Polikoff

unread,
May 14, 2021, 6:40:24 PM5/14/21
to topbrai...@googlegroups.com
I can explain how the data is stored in more detail:

There is a change resource that has the time of a change.

<urn:x-change:2021-05-14T21-56-29.119ZAdministrator-61d2232b-2b12-493b-92e0-815d259e907d>
  rdf:type teamwork:Change ;
  dcterms:created "2021-05-14T21:56:29.119Z"^^xsd:dateTime ;
  sioc:has_creator <urn:x-tb-users:Administrator> ;

Change resource is a subject of added and deleted triples in this transaction. These triples capture what exactly was added or deleted.

Let’s say, an alternative label was added for Raleigh. You will get:

<urn:x-change:2021-05-14T21-56-29.119ZAdministrator-61d2232b-2b12-493b-92e0-815d259e907d>
  rdf:type teamwork:Change ;
  dcterms:created "2021-05-14T21:56:29.119Z"^^xsd:dateTime ;
  sioc:has_creator <urn:x-tb-users:Administrator> ;
 teamwork:added [
      teamwork:object "new synonym" ;
      teamwork:predicate skos:altLabel ;
      teamwork:subject g:Raleigh ;
    ] ;

If you looking for the last change only, then you need to go for the most recent date among the change records that did something with each concept - in the example above g:Raleigh. There may be multiple changes where g:Raleigh is the value of a teamwork:subject, you want to select the one with the greatest  dcterms:created to determine the last date/time of a change.

If a change happened in a working copy, the change resource will have the tag property which value is a working copy. For example.

<urn:x-change:2021-05-14T21-56-29.119ZAdministrator-61d2232b-2b12-493b-92e0-815d259e907d>
teamwork:tag <urn:x-tags:basic_workflow___x__administrator_on_2021_05_14_17_55_39>.

If you want to include only committed changes and go by the date of commit, not the date a change was made, this adds some complexity since the most recent change is not necessary the one where the edit happened most recently. You need to:

First, select only changes that are associated with a workflow/working copy that is committed {?wc. teamwork:status teamwork:Committed} 

And look for the date of commit as opposed to the date of a particular change. The workflow captures all its status changes, this gives you the date of commit.

For example,

<urn:x-tags:basic_workflow___x__administrator_on_2021_05_14_17_55_39>
  rdf:type teamwork:Tag ;
  teamwork:status teamwork:Committed ;
  teamwork:statusChange [
      dcterms:created "2021-05-14T18:02:37.739-04:00"^^xsd:dateTime ;
      sioc:has_creator <urn:x-tb-users:Administrator> ;
      teamwork:newStatus teamwork:FrozenForReview ;
    ] ;
  teamwork:statusChange [
      dcterms:created "2021-05-14T18:03:43.626-04:00"^^xsd:dateTime ;
      sioc:has_creator <urn:x-tb-users:Administrator> ;
      teamwork:newStatus teamwork:Approved ;
    ] ;
  teamwork:statusChange [
      dcterms:created "2021-05-14T18:04:00.756-04:00"^^xsd:dateTime ;
      sioc:has_creator <urn:x-tb-users:Administrator> ;
      teamwork:newStatus teamwork:Committed ;
    ] ;



--
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-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/ba353455-1708-4ecf-a280-20d654ac9c10n%40googlegroups.com.

cbur...@healthwise.org

unread,
May 14, 2021, 7:44:05 PM5/14/21
to TopBraid Suite Users
Irene, thanks for the detailed response.

I have a few follow-up questions:
1. You wrote: "There may be multiple changes where g:Raleigh is the value of a teamwork:subject, you want to select the one with the greatest  dcterms:created to determine the last date/time of a change." How would you recommend doing that? (I wouldn't be surprised if our change history contains 20+ changes for any given concept.)
2. Do you think it would be possible to add a teamwork function in the future that gets the last changed date for resources in a more "out of the box" way? This must be a relatively common use case.
3. Your response makes me think there is probably no published documentation about TTF other than what I've found so far. Would you consider making a full spec available to TQ users?

Irene Polikoff

unread,
May 14, 2021, 9:17:43 PM5/14/21
to topbrai...@googlegroups.com
Hi Carl,

If you go into Available Web Services on the Server Administration page and then select Teamwork SPIN Templates from the list, you will see a template that gets all committed changes - irrespective if they were done in a workflow or not. 



You can see the query used in the template. It is close to what you need, except:
  1. It gets all changes for all resources ordered by date
  2. The date is the date of change, not the date of commit of a workflow

You can change the query to GROUP BY ?subject and do a MAX for ?createDate. This should address #1. Some examples are for SPARQL aggregate functions are available at https://www.w3.org/TR/sparql11-query/#aggregates

Something like:

SELECT  ?subject (MAX(?createDate) AS ?date
WHERE {
        ?change a teamwork:Change .
        ?change teamwork:status teamwork:Committed .
        ?change dcterms:created ?createDate .
        ?change teamwork:added|teamwork:deleted ?changetriple .
        ?changetriple teamwork:subject ?subject .
        ?change ?prop ?changetriple .

}
GROUP BY (?subject)

To address #2, I suppose you can do a UNION where in one part of a union you get all changes done directly (no teamworks:tag values) and in another part all changes done in a workflow (there is a teamworks:tag value) - for these you would bind the createDate to the date of commit, instead of the date of change. 

I don’t have enough diverse change data handy to test such query.

There may be a function already that gets the last change date. Let’s see if one of the developers responds to this post.
If such function is available, I doubt it would use the exact logic you specified - the commit date as opposed to the date the change was made. It is not that this way of looking at the time of change does not make sense - it depends on the point of view.

With respect to describing the data model, we will take a look at extending the documentation. I typically simply make a couple of changes and then look at how they are stored.

Hope this helps,

Irene


Reply all
Reply to author
Forward
0 new messages