diff --git a/ontology/ontology.json b/ontology/ontology.json new file mode 100644 index 0000000..9e4cae4 --- /dev/null +++ b/ontology/ontology.json @@ -0,0 +1,57 @@ +{ + "architecture": { + "rhythmanalysis": { + "circadian": { + "season": {}, + "time of day": {}, + "body rhythm": {}, + "weather": {} + }, + "the everyday": { + "activity": {}, + "animal": {}, + "architectural atmosphere": {}, + "architectural element": {}, + "architectural element action": {}, + "architectural element state": {}, + "bio": {}, + "building material": {}, + "building type": {}, + "camera height and angle": {}, + "camera movement": {}, + "clothing": {}, + "container": {}, + "cookware": {}, + "decor": {}, + "dramatic context": {}, + "element": {}, + "filming direction": {}, + "food and drink": {}, + "furniture": {}, + "homeware": {}, + "lived space": {}, + "location": {}, + "miscellaneous": {}, + "occupancy": {}, + "place": {}, + "scene tone": {}, + "tableware": {}, + "type": {} + } + } + }, + "cinema": { + "mise en scene": { + "dramatic mood": {}, + "character": {} + }, + "mise en cadre": { + "shoot": {}, + "shot type": {}, + "line": {}, + "shape": {}, + "space": {} + } + }, + "other": {} +} diff --git a/ontology/update.py b/ontology/update.py new file mode 100755 index 0000000..47125c6 --- /dev/null +++ b/ontology/update.py @@ -0,0 +1,68 @@ +#!/usr/bin/python3 +import json +import os +from collections import defaultdict + +def find_path(parent, root=None, path=None): + if root is None: + root = ontology + if path == None: + path = [] + for key in root: + if key == parent: + return path + [key] + elif root[key]: + r = find_path(parent, root[key], path + [key]) + if r: + return r + +def get_node(name, children): + node = { + "size": len(children) + 100, + "name": name, + "children": [get_node(child, children[child]) for child in children] + } + if not node['children']: + del node['children'] + return node + + +if __name__ == '__main__': + base = os.path.abspath(os.path.dirname(__file__)) + os.chdir(base) + + keywords = json.load(open('keywords.json')) + ontology = json.load(open('ontology.json')) + + tree = defaultdict(dict) + + for keyword in keywords: + if ': ' not in keyword: + parent = 'other' + child = keyword + else: + parent, child = keyword.split(': ') + path = find_path(parent) + if path: + p = tree + for part in path: + if part not in p: + p[part] = {} + p = p[part] + p[child] = {} + else: + print('missing root - %s: %s' % (parent, child)) + + #print(json.dumps(tree, indent=4, sort_keys=True)) + sized_ontology = { + "size": len(tree), + "name": "CineMuseSpace", + "children": [] + } + for name in tree: + children = tree[name] + child = get_node(name, tree[name]) + sized_ontology['children'].append(child) + + with open('../static/ontology/sized_ontology.json', 'w') as fd: + json.dump(sized_ontology, fd, indent=4, sort_keys=True) diff --git a/ontology/update_keywords.py b/ontology/update_keywords.py new file mode 100755 index 0000000..f0a5b07 --- /dev/null +++ b/ontology/update_keywords.py @@ -0,0 +1,46 @@ +#!/usr/bin/python3 + +import getpass +import json +import sys + +import ox +import ox.web.auth + +site = 'pandora.cinemusespace.com' +api = ox.API('https://%s/api/' % site) +update = False +try: + credentials = ox.web.auth.get(site) +except: + credentials = {} + print('Please provide your username and password for %s:' % site) + credentials['username'] = input('Username: ') + credentials['password'] = getpass.getpass('Password: ') + update = True +r = api.signin(**credentials) +if 'errors' in r.get('data', {}): + for kv in r['data']['errors'].items(): + print('%s: %s' % kv) + sys.exit(1) +if update: + ox.web.auth.update(site, credentials) + +keywords = set() +for annotation in api.findAnnotations({ + 'query': { + 'conditions': [{ + 'key': 'layer', + 'value': 'keywords', + 'operator': '==' + }], + 'operator': '&' + }, + 'keys': ['id', 'in', 'out', 'value', 'user', 'created'], + 'range': [0, 500000] +})['data']['items']: + keywords.add(annotation['value']) + + +with open('keywords.json', 'w') as fd: + json.dump(list(sorted(keywords)), fd, indent=4) diff --git a/static/ontology/index.css b/static/ontology/index.css new file mode 100644 index 0000000..e821750 --- /dev/null +++ b/static/ontology/index.css @@ -0,0 +1,16 @@ +.node circle { + fill: #fff; + stroke: steelblue; + stroke-width: 1.5px; +} + +.node { + cursor: pointer; + font: 10px sans-serif; +} + +.link { + fill: none; + stroke: #ccc; + stroke-width: 1.5px; +} diff --git a/static/ontology/index.html b/static/ontology/index.html new file mode 100644 index 0000000..b2e3f28 --- /dev/null +++ b/static/ontology/index.html @@ -0,0 +1,12 @@ + + +
+ + + +