Instead of associating only nodes with taxonomy terms, It would be immensely useful to classify URIs instead. This is a superset of our current functionality, also offerring us a way to classify users, comments, feeds, and other non node items.

I would not expect for taxonomy.module to provide a UI for selecting URLs similar to the select box for nodes, just provide an API for other modules to use.

Idea suggest at this feature request.

Comments

kika’s picture

It would be also a killer feature for distributed metadata systems such as XFML: http://xfml.org

But how to create such an extendable API?
Serialize extra fields to a term_data table? ANOTHER set of tables?

moshe weitzman’s picture

Priority: Major » Normal

I like Kjartan's proposal a lot. Of course, I proposed a less mature version of this in October: http://list.drupal.org/drupal-devel/2002-October/007901.html

At first glance, it seems that adding a column for Domain is easier than associating URIs directly with terms.

-moshe

----- Original Message -----
From: "Kjartan Mannes"
To:
Sent: Thursday, December 12, 2002 2:11 PM
Subject: Re: [drupal-devel] feature #899 : Classify *anything* in a taxonomy

> Thursday, December 12, 2002, 7:42:59 PM, weitzman @ www . drop . org wrote:
> > Instead of associating only nodes with taxonomy terms, It would be
> > immensely useful to classify URIs instead. This is a superset of our
> > current functionality, also offerring us a way to classify users,
> > comments, feeds, and other non node items.
>
> I'm starting to dislike the current taxonomy API. Just too many support
> functions to do virtually the same thing. Just gonna throw some vague
> ideas out there and see how they land.
>
> Terms should not be linked to nid, but instead a general object. The
> table could look like:
>
> term_links table:
> | context | id | tid
> |----------|--------|----
> | node | 2 | 4
> | url | 2 | 2
> | node | 3 | 5
>
> Then have functions ala:
>
> taxonomy_get_term($conditions) {
> return array of terms matching conditions
> }
>
> taxonomy_get_vocabulary($conditions) {
> return array of vocabs matching conditions
> }
>
> taxonomy_get_synonym($conditions) {
> return array of synonyms matching conditions
> }
>
> taxonomy_get_hierarchy($conditions) {
> return array of hierarchy matching conditions
> }
>
> taxonomy_get_relation($conditions) {
> return array of relations matching conditions
> }
>
> taxonomy_get_link($conditions) {
> // For all links to nodes: $conditions = array("context" => "node");
> // For all links to a specific url: $conditions = array("context" => "url", "id" => 3);
> // For urls linked to a tid: $conditions = array("context" => "url", tid" => 3);
> return array of matching links
> }
>
> taxononmy_set_link($data) {
> // $data = array("context" => "node", "id" => 4, "tid" => 4");
> }
>
> If you added vid to the term_link table you could do pretty much
> anything with those functions. To me it just feels cleaner, and less
> functions to remember. Then again my knowledge of the taxonomy module
> isn't perfect so I don't know if this is a good idea.
>
> --
> Kjartan (http://natrak.net/)

moshe weitzman’s picture

Here is a 7 line patch which enables classifying anything in a vocabulary, not just nodes. This is done by adding a 'domain' column to the term_node table. Usually this column has 'node_nid' as its domain but modules are expected to provide their own domains.

for example, assume a module called feed.module which wants to classify feeds into a taxonomy. you can use 'feed_fid' as your domain and then add feed/term associations at will. The UI for adding these assocations is currently left up to the calling module, and not the taxonomy API. I added a '_taxo()' hook so that these non-node modules may hook into the Vocabulary admin page.

This feature is a start for private taxonomies as well.

In order to use this patch, you must add a column to your term_node table using the following SQL statement

ALTER TABLE term_node ADD domain VARCHAR(255) NOT NULL;

I would think that feeds are a good candidate for being classified as a proof of concept (breyten?) ...

Index: modules/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy.module,v
retrieving revision 1.46
diff -u -r1.46 taxonomy.module
--- modules/taxonomy.module	15 Apr 2003 19:50:04 -0000	1.46
+++ modules/taxonomy.module	26 Apr 2003 15:50:20 -0000
@@ -69,7 +69,7 @@
 
 function taxonomy_form_vocabulary($edit = array()) {
   foreach (module_list() as $name) {
-    if (module_hook($name, "node")) {
+    if (module_hook($name, "node") || module_hook($name, "taxo")) {
       $nodetypes[$name] = $name;
     }
   }
@@ -362,8 +362,8 @@
 }
 
 // return array of terms of a node beloging to a particular vocabulary identified by $vid
-function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = "tid") {
-  $result = db_query("SELECT t.* FROM term_data t, term_node r WHERE t.tid = r.tid AND t.vid = '%d' AND r.nid = '%d' ORDER BY weight", $vid, $nid);
+function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = "tid", $domain = "node_nid") {
+  $result = db_query("SELECT t.* FROM term_data t, term_node r WHERE t.tid = r.tid AND t.vid = '%d' AND r.nid = '%d' AND r.domain = '%s' ORDER BY weight", $vid, $nid, $domain);
   $terms = array();
   while ($term = db_fetch_object($result)) {
     $terms[$term->$key] = $term;
@@ -372,11 +372,11 @@
 }
 
 // return array of terms of a node
-function taxonomy_node_get_terms($nid, $key = "tid") {
+function taxonomy_node_get_terms($nid, $key = "tid", $domain = "node_nid") {
   static $terms;
 
   if (!isset($terms[$nid])) {
-    $result = db_query("SELECT t.* FROM term_data t, term_node r WHERE r.tid = t.tid AND r.nid = '%d' ORDER BY weight, name", $nid);
+    $result = db_query("SELECT t.* FROM term_data t, term_node r WHERE r.tid = t.tid AND r.nid = '%d' AND r.domain = '%s' ORDER BY weight, name", $nid, $domain);
     $terms[$nid] = array();
     while ($term = db_fetch_object($result)) {
       $terms[$nid][$term->$key] = $term;
@@ -386,12 +386,13 @@
 }
 
 // save terms of a node
-function taxonomy_node_save($nid, $terms) {
+function taxonomy_node_save($nid, $terms, $domain = "node_nid") {
+  
   taxonomy_node_delete($nid);
 
   if ($terms) {
     foreach ($terms as $term) {
-      db_query("INSERT INTO term_node (nid, tid) VALUES ('%d', '%d')", $nid, $term);
+      db_query("INSERT INTO term_node (nid, tid, domain) VALUES ('%d', '%d', '%s')", $nid, $term, $domain);
     }
   }
 }
 }
 
 // return array of terms of a node
-function taxonomy_node_get_terms($nid, $key = "tid") {
+function taxonomy_node_get_terms($nid, $key = "tid", $domain = "node_nid") {
   static $terms;
 
   if (!isset($terms[$nid])) {
-    $result = db_query("SELECT t.* FROM term_data t, term_node r WHERE r.tid = t.tid AND r.nid = '%d' ORDER BY weight, name", $nid);
+    $result = db_query("SELECT t.* FROM term_data t, term_node r WHERE r.tid = t.tid AND r.nid = '%d' AND r.domain = '%s' ORDER BY weight, name", $nid, $domain);
     $terms[$nid] = array();
     while ($term = db_fetch_object($result)) {
       $terms[$nid][$term->$key] = $term;
@@ -386,12 +386,13 @@
 }
 
 // save terms of a node
-function taxonomy_node_save($nid, $terms) {
+function taxonomy_node_save($nid, $terms, $domain = "node_nid") {
+  
   taxonomy_node_delete($nid);
 
   if ($terms) {
     foreach ($terms as $term) {
-      db_query("INSERT INTO term_node (nid, tid) VALUES ('%d', '%d')", $nid, $term);
+      db_query("INSERT INTO term_node (nid, tid, domain) VALUES ('%d', '%d', '%s')", $nid, $term, $domain);
     }
   }
 }

moshe weitzman’s picture

Breyten has given positive feedback for the patch here. Anyone else interested in this? It is ready for CVS consideration IMO.

Anonymous’s picture

Upon further review, the "taxo" hook introduced at the top of the previously posted patch is not necessary. Please ignore it.

steph’s picture

Title: Classify *anything* in a taxonomy » Re: [drupal-devel] feature #899 : Classify *anything* in a taxonomy
Component: taxonomy.module »
Category: feature »

Ok.. classifying anything in a taxonomy is something I am looking for at
the moment.

I am wanting to be able to classify user profiles in a taxo , but how
would this 7 line patch affect the taxonomy/or/ search
functionality , which afaik can only list nodes.

On Sat, 2003-05-10 at 14:57, weitzman@www.drop.org wrote:

moshe weitzman’s picture

Version: » master
Component: » taxonomy.module
Category: » bug

In order to view non-nodes which have been classified in the taxonomy, you have to roll your own view module which implements the txonomy_node_get_terms() function. That function name is misleading because after this patch, it can operate on non-nodes as well - see the 3rd parameter. But changing the function name means changing many other modules so I choose to keep it for now.

You cannot simply use the taxonomy/view/or/x syntax because taxonomy doesn't know how to render your 'anything' items.

moshe weitzman’s picture

And I should add that you have to roll your own UI for associating your 'anything' with taxonomy terms. This patch adjusts the core API, not user interface.

Mark Cheverton’s picture

Generally do people think this is the best way of proceeding - allowing anything to be classified. With the effort to make comments nodes I would advocate that the core requirement is that users (and anything else that would be classified) should have a node representation, then we can do things like attach taxos (useful say for the user selecting a country when registering and other profile data) and also attach things to a user node like a FOAF record.

The downside as I see it is the difficulty in doing this without breaking all the DA modules, but it would provide alot of solutions to things like the profiles module, and enable some more advanced social software applications once you can start to group users together just like you can group nodes making applications such as ecademy much easier to build.

-Mark

JonBob’s picture

Category: bug » feature

I agree with Mark. It seems much more flexible and powerful in the long run to keep taxonomy as a node classification system and make more types of information into nodes. Significant work has been done on turning feeds into nodes (http://drupal.org/node/view/468). It has frequently been stated that comments should be migrated over to nodes. If users could become nodes as well, that covers the use cases of the new domain field that have been given here as examples. We also have the user interface issue already solved by the existing node interface if taxonomy covers nodes only.
All that said, private taxonomies have also been frequently suggested, and as Moshe noted, this could be a positive step in that direction.

moshe weitzman’s picture

This discussion about how classification should work is nice, but we have to talk about code at some point. Specifically, we have talked for more than year about storing comments as nodes. But no patch for this has ever emerged. Maybe it is too hard, or maybe noone is motivated enough. Comment.module just underwent a significant overhaul, and it didn't include transition to node storage.

My point is that we have, in this project item, a working patch. In all other scenarios, we have hot air. This difference is very important. At some point, saying 'everything should be a node' is much less helpful than producing code code which gets us there.

I'n not trying to belittle an important debate, I just want to emphasize the importance of working code over theoretical discussion.

moshe weitzman’s picture

Title: Re: [drupal-devel] feature #899 : Classify *anything* in a taxonomy » Classify *anything* in a taxonomy
Version: master »
moshe weitzman’s picture

moshe weitzman’s picture

Assigned: Unassigned » moshe weitzman
Dries’s picture

If we want to use one table (currently term_node) to bind different terms to different domains then we'll want to rename some tables and functions for sake of clarity and consistency. Moreover, we should try to generalize all node specific code. For example, we'll want to rework the administration pages so one can bind a single vocabulary to multiple domains, say 'nodes' and 'users'.

I'd like to see this kind of functionality hit CVS but while Moshe's patch might be invaluable as a proof of concept, it needs to evolve some more before it can be considered CVS worthy. Renaming some tables and functions, rethinking some of the APIs and reworking snippets of the user interface strike me as important, no?

Dries’s picture

moshe weitzman’s picture

anyone interested in reviving this effort? i think its still worth exploring.

pamphile’s picture

Of of the anticipated benefits is that you will be able to:

1. launch multiple websites based on your categories.
2. Use one codebase, intead of multiple codebases.

http://01wholesale.com

bdragon’s picture

Version: » 7.x-dev

/me dredges this issue back to the top of the queue. ;)

This is a *very* interesting idea, and IMHO merits further discussion.

Router paths come to mind...

dmitrig01’s picture

I am going to try this one in 7. It's a great idea and should definitely get in... /me smells comment_taxonomy and user_taxonomy modules

mlncn’s picture

Subscribing.

benjamin, Agaric Design Collective

moshe weitzman’s picture

Assigned: moshe weitzman » Unassigned

One possible way forward is for taxonomy to become a 'field' in #265604: Fields in core sense. Thats a ways into the future though.

marcp’s picture

Journal could make good use of this feature, too: #480198: Allow single tags for Journal entries

Frando’s picture

Status: Active » Closed (duplicate)