Quick Start to Working in an RDF Mindset

Sep 3, 2015 at 6:39 PM
Edited Sep 3, 2015 at 6:41 PM
I've read the documentation of BrightstarDB's entity framework and I think I get the jist of how it works, my question has more to do with how to enforce advance relationships espically at run time.

For example I want to define a concept of Character which is a Species. Human is a Species. Humans can walk. Jack is a Human. Even more so I want to do this to be dynamic, so the concepts of Character and Species might be defined strongly typed, but Human for sure is dynamic.

How would I model that in Brightstar's Entity Framework?

Then walking is temporal and directional, Jack walks from A to B @ rate of 1mph. How would I model that?

I'm totally new to RDF so these might be really stupid questions, any help would be appreciated.
Sep 4, 2015 at 10:23 AM

I think some advanced relationships that are possible with RDF are probably not possible in the confines of C# classes/interfaces.

I think that your model could be quite close to what you outline:

Define ICharacter and ISpecies as interfaces.
ICharacter has a Species property which returns an instance that implements the ISpecies interface.
Then on your ISpecies class you would define properties that specify common species characteristics such as a base movement rate.
Human might have additional properties and actually in B*, that is OK - you can split those other properties out into other interface and then use the casting mechanism to change the EF class you bind to at runtime (see http://brightstardb.readthedocs.org/en/latest/Entity_Framework/#casting-entities).

Another thing to mention is that you can also extend the generated class as it is deliberately generated as a partial class. So lets say for example that you want to allow characters to have a movement bonus that might vary from character to character; you could add a property to ICharacter to record this bonus; and then add a method to the Character class to return the base movement rate + the movement bonus. Hopefully you can see what I mean!

Walking and other such actions I often model as events. So I might have an IEvent base interface with properties like Start, End (or Duration). Then you can create derived interfaces such as MovementEvent which might add properties like FromLocation, ToLocation and Rate. Again you could make use of methods added to the derived classes to do things like calculate and update the Duration of an event based on other information (like the distance between FromLocation and ToLocation and the Rate of movement). By capturing events you can do things such as create dependencies between events (e.g. event B starts after event A completes) or create hierarchies of events (e.g. event A consists of sub-events B and C), and so you can start to get some useful flexibility out of it. You could take a look at http://motools.sourceforge.net/event/event.html for some inspiration for a simple but quite flexible event model.

Finally I would also say that if you find EF to be a bottleneck, it might be worth taking the time to learn SPARQL and use SPARQL and our DataObjects API - this is more low-level (no LINQ, so you need SPARQL for the queries), but much more flexible and it maps to dynamic objects in C# so it may end up being easier to work with and modify as your requirements develop.

Hope this helps!

Sep 4, 2015 at 1:38 PM
Thank you for the quick reply.

Can I mix and match EF and your Data API? For example I do the high level modeling in EF and write a query engine through your Data API?