Published
Edited
Sep 28, 2021
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof destroySchemaButton = Button(`destroy Schema`, {value: "⬇️ click to destroy schema", reduce: async () => {
await destroySchema()
return `schema destroyed 💥`
}})
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
schema = ({
Entity: {
label: 'Entity', // uses key/id if label isn't given
props: {
broader: {
type: 'Entity'
},
image: {
label: 'image',
description: 'image of entity',
type: 'Image'
},
cover: {
description: 'cover image of entity shown in workbench',
type: 'Image'
}
},
subclasses: {
Event: {
subclasses: {
Production: {
props: {
inputs: {
type: 'Concept'
},
uses: {
type: 'Object'
},
outputs: {
type: 'Concept'
},
takesPlaceIn: {
label: 'takes place in',
type: 'Place'
}
}
}
}
},
Person: {
schemaProps: {
wd: 'wd:Q5',
background: 'yellow',
text: 'indigo',
light: true
},
props: {
placeOfBirth: {
label: 'place of birth',
type: 'Place',
schemaProps: {
wdt: 'wdt:P19'
}
},
placeOfDeath: {
label: 'place of death',
type: 'Place',
schemaProps: {
wdt: 'wdt:P20'
}
},
GND: {
type: 'xdd:url',
}
}
},
PhysicalThing: {
label: 'Physical Thing',
subclasses: {
Artefact: {
schemaProps: {
background: 'blue',
text: 'teal',
light: false
},
props: {
exemplifies: {
type: 'Object'
},
hasFormerOrCurrentOwner: {
label: 'has former or current owner',
type: 'Person'
},
hasFormerOrCurrentLocation: {
label: 'has former or current location',
type: 'Place'
},
consistsOf: {
label: 'consists of',
type: 'Material'
},
idEM: {
label: 'id EM',
description: 'id (Ident_ Nr_) used by the Ethnological Museum of Berlin',
type: 'xsd:string'
}
}
}
}
},
Concept: {
subclasses: {
Object: {
schemaProps: {
background: 'red',
text: 'yellow',
light: false
}
},
Material: {
schemaProps: {
background: 'magenta',
text: 'red',
light: true
}
}
}
},
Place: {
schemaProps: {
wd: 'wd:Q2221906',
background: 'orange',
text: 'blue',
light: true
}
}
}
},
File: {
props: {
url: {
type: 'xdd:url'
},
path: {
type: 'xsd:string'
}
},
subclasses: {
Image: {}
}
},
View: {
description: 'A collection of Cards in a workbench canvas',
props: {
cards: {
type: 'Card'
}
},
},
Card: {
object: true,
description: 'An instance of an entity in the workbench',
props: {
entity: {
type: 'Entity',
},
x: {
type: 'xsd:decimal'
},
y: {
type: 'xsd:decimal'
},
collapsed: {
type: 'xsd:boolean'
}
},
}
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function parseSchemaProps (schema) {
return Object.keys(schema).map(id => {
const doctype = schema[id]
const propProps = doctype.props ? Object.keys(doctype.props).map(id => {
const prop = doctype.props[id]
return Object.keys(prop.schemaProps || {}).map(key => {
return [
`scm:${id}`,
`scm:${key}`,
typeof prop.schemaProps[key] === 'boolean' ? {'@type': 'xsd:boolean', '@value': prop.schemaProps[key]} : `${prop.schemaProps[key]}`
]
})
}) : []
const classProps = [Object.keys(doctype.schemaProps || {}).map(key => {
return [
`scm:${id}`,
`scm:${key}`,
typeof doctype.schemaProps[key] === 'boolean' ? {'@type': 'xsd:boolean', '@value': doctype.schemaProps[key]} : `${doctype.schemaProps[key]}`
]
})]
const subclassProps = doctype.subclasses ? parseSchemaProps(doctype.subclasses) : []
return [classProps, propProps, ...subclassProps]
}).flat()
.filter(quad => quad.length > 0)
}
Insert cell
async function createSchema() {
Client.db(database)
const res = await query(WOQL.and(
...schemaProps.map(eqProp => WOQL.insert_property_data(eqProp)),
...doctypes.map(doctype => WOQL.insert_doctype_data(doctype)),
...objects.map(object => WOQL.insert_class_data(object)),
...props.map(prop => WOQL.insert_property_data(prop)),
...eqs.map(eq => WOQL.add_quad(...eq, 'schema/main'))
))
return res
}
Insert cell
async function destroySchema() {
Client.db(database)
const res = await query(WOQL.nuke("schema/main"))
return res.bindings
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more