In a Drupal Triplestore, only Items should have Statements

I was setting up the Metatag module on this blog and it got me thinking about something I wrote about previously. When I originally wrote about a triplestore in Drupal, I was thinking that the user would be able to add Statements to anything, because, why not? However, the more I thought about it, the more I realized this didn't make any sense. For starters, one of the fundamental concepts that needs to be preserved is being able to query a single entity for all of the data and being able to preserve several hierarchies of that data. For instance, you may have a class of restaurant and subclass of McDonald's and lastly, an instance of McDonald's which is your local physical location. Without having a single entity to represent this, it would be difficult to attempt to query for all of the restaurants in your local area and discover the McDonald's, which are only indirectly related to restaurant.

But then we get to the problem that made me think about Statements on other entities in the first place: there should be a way to add structured data to any entity in Drupal. I think a better solution might be to create a special Entity Reference field that creates a new item if one doesn't already exist and uses an entity bundle and field mapping to create and update an Item with the mapped data. This will create duplicate data, but will simplify the data access model. All of the existing fields can be mapped to Value entity fields of the same data type. The only exception is Entity Reference which will need to follow the entity, and create an Item for that entity. When create, update, or delete actions are preformed, Activity objects will be created providing a log of changes to these entities.

Another thing I was wrong about was the need to implement SPARQL to insert items. I think that is a ton of work just to get off the ground. Instead, it would be better to implement the endpoints in ActivityPub. While they do not provide the flexibility of SPARQL, it lets apps like chickaree start using the store much sooner.