From 0654140f518e290063b573046609dd0cb688d7e5 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sat, 14 Jan 2012 11:50:46 +0100 Subject: [PATCH] extend features of the subtype predicate: control predicates used for connecting concepts of the types that have a subtype relation --- concept.py | 25 ++++++++++++++++++++----- configure.zcml | 9 +++++++++ external/element.py | 19 +++++++++++++++---- interfaces.py | 14 +++++++++++--- predicate.py | 21 ++++++++++++++++----- tests/setup.py | 5 ++++- 6 files changed, 75 insertions(+), 18 deletions(-) diff --git a/concept.py b/concept.py index 9a27490..d063d46 100644 --- a/concept.py +++ b/concept.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2011 Helmut Merz helmutm@cy55.de +# Copyright (c) 2012 Helmut Merz helmutm@cy55.de # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,8 +18,6 @@ """ Definition of the Concept and related classes. - -$Id$ """ from zope import component, schema @@ -210,9 +208,26 @@ class Concept(Contained, Persistent): return [r.first for r in self.getParentRelations(predicates, sort=sort, noSecurityCheck=noSecurityCheck)] - def assignChild(self, concept, predicate=None, order=0, relevance=1.0): + def checkPredicate(self, child, predicate=None): + cm = self.getConceptManager() + defaultPredicate = cm.getDefaultPredicate() if predicate is None: - predicate = self.getConceptManager().getDefaultPredicate() + predicate = defaultPredicate + if predicate == defaultPredicate: + subtypePred = cm.get('issubtype') + if subtypePred is not None: + subtypeRels = list(self.conceptType.getChildRelations( + [subtypePred], child.conceptType)) + if subtypeRels: + from loops.predicate import adaptedRelation + rel = adaptedRelation(subtypeRels[0]) + predName = rel.usePredicate + if predName and predName != u'standard': + predicate = cm[predName] + return predicate + + def assignChild(self, concept, predicate=None, order=0, relevance=1.0): + predicate = self.checkPredicate(concept, predicate) registry = component.getUtility(IRelationRegistry) rel = ConceptRelation(self, concept, predicate) if order != 0: diff --git a/configure.zcml b/configure.zcml index 908bb47..1692294 100644 --- a/configure.zcml +++ b/configure.zcml @@ -263,6 +263,15 @@ set_schema="loops.interfaces.IPredicate" /> + + + + + +