work in progress: rels
This commit is contained in:
parent
1bf5e82afc
commit
a108ad9fc3
3 changed files with 30 additions and 15 deletions
|
@ -24,17 +24,6 @@ class IContainer(ITraversable):
|
|||
and the value object (e.g. `parent´ and `name`) are stored correctly."""
|
||||
|
||||
|
||||
class IConcept(IContainer):
|
||||
|
||||
def parents(*predicates):
|
||||
"""Return a sequence of `Triple`s in which this object is
|
||||
referenced as `second`."""
|
||||
|
||||
def children(*predicates):
|
||||
"""Return a sequence of `Triple`s in which this object is
|
||||
referenced as `first`."""
|
||||
|
||||
|
||||
class IView(Interface):
|
||||
|
||||
def __call__():
|
||||
|
|
|
@ -3,23 +3,39 @@
|
|||
"""Core classes for concept map structure."""
|
||||
|
||||
from zope.interface import implementer
|
||||
from scopes.interfaces import IConcept
|
||||
from scopes.storage.common import registerContainerClass, registry
|
||||
from scopes.storage.tracking import Container, Track
|
||||
|
||||
|
||||
@implementer(IConcept)
|
||||
class Concept(Track):
|
||||
|
||||
headFields = ['name']
|
||||
|
||||
def parents(self, predicate=None):
|
||||
return self.container.queryRels(second=self, predicate=predicate)
|
||||
|
||||
def children(self, predicate=None):
|
||||
return self.container.queryRels(first=self, predicate=predicate)
|
||||
|
||||
|
||||
class Concepts(Container):
|
||||
|
||||
insertOnChange = False
|
||||
indexes = None
|
||||
|
||||
def queryRels(self, **crit):
|
||||
pred = crit.get(predicate)
|
||||
if pred is not None and isinstance(pred, ('string', 'bytes')):
|
||||
crit['predicate'] = self.storage.getContainer('pred').queryLast(name=pred)
|
||||
for k, v in crit.items:
|
||||
if isinstance(v, Track):
|
||||
crit[k] = v.uid
|
||||
rels = self.storage.getContainer('rel')
|
||||
return rels.query(**crit)
|
||||
|
||||
|
||||
# implementation of relationships between concepts using RDF-like triples
|
||||
|
||||
class Predicate(Concept):
|
||||
|
||||
prefix = 'pred'
|
||||
|
@ -37,6 +53,15 @@ class Triple(Track):
|
|||
headFields = ['first', 'second', 'predicate']
|
||||
prefix = 'rel'
|
||||
|
||||
def getFirst(self):
|
||||
return self.container.storage.getItem(self.first)
|
||||
|
||||
def getSecond(self):
|
||||
return self.container.storage.getItem(self.second)
|
||||
|
||||
def getPredicate(self):
|
||||
return self.container.storage.getItem(self.second)
|
||||
|
||||
|
||||
@registerContainerClass
|
||||
class Rels(Container):
|
||||
|
@ -47,6 +72,8 @@ class Rels(Container):
|
|||
tableName = 'rels'
|
||||
insertOnChange = False
|
||||
|
||||
defaultPredicate = 'standard'
|
||||
|
||||
|
||||
# types stuff
|
||||
|
||||
|
@ -75,7 +102,6 @@ class Types(Concepts):
|
|||
def storeType(storage, cls, name):
|
||||
types = storage.create(Types)
|
||||
types.save(Type(name, cls.prefix))
|
||||
storage.commit()
|
||||
|
||||
def setupCoreTypes(storage):
|
||||
for c in registry.values():
|
||||
|
|
|
@ -169,7 +169,7 @@ class Container(object):
|
|||
*r[1:-2], trackId=r[0],timeStamp=r[-2], data=r[-1], container=self)
|
||||
|
||||
def setupWhere(self, crit):
|
||||
return [self.table.c[k.lower()] == v for k, v in crit.items()]
|
||||
return [self.table.c[k.lower()] == v for k, v in crit.items() if v is not None]
|
||||
|
||||
def setupValues(self, track, withTrackId=False):
|
||||
values = {}
|
||||
|
|
Loading…
Add table
Reference in a new issue