ncbo / ncbo_rest_sample_code

Sample code that demonstrates the use of the NCBO REST services
http://data.bioontology.org/documentation
40 stars 33 forks source link

Java examples: CreateMapping throws java.lang.Exception #6

Open jvendetti opened 7 years ago

jvendetti commented 7 years ago

Executing the main method in CreateMapping.java results in the following exception:

java.lang.Exception: {"errors":["Input does not contain classes"],"status":400}
    at CreateMapping.postJSON(CreateMapping.java:98)
    at CreateMapping.main(CreateMapping.java:51)
jvendetti commented 7 years ago

Looks like the sample code stopped working after this Aug., 2014 commit:

https://github.com/ncbo/ontologies_api/commit/af851ffaee43450b18ea847539e653ffeae27dce#diff-2c60916f20816a3d25cac7bafac3b587

... changed one of the required input parameter names from "terms" to "classes".

jvendetti commented 6 years ago

On further recent investigation, the exception results not just from a change in parameter names for the /mappings endpoint. The example code is also generating JSON that's not compliant with what the endpoint is expecting. This is an example of the JSON that's currently generated:

{
  "creator" : "http://stagedata.bioontology.org/user/vendetti",
  "relation" : "http://www.w3.org/2002/07/owl#sameAs",
  "source" : "MY_USER",
  "source_name" : "MyUsers's Mapping Data",
  "comment" : "This mapping creates a same as mapping between melanoma (NCIT) and melanoma (SNOMEDCT)",
  "terms" : [ {
    "ontology" : "NCIT",
    "class" : [ "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C8711" ]
  }, {
    "ontology" : "SNOMEDCT",
    "class" : [ "http://purl.bioontology.org/ontology/SNOMEDCT/372244006" ]
  } ]
}

... and this is an example of the JSON structure that the mappings endpoint requires:

{
  "creator" : "http://data.bioontology.org/user/vendetti",
  "relation" : "http://www.w3.org/2002/07/owl#sameAs",
  "source" : "vendetti",
  "source_name" : "Jennifer's Test Mapping Data",
  "comment" : "Creates a same as mapping between Melanoma (NCIT) and Malignant melanoma (SNOMEDCT)",
  "classes" : { 
    "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C3224" : "NCIT",
    "http://purl.bioontology.org/ontology/SNOMEDCT/2092003":"SNOMEDCT"
  }
}