# Re: [Zope3-dev] Yet Another Relations (aka Reference) Engine...

```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:
>
>     relations.search(predicate=is_like, first=A)
>
> to get all the B:s in relation with A independently of the
> position.```
```

Nevertheless let me try it "my way":

that is implemented by a class
SymmetricalRelation(PredicateRelation) (PredicateRelation is an
http://svn.cy55.de/viewcvs/Zope3/src/cybertools/trunk/relation,
Concept is some imaginary class used for conceptual modelling).

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

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

True

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]
[True]

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

ISymmetricalRelation has a method getOther():

>>> [r.getOther(crazy) for r in rels1]

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.

Helmut

_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

```