ruby-rdf / spira

Spira is a framework for viewing RDF data as model objects
http://rubygems.org/gems/spira
The Unlicense
58 stars 36 forks source link

Spira#count counts subjects - should it count instances? #37

Open Robsteranium opened 10 years ago

Robsteranium commented 10 years ago

I'm just getting to grips with Spira and I've found something that strikes me as odd (the mailing list looks a bit quiet so I'm posting here instead). I wonder if this is an expectation set by the OOP/ ActiveRecord world that simply doesn't apply in the graph/ RDF world...

I expect Spira::Base#count to return the count of objects of the relevant type - i.e. the distinct count of "?s a ", the number of instances. Instead #count returns the count of occurrences of those subjects - i.e. the number of triples where a "?s a " is the subject. In OOP terms this is basically like counting the number of attributes which is certainly not what I would expect.

I realise that what might need 'fixing' is in fact my expectations about how objects work in a graph world. If so, I'd be very grateful if someone could elaborate on this.

Nevertheless the apparent congruence between the AR and Spira public APIs leads me to believe that I won't be the only one making this mistake! It might be clearer, for example, if Spira distinguished between a #count and a #count_of_subjects method.

cordawyn commented 10 years ago

I agree with you here. However, it should be noted that there are two count methods defined for Spira::Base: a class method and an instance method. I believe, Spira::Base.count (class method) should return the number of "model types" (and it actually says so). Spira::Base#count returns "the number of RDF::Statements this projection has" (looks to be implemented properly).

So, if Spira::Base.count does not work as expected, there's definitely a bug there. Please make sure you're using the correct "count" ;-) Does Spira::Base.count work for you?

Speaking of the congruence between AR and Spira, you'd also call ActiveRecord::Base.count to count the records in the DB, not (non-existant) ActiveRecord::Base#count.