SPARQL/REST services(s) to traverse through Hierarchical Vocabularies

371 views
Skip to first unread message

sanjeev devireddy

unread,
Mar 27, 2017, 10:18:48 AM3/27/17
to TopBraid Suite Users
Hi,
There is a requirement to generate a HTML page as shown below for a given vocabulary. So I just want check that, are there any SPARQL / REST services to traverse through all the Subjects/Nodes with predicates and objects of a given vocabulary.

In specific, we are looking for SPARQL/REST service(s) to achieve the following,
1) One SPARQL/REST service to get all Top-level/Root Subjects with all of their Predicates and Objects
2) One SPARQL/REST service to get Descendant Subjects with all of their Predicates and Objects of a given parent.

We want to make this implementation as much as generic. I means by passing the name/Graph URI of a given vocabulary, the same SPARQL/REST services should be able to return the respective vocabulary's desired data.

Thanks,

                                                                 EVN Vocabulary




Desired HTML Page




Pat Doyle

unread,
Mar 27, 2017, 5:05:23 PM3/27/17
to TopBraid Suite Users
Sanjeev,

This can be done with a combination of a few of our different built in services. All of our services allow for a _base parameter, which denotes the base graph upon which to run the service against - so they can be run generically against any graph we choose. 

skostemplate:RootConcepts will return all of the root concepts for you.  For 5.3 - we've added skosTemplate:TopConcepts - which will return the same result for Taxonomies in a slightly more performant manner.  

skostemplate:NarrowerConcepts will return all of the children of a specific concept for you. 

Information on the skostemplate services can be found here (with TBCME running):

The ones we're interested in are under the 'TopBraid SKOS Templates' heading.  

the DESCRIBE servlet can be used to return all of the information about a specific concept - so we can use this to get all of the predicates/objects for a specific item.  More information on this can be found in TBCME Help under TopBraid Composer -> TopBraid Live Integration -> The DESCRIBE servlet.


Ultimately, you could do something like this:
1) get all roots
2) get all info about a root
3) get all children of the root
4) get all info about each child and go back to 3

1 would be achieved with skostemplate:RootConcepts, 3 would be achieved with skostemplate:NarrowerConcepts, and 2 and 4 would be achieved with the DESCRIBE servlet.  If you want to user a smaller number of services, you also have the option of writing your own.

Hope it helps,
Pat

--
You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include the TopBraid Suite family of products and its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
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-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sanjeev devireddy

unread,
Mar 31, 2017, 12:32:22 AM3/31/17
to TopBraid Suite Users
Thanks Pat, we will try that.

Thanks,
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.

sanjeev devireddy

unread,
Apr 3, 2017, 10:58:09 AM4/3/17
to TopBraid Suite Users
Pat,
Regarding the DESCRIBE servlet, the service http://localhost:8083/tbl/describe?_resource=http://topquadrant.com/ns/examples/geography%23Japan&_format=application%2Frdf%2Bxml&_base=urn:x-evn-master:geo returns some property names with prefixes (as shown below). So it is bit difficult to remove those prefixes and then to display those property names to the end users .





I just want to check that is there a way to get the property names with out the prefixes(as displayed in the screen shot of EVN UI below).




 

On Tuesday, March 28, 2017 at 2:35:23 AM UTC+5:30, Pat Doyle wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
Auto Generated Inline Image 1
Auto Generated Inline Image 2

Pat Doyle

unread,
Apr 3, 2017, 3:13:29 PM4/3/17
to TopBraid Suite Users
Sanjeev,

The swa:GetLabel call allows you to return a user friendly label for a specific property.  This is listed under the 'SWA SPIN Modules' heading on the Available Web Services page.  

Once you have the result from the DESCRIBE servlet, you could build a URI and make a call like this to get the user friendly label:

With that being said, you also have full capabilities to write your own web services to return data in exactly the format you'd like.  Instead of using the DESCRIBE servlet, you could create a reusable SPIN template with a SPARQL query like this:

SELECT * WHERE {
GRAPH <urn:x-evn-master:geo> {
BIND (ui:label(?p) AS ?label)
}
}

This would return the results for Japan in a format with the more user-friendly predicate labels already associated with the specific values.  This could be extended to, instead of having Japan hardcoded in - allow for a resource parameter to be passed in at runtime.  More information on the SPIN template service can be found in the help under TopBraid Composer --> TopBraid Live Integration --> SPIN Template Service


Regards, 
Pat

To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-users+unsubscribe@googlegroups.com.

sanjeev devireddy

unread,
Apr 7, 2017, 11:28:04 AM4/7/17
to TopBraid Suite Users
Thanks Pat, for the suggestion.
   By following the documentation given in the link http://uispin.org/swon.html , we are able to implement our own REST services, which can return the JSON output type in a desired structure.
   But We are facing an issue with the service skostemplate:RootConcepts and the SPARQL associated with it. This service/SPARQL returns the expected results(root concepts) with the EVN's example vocabularies like Geography Vocabulary, IPTC News Codes. But the same service/SPARQL returns the empty result set when tried with our Vocabularies. 

At the same time, the skostemplate:BroaderConcepts (spin:SelectTemplate) service and the SPARQL associated with returns the expected results with our Vocabularies also.

So I just want to check that, is there any protocol/standard need to be followed while creating the vocabularies? So that the available REST services/SPARQLs return expected results for all the vocabularies.

Thanks,

Holger Knublauch

unread,
Apr 9, 2017, 8:02:05 PM4/9/17
to topbrai...@googlegroups.com
You can explore what is expected by these templates if you open the file

    teamwork.topbraidlive.org\taxonomy\spin\skostemplates.spin.ttl

in TBC. You can see that skostemplate:RootConcepts has the following spin:body:

SELECT DISTINCT ?result
WHERE {
    ?type (rdfs:subClassOf)* skos:Concept .
    ?result a ?type .
    FILTER NOT EXISTS {
        ?result skos:broader ?parent .
    } .
}

So if you have zero results then there is no instance of skos:Concept that does not have any skos:broader values. Some SKOS files that I have seen declare root concepts to have a ConceptScheme as their skos:broader, so maybe this is what's going on for your examples.

HTH
Holger

Irene Polikoff

unread,
Apr 9, 2017, 9:03:35 PM4/9/17
to topbrai...@googlegroups.com
Another way to get this info, is by looking at the Administration screen -> Available web services.

sanjeev devireddy

unread,
Apr 13, 2017, 1:55:29 AM4/13/17
to TopBraid Suite Users
Hi Holger,
  You said that Some SKOS files that you have seen declare root concepts to have a ConceptScheme as their skos:broader and that may be the same case with our examples.
     Actually for any Vocabulary there is an option to export in JSON-LD, N-Triples, RDF/XML & Turtle formats but I have no idea on how to get the SKOS file of a Vocabulary. Could you please help us on how to get the SKOS file of a Vocabulary?
      Here is an example of our Vocabulary(AbcVocabulary) in ttl format. I hope it could give some basic idea on how our vocabulary is structured. If not, please let me know list of things that I can check and come back to you.



Thanks,
sanjeev
Auto Generated Inline Image 1

Holger Knublauch

unread,
Apr 13, 2017, 2:02:17 AM4/13/17
to topbrai...@googlegroups.com


On 13/04/2017 15:55, sanjeev devireddy wrote:
Hi Holger,
  You said that Some SKOS files that you have seen declare root concepts to have a ConceptScheme as their skos:broader and that may be the same case with our examples.
     Actually for any Vocabulary there is an option to export in JSON-LD, N-Triples, RDF/XML & Turtle formats but I have no idea on how to get the SKOS file of a Vocabulary. Could you please help us on how to get the SKOS file of a Vocabulary?

There is no format called SKOS. SKOS is just an instance of RDF, and can be written in Turtle and the other RDF formats. What would you expect a SKOS file to contain?


      Here is an example of our Vocabulary(AbcVocabulary) in ttl format. I hope it could give some basic idea on how our vocabulary is structured. If not, please let me know list of things that I can check and come back to you.

Your file doesn't indicate whether first and second have the ConceptSchema as their skos:broader triple. But you should also be able to see that from the UI.

Holger

sanjeev devireddy

unread,
Apr 13, 2017, 2:47:54 AM4/13/17
to TopBraid Suite Users
Hi Holger,
     Please check the below screen shot. I hope you are asking about the the same UI view. If not please let me know then I will get that view. At least in this view there is no skos:broader property/triple.
   Actually, I don't see a property called skos:broader (in our example the prefix is j.2 for skos/core) for all the Top Concepts in the ttl file, which is similar to the Geography Vocabulary(EVN's example vocabulary) Top Concepts.




Thanks,
Auto Generated Inline Image 1

sanjeev devireddy

unread,
Apr 13, 2017, 3:23:05 AM4/13/17
to TopBraid Suite Users
Hi Holger,
     One thing that we observed is that by removing the line (?type (rdfs:subClassOf)* j.2:Concept  .) from the SPARQL, it returns all the required Top Concepts (no other Concepts) of our Vocabulary but it also returns some unwanted values like URN of the Vocabulary, urn:x-search, etc.. as shown in the below screen shot.

SPARQL:

PREFIX j.2: <http://www.w3.org/2004/02/skos/core#>
SELECT DISTINCT ?result
            WHERE {
                GRAPH <urn:x-evn-master:AbcVocabulary> {

                    ?result a ?type .
                    FILTER NOT EXISTS {
                        ?result j.2:broader ?parent .
                    } .
                } .
}





Thanks,
sanjeev
Auto Generated Inline Image 1

sanjeev devireddy

unread,
Apr 13, 2017, 6:54:53 AM4/13/17
to TopBraid Suite Users
Hi Holger,
        Another observation is that in the SPARQL when the rdf:type of the Top Concepts is specified instead of skos:concept in the line (?type (rdfs:subClassOf)* skos:Concept  .) then the SPARQL returns the expected results. But this SPARQL can't be generic(to work with any vocabulary). Or we may need to go by work around like, first find the rdf:type of the root concepts of a Vocabulary every time and use that rdf:type in this SPARQL. Please check and let us know your observations. 

SPARQL

SELECT DISTINCT ?result
            WHERE {
                GRAPH <urn:x-evn-master:AbcVocabulary> {
                    ?type (rdfs:subClassOf)* <http://example.org/pqr#Topic> .

                    ?result a ?type .
                    FILTER NOT EXISTS {
                        ?result skos:broader ?parent .
                    } .
                } .
            }



Thanks,
sanjeev

Irene Polikoff

unread,
Apr 13, 2017, 7:01:26 AM4/13/17
to topbrai...@googlegroups.com
Sanjeev,

JSON-LD, N-Triples, RDF/XML & Turtle are serialization formats for RDF. SKOS is not a serialization format, it is an industry standard vocabulary that is used to describe your vocabulary, meaning your concepts and their relationships. It has a few classes, but primarily, it gives you predicates to use in describing your vocabulary, such as skos:prefLabel, skos:note, skos:broader. As long as you are using this vocabulary, any file you export is said to be a SKOS file, irrespective of the serialization format.

Irene

Sent from my iPhone
<Auto Generated Inline Image 1>

Irene Polikoff

unread,
Apr 13, 2017, 9:29:39 AM4/13/17
to topbrai...@googlegroups.com
Hi Sanjeev,

Your query looks OK, but as you said it will not be generic unless every vocabulary uses instances  <http://example.org/pqr#Topic> as top concepts.

  If you are using classes that are not subclasses of skos:Concept, than the standard service would not work. Would it be a problem for you to make http://example.org/pqr#Topic> sub class of skos:Concept?

There is also another possibility of a generic query. If you are using TopBraid EVN, than you must be using skos:ConceptScheme and there is a skos:hasTopConcept relationship between it and the top concepts. If so, you can try simply:

SELECT DISTINCT ?result
            WHERE {
                GRAPH <urn:x-evn-master:AbcVocabulary> {
                    ?scheme a skos:ConceptScheme .
                    ?scheme skos:hasTopConcept ?result .
                } .
            }

sanjeev devireddy

unread,
Apr 14, 2017, 2:47:54 AM4/14/17
to TopBraid Suite Users
Hi Irene,
        Normally we follow the same structure like create one main class(in the below example it is MainConcept) as subclass of skos:Concept (http://www.w3.org/2004/02/skos/core#Concept) and then all our remaining classes are as sub classes of our main class as shown in the below screen shot. But not sure why our classes are not recognized as sub classes of  skos:Concept by that Root Concepts service/SPARQL.
        Any way, the other SPARQL that you gave with skos:ConceptScheme and skos:hasTopConcept  works fine to get Root/Top Concepts of our Vocabularies. I tried with 3 of our vocabularies, to which I have access and I hope it works with all the other vocabularies also that are available in our EVN instance.

       Thanks a lot for the SPARQL and the simple, clear explanation of SKOS.




Thanks,
sanjeev
Auto Generated Inline Image 1

Holger Knublauch

unread,
Apr 14, 2017, 2:52:44 AM4/14/17
to topbrai...@googlegroups.com


On 14/04/2017 16:47, sanjeev devireddy wrote:
Hi Irene,
        Normally we follow the same structure like create one main class(in the below example it is MainConcept) as subclass of skos:Concept (http://www.w3.org/2004/02/skos/core#Concept) and then all our remaining classes are as sub classes of our main class as shown in the below screen shot. But not sure why our classes are not recognized as sub classes of  skos:Concept by that Root Concepts service/SPARQL.

Are all subclass definitions in the same graph? If they are imported from some other graph (e.g. an Ontology) you may want to verify that when you run SPARQL queries that these queries operate on the union graph, not just the "base" graph. To get a graph with imports, use something like

BIND (ui:graphWithImports(<myBaseGraph>) AS ?graph) .
GRAPH ?graph {
    ...
}

(Speculating)

Holger

sanjeev devireddy

unread,
Apr 14, 2017, 5:39:51 AM4/14/17
to TopBraid Suite Users
Many Thanks Holger,
        By adding the line BIND (ui:graphWithImports(<myBaseGraph>) AS ?graph) . to the Root Concepts SPARQL, it works with our vocabularies also. Since the SPARQL works by adding that new line so I assume some/all sub classes are imported from some other graph (e.g. an Ontology). Actually we(developers) are not involved in Vocabulary/Ontology designing, so I will check with our ontologist on this.
  

Thanks,
sanjeev
Reply all
Reply to author
Forward
0 new messages