Am Freitag, 11. November 2005 17:26 schrieb Jean-Marc Orliaguet:

> if the relation is symmetrical, there are 2 relations:
>     A is like B
> means:
>    A resembles B
> and
>    B resembles A    ( or A __ is resembled by __ B )
> which you can express as a compound predicate:
>     is_like = CompoundPredicate(Predicate('_ resembles _', '_
> is resembled by _'))
> and do a query with:
>, first=A)
> to get all the B:s in relation with A independently of the
> position.

Interesting, maybe I should learn more about predicate logic...

Nevertheless let me try it "my way":

Let's have an interface ISymmetricalRelation(IDyadicRelation) 
that is implemented by a class 
SymmetricalRelation(PredicateRelation) (PredicateRelation is an 
example from the README.txt, 
Concept is some imaginary class used for conceptual modelling).

  >>> isSynonym = Predicate('__ is a synonym of __')
  >>> crazy = Concept('crazy')
  >>> mad = Concept('mad')

Then the contract for ISymmetricalRelation would look like this 
(this is not strictly necessary but makes it easier to 

  >>> SymmetricalRelation(isSynonym, crazy, mad) == 
SymmetricalRelation(isSynonym, mad, crazy)

Now we register such a relation:

  >>> relations.register(SymmetricalRelation(isSynonym, crazy, 

and query in two ways:

  >>> rels1 = relations.query(relationship=isSynonym, 
  ...                         first=crazy) 
  >>> rels2 = relations.query(relationship=isSynonym, 
  ...                         second=crazy) 

then all the found relations must be identical:

  >>> [r1 in rels2 for r1 in rels1]

(When I'd query for 'mad' I'd get the same results; I could also 
omit the relationship parameter on the query() call.)

In addition to the standard IDyadicRelation interface, 
ISymmetricalRelation has a method getOther():

  >>> [r.getOther(crazy) for r in rels1]
  [<Concept 'mad'>]

This is all I need to find all the synonyms of 'mad'.

Don't ask me about the implementation now - I just don't care at 
the moment...

> Then most of the relations do have a direction ( __ has author
> __, __ was modified by __,  ...)

Yes, a symmetrical relationship is a special case, and one could 
even handle it on the application layer. Nevertheless I think 
it's a good idea to consider it.


Zope3-dev mailing list

Reply via email to