Index: rdf-smush.c =================================================================== --- rdf-smush.c (revision 74) +++ rdf-smush.c (revision 76) @@ -200,7 +200,7 @@ librdf_model *tempmodel; librdf_stream *ostream, *sstream, *rstream; librdf_statement *osearch=NULL, *ssearch, *rewrites; - librdf_node *object, *prevobject=NULL, *canonical, *subject, *prevsubject=NULL; + librdf_node *object, *prevobject=NULL, *canonical=NULL, *subject, *prevsubject=NULL; int rc; if (!opts.quiet || opts.list) { @@ -238,6 +238,7 @@ } /* Loop through all objects of IFP (possibly only in given context) */ while (ostream && !librdf_stream_end(ostream)) { + canonical=NULL; if (!(object=librdf_new_node_from_node(librdf_statement_get_object(librdf_stream_get_object(ostream))))) return 4; /* Skip empty literal values, a source of error, and duplicates... */ @@ -263,7 +264,21 @@ continue; } /* Save first rewritable candidate subject as canonical. */ - canonical=librdf_new_node_from_node(librdf_statement_get_subject(librdf_stream_get_object(sstream))); + while (!librdf_stream_end(sstream)) { + if (!canonical) { + canonical=librdf_new_node_from_node(librdf_statement_get_subject(librdf_stream_get_object(sstream))); + } else { + librdf_node *candidate=librdf_new_node_from_node(librdf_statement_get_subject(librdf_stream_get_object(sstream))); + if ((librdf_node_get_type(candidate)==LIBRDF_NODE_TYPE_RESOURCE && librdf_node_get_type(canonical)!=LIBRDF_NODE_TYPE_RESOURCE) || (librdf_node_get_type(candidate)==LIBRDF_NODE_TYPE_RESOURCE && librdf_node_get_type(canonical)==LIBRDF_NODE_TYPE_RESOURCE && strlen(librdf_node_to_string(candidate)) < strlen(librdf_node_to_string(canonical)))) { + canonical=librdf_new_node_from_node(librdf_statement_get_subject(librdf_stream_get_object(sstream))); + } + librdf_free_node(candidate); + } + librdf_stream_next(sstream); + + } + librdf_free_stream(sstream); + sstream=librdf_model_find_statements(model,ssearch); if (!opts.quiet) { stamp(argv0,t0); char *o=librdf_node_to_string(object); @@ -375,6 +390,15 @@ return rc+64; librdf_free_statement(rewrites); } + /* Add owl:SameAs if URIs */ + if(librdf_node_get_type(subject)==LIBRDF_NODE_TYPE_RESOURCE && librdf_node_get_type(canonical)==LIBRDF_NODE_TYPE_RESOURCE) { + librdf_node *sameuri = librdf_new_node_from_uri_string(world, "http://www.w3.org/2002/07/owl#sameAs"); + librdf_statement *sameas = librdf_new_statement_from_nodes(world, canonical, sameuri, subject); + librdf_model_add_statement(model, sameas); + fprintf(stdout, "Adding owl:sameAs statement: %s owl:sameAs %s\n", librdf_node_to_string(canonical), librdf_node_to_string(subject)); + librdf_free_statement(sameas); + librdf_free_node(sameuri); + } librdf_stream_next(rstream); } if (rstream)