sempr-tk / sempr

SEMPR - Semantic Environment Mapping, Processing and Reasoning
BSD 3-Clause "New" or "Revised" License
7 stars 1 forks source link

Reworked RDFEntity interface and added SemanticEntity #37

Closed niniemann closed 6 years ago

niniemann commented 6 years ago

This PR implements two major changes which build upon each other:

  1. The RDFEntity has essentially been renamed to RDFVector. The RDFEntity-Class still exists, but is only used as an interface to containers of rdf triples. Every RDFEntity must be iterable, but can provide its own implementation of the iterator. Using this I also simplified the RDFPropertyMap, which had a really messed up structure as it had to store everything twice -- once in a map, once in the RDFEntitys triple-vector. Now the RDFPropertyMap only stores a map and constructs the triples on demand.
  2. I implemented the SemanticEntity-class, which follows a completely different approach to provide RDF triples to the data: You can register member variables to make them directly visible, which allows you to use them as usual (type safety etc), without any casting involved. See the updated README for more information.

Of course there are still some limitations. One of them is the fact that you need to derive from SemanticEntity to make use of its features... This may be improved in the future.

Oh, and I'm also not quite satisfied with the RDFEntity-iterator-stuff. Both the RDFPropertyMap and the SemanticEntity do not store any actual Triples , but the iterator constructs them on demand, without storing them. I use a static variable in the iterators dereference-operator for that, but that means that the returned const Triple& is not really const! As soon as the iterator is incremented and dereferenced again, the static local variable changes its value... And when the iterator goes out of scope? :slightly_frowning_face:

So, be careful with that, I haven't really figured out how to do this properly. Any ideas? (Take a look at this part of the code to see what I mean).

niniemann commented 6 years ago

By the way, although this implementation differs from what I proposed previously, it fixes #31. The overhaul of RDFPropertyMap has removed the need for the workaround when deleting entries, and the SemanticEntity is the static alternative.

niniemann commented 6 years ago

I've updated the TripleIterator to return triples by value instead of reference. I'm still open for naming-suggestions, but wouldn't mind to leave it as it is. :wink: