how to

98 views
Skip to first unread message

Kasia Kryczka

unread,
Mar 30, 2023, 5:31:21 AM3/30/23
to TopBraid Suite Users
Hi, 

I have about 170 collections with missing value- the collections are listed from the query.
I need to insert a value <urn:xyz>.
Is it possible to create a loop that goes through all listed collections and inserts the missing value?

Thanks,

Kasia

Holger Knublauch

unread,
Mar 30, 2023, 5:37:14 AM3/30/23
to topbrai...@googlegroups.com
From the Script Editor panel, you could run something like

dataset.masterGraphs().forEach(masterGraph => {
console.log('Adding to ' + masterGraph);
graph.transaction(masterGraph, 'Adding something', () => {
let subject = graph.namedNode(masterGraph);
subject.add(rdfs.comment, "Added");
})
})

Watch out though, the green code above is dangerous and will really add triples to every asset collection. (That's also why I didn't run it on my machine, so I hope it works).

Holger


--
The topics of this mailing list include TopBraid EDG and related technologies such as SHACL.
To post to this group, send email to topbrai...@googlegroups.com
---
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/b388bfe2-422f-42a6-9a41-11ddf6e5744an%40googlegroups.com.

Kasia Kryczka

unread,
Jul 19, 2023, 8:06:58 AM7/19/23
to TopBraid Suite Users
Hi,

When I added this comment (with the script above )and deleted it later (in Script editor) it seems that this change is not saved in the change history. 

Where can I find that this change happened?

Thanks,

Kasia

Holger Knublauch

unread,
Jul 19, 2023, 8:22:33 AM7/19/23
to topbrai...@googlegroups.com
On 19 Jul 2023, at 1:06 pm, Kasia Kryczka <sparql...@gmail.com> wrote:

Hi,

When I added this comment (with the script above )and deleted it later (in Script editor) it seems that this change is not saved in the change history. 

Where can I find that this change happened?

The script below writes to the master graphs directly, bypassing the change history.

To have the changes recorded, you need to use a slightly different graph, which includes the user name.

One way to do that is to do something like 

graph.transaction(masterGraph + ':Administrator, ...

or

graph.transaction(masterGraph + ':' + tbs.currentUserId(), ...

This will use something like urn:x-evn-master:geo:Administrator and changes to that will create change history items too.

HTH
Holger



Kasia Kryczka

unread,
Jul 19, 2023, 8:59:11 AM7/19/23
to TopBraid Suite Users
Hi Holger,

thank you for quick reply.

I'll try do do that.

Br,

Kasia

Kasia Kryczka

unread,
Aug 23, 2023, 8:54:57 AM8/23/23
to TopBraid Suite Users
Hi Holger,

it seems that we need more of this script. How to make changes to mastergraph and on their classes as well. 

How can we modify the script?

Thanks,

Kasia

Holger Knublauch

unread,
Aug 23, 2023, 11:40:53 AM8/23/23
to topbrai...@googlegroups.com
Sorry I don't understand the question. What do you have and what needs to be changed?

Holger


Kasia Kryczka

unread,
Aug 24, 2023, 4:43:03 AM8/24/23
to TopBraid Suite Users
Hi Holger,

we have this script :

dataset.masterGraphs().forEach(masterGraph=> {

    console.log('Adding to ' + masterGraph);

    graph.transaction(masterGraph + ':' +tbs.currentUserId(), 'Adding something', () => {

        let subject =graph.namedNode(masterGraph); subject.add(rdfs.comment,"Added");

    });

});


just add something to the history. This adds the change only to the ontology level, is it possible to add the change to their classes as well ( to all lower levels) ?

Hope this helps.

Br,

Kasia

Holger Knublauch

unread,
Aug 24, 2023, 4:57:52 AM8/24/23
to topbrai...@googlegroups.com

On 24 Aug 2023, at 9:43 am, Kasia Kryczka <sparql...@gmail.com> wrote:

Hi Holger,

we have this script :
dataset.masterGraphs().forEach(masterGraph=> {
    console.log('Adding to ' + masterGraph);
    graph.transaction(masterGraph + ':' +tbs.currentUserId(), 'Adding something', () => {
        let subject =graph.namedNode(masterGraph); subject.add(rdfs.comment,"Added");
    });
});

just add something to the history. This adds the change only to the ontology level, is it possible to add the change to their classes as well ( to all lower levels) ?

The script above only uses masterGraph as subject. If you want to add triples to specific classes, you need to know the URIs of these classes, e.g.

let subject = graph.namedNode('http://example.org/myOntology#MyClass");
subject.add(rdfs.comment, "Added comment to the class");

If you don't know the exact URI of the classes you want to modify you could first find all instances of owl:Class or use a SPARQL query to find them, then iterate over those.

Holger


Kasia Kryczka

unread,
Aug 31, 2023, 7:19:44 AM8/31/23
to TopBraid Suite Users
HI Holger,

and could you show an example how to find all owl:Class with js or how to use sparql query to insert the comment?
I have the query to get all owl:Class but I don't know how to use it with js.

Thanks,

Kasia

Holger Knublauch

unread,
Aug 31, 2023, 7:35:25 AM8/31/23
to topbrai...@googlegroups.com
owl.everyClass().forEach(cls => {
cls.add(rdfs.comment, 'Hello World')
})

or with any SPARQL:

graph.select(`
SELECT ?cls
WHERE {
?cls rdf:type/rdfs:subClassOf* owl:Class .
}`).bindings.forEach(b => {
let cls = b.cls;
cls.add(rdfs.comment, 'Hello World')
})

HTH
Holger


Kasia Kryczka

unread,
Sep 1, 2023, 3:27:23 AM9/1/23
to TopBraid Suite Users
Holger,

thank you :)

Br,

Kasia

Kasia Kryczka

unread,
Sep 21, 2023, 7:42:27 AM9/21/23
to TopBraid Suite Users
Hi again,

I tried to use the above example with my query:

graph.select(`
    SELECT ?masterGraph
WHERE {
    GRAPH ?masterGraph {
    ?masterGraph rdf:type teamwork:Vocabulary .}
FILTER NOT EXISTS {
    GRAPH ?masterGraph {
      ?s edg:subjectArea ?o .
    }
  }
  FILTER (STRSTARTS(STR(?masterGraph),"urn:x-evn-master:") &&(!STRENDS(STR(?masterGraph),"singleton")) )}`
  ).bindings.forEach(b => {
let masterGraph = b.masterGraph;
 console.log (b.masterGraph)
 masterGraph.add(rdfs.comment, 'hello hello')
})


but it only add comment to the graph from which I run the script. In the change history panel in the same graph there's information that the comment was added but when I go to those other graphs the comment is not visible. 
<urn:x-evn-master:ontology_test_creation>
  rdfs:comment "hello hello" ;
.
<urn:x-evn-master:test3_ontology>
  rdfs:comment "hello hello" ;
.
<urn:x-evn-master:test_test_core_glossary>
  rdfs:comment "hello hello" ;
.
<urn:x-evn-master:x_idea_testontology_v10>
  rdfs:comment "hello hello" ;


Can you tell me what I'm doing wrong :)


Thanks,

Kasia

Holger Knublauch

unread,
Sep 21, 2023, 7:49:04 AM9/21/23
to topbrai...@googlegroups.com
On 21 Sep 2023, at 1:42 pm, Kasia Kryczka <sparql...@gmail.com> wrote:

Hi again,

I tried to use the above example with my query:

graph.select(`
    SELECT ?masterGraph
WHERE {
    GRAPH ?masterGraph {
    ?masterGraph rdf:type teamwork:Vocabulary .}
FILTER NOT EXISTS {
    GRAPH ?masterGraph {
      ?s edg:subjectArea ?o .
    }
  }
  FILTER (STRSTARTS(STR(?masterGraph),"urn:x-evn-master:") &&(!STRENDS(STR(?masterGraph),"singleton")) )}`
  ).bindings.forEach(b => {
let masterGraph = b.masterGraph;
 console.log (b.masterGraph);
graph.transaction(b.masterGraph, 'Adding comment', () => {
 masterGraph.add(rdfs.comment, 'hello hello')
});
})


You need to switch the active graph, using graph.transaction as above.

HTH
Holger


Kasia Kryczka

unread,
Sep 21, 2023, 7:58:18 AM9/21/23
to TopBraid Suite Users
oh ok :)

Thank you!

Reply all
Reply to author
Forward
0 new messages