...
An example JSON Schema that describes products might look like:
Code Block |
---|
{
"name":"Product",
"properties":{
"id":{
"type":"number",
"description":"Product identifier",
"required":true
},
"name":{
"description":"Name of the product",
"type":"string",
"required":true
},
"price":{
"required":true,
"type": "number",
"minimum":0,
"required":true
},
"tags":{
"type":"array",
"items":{
"type":"string"
}
}
},
"additionalProperties":{
"releaseStatus":{
"type":"string",
"description":"The release status of a product",
"enum":[ "PROTOTYPE", "RELEASED", "RECALLED", DEPRECIATED"]
}
}
}
|
...
Code Block |
---|
// This class represents a JSON Schema as defined by: http://tools.ietf.org/html/draft-zyp-json-schema-03
class ObjectSchema {
...
// This map defines the primary fields of an Object
Map<String, ObjectSchema> properties;
// This map defines the additional Annotations of an Object.
Map<String, ObjectSchema> additionalProperties;
...
}
|
...
A new entity will be created by first creating a new JSON text file in the lib-auto-generated project's src/main/resources folder. Folder hierarchies should be used to represent the equivalent of "packages" for each entity.
The following example show where a Dataset an Example entity might be created:
Code Block |
---|
/lib-auto-generated/src/main/resource/org/sagebionetworks/entity/type/Example.json
|
Lets say we also want to define an Annotation type and use it to help define our Example.json. This annotation type definition JSON text file might be created in the following location:
Code Block |
---|
/lib-auto-generated/src/main/resource/org/sagebionetworks/annotation/types/BioOntologyTissueType.json
|
Before we look at the definition of our Example.json let's first look at the definition of our new BioOntologyTissueType.json. For this example we want to use an external ontology to control the valid values for
BioOntologyTissueType.json
Code Block |
---|
{
"type":"string",
"format":"uri",
"enum":["SPARQL":"
PREFIX abc: <http://purl.bioontology.org/ontology/MCCL#>
SELECT ?uri
WHERE {
?y abc:FullId ?uri ;
abc:isA abc:/FMA_9637 .
}
"]
}
|
In this example, we can see that we expect the values to be URI strings limited to the values returned from a SPARQL query. In this case, the SPARQL query translates to the following:
Code Block |
---|
Find all URIs from the http://purl.bioontology.org/ontology that are classified as "Is A" Tissue (Tissue is defined as http://purl.bioontology.org/ontology/MCCL/FMA_9637).
|
Now that we have defined an Annotation Type for Tissue's defined by the http://purl.bioontology.org/
...
ontology, we can now use this type to define an entity.
Here is our definition of our example Entity:
Example.json
Code Block |
---|
{
"extends":"org/sagebionetworks/entity/type/Entity.json"
"name":"Product",
"properties":{
"id":{
"type":"number",
"description":"Example identifier",
"required":true
},
"name":{
"description":"Name of the Example",
"type":"string",
"required":true
},
},
"additionalProperties":{
"tissue":{
"type":"object",
"$ref":"org/sagebionetworks/annotation/types/BioOntologyTissueType.json"
}
}
}
|
The first thing to point out about our Example.json is that it extends Entity.json, which makes it a Synapse Entity. This implies it inherits all of its values from the base Entity. The second thing to point out is that it defines a type called "tissue" in its additional properties that is based on the annotation type we defined earlier.