Incorrect Sum if more than one property has same numerical value

From semantic-mediawiki.org

No, the sum is correct based on the declaration of `[[Regimen::1]] [[Regimen::1]][[Regimen::1]]` which is equal to `[[Regimen::1]]` due to `[[Regimen::1]]` representing the same fact about the subject X possessing an attribute of `Regimen` with `1`.

Modeling is based on a declarative attribute not a mere collection of added annotation like `[[Regimen::1]] [[Regimen::1]] ...` if you need to add the same fact (being Regimen=1) then I'd suggested you have a look at the subobject to model your data (see Examples/Queries/Aggregating numbers).

08:14, 28 January 2015

Thank you very much, I appreciate your response. I've taken your example and worked out something that can work for me (I understand that I don't need to separate #subobject:1, etc. like this, but it's how my use case will be):

{{#subobject:1
 |Regimen=1
}}
{{#subobject:2
 |Regimen=1
}}
{{#subobject:1
 |Variant=1
}}
{{#subobject:2
 |Variant=1
}}
{{#subobject:3
 |Variant=1
}}
{{#subobject:4
 |Variant=1
}}
{{#subobject:5
 |Variant=1
}}
Total Regimens: {{#ask: [[Regimen::+]]
 |?Regimen
 |format=sum
}}

Total Variants: {{#ask: [[Variant::+]]
 |?Variant
 |format=sum
}}

As a trial, I've put the above data on two separate pages, but I'm confused why the query only returns the sum from a single page (Regimens: 2; Variants: 5) rather than across the entire site (which I thought was the default). What needs to be changed about my query to be able to calculate a total for the number of times Regimen=1 and Variant=1 is used throughout the entire wiki?

To verify, Special:Properties shows:

Regimen of type Number (4 uses)
Variant of type Number (10 uses)

I'd just like to be able to display this as a number elsewhere on the site. In case it helps, the pages are: http://hemonc.org/wiki/Editing_test_page http://hemonc.org/wiki/Editing_test_page_2

Is there any way to avoid needing to manually assign #subobject:n, #subobject:n+1, #subobject:n+2, etc.? It doesn't appear so....

Thank you again--we're planning on utilizing many other functions of Semantic Mediawiki once we can learn the basics.

10:24, 28 January 2015

> Is there any way to avoid needing to manually assign #subobject:n, #subobject:n+1, #subobject:n+2, etc.? It doesn't appear so....

Rather then trying to follow the normal "data hoarding" approach, SMW enforces some conceptional restrictions on how "facts" can and should be modeled (e.g. Help:Classification).

The main object of interest to describe something is the subject (which in most cases is a wikipage) and by assigning a predicate together with a value (e.g. Regimen=1 and Variant=1) one describes this subject though those attributes. If such attributive declaration represents the same "fact" it is handled as the same entity of knowledge (a thing that describes the subject and therefore only appears once).

The same principle about "describing the same thing" is applied to subobjects. If a subobject contains the same declarations then it is being recognized as being the same (technically a hash is produced to compare those entities) unless it describes something different (using an explicit name opposed to the auto-identifier given without an explicit name). Using a different name on a subobject embedded within the same subject creates an independent entity about something that may or may not describe by the same facts.

Doing:

{{#subobject:
 |Foo=Bar
}}
{{#subobject:
 |Foo=Bar
}}

represents the same fact while

{{#subobject:Foo
 |Foo=Bar
}}
{{#subobject:Bar
 |Foo=Bar
}}

are equal in its declaration to produce the same annotation but are different to the end that it represents Subject X#Foo and the other Subject X#Bar. While it may seem to split hairs nevertheless it creates a clear and explicit distinction between those two subobjects.

The same thing can be achieved by using `@sortkey` (those are not equal hence treated as different entities and therefore can be queried individually):

{{#subobject:
 |Foo=Bar
 |@sortkey=Foo
}}
{{#subobject:
 |Foo=Bar
 |@sortkey=Bar
}}

PS: Sorry for the lengthy reply and I hope it explains the issue a bit better.

PSS: If you are unsure about how to model your content, it is always recommended to ask on the Semantic MediaWiki mailing lists for suggestions or if you encounter a technical issue to refer to [0].

[0] https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues

11:50, 28 January 2015

Thank you again. I believe I understand the reason for things being structured this way--I just wish there was a slightly easier alternative for my use case.

Regarding:

As a trial, I've put the above data on two separate pages, but I'm confused why the query only returns the sum from a single page (Regimens: 2; Variants: 5) rather than across the entire site (which I thought was the default). 

It is now displaying the proper totals Sum Regimen: 4 Sum Variant: 10

So this delayed update was likely due to caching or something else on my side. I had emailed the mailing list--that message is still in the moderation queue.

15:39, 28 January 2015