adding well-formed tuples to taxonomy via SWP and SPARQL

41 views
Skip to first unread message

Michael Phelan

unread,
Jan 17, 2020, 9:08:37 AM1/17/20
to TopBraid Suite Users
I am writing a batch job which adds tuples to a Taxonomy in TopBraid EDG. I am struggling with adding well-formed tuples. I would appreciate some guidance on where my approach is falling short.

An example of the end-state of the Taxonomy after one record has been inserted (though ultimately there will be many records inserted) is below, with private details removed. The tuple which I am struggling to add has this as its first line:
scorg:b363fc0a-2c2c-11b2-80af-001dd8b72b91

# baseURI: urn:x-evn-master:somecompany_organizations
# imports: urn:x-evn-master:somecompany_organization

@prefix metadata:  <http://topbraid.org/metadata#> .
@prefix teamwork:  <http://topbraid.org/teamwork#> .

morg:CONCEPTSCHEME-7d2934e3-2c2b-11b2-8097-001dd8b72b91
    <http://www.w3.org/2004/02/skos/core#hasTopConcept>  scorg:b363fc0a-2c2c-11b2-80af-001dd8b72b91 ;
    rdfs:label    "some company Organizations" ;

    rdfs:comment  "Concept scheme for some company Import Service" .


<urn:x-evn-master:somecompany_organizations>
    rdf:type         owl:Ontology ;

    owl:imports      <http://topbraid.org/skos.shapes> ;

    rdfs:label       "somecompany_organizations" ;

    rdfs:comment     "some company Organization Taxonomy for Organization Import Service" ;

    owl:imports      <urn:x-evn-master:somecompany_organization> ;

    metadata:status  metadata:UnderDevelopmentStatus .


scorg:b363fc0a-2c2c-11b2-80af-001dd8b72b91

    rdfs:subClassOf  teamwork:Vocabulary .


teamwork:Vocabulary  rdfs:subClassOf  owl:Ontology .


<urn:x-evn-master:somecompany_organizations>
    rdf:type     teamwork:Vocabulary ;



The means by which I am attempting to add these tuples is via SWP and SPARQL.

The data is brought in from a RESTful service in JSON format. The sml:ImportTextFromURL function GETs the JSON data, which is subsequently assigned to a JSON object via the ui:json function.

The query graph is then set via ui:setContext ui:queryGraph. The query graph is set to the taxonomy via the IRI function, with the following value.
urn:x-evn-master:somecompany_organizations

The JSON attribute-value pairs are subsequently assigned to variables within the SPARQL insert statement using BIND.

The SPARQL insert statement is below. There are problems with this statement. I can insert the skos:prefLabel and the org_id to be well-formed, but adding anything further results in badly formed RDF. I am hoping that I may get some guidance from the community as to how to modify this insert statement so that it produces well-formed tuples of the format provided above. The example tuple above has this as its first line:
scorg:b363fc0a-2c2c-11b2-80af-001dd8b72b91

Thank you in advance for any insights.

<ui:update ui:updateQuery="{!
    INSERT {
        ?division skos:prefLabel ?orgNameString .
    }
    WHERE {
        BIND (ui:jsonValue(?json, &quot;results&quot;) AS ?array) .
        ?array ui:jsonArrayMembers ?object .
        BIND (ui:jsonValue(?object, &quot;org_id&quot;) AS ?orgID) .
        BIND (ui:jsonString(?orgID) AS ?orgString) .
        BIND (ui:jsonValue(?object, &quot;org_name&quot;) AS ?orgName) .
        BIND (ui:jsonString(?orgName) AS ?orgNameString) .
        BIND (spif:generateUUID() AS ?tbeOrgID) .
} }"/>









Michael Phelan

unread,
Jan 17, 2020, 9:55:16 AM1/17/20
to TopBraid Suite Users
I am pasting the Taxonomy a second time, as there was a typo in one of the namespace references.

# baseURI: urn:x-evn-master:somecompany_organizations
# imports: urn:x-evn-master:somecompany_organization

@prefix metadata:  <http://topbraid.org/metadata#> .
@prefix teamwork:  <http://topbraid.org/teamwork#> .

scorg:CONCEPTSCHEME-7d2934e3-2c2b-11b2-8097-001dd8b72b91
   <http://www.w3.org/2004/02/skos/core#hasTopConcept>  scorg:b363fc0a-2c2c-11b2-80af-001dd8b72b91 ;
   rdfs:label    "some company Organizations" ;

    rdfs:comment  "Concept scheme for some company Import Service" .


<urn:x-evn-master:somecompany_organizations>
   rdf:type         owl:Ontology ;

    owl:imports      <http://topbraid.org/skos.shapes> ;

    rdfs:label       "somecompany_organizations" ;

    rdfs:comment     "some company Organization Taxonomy for Organization Import Service" ;

   owl:imports      <urn:x-evn-master:somecompany_organization> ;

    metadata:status  metadata:UnderDevelopmentStatus .


scorg:b363fc0a-2c2c-11b2-80af-001dd8b72b91

   rdfs:subClassOf  teamwork:Vocabulary .


teamwork:Vocabulary  rdfs:subClassOf  owl:Ontology .


<urn:x-evn-master:somecompany_organizations>
   rdf:type     teamwork:Vocabulary ;


Irene Polikoff

unread,
Jan 17, 2020, 10:14:04 AM1/17/20
to topbrai...@googlegroups.com
There are 3 triples here: id, label and type

They all look fine syntactically.

What do you mean by ‘not well formed’?
--
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/665217d7-73ef-4ab2-bed0-161af0fa3569%40googlegroups.com.

Michael Phelan

unread,
Jan 17, 2020, 3:35:34 PM1/17/20
to TopBraid Suite Users
The RDF I provided at the beginning was entirely produced using the TopBraid EDG web interface's taxonomy editor. My goal is to produce a large number of tuples in the same taxonomy which have the same form as the A1 test org, but with details taken from the data provided by the JSON document. At present, the SPARQL I provided produces the org_id tuple data in a comma-delineated list, based on runs to my localhost EDG server. I am providing an abbreviated version of the RDF that the current SPARQL produces, below.

# baseURI: urn:x-evn-master:somecompany_organizations1_3

@prefix metadata: <http://topbraid.org/metadata#> .
                "A1" , "A2" , "A3";
                "A1" , "A2" , "A3" .

<urn:x-evn-master:somecompany_organizations1_3>
        a                owl:Ontology ;
        rdfs:label       "somecompany_organizations1_2" ;
        metadata:status  metadata:UnderDevelopmentStatus ;
        teamwork:newInstancesUserCannotModifyURI
                false ;
        owl:imports      <http://topbraid.org/skos.shapes> , <http://topbraid.org/imported> .


To unsubscribe from this group and stop receiving emails from it, send an email to topbrai...@googlegroups.com.

Irene Polikoff

unread,
Jan 17, 2020, 4:10:45 PM1/17/20
to topbrai...@googlegroups.com
Are you saying that your SPARQL generates label and id triples, but fails to generate type triples such as


And this is your problem?

I am confused by your terminology of “not well-formed tuples”. I am not sure what this means in this context. Do you mean that some triples that you are expecting to generate for each subject are missing?

This would happen if a variable you are using to construct triples was unbound.

For example:

SPARQL INSERT {?s a ?o1.
?s rdtfs:label ?o2.}

If let's say ?o1 was unbound then you would not get the type triple. If ?o2 was unbound, you would not get the label triple. If ?s was unbound you would not get neither of the triples.

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/96b4409a-c54c-40e5-ab9a-b9860d12d9a1%40googlegroups.com.

Michael Phelan

unread,
Jan 18, 2020, 3:48:27 PM1/18/20
to TopBraid Suite Users
Thank you very much for your additional advice.

"Not well-formed tuples" is likely the wrong terminology. To put things literally, I currently am producing the first example below, and I need to be producing the second example below.

First example:
               "Acme" , "Bachman" , "Connor" .


Second example:

Michael Phelan

unread,
Jan 18, 2020, 3:50:15 PM1/18/20
to TopBraid Suite Users
Please note that the class ID global identifier would be unique for each of the records (in my second example I just pasted in the same ID for all three items).
@prefix rdfs:  <<a href="http://www.w3.org/2000/01/rdf-schema#

Holger Knublauch

unread,
Jan 18, 2020, 5:20:18 PM1/18/20
to topbrai...@googlegroups.com
The query that you mentioned earlier was


INSERT {
        ?division skos:prefLabel ?orgNameString .
    }
    WHERE {
        BIND (ui:jsonValue(?json, &quot;results&quot;) AS ?array) .
        ?array ui:jsonArrayMembers ?object .
        BIND (ui:jsonValue(?object, &quot;org_id&quot;) AS ?orgID) .
        BIND (ui:jsonString(?orgID) AS ?orgString) .
        BIND (ui:jsonValue(?object, &quot;org_name&quot;) AS ?orgName) .
        BIND (ui:jsonString(?orgName) AS ?orgNameString) .
        BIND (spif:generateUUID() AS ?tbeOrgID) .
}

However, in the INSERT this query seems to use the same value for ?division in each iteration. Try replacing the spif:buildURI line with

    BIND (BNODE() AS ?division)

This would produce a different blank node for each array member.

HTH
Holger


--
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/ec159f8c-f8f9-4280-b68a-c69c1515c5d3%40googlegroups.com.

Irene Polikoff

unread,
Jan 18, 2020, 5:26:23 PM1/18/20
to topbrai...@googlegroups.com
Hi Michael,

There are no records in RDF. There are just triples. Each triple has subject, predicate and object.

Is exactly the same as

scorg:b363fc0a-2c2c-11b2-80af-001dd8b72b91

scorg:b363fc0a-2c2c-11b2-80af-001dd8b72b91

scorg:b363fc0a-2c2c-11b2-80af-001dd8b72b91

When triples are serialized the first syntax is just a short hand for the second, but they both represent the same triples.

As I understand it, you want something like

Scorg:b363fc0a-2c2c-11b2-80af-001dd8b72b92
Scorg:b363fc0a-2c2c-11b2-80af-001dd8b72b93

If so, you have three issues:


Correct?

The third problem is the easiest one to fix. 

The object of new triples with skos:prefLabel you are using whatever is bound to ?orgNameString variable. And for triples with <https://schema.somecompany.com/ontologies/somecompany_organization#org_id> predicate you are using whatever is bound to ?orgString variable. Simply switch them around.

As for the rest, clearly you have 3 different things in your JSON input with three different labels and ids, but you are using only one subject URI in your SPARQL that is bound to ?division in
If you are relatively new to SPARQL, I would recommend playing more with it, running different queries, etc. in order to get a stronger handle on how it operates. I would do it in TBC with some different sample datasets.


--
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/ec159f8c-f8f9-4280-b68a-c69c1515c5d3%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages