I am trying to build a POC search engine for an internal site at my company. I am using GraphDB and have put some base data in that looks like this:
Page -hasField-> Field
Field -hasOption-> Option
Not all fields have options. All of the types have labels that I'll be searching. What I'd like to return is any Page
, Field
, or Option
whose label contains the text, the path from the containing report to the node, and the labels for all nodes and edges along the way. So, if the page name contains the text, just the page and its label are returned. If an option contains the text Page -hasField-> Field -hasOption-> Option
will be returned along with all of their labels as well. This is so that we can better describe why a page is being returned and how the user can interact with the page to get the results they desire.
In my mind, I've broken down the problem into 3 parts and have found various solutions for each, but I can't seem to tie them together. The first is to find the nodes and the report to which they belong (easily done).
The second is to find all triples along the path. While I can do this by hard-coding the relationships, I'd like to keep this generic, if possible, so that new relationships are automatically picked up as we build out the graph.
The third is to structure the results into a tree with each page as a root and the Fields
and Options
nested so that the application is able to display the pages as results with descriptions of each of the matching fields/options underneath. I have found that if I use CONSTRUCT
with JSON-LD as the output format (with all of the triples for testing right now), this gets me most of the way there, however it doesn't build out the tree so much as list each of the nodes along with the URI for the child nodes. I've read that you can do "framing" on this, but I'm not sure if this is something that is done in SPARQL or the application.
So, to summarize my questions:
- Is it possible to use SPARQL to get the information that I want in the format that I want (or at least most of the way there where I can easily do the rest in the application)?
- Am I thinking about the problem correctly? If not, how should I be thinking about it?
- Is it possible to return all of the triples that make up a path between two nodes? More specifically, if I have a list of pairs of nodes, is it possible to return all of the triples that make up all of the paths between all pairs?
- Is it possible to take the previous result set of triples and turn that into a tree in JSON? Is it best to use "framing" or is there some other term that I should be searching for?