GraphQL

75 views
Skip to first unread message

Mike Bendorf

unread,
Oct 18, 2019, 7:29:07 PM10/18/19
to TopBraid Suite Users
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
- Return Broader or Narrower for an Specific Concept and for an Specific Scheme

This is a new installation of TopBraid and we have just added some Taxonomies through the Import RDF File option.

Very much appreciated,
Mike

Holger Knublauch

unread,
Oct 18, 2019, 9:32:06 PM10/18/19
to topbrai...@googlegroups.com


On 19/10/2019 09:27, Mike Bendorf wrote:
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.

Mike Bendorf

unread,
Oct 23, 2019, 2:25:50 PM10/23/19
to TopBraid Suite Users
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

Much appreciated,

Mike

Holger Knublauch

unread,
Oct 23, 2019, 7:13:13 PM10/23/19
to topbrai...@googlegroups.com


On 24/10/2019 04:25, Mike Bendorf wrote:
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.
Ok good.


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.

MB MB

unread,
Dec 2, 2019, 8:34:28 PM12/2/19
to TopBraid Suite Users
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:

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



Irene Polikoff

unread,
Dec 2, 2019, 8:54:52 PM12/2/19
to topbrai...@googlegroups.com
6.3 will be released soon.

With it, you will be able to query class hierarchy the same way as you query taxonomy

For example:

{
    uri
    superClassOf {
      uri
      superClassOf {
        uri
      }
    }
  }
}

Gives you owl:Thing and two levels down. You can also use something else as a root.


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:

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>

Holger Knublauch

unread,
Dec 2, 2019, 8:59:48 PM12/2/19
to topbrai...@googlegroups.com

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.

MB MB

unread,
Dec 3, 2019, 3:47:06 PM12/3/19
to topbrai...@googlegroups.com
Hi Holger,

Yes, please do so. That would be great

Mike

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.

Holger Knublauch

unread,
Dec 3, 2019, 8:27:13 PM12/3/19
to topbrai...@googlegroups.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

http://localhost:8083/tbl/swp?_viewClass=classTreeJSON:getClassTreeJSON&rootClass=owl:Thing&_base=http://topbraid.org/examples/kennedys&_withImports=true

HTH
Holger
classTreeJSON.ui.ttlx
Reply all
Reply to author
Forward
0 new messages