Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph data API operation #267

Merged
merged 34 commits into from
Nov 28, 2016
Merged

Graph data API operation #267

merged 34 commits into from
Nov 28, 2016

Conversation

benjamingeer
Copy link

@benjamingeer benjamingeer commented Sep 19, 2016

This implements the API operation /v1/graphdata/, which returns a graph of resources that are reachable from a certain resource.

  • The depth of the search is configurable in the request (via the ?depth query parameter, currently not used in the SALSAH GUI, so it defaults to a depth of 4).
  • The graph includes both outbound and inbound links.
  • The graph includes any link that's a subproperty of knora-base:hasLinkTo, except:
    • If resource R1 knora-base:isPartOf resource R2, no link from R1 to R2 is included in the graph.
  • The graph excludes deleted resources and links, as well as resources and links that the user doesn't have permission to see.

The old SALSAH GUI used arbor.js to render the graph in JavaScript. Since that library hasn't been updated in 5 years, I've replaced it with the better-maintained and easier-to-use Cytoscape library.

After much experimentation with different SPARQL query designs (see #269), this implementation uses simple recursive SPARQL queries. I haven't tested it with a huge graph, but performance seems OK for graphs that aren't very big. To improve performance, it doesn't return resource properties (as the old SALSAH did). RDFS inference is also used on GraphDB for better performance.

I also did a little refactoring so the responders no longer decide whether to use inference, in the interest of simplifying the responders. Since not every triplestore offers this choice on a per-query basis, I think it's better to assume that either the repository was created with inference enabled or it wasn't. So now the store package enables inference only with GraphDB, and it's up to the templates to disable it if they don't want it (which they currently do anyway).

Closes #269.

@benjamingeer benjamingeer added the enhancement improve existing code or new feature label Sep 19, 2016
@benjamingeer benjamingeer added this to the Beta Release milestone Sep 19, 2016
@benjamingeer benjamingeer changed the title Graph view query Graph data API operation Nov 18, 2016
@tobiasschweizer
Copy link
Contributor

tobiasschweizer commented Nov 25, 2016

I have a problem regarding permissions. I wanted to open http://localhost:3333/v1/graphdata/http%3A%2F%2Fdata.knora.org%2Fa-thing-with-text-values in graph view, but did not see any results. I am logged in as anything-user.

These two API requests give me all information about the resources (including the links):
http://localhost:3333/v1/resources/http%3A%2F%2Fdata.knora.org%2Fa-thing-with-text-values
http://localhost:3333/v1/resources/http%3A%2F%2Fdata.knora.org%2Fa-thing

But the request to graph view gives me an empty result
http://localhost:3333/v1/graphdata/http%3A%2F%2Fdata.knora.org%2Fa-thing-with-text-values

{
    "nodes": [],
    "edges": [],
    "userdata": {
        "email": "anything.user01@example.org",
        "username": "anything-user",
        "firstname": "Anything",
        "projects_info": [{
            "basepath": null,
            "shortname": "anything",
            "description": null,
            "logo": null,
            "id": "http://data.knora.org/projects/anything",
            "keywords": null,
            "rights": null,
            "longname": "Anything Project"
        }],
        "user_id": "http://data.knora.org/users/9XBCrDV3SRa7kS1WwynB4Q",
        "lastname": "User01",
        "token": null,
        "active_project": null,
        "projects": ["http://data.knora.org/projects/anything"],
        "lang": "de",
        "password": null
    },
    "status": 0
}

@tobiasschweizer
Copy link
Contributor

tobiasschweizer commented Nov 25, 2016

Do you plan to include the resources' properties (besides linking properties) as well?

In the old graph view, we had the option to expand a resource's properties to get more information about the instance.

@@ -20,7 +20,7 @@
knora-base:isDeleted false ;
knora-base:attachedToUser <http://data.knora.org/users/9XBCrDV3SRa7kS1WwynB4Q> ;
knora-base:attachedToProject <http://data.knora.org/projects/anything> ;
rdfs:label "Ein Ding für wen, der die Dinge liebe" ;
rdfs:label "Ein Ding für wen, dem die Dinge gefallen" ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

für jemanden, dem

the new generation of triplestores will do a grammar check and randomly reject transactions if the found a violation of German grammar

@benjamingeer
Copy link
Author

Do you plan to include the resources' properties (besides linking properties) as well?

Lukas and I decided not to do this, for better performance. We can add some JavaScript that opens the resource viewer if you click on a node.

@benjamingeer
Copy link
Author

But the request to graph view gives me an empty result

This is because I forgot that link values for standoff links don't have permissions. Fixed.

I also noticed that if you query a node that has no links, you get an empty graph. Fixed this too.

Added tests for both cases.

@tobiasschweizer
Copy link
Contributor

Ok, the query for http://localhost:3333/v1/graphdata/http%3A%2F%2Fdata.knora.org%2Fa-thing-with-text-values works now.

I encounter a strange behavior when opening some resources of type Thing in the GUI. Sometimes the GUI tries to display them as if they were books.

For example in the case of "excluded alpha":

excluded_alpha

Could this be caused by a change in imagebase.js?

Another thing that attracted my attention is the mouse wheel event in the graph view. I would expect it to make the graph scale but instead it flickers.

# Conflicts:
#	webapi/src/main/scala/org/knora/webapi/KnoraService.scala

QueryResultEdge(
linkValueIri = rowMap("linkValue"),
sourceNodeIri = if (outbound) startNode.nodeIri else nodeIri,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment here explaining why the Iris are swapped depending on the state of outbound (outgoing or incoming links)?

@benjamingeer
Copy link
Author

I opened another issue for the isPartOf problem: #334, and added comments as requested. OK to merge now?

@benjamingeer benjamingeer merged commit 0ffbf84 into develop Nov 28, 2016
@benjamingeer benjamingeer deleted the wip/graph-query branch November 28, 2016 13:51
SepidehAlassi added a commit that referenced this pull request Dec 13, 2016
* develop:
  Improve configuration for more concurrent requests (#338)
  Upgrade to Scala 2.12 (#343)
  Fix various inconsistencies in knora-base.ttl and docs. (#330)
  Fix language switching and login/logout in SALSAH (#331)
  Graph data API operation (#267)
  Allow connections over HTTPS (#332)
  Update README.md
  Add link to GraphDB.
  fix (salsah): Add missing JavaScript “var”.
  fix (webapi): Fix RouteUtilV1 so it returns HTML instead of JSON when requested (#326)
  Ontology and documentation fixes. (#325)
  fix (salsah): Create multiple links in a resource, and other bug fixes (#315)
  feature (webapi): Make TransformData fix “test” labels on regions. (#311)
  Fixes for subclasses and subproperties (#303)
  Add script to update docs on knora.org (#300)
  docs: Make trivial change for testing purposes.
  fix (webapi): CORS problems (#307)
  Use inference to optimise searches on GraphDB (#301)
@benjamingeer benjamingeer mentioned this pull request Jul 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improve existing code or new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants