Changeset 2083

Show
Ignore:
Timestamp:
06/03/09 13:08:36 (15 months ago)
Author:
drobilla
Message:

Same treatment for discovery of plugin classes.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/slv2/src/world.c

    r2082 r2083  
    401401                "SELECT DISTINCT ?spec ?data WHERE {\n" 
    402402                "       ?spec a            :Specification ;\n" 
    403                 "         rdfs:seeAlso ?data .\n" 
     403                "             rdfs:seeAlso ?data .\n" 
    404404                "}\n"; 
    405405 
     
    410410        while (!librdf_query_results_finished(results)) { 
    411411                librdf_node* spec_node = librdf_query_results_get_binding_value(results, 0); 
    412                 //librdf_uri*  spec_uri  = librdf_node_get_uri(spec_node); 
    413412                librdf_node* data_node = librdf_query_results_get_binding_value(results, 1); 
    414413                librdf_uri*  data_uri  = librdf_node_get_uri(data_node); 
     
    431430{ 
    432431        // FIXME: This will need to be a bit more clever when more data is around 
    433         // than the ontology (ie classes which aren't LV2 plugin_classes) 
    434  
    435         // FIXME: This loads things that aren't plugin categories 
     432        // than the ontology (ie classes which aren't LV2 plugin_classes), it 
     433        // currently loads things that aren't actually plugin classes 
    436434 
    437435        unsigned char* query_string = (unsigned char*) 
     
    455453                const char*  label       = (const char*)librdf_node_get_literal_value(label_node); 
    456454 
    457                 assert(class_uri); 
    458  
    459                 SLV2PluginClass plugin_class = slv2_plugin_class_new(world, 
    460                                 parent_uri, class_uri, label); 
    461                 raptor_sequence_push(world->plugin_classes, plugin_class); 
    462                 // FIXME: Slow!  ORDER BY broken in certain versions of redland? 
    463                 raptor_sequence_sort(world->plugin_classes, slv2_plugin_class_compare_by_uri); 
     455                if (class_uri && parent_uri) { 
     456                        SLV2PluginClass plugin_class = NULL; 
     457 
     458                        // Check if this is another match for the last plugin (avoid search) 
     459                        SLV2PluginClasses classes = world->plugin_classes; 
     460                        const unsigned n_classes = raptor_sequence_size(classes); 
     461                        if (n_classes >= 1) { 
     462                                SLV2PluginClass prev = raptor_sequence_get_at(classes, n_classes - 1); 
     463                                if (librdf_uri_equals(class_uri, prev->uri->val.uri_val)) 
     464                                        plugin_class = prev; 
     465                        } 
     466 
     467                        SLV2Value uri = slv2_value_new_librdf_uri(world, class_uri); 
     468 
     469                        // If this class differs from the last, append a new one 
     470                        if (!plugin_class) { 
     471                                if (n_classes == 0) { 
     472                                        plugin_class = slv2_plugin_class_new(world, parent_uri, class_uri, label); 
     473                                        raptor_sequence_push(classes, plugin_class); 
     474                                } else { 
     475                                        SLV2PluginClass first = raptor_sequence_get_at(classes, 0); 
     476                                        SLV2PluginClass prev  = raptor_sequence_get_at(classes, n_classes - 1); 
     477 
     478                                        // If the URI is > the last in the list, just append (avoid sort) 
     479                                        if (strcmp( 
     480                                                        slv2_value_as_string(slv2_plugin_class_get_uri(prev)), 
     481                                                        (const char*)librdf_uri_as_string(class_uri)) < 0) { 
     482                                                plugin_class = slv2_plugin_class_new(world, parent_uri, class_uri, label); 
     483                                                raptor_sequence_push(classes, plugin_class); 
     484 
     485                                        // If the URI is < the first in the list, just prepend (avoid sort) 
     486                                        } else if (strcmp( 
     487                                                        slv2_value_as_string(slv2_plugin_class_get_uri(first)), 
     488                                                        (const char*)librdf_uri_as_string(class_uri)) > 0) { 
     489                                                plugin_class = slv2_plugin_class_new(world, parent_uri, class_uri, label); 
     490                                                raptor_sequence_shift(classes, plugin_class); 
     491 
     492                                        // Otherwise the query engine is giving us unsorted results :/ 
     493                                        } else { 
     494                                                plugin_class = slv2_plugin_classes_get_by_uri(classes, uri); 
     495                                                if (!plugin_class) { 
     496                                                        plugin_class = slv2_plugin_class_new(world, parent_uri, class_uri, label); 
     497                                                        raptor_sequence_push(classes, plugin_class); 
     498                                                        raptor_sequence_sort(classes, slv2_plugin_class_compare_by_uri); 
     499                                                } 
     500                                        } 
     501                                } 
     502                        } else { 
     503                                // TODO: Support classes with several parents 
     504                        } 
     505                } 
    464506 
    465507                librdf_free_node(class_node); 
     
    469511                librdf_query_results_next(results); 
    470512        } 
    471  
    472         // FIXME: filter list here 
    473513 
    474514        librdf_free_query_results(results); 
     
    550590                        SLV2Value uri = slv2_value_new_librdf_uri(world, plugin_uri); 
    551591 
    552                         // If this plugin differs from the last, append a new SLV2Plugin 
     592                        // If this plugin differs from the last, append a new one 
    553593                        if (!plugin) { 
    554594                                if (n_plugins == 0) {