GraphStore`
GraphStore`

SPARQLAggregate

SPARQLAggregate["var"agg]

is a query operator that yields a solution containing the variable "var" whose value is computed from the aggregate agg.

SPARQLAggregate[{"var1"agg1,"var2"agg2,}]

yields a solution containing multiple aggregates.

SPARQLAggregate[aggs,groupby]

aggregates solutions grouped by the value of groupby.

SPARQLAggregate[aggs,groupby,having]

includes only groups for which having evaluates to True.

SPARQLAggregate[aggs,groupby,having,orderby]

orders groups by the value of orderby.

Details and Options

  • A RightComposition of operators SPARQLSelect[]/*/*SPARQLAggregate[]/* can be used in SPARQLExecute to query a SPARQL endpoint. Composition is also supported.
  • SPARQLAggregate[] can be applied to the result of a SPARQLSelect query.
  • In SPARQLAggregate["var"agg], agg is usually of the form SPARQLEvaluation["f"][u1,u2,], where "f" is the name of a SPARQL aggregate function, and each ui is a SPARQLVariable whose associated values withing a solution group are supplied to the aggregate function.
  • Named SPARQL aggregate functions include:
  • "COUNT"counts the number of elements in a group
    "SUM"totals the values of a group
    "MIN"returns the minimum value in a group
    "MAX"returns the maximum value in a group
    "AVG"returns the averag of the values in a group
    "GROUP_CONCAT"joins String values of a group
    "SAMPLE"returns an arbitrary value from the group
  • SPARQLEvaluation["GROUP_CONCAT"][var, "Separator" -> "sep"] can be used to join strings using separator "sep". The default separator is " " (space).

Examples

open allclose all

Basic Examples  (1)

Data about fruits:

The vocabulary:

Count the fruits:

Find the number of fruits per color:

Scope  (4)

Compute the total of the values associated with key "x":

Aggregate after grouping by the value of key "y":

Filter groups by the mean of the values of key "x":

Order groups by a sample of the values of key "y" in descending order:

Data about works and composers:

Count the number of works by composer:

The same query using a SPARQL query string:

Specify a graph which contains multiple values per entity for property p1:

Obtain the data, taking for each entity the maximum value of property p1:

Specify a separator for the "GROUP_CONCAT" aggregate:

Generalizations & Extensions  (1)

The aggregate can be an arbitrary function:

Multiple arguments can be given:

Applications  (1)

Compute the mean and the weighted mean of some data:

Wolfram Research (2019), SPARQLAggregate, Wolfram Language function, https://reference.wolfram.com/language/GraphStore/ref/SPARQLAggregate.html.

Text

Wolfram Research (2019), SPARQLAggregate, Wolfram Language function, https://reference.wolfram.com/language/GraphStore/ref/SPARQLAggregate.html.

CMS

Wolfram Language. 2019. "SPARQLAggregate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/GraphStore/ref/SPARQLAggregate.html.

APA

Wolfram Language. (2019). SPARQLAggregate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/GraphStore/ref/SPARQLAggregate.html

BibTeX

@misc{reference.wolfram_2024_sparqlaggregate, author="Wolfram Research", title="{SPARQLAggregate}", year="2019", howpublished="\url{https://reference.wolfram.com/language/GraphStore/ref/SPARQLAggregate.html}", note=[Accessed: 22-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_sparqlaggregate, organization={Wolfram Research}, title={SPARQLAggregate}, year={2019}, url={https://reference.wolfram.com/language/GraphStore/ref/SPARQLAggregate.html}, note=[Accessed: 22-November-2024 ]}