GSoC idea: Create transitive relationship field

Events happening in the community are now at Drupal community events on www.drupal.org.
Anonymous's picture

The "parent term" property on a taxonomy term is a unique, non-field-api, non-transferrable relation that has not been upgraded to Field API. This GSoC idea does not propose to replace this in core as the short term goal, because a transitive relationship field can exist side-by-side with the current "parent term" field and the "parent term" field can be drupal_alter'ed out of existence. However, if this project succeeds, it would be developed further to include in core.

A transitive relationship is what the parent term property describes. For example, Orlando is in Florida, Florida is in the United States, therefore by the mathematical laws of transitive relations we can know that Orlando is in the United States.

If you check in Taxonomy module, you'll see that there's a lot of "one-off" code for this relationship around this parent term property. There's UI code for generating widget values. There's code for generating SQL that lets us get a term's relationships to nodes, that term's children's relationships to nodes and that term's grandchildren's relationships to nodes. Views also duplicates or repeats much of this in its various handlers.

To express these relations in Field API presents some significant challenges. It requires taking a concrete thing (the parent column in the term_hierarchy table) and making it abstract and reusable. I see this work having three phases. Accomplishing the first is the baseline for success of the GSoC proposal.

  1. Let any entities have transitive (hierarchical) relationships--not just terms--using Entity API or Field API to store data and produce widgets.
  2. Add (dynamically when needed?) new indexes on the field to support higher performing SELECT queries at the cost of rarer INSERT queries. I'm thinking of the left-and-right "nested set" method, but there may be others.
  3. Support non-SQL data storage.

It may be possible to contribute to an existing Drupal project, but I still need to do my research. Relation module is a broader initiative to improve relationship handling in Drupal. I contributed only a seed of what this project has become, and I really don't know much about it at the moment. Please suggest any other Drupal projects I should review before finalizing my proposal.

What does this project lead to? Here are a few ideas:

  • Any entity can have a transitive relationship with another entity. One user might supervise another user so that users can have authority over other users. Because nodes have revisions, authorship and status, nodes might be more useful for creating content hierarchies.
  • More consistent RDF expressions.
  • The notion of controlled vocabularies as a defined set of terms that share a vocabulary ID might be redefined to mean "any entities that have transitive relationships with each other through a particular field."
  • Terms whither away as a special class of entities because their character of having relationships is no longer unique.

My qualifications for this project: I'm responsible for taxonomy term reference field, the only relationship-like field in core. As a result of this, I'm a maintainer of taxonomy.module. I wrote a little (tiny) bit of Field API, but I'm competent with Field API in general. I presented some slides and spoke about my scattered thoughts about Drupal relationships and links at the Drupalcon San Francisco core developer summit. I also am working on oEmbed which is also all about links and relationships. I also love taxonomy, vocabularies. I am a big vocabulary nerd.

Comments

Could this be built on

owen barton's picture

Could this be built on relation module? It seems that if you have the relation type entity defined "is geographically in" that Orlando uses to reference Florida and Florida uses to reference United States, so the fundamental principle is there. Of course there may well be a need to alternate widgets/formatters, as well as high-performance denormalized storage, but it seems like the basic structure could still work.

Relation module

bangpound's picture

I've updated the proposal. I didn't mean to sound unwilling to contribute to an existing project, but I still need to do my research.

I was wondering why synonyms

sigismo's picture

I was wondering why synonyms isn't like this

Synonyms are "simpler"

bangpound's picture

Just for completeness, I'll mention that "synonym" has meant a few things in terms of taxonomy. Synonyms can be a "preferred label" (the way it works in Drupal 6). They can also be two separate entities with an equivalence relationship shared between them.

Transitive relationships could rely on the same code foundation as equivalence relationships. For example, Relations module uses Drupal entities which exist independently of the entities (nodes, terms) they're related to. Perhaps different kinds of relationships will extend or alter this basic relationship entity.

I'll consider synonyms when revising my proposal, but I really want to focus on transitive relationships to continue the modernization of taxonomy in Drupal.

Generalize?

ronald_istos's picture

Rather late in the game but I've been travelling a bit these days.

I really like the idea of supporting transitive relationships consistently across all entities and rightly so that would eventually make taxonomy terms a redundant concept from a functional point of view but they might still be very useful "virtual" concept to have around so as not to break the mental model of how Drupal sites are (with nodes tagged with taxonomy terms, etc).

What I would add from an RDF perspective is that there are really four types of relationships we would want.

Transitivity - explained above

Symmetry - if A and B are in a relationship then B and A are in the same relationship

Functionality - if A and B are related via a role and A and C are related by the same role then B and C are the same thing (owl:sameAs). This might be what synonyms are?

Inverse Functionality - the equivalent of the inverse of a role, as described above, being functional (e.g. for A hasModuleMantainer B the inverse would be a role B isModuleMaintainer of A)

Now - we are probably pushing it way too far to try and get all this in but we do have examples of all this in the Drupal contrib world. Hierarchy is about transitivity, node backrefs is about symmetry while functionality and inverse functionality are also some times supported by backrefs. It is more about explicitly and a bit more formally stating what is happening.

In any case I would suggest the project focuses on transitive relationships to start and we can discuss how complicated or not it would be to make it a more generalized solution.

All of this is (as already mentioned) predicated by studying where the Relation module stands right now.

Would be more than happy to help developing this further.

Not eligible for GSoC

bangpound's picture

I had thought that in previous years, anyone was eligible to be a GSoC student. Regardless of whether my memory is correct, this year the rules are that students must be enrolled in a college or university. This idea is not going to be proposed for GSoC, but I appreciate all the feedback.

Taxonomy

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: