query{
conceptSchemes{
label
}
}
Hi,
I work for Minerva Intelligence and I have a question about GraphQL. I have been able to run a few queries on our endpoint to return basic information from our taxonomies for ex.
query{
conceptSchemes{
label
}
}
which shows me every Concept Scheme, indicating endpoint is active. But instead I would like to do the following:
- Return all Concepts for an Specific Scheme
You can access a specific resource with the (uri: "...") argument, e.g.
{
conceptSchemes(uri:
"http://topquadrant.com/ns/examples/geography#Geography") {
label
}
}
Now, getting the root concepts is simple
{
conceptSchemes(uri:
"http://topquadrant.com/ns/examples/geography#Geography") {
label
hasTopConcept {
label
}
}
}
while getting all concepts that are (recursively) children of the root concepts is harder without some extra adjustments. This solution here would give you the first level of children
{
conceptSchemes(uri:
"http://topquadrant.com/ns/examples/geography#Geography") {
label
hasTopConcept {
label
narrower {
label
}
}
}
}
yet GraphQL isn't designed to return arbitrary nesting, as the structure of the query needs to reflect the structure of the resulting JSON. If you want to get a "flat" list of every concept under a certain schema, then you'd either need to extend the GraphQL schema by a new field that would allow you to flatten the structure, or fall back to SPARQL. In SPARQL this would be
SELECT DISTINCT ?concept ?label
WHERE {
<http://topquadrant.com/ns/examples/geography#Geography>
skos:hasTopConcept ?topConcept .
?concept skos:broader* ?topConcept .
BIND (ui:label(?concept) AS ?label)
} ORDER BY ?label
which is possible because SPARQL has a * operator that recursively walks a property.
To ask a similar query in GraphQL, the schema can be extended to create a similar "flattened" field such as narrowerTransitive, which would be inferred using a sh:values rule. In fact, the next TopBraid release will have such a field, and it's defined in SHACL using
skosgeneric:Concept-narrowerTransitive
rdf:type sh:PropertyShape ;
sh:path skos:narrowerTransitive ;
sh:description "Gets the concept plus all narrower concepts,
recursively." ;
sh:name "narrower transitive" ;
sh:node skosgeneric:Concept ;
sh:nodeKind sh:IRI ;
sh:values [
sh:path [
sh:zeroOrMorePath [
sh:inversePath skos:broader ;
] ;
] ;
] ;
.
If this type of query is what you need, I could prepare a patch
for you.
- Return Broader or Narrower for an Specific Concept and for an Specific Scheme
As I said above, you can access a specific concept or scheme using uri:"...". For example
{
concepts (uri:
"http://topquadrant.com/ns/examples/geography#Germany") {
label
narrower {
label
}
broader {
label
}
}
}
More documentation can be found in the Tutorial link near the GraphQL link in TopBraid EDG, or online at
https://www.topquadrant.com/graphql/graphql-queries.html
HTH
Holger
This is a new installation of TopBraid and we have just added some Taxonomies through the Import RDF File option.
Very much appreciated,
Mike
--
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/91ebb5d5-be47-4302-b67e-3e4075cc4945%40googlegroups.com.
{
conceptSchemes(uri: "http://resource.geosciml.org/classifierscheme/cgi/2016.01/earth-resource-expression") {
label
hasTopConcept {
label
narrower {
label
narrower {
label
narrower {
label
}
}
}
}
}
}
Hi Holger,
My final intention is to get data in the shape of a tree. Based on your example I managed to explore a taxonomy many levels down just by adding the following:
{
conceptSchemes(uri: "http://resource.geosciml.org/classifierscheme/cgi/2016.01/earth-resource-expression") {
label
hasTopConcept {
label
narrower {
label
narrower {
label
narrower {
label
}
}
}
}
}
}
This is fine since I know how many levels deep I have to go.
Can I do the same with an Ontology, and can you help we with a base querie as well please?
I noticed GRAPQL for ontologies requires a Shape/Class, but the list available doesn't reflect the structure of my ontology. I'm not sure what's the right step here
Up until 6.2 there is no way to query Ontologies with GraphQL. In 6.3 we have added that ability using the so-called metashapes schema.
To query a subclass hierarchy in 6.2 or earlier, you'll need to
use SPARQL. However, you cannot use SPARQL to produce a JSON tree
structure. To produce arbitrary JSON we do have a technology
called SWP with its SWON library. If you tell me what kind of
input you have (a superclass or all classes?) and what output you
need, I can send you an SWP script to produce such query web
services.
Holger
Much appreciated,
Mike
--
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/8a770baf-5f0a-48c4-8385-7ad925c626e8%40googlegroups.com.
Enter code here...Regards,
Mike
On Dec 2, 2019, at 8:28 PM, MB MB <bendor...@gmail.com> wrote:
Hi Holger,Thanks for your help so far. Even if there is a pure SPARQL version we can work out a JSON tree from it, but we are also interested in the SWP version as well. For this example we can use:Default namespace: http://example.org/ontologies/mike_test_2#Top Class: http://www.w3.org/2002/07/owl#Thing (I don't know if you need this)This is how our EDG console looks like.
<Capture.PNG>
Enter code here...By querying any of the available end points, we are looking to get back a JSON object similar to what EDG displays on the console.
<Capture.PNG>
Regards,
Mike
--
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/5675bed8-ef0e-42f9-95b4-001f092aeb75%40googlegroups.com.
<Capture.PNG><Capture.PNG>
In addition to what Irene said about GraphQL, note that our (class) tree components only ever load one level at a time, so a "flat" query is sufficient to return the immediate children of each parent node.
To produce a recursive JSON structure of arbitrary depth you need
something like SWP, creating a SWON-based element that calls
itself. However, this should be made solid against infinite
recursion, i.e. record which nodes have already been reached in
something like ui:tempGraph. I don't have an example of that
pre-built but could produce one if you are interested.
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/5675bed8-ef0e-42f9-95b4-001f092aeb75%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/topbraid-users/WbSBy-qqr0E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/2ff93add-a3f1-5472-1b46-dcf354cb95ec%40topquadrant.com.
Please find a solution using SWP attached. The bulk of the work is done via

which recursively calls itself for all children. The tempGraph is used to prevent infinite cycles (I think).
Put the file into your workspace and refresh services or restart, then call something like
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/CADoe7Nt5oZyL6c1PmxbUtBuhGtf1zDC_YgLjufVxNg_Y-%2BtRiQ%40mail.gmail.com.