work in progress: relationships
This commit is contained in:
parent
dfc5cefcee
commit
e676e10e33
3 changed files with 16 additions and 3 deletions
|
@ -7,6 +7,8 @@ from scopes.interfaces import IContainer
|
||||||
from scopes.storage.common import registerContainerClass, registry
|
from scopes.storage.common import registerContainerClass, registry
|
||||||
from scopes.storage.tracking import Container, Track
|
from scopes.storage.tracking import Container, Track
|
||||||
|
|
||||||
|
defaultPredicate = 'standard'
|
||||||
|
|
||||||
|
|
||||||
class Concept(Track):
|
class Concept(Track):
|
||||||
|
|
||||||
|
@ -21,6 +23,10 @@ class Concept(Track):
|
||||||
def values(self):
|
def values(self):
|
||||||
return (t.getSecond() for t in self.children(Rels.defaultPredicate))
|
return (t.getSecond() for t in self.children(Rels.defaultPredicate))
|
||||||
|
|
||||||
|
def addChild(self, child, predicate = defaultPredicate):
|
||||||
|
rels = self.container.storage.getContainer(Triple)
|
||||||
|
rels.save(Triple(self.uid, child.uid, predicate))
|
||||||
|
|
||||||
|
|
||||||
class Concepts(Container):
|
class Concepts(Container):
|
||||||
|
|
||||||
|
@ -52,8 +58,6 @@ class Predicates(Concepts):
|
||||||
tableName = 'preds'
|
tableName = 'preds'
|
||||||
|
|
||||||
|
|
||||||
defaultPredicate = 'standard'
|
|
||||||
|
|
||||||
def storePredicate(storage, name):
|
def storePredicate(storage, name):
|
||||||
preds = storage.getContainer(Predicate)
|
preds = storage.getContainer(Predicate)
|
||||||
preds.save(Predicate(name))
|
preds.save(Predicate(name))
|
||||||
|
|
|
@ -20,8 +20,12 @@ class Track(object):
|
||||||
headFields = ['taskId', 'userName']
|
headFields = ['taskId', 'userName']
|
||||||
prefix = 'rec'
|
prefix = 'rec'
|
||||||
|
|
||||||
def __init__(self, *keys, data=None, timeStamp=None, trackId=None, container=None):
|
def __init__(self, *keys, data=None, timeStamp=None, trackId=None,
|
||||||
|
container=None, **kw):
|
||||||
self.head = {}
|
self.head = {}
|
||||||
|
for k, v in kw.items():
|
||||||
|
if k in self.headFields:
|
||||||
|
self.head[k] = kw.pop(k)
|
||||||
for ix, k in enumerate(keys):
|
for ix, k in enumerate(keys):
|
||||||
self.head[self.headFields[ix]] = k
|
self.head[self.headFields[ix]] = k
|
||||||
for k in self.headFields:
|
for k in self.headFields:
|
||||||
|
|
|
@ -108,6 +108,11 @@ def test_topic(self, config):
|
||||||
tp_itc = topic.Topic('itc', data=dict(
|
tp_itc = topic.Topic('itc', data=dict(
|
||||||
title='ITC', description='Information and Communication Technology'))
|
title='ITC', description='Information and Communication Technology'))
|
||||||
topics.save(tp_itc)
|
topics.save(tp_itc)
|
||||||
|
tp_proglang = topic.Topic('prog_lang', data=dict(
|
||||||
|
title='Programming Languages',
|
||||||
|
description='Programming Languages'))
|
||||||
|
topics.save(tp_proglang)
|
||||||
|
tp_itc.addChild(tp_proglang)
|
||||||
|
|
||||||
storage.commit()
|
storage.commit()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue