I am trying to use SPARQL Views to import data directly from a VIVO SPARQL endpoint. Specifically, I am trying to display a particular faculty's publications. VIVO links an author's publications in the following fashion:
?authoruri vivo:authorInAuthorship ?authorshipuri
?authorshipuri vivo:linkedInformationResource ?articleuri
I can add the first relationship (as an attachment) and get all of the authorshipuris and the corresponding articleuri, but when I add a second relationship to the attachment to connect say bibo:abstract (which the articleuri links to) the following error is generated:
Notice: Undefined index: triples in sparql_views_plugin_query_sparql->build_graph_pattern() (line 256 of /www/ebremer/sites/all/modules/sparql_views/plugins/sparql_views_plugin_query_sparql.inc).
Notice: Undefined index: optionals in sparql_views_plugin_query_sparql->build_graph_pattern() (line 259 of /www/ebremer/sites/all/modules/sparql_views/plugins/sparql_views_plugin_query_sparql.inc).
Warning: Invalid argument supplied for foreach() in sparql_views_plugin_query_sparql->build_graph_pattern() (line 259 of /www/ebremer/sites/all/modules/sparql_views/plugins/sparql_views_plugin_query_sparql.inc).
Notice: Undefined index: triples in sparql_views_plugin_query_sparql->build_graph_pattern() (line 256 of /www/ebremer/sites/all/modules/sparql_views/plugins/sparql_views_plugin_query_sparql.inc).
Notice: Undefined index: optionals in sparql_views_plugin_query_sparql->build_graph_pattern() (line 259 of /www/ebremer/sites/all/modules/sparql_views/plugins/sparql_views_plugin_query_sparql.inc).
Warning: Invalid argument supplied for foreach() in sparql_views_plugin_query_sparql->build_graph_pattern() (line 259 of /www/ebremer/sites/all/modules/sparql_views/plugins/sparql_views_plugin_query_sparql.inc).
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | sparql_views-multirelationship-1593256-6243284.patch | 1.25 KB | ebremer |
| #7 | sparqlviewerror.pdf | 818.42 KB | ebremer |
| #6 | SVerr.pdf | 2.24 MB | ebremer |
Comments
Comment #1
ebremer commentedOk, update on my own problem. A tremedous help was turning on for all views "Show the SQL query". Normally I have never needed to do this, but, in the case of SPARQL Views it shows the SPARQL generated NOT any Drupal SQL. Very handy! With this, I determined from the generated SPARQL the following:
1) I had listed bibo in the Drupal RDF namespaces as "http://purl.org/ontology/bibo#" instead of "http://purl.org/ontology/bibo/"
2) I had forgotten to link my test field, in this case pmid, to the relationship "linkedInformationResource".
3) The generated SPARQL is correct:
PREFIX vivo:
PREFIX foaf:
PREFIX bibo:
SELECT DISTINCT ?person ?person_field_publication ?publink_field_linkedinformationresource ?publication_field_pmid
WHERE {
?person vivo:authorInAuthorship ?person_field_publication; foaf:lastName "Goodman"; foaf:firstName "Steven"; vivo:authorInAuthorship ?person_field_publication.
?person_field_publication vivo:linkedInformationResource ?publink_field_linkedinformationresource; vivo:linkedInformationResource ?publink_field_linkedinformationresource.
?publink_field_linkedinformationresource bibo:pmid ?publication_field_pmid.
}
LIMIT 10 OFFSET 0
which can be tested again my SPARQL endpoint http://link.informatics.stonybrook.edu/sparql (it's Virtuoso), default graph URI as "http://reach.suny.edu/".
BUT, I still get the original reported error when I try to use the SPARQL view from within Drupal.
- E
Comment #2
ebremer commentedOk, I just noticed this - the error occurs when I look at the final page (outside the views editor), but works beautifully in the "preview" within the context of the views editor....
Comment #3
ebremer commentedupdate: cleared the caches and the view works in and out of the views editor now, but, the error still shows outside the context of the views editor
Comment #4
ebremer commentedUpdate: added Drupal for firebug to dump out some variable data before the problem line 256 in the code. Since the # of elements is restricted to 10, the variable dump line that I added just before 256:
firep($pattern_elements,"looping...");
fires 10 times as expected. In a couple of the loops, it becomes apparent that in two cases based on the data why line 256 triggers and error:
$subject_pattern .= $pattern_elements['triples'] . "\n";
In two cases 'triples' is undefined at the expected level in the array.
Drupal for Firebug General Messages:
looping...:
Array
(
[triples] => ?person foaf:lastName "Goodman"; foaf:firstName "Steven"; foaf:firstName ?person_field_first_name; foaf:lastName ?person_field_last_name; vitro:mainImage ?person_field_image.
[optionals] => Array
(
[0] => Array
(
[object] => person_field_title
[statement] => ?person vivo:preferredTitle ?person_field_title
)
[1] => Array
(
[object] => person_field_office_phone
[statement] => ?person vivo:phoneNumber ?person_field_office_phone
)
[2] => Array
(
[object] => person_field_research_overview
[statement] => ?person vivo:researchOverview ?person_field_research_overview
)
)
)
looping...:
Array
(
[triples] => ?person foaf:lastName "Goodman"; foaf:firstName "Steven"; foaf:firstName ?person_field_first_name; foaf:lastName ?person_field_last_name; vitro:mainImage ?person_field_image.
[optionals] => Array
(
[0] => Array
(
[object] => person_field_title
[statement] => ?person vivo:preferredTitle ?person_field_title
)
[1] => Array
(
[object] => person_field_office_phone
[statement] => ?person vivo:phoneNumber ?person_field_office_phone
)
[2] => Array
(
[object] => person_field_research_overview
[statement] => ?person vivo:researchOverview ?person_field_research_overview
)
)
)
looping...:
Array
(
[triples] => ?person vivo:authorInAuthorship ?person_field_publication; foaf:lastName "Goodman"; foaf:firstName "Steven"; vivo:authorInAuthorship ?person_field_publication.
[optionals] => Array
(
)
[relationships] => Array
(
[person_field_publication] => Array
(
[triples] => ?person_field_publication vivo:linkedInformationResource ?publink_field_linkedinformationresource; vivo:linkedInformationResource ?publink_field_linkedinformationresource.
[optionals] => Array
(
)
)
)
)
looping...:
Array
(
[triples] => ?person_field_publication vivo:linkedInformationResource ?publink_field_linkedinformationresource; vivo:linkedInformationResource ?publink_field_linkedinformationresource.
[optionals] => Array
(
)
)
looping...:
Array
(
[relationships] => Array
(
[publink_field_linkedinformationresource] => Array
(
[triples] => ?publink_field_linkedinformationresource bibo:pmid ?publication_field_pmid.
[optionals] => Array
(
)
)
)
)
looping...:
Array
(
[triples] => ?publink_field_linkedinformationresource bibo:pmid ?publication_field_pmid.
[optionals] => Array
(
)
)
looping...:
Array
(
[triples] => ?person vivo:authorInAuthorship ?person_field_publication; foaf:lastName "Goodman"; foaf:firstName "Steven"; vivo:authorInAuthorship ?person_field_publication.
[optionals] => Array
(
)
[relationships] => Array
(
[person_field_publication] => Array
(
[triples] => ?person_field_publication vivo:linkedInformationResource ?publink_field_linkedinformationresource; vivo:linkedInformationResource ?publink_field_linkedinformationresource.
[optionals] => Array
(
)
)
)
)
looping...:
Array
(
[triples] => ?person_field_publication vivo:linkedInformationResource ?publink_field_linkedinformationresource; vivo:linkedInformationResource ?publink_field_linkedinformationresource.
[optionals] => Array
(
)
)
looping...:
Array
(
[relationships] => Array
(
[publink_field_linkedinformationresource] => Array
(
[triples] => ?publink_field_linkedinformationresource bibo:pmid ?publication_field_pmid.
[optionals] => Array
(
)
)
)
)
looping...:
Array
(
[triples] => ?publink_field_linkedinformationresource bibo:pmid ?publication_field_pmid.
[optionals] => Array
(
)
)
Comment #5
Anonymous (not verified) commentedI'm not sure whether Drupal for Firebug is the best tool here, you might want to try Devel's dpm(). A screenshot of the Krumo output would be helpful.
Comment #6
ebremer commentedAttached. - E
Comment #7
ebremer commentedI was able to get the data out the way I wanted with the final SPARQL query be generated by SPARQL VIEWS as follows and run against http://link.informatics.stonybrook.edu/sparql:
===========================
PREFIX vivo:
PREFIX foaf:
PREFIX bibo:
SELECT DISTINCT ?publink_field_pmid ?publink_field_abstract
WHERE {
?person vivo:authorInAuthorship ?person_field_authorinauthorship; foaf:lastName "Goodman"; foaf:firstName "Steven".
?person_field_authorinauthorship vivo:linkedInformationResource ?publink_field_linkedinformationresource.
?publink_field_linkedinformationresource bibo:pmid ?publink_field_pmid; bibo:abstract ?publink_field_abstract.
}
==============================
Although it all looks good in the preview, the original errors still show up in the final rendered page (the data is there though). Attached is a view of the first two pages of output. - Erich
Comment #8
ebremer commentedOk, I got my errors to go away. I modified sites/all/modules/sparql_views/plugins/sparql_views_plugin_query_sparql.in, this being the file where the errors were coming from, as shown below. In my case, with the second relationship, there are two entries in $pattern_elements that do not contain 'triples' or 'optionals'. I added if/then to test to see if they were set before entering the critical sections and the error went away. I'm still studying the code to see if this is the correct way to handle it.
Comment #9
Anonymous (not verified) commentedAwesome, thanks for following up on this :)
Could you post that as a patch? If you've never done that before, there are great instructions for creating patches on Jacine's blog.
Comment #10
ebremer commentedNo, I never actually created a patch before for Drupal, so, it's about time I learn. :-) See attached. The patch deals with the cases where $pattern_elements doesn't have 'triples' or 'optionals' set, but it may be better to modify the code where the unset entries are created so that the check never needs to be made. I'm still studying the code. For now, I'm able to move ahead and I have gotten some complex relationships to work pulling various VIVO triples together from my endpoint and then displaying them using a combination of Views and quick tabs.
Comment #11
ebremer commented