neosemantics
neosemantics copied to clipboard
Feature: Optional specificity for schema mappings
Summary of the Problem:
There currently doesn't appear to be a way to designate properties on different types of nodes but with the same name as different RDF schema types. I think this would be a common use-case, so please let me know if I've missed the proper way to solve this problem or other workarounds.
Description:
For example, if you have a title
property in two different nodes, you can’t specify a mapping specific to the node, only the property name across all nodes.
So the following would be impossible, since there is no more specificity that can be made when defining mappings for the second argument in addSchemaToMapping(<mapping reference node>, <neo4j element>, <rdf element>)
:
Neo4j Schema Element | Element Type | Schema.org Element |
---|---|---|
Person | label | http://schema.org/Person |
title | property | https://schema.org/jobTitle |
------------ | ------------- | ------------- |
Movie | label | http://schema.org/Movie |
title | property | http://schema.org/name |
Workaround # 1: A potential, but impractical solution would be to disambiguate the Neo4j schema properties in the LPG graph, to look like:
Neo4j Schema Element | Element Type | Schema.org Element |
---|---|---|
Person | label | http://schema.org/Person |
person.title | property | https://schema.org/jobTitle |
------------ | ------------- | ------------- |
Movie | label | http://schema.org/Movie |
movie.title | property | http://schema.org/name |
Then you can have separate mappings for each one, but that means many of the properties we store on nodes in the LPG need prefixes to namespace them which makes non-RDF querying much more verbose.
Workaround # 2:
There is an option to use classes as nodes instead of as labels which may help.
However, my intention was hoping to avoid direct coupling of the RDF neosemantics
naming conventions in my graph by using the nice schema mapping features.
Proposed Solution
An optional argument to the addMappingToSchema
could limit the mapping to only be applied to a Node or Relationship type, like so:
addSchemaToMapping(<mapping reference node>, <neo4j element>, <rdf element>, <applicable labels>)
To minimize the impact on existing users, the new label-scoped mappings could be stored separately from the existing mappings and would take precedence over un-scoped mappings when determining the RDF schema element to use.
And thank you! I really appreciate this useful library and all of the wonderful features that are already available.
Hi @dshunfen , thanks for your comment!
You're right, in its current version there is no way of defining label-specific property mappings. I did a number of simplifying assumptions when designing the mapping feature in an attempt not to over-engineer it before hearing from people using it.
One of these assumptions was to think that people apply naming conventions for properties similar to what you describe as workaround 1, that is using customerName
or customerTitle
as property names for nodes labelled as Customer
rather than just name
or title
. But I understand that it is not always the case and sometimes generic property names are used for good reason.
I like your proposed solution. Watch this space for updates.
Cheers,
JB.