0

I'm new to SPARQL. I would like to get the preferred name of classes and their one top level upper classes and also their synonyms in the Radlex ontology, as hosted at BioPortal.

And The Output I want to see: output

Term: equal density subClassOf: density descriptor Synonym: isodens, equal-density,isodense

It looks like, the code below solved my problem, but still requires some modification. Because, it brings all off the upper classes but I only want one level upper class.

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT  ?concept ?subClassOf
WHERE
{ GRAPH <http://bioportal.bioontology.org/ontologies/RADLEX_OWL>
  { ?term  a <http://bioontology.org/projects/ontologies/radlex/radlexOwl#radlex_metaclass> ;
        <http://bioontology.org/projects/ontologies/radlex/radlexOwl#Preferred_name>  ?concept
  }
  ?term rdfs:subClassOf ?upperClass. 
  ?upperClass <http://bioontology.org/projects/ontologies/radlex/radlexOwl#Preferred_name>  ?subClassOf.
} LIMIT 10 OFFSET 10

2 Answers2

3

It looks like one of your main struggles is finding where to start, or how to specify the root of the Radlex subclasses.

I have no experience with Radlex, and I haven't been using Bioportal much recently. When I opened the Radlex ontology in Protege, its class hierarchy looked reasonable to me. But the results from the Bioportal endpoint are surprising.

For example, RID5635 "coin" is a subclass of RID5633 "personal item", and is an instance of radlex_metaclass, but not an instance of owl:Class, as I would expect from using OBO foundry ontologies. It doesn't look like all of the Radlex subclasses come from the radlex_metaclass, so that makes it trickier to get all of the subclasses with a single triple pattern like

?s a owl:Class

It also doesn't look like the Bioportal endpoint supports RDFS property paths, so we can't ask for

?s a rdfs:subClassOf* <http://bioontology.org/projects/ontologies/radlex/radlexOwl#RID1>

Therefore, I can't guarantee that this query returns all of the subclasses in Radlex... just all of the immediate subclasses of radlex_metaclass

Finally, as AKSW pointed out, http://bioontology.org/projects/ontologies/radlex/radlexOwl# is the name of the ontology, not a superclass. It doesn't have subclasses and is not a solution to the root finding problem I described at the top of this answer.

I added a named graph restriction, but that probably isn't doing anything that isn't already done by asking for http://bioontology.org/projects/ontologies/radlex/radlexOwl#radlex_metaclass instances.

SELECT DISTINCT  *
WHERE
  { GRAPH <http://bioportal.bioontology.org/ontologies/RADLEX_OWL>
      { ?radlexclass  a <http://bioontology.org/projects/ontologies/radlex/radlexOwl#radlex_metaclass> ;
            <http://bioontology.org/projects/ontologies/radlex/radlexOwl#Preferred_name>  ?prefName
      }
  }

gives results like this

+------------------------------------------------------------------------+---------------------------------------------------------------------+
|                              radlexclass                               |                              prefName                               |
+------------------------------------------------------------------------+---------------------------------------------------------------------+
| <http://bioontology.org/projects/ontologies/radlex/radlexOwl#RID19012> | "posterior root of left first sacral nerve"                         |
| <http://bioontology.org/projects/ontologies/radlex/radlexOwl#RID23593> | "nerve to third posterior cervical intertransversarius"             |
| <http://bioontology.org/projects/ontologies/radlex/radlexOwl#RID11053> | "hydrophilic wire"                                                  |
| <http://bioontology.org/projects/ontologies/radlex/radlexOwl#RID5825>  | "right"                                                             |
| <http://bioontology.org/projects/ontologies/radlex/radlexOwl#RID18947> | "posterior root of sixth cervical nerve"                            |
| <http://bioontology.org/projects/ontologies/radlex/radlexOwl#RID16116> | "set of short association fibers of telencephalon"                  |
| <http://bioontology.org/projects/ontologies/radlex/radlexOwl#RID23701> | "left third thoracic nerve"                                         |
| <http://bioontology.org/projects/ontologies/radlex/radlexOwl#RID23274> | "ascending branch of meningeal branch of right second sacral nerve" |
| <http://bioontology.org/projects/ontologies/radlex/radlexOwl#RID25244> | "right intermediomedial nucleus"                                    |
| <http://bioontology.org/projects/ontologies/radlex/radlexOwl#RID5699>  | "coalescent"                                                        |
+------------------------------------------------------------------------+---------------------------------------------------------------------+

etc.

Mark Miller
  • 3,011
  • 1
  • 14
  • 34
  • Thank you very much for your comment Mark! I just modified it and wrote the code below. It helped a lot. –  Jun 22 '17 at 23:44
  • Glad to hear it. Stick with it. Someday you will look back and ask "how did I ever manage without RDF and SPARQL?!" – Mark Miller Jun 23 '17 at 02:29
0
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX radlex: <http://bioontology.org/projects/ontologies/radlex/radlexOwlDlComponent#>

SELECT DISTINCT ?term ?name ?synonym ?subClassOf ?subClassOf_name
FROM <http://bioportal.bioontology.org/ontologies/RID>
WHERE
{
 ?term radlex:Preferred_name ?name .
 ?term radlex:Synonym ?synonym .
 ?term rdfs:subClassOf ?subClassOf .
 ?subClassOf radlex:Preferred_name ?subClassOf_name
} LIMIT 10
  • Are you sure?! What I see here on 2017-06-22T22:34:00-05:00 is not even valid SAPRQL. http://www.sparql.org says: 'Lexical error at line 5, column 189. Encountered: "\r" (13), after : "prefName"' And that's just the first error. I see at least one more after that. If you can edit the query to actually run, we can talk about how to get the desired amount of class-level detail. – Mark Miller Jun 23 '17 at 02:36
  • yes, that's much better. I'll look that over later today. Why don't you type out an example of the output you would like to see, with at lest a few real Radlex classes. – Mark Miller Jun 23 '17 at 16:56
  • And The Output I wanted to see: [output] **Term**: equal density **subClassOf**: density descriptor **Synonym**: isodens, equal-density,isodense –  Jun 23 '17 at 17:18
  • so you want all synonyms for a given subclass concatenated on the same line? do you know how to do aggregation of SPARQL results? you would use group_concat in that case. https://stackoverflow.com/questions/18212697/aggregating-results-from-sparql-query – Mark Miller Jun 23 '17 at 17:28
  • I was going step by step, but I could not even solve upper class problem. Thanks for the recommendation, I will study aggregation which I am not htat much familiar, yet. –  Jun 23 '17 at 17:44