Re: Network Example: Sibling of Opposite Gender

From: Neo <neo55592_at_hotmail.com>
Date: 24 Dec 2006 14:38:32 -0800
Message-ID: <1166999912.307352.67220_at_i12g2000cwa.googlegroups.com>


> > 1. (new 'male 'gender) (new 'female 'gender)
> > 2. (new 'opposite 'verb) (set male opposite female) (set female opposite male)

> I feel define opposite is redundant.

You are suggesting that line 1 above already implies line 2 and therefore it is redundant. I will try to show below why they may not be from a database's point of view.

> Because there are only two gender, it is enough that you look for different gender.

If I couldn't get you to consider asexual and bisexual as possible genders, I would change the attribute to something else like temperature where instances might include hot, warm, cool, cold, etc. This would demonstrate that using the NOT function to determine the opposite value, isn't a general solution.

Please note that underlying the example is a network. The names of nodes and relationships are only meant for convenience. If those names make it appear as if a certain network is impossible (ie a person's gender being asexual or bisexual), think of the network in general terms such as node1, node2, relationship1, relationship2, etc.

Let us now generalize the above example to see if line 2 is necessary. Below is the generalized version of line 1:

  1. (new 'node1 'class1) (new 'node2 'class1)

In RM, the above might be equivalent to two tuples in a relation. Can you or, more importantly, the db determine that node1/tuple1 is the opposite of node2/tuple2? Futhermore, if we generalize opposite to relationship1, does knowing that node1's relationship1 to node2, automatically imply that node2 has a relationship1 back to node1?

If one queries dbd for the opposite of male, it reponds female. If one queries dbd for the opposite of female, it responds male. In fact, given node1 and node2, dbd can determine the relationship between them. Without explicitly storing this information in the RMDB, how can it answer them systematically? Can RMDBs systematically assume that in a relation containing two tuples, the tuples are opposites of each other? What if later the relation has three tuples? Using the NOT function to determine the opposite value isn't a general solution.

Also consider the general case where an entity's attribute can have mutiple values. For example john's gender preference can include male, female, bisexual, etc. Hypothetically, a person's gender could be male and female simultaneous (perhaps with a little surgery :). If certain node and relationship names make this seem impossible, re-think in terms of general terms like N1, R1, etc.

> I can't understand that in where do you think difficulty is. I feel you, trying to invent new DB other than RDB, should study more RDB (Especially SQL language) and understand capability of SQL. After you find weakness or shortcoming of SQL, you should design new DB with full capability of SQL, without some of shortcoming of SQL and hopefully having more strong functionality. Many time I saw samples of dbd. But, as far as samples I saw, they are easily translated into RDB(SQL).

You are correct in that many dbd examples are actually easier to manage in RMDBs. After all, RM is optimized for certain types of networks, just as the Hierarchal Data Model is optimized for certain types of networks. However there are some networks than no other data model can manage as systematically as dbd. I have not yet seen a systematic RM/RMDB solution to the types of network underlying the example above.

> Note: Please, don't think MS Access is real RDB. It's SQL is too restrictive.You shoud consider RDBs are Oracle, DB2, MS SQL Server, PostgreSQL.(Although, I don't know other RDB. someone knows more) May be MySQL can be included it. In past it's SQL was also too restrictive and weak functionality. But, recently it's functionality of SQL is rapidly growing.

In general, I too agree RM/RMDBs are excellent tools for managing data, especially where data structures fit in relations without excessive NULLs and joins. I personally like MS Access and MS SQL Server. A network-type db may be more appropriate for cases where data structure is highly complex/varied, unknown at design-time and one needs to minimize impact on existing app in order to meet new requirements (ie AI-type apps).

> Recently, I saw a sample like this titled "How to find Brothers and Sisters?" The problem is "Suppose Adam has children named John(male), Jack(male) and Mary(female). What schema/query finds John's brothers and sisters based only on direct relationships to parent and gender. A direct relationship would be parent/child. An indirect/derived relationship would be brother/sister. The query is not to use Adam directly." That was answed by Cimode.

Although Cimode was on the right track, none of his queries produce the correct result. Can you specifiy the one you think does?

> You can find SQL answer of this problem easily by referencing it.

I still haven't found one that is similarly equivalent. Can you provide a reference?

> here is another answer of SQL.
> table Person
> Name Gender Father Mother
> 'adam' 'male' NULL, NULL
> 'john' 'male', 'adam' NULL
> 'jack' 'male', 'adam' NULL
> 'mary' 'female' 'adam' NULL
>
> SELECT sibling.name AS "john's sibling" /* of opposite gender */
> FROM person john /* (Get) john's ... */
> , person sibling /* by getting persons */
> WHERE john.name = 'john' /* john's */
> AND sibling.gender <> john.gender /* whose gender is opposite */
> AND sibling.father = john.father /* and is child of john's parent */
> AND sibling.name <> john.name /* and is not himself */

The above is another efficient solution. (A minor note, in the original example, it is unknown if Adam is a male or female). Let us now compare how the network-type and RMDB solutions adapt to new requirements. Suppose the original Adam (now known to be age 30) has a new child also named Adam whose age is 5 and his gender is bisexual. Also suppose, there is a second new child again named Adam age 7 who has two parents: Adam (age 30) and new person also named Adam (age 65). And the gender of little Adam (age 5) is unknown. Here is how to add them in dbd without affecting the original query.

(new 'age)
(set+ adam age '30)

(new 'adam 'person)
(set+ (it) age '5)
(set+ (it) gender 'bisexual)
(set    (and (get * name 'adam) (get * age 30))    child (it))

(new 'adam 'person)
(set+ (it) age '65)

(new 'adam 'person)
(set+ (it) age '7)
(set    (and (get * name 'adam) (get * age 30))    child (it))
(set    (and (get * name 'adam) (get * age 65))    child (it))

How can I add the above data without affecting the RMDB query. If not possible, go ahead and revise schema/query (it may start to look like Cimode's). Also do you consider a NULL value to be an opposite of male? Does NOT(male) yield NULL? Is Three Valued Logic (3VL) acceptable? Received on Sun Dec 24 2006 - 23:38:32 CET

Original text of this message