query-40fd208ab2bd8f31090d4570ac9157d3

rq turtle/ttl

Software licenses

Taking in consideration license-sub-editions and counting software using them.

Taking in consideration direct-usage by that license.

Taking in consideration FSF and OSI approval.

Author: [[User:Valerio Bozzolan]] and contributors

Date: 2023

License: CC 0, public domain

https://phabricator.wikimedia.org/P52339

https://www.wikidata.org/wiki/User:Valerio_Bozzolan

SELECT ?count_broad_software ?count_exact_software ?license ?licenseLabel ?min_license_date ?approved_fsf ?approved_osi WHERE {

# START SUB-QUERY: NO-LABEL { SELECT ?license (COUNT (DISTINCT ?broad_software) AS ?count_broad_software) (SAMPLE(?count_exact_software) AS ?count_exact_software) (SAMPLE(?min_license_date) AS ?min_license_date) WHERE {

  # START SUB-QUERY: SOFTWARE COUNTER
  {
    SELECT
      ?license
      (COUNT(DISTINCT ?software)  AS ?count_exact_software)
      (MIN   (?license_date) AS ?min_license_date)
    WHERE
    {

      # START SUB-QUERY: LICENSE
      {
        SELECT ?license WHERE {
          # This is a license.
          ?license wdt:P31/wdt:P279* wd:Q207621.

          # The license must not be confused with a software (it happens).
          MINUS {
            ?license wdt:P31/wdt:P279* wd:Q7397.
          }
        } GROUP BY ?license
      }
      # STOP SUB-QUERY: LICENSE

      # License must be used by software.
      ?software wdt:P275 ?license.
      wd:Q7397 ^wdt:P279*/^wdt:P31 ?software.

      # The license may have a publication date.
      OPTIONAL {
        ?license wdt:P577 ?license_date.
      }

    } GROUP BY ?license
  }
  # STOP SUB-QUERY: SOFTWARE COUNTER

  # License may have editions.
  # Software may use this license edition.
  OPTIONAL {
    ?child_license wdt:P629*/wdt:P279* ?license.
    ?broad_software wdt:P275 ?child_license.
    wd:Q7397 ^wdt:P279*/^wdt:P31 ?broad_software.
  }
} GROUP BY ?license

} # STOP SUB-QUERY: NO-LABEL

# The license may be approved by OSI / FSF. BIND (EXISTS{?license wdt:P790 wd:Q48413. } AS ?exists_fsf ) BIND (EXISTS{?license wdt:P790 wd:Q845918.} AS ?exists_osi ) BIND (IF(?exists_fsf, "✅ FSF", "❌ FSF") AS ?approved_fsf) BIND (IF(?exists_osi, "✅ OSI", "❌ OSI") AS ?approved_osi)

# Helps get the label in your language, if not, then en language SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY DESC(?count_broad_software)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Software licenses
# Taking in consideration license-sub-editions and counting software using them.
# Taking in consideration direct-usage by that license.
# Taking in consideration FSF and OSI approval.
# Author: [[User:Valerio Bozzolan]] and contributors
# Date: 2023
# License: CC 0, public domain
# https://phabricator.wikimedia.org/P52339
# https://www.wikidata.org/wiki/User:Valerio_Bozzolan

SELECT 
  ?count_broad_software
  ?count_exact_software
  ?license
  ?licenseLabel
  ?min_license_date
  ?approved_fsf
  ?approved_osi
WHERE
{

  # START SUB-QUERY: NO-LABEL
  {
    SELECT 
      ?license
      (COUNT (DISTINCT ?broad_software) AS ?count_broad_software)
      (SAMPLE(?count_exact_software)    AS ?count_exact_software)
      (SAMPLE(?min_license_date)        AS ?min_license_date)
    WHERE 
    {

      # START SUB-QUERY: SOFTWARE COUNTER
      {
        SELECT
          ?license
          (COUNT(DISTINCT ?software)  AS ?count_exact_software)
          (MIN   (?license_date) AS ?min_license_date)
        WHERE
        {

          # START SUB-QUERY: LICENSE
          {
            SELECT ?license WHERE {
              # This is a license.
              ?license wdt:P31/wdt:P279* wd:Q207621.

              # The license must not be confused with a software (it happens).
              MINUS {
                ?license wdt:P31/wdt:P279* wd:Q7397.
              }
            } GROUP BY ?license
          }
          # STOP SUB-QUERY: LICENSE

          # License must be used by software.
          ?software wdt:P275 ?license.
          wd:Q7397 ^wdt:P279*/^wdt:P31 ?software.

          # The license may have a publication date.
          OPTIONAL {
            ?license wdt:P577 ?license_date.
          }

        } GROUP BY ?license
      }
      # STOP SUB-QUERY: SOFTWARE COUNTER

      # License may have editions.
      # Software may use this license edition.
      OPTIONAL {
        ?child_license wdt:P629*/wdt:P279* ?license.
        ?broad_software wdt:P275 ?child_license.
        wd:Q7397 ^wdt:P279*/^wdt:P31 ?broad_software.
      }
    } GROUP BY ?license
  }
  # STOP SUB-QUERY: NO-LABEL  

  # The license may be approved by OSI / FSF.
  BIND (EXISTS{?license wdt:P790 wd:Q48413. } AS ?exists_fsf )
  BIND (EXISTS{?license wdt:P790 wd:Q845918.} AS ?exists_osi )
  BIND (IF(?exists_fsf, "✅ FSF", "❌ FSF")   AS ?approved_fsf)
  BIND (IF(?exists_osi, "✅ OSI", "❌ OSI")   AS ?approved_osi)

  # Helps get the label in your language, if not, then en language
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?count_broad_software)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v11("?approved_fsf"):::projected v12("?approved_osi"):::projected v8("?broad_software") v7("?child_license") v9("?count_broad_software"):::projected v9("?count_exact_software"):::projected v9("?exists_fsf") v10("?exists_osi") v2("?license"):::projected v4("?license_date") v9("?min_license_date"):::projected v3("?software") a1((" ")) a2((" ")) a3((" ")) a4((" ")) a5((" ")) c4(["wd:Q7397"]):::iri c9(["bd:serviceParam"]):::iri c3(["wd:Q207621"]):::iri c11(["#91;AUTO_LANGUAGE#93;,en"]):::literal v2 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c3 subgraph minus0["MINUS"] style minus0 stroke-width:6px,fill:pink,stroke:red; v2 --"wdt:P31"--> a2 a2 --"wdt:P279"--> c4 end v3 --"wdt:P275"--> v2 a3 --"wdt:P279"--> c4 v3 --"wdt:P31"--> a3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P577".-> v4 end bind3[/"count(?software)"/] v3 --o bind3 bind3 --as--o v9 bind4[/"min(?license_date)"/] v4 --o bind4 bind4 --as--o v9 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P629".-> a4 a4 --"wdt:P279"--> v2 v8 --"wdt:P275"--> v7 a5 --"wdt:P279"--> c4 v8 --"wdt:P31"--> a5 end bind8[/"count(?broad_software)"/] v8 --o bind8 bind8 --as--o v9 bind9[/"sample(?count_exact_software)"/] v9 --o bind9 bind9 --as--o v9 bind10[/"sample(?min_license_date)"/] v9 --o bind10 bind10 --as--o v9 v2 --"wdt:P790"--> null bind11[/" "/] subgraph bind11e0["Exists Clause"] e0v1 --"wdt:P790"--> e0c2 e0v1("?license"):::projected e0c2(["wd:Q48413"]):::iri end bind11--EXISTS--> bind11e0 v2 --o bind11 null --o bind11 null --o bind11 bind11 --as--o v9 v2 --"wdt:P790"--> null bind12[/" "/] subgraph bind12e1["Exists Clause"] e1v1 --"wdt:P790"--> e1c2 e1v1("?license"):::projected e1c2(["wd:Q845918"]):::iri end bind12--EXISTS--> bind12e1 v2 --o bind12 null --o bind12 null --o bind12 bind12 --as--o v10 bind13[/"if(?exists_fsf,'✅ FSF','❌ FSF')"/] v9 --o bind13 bind13 --as--o v11 bind14[/"if(?exists_osi,'✅ OSI','❌ OSI')"/] v10 --o bind14 bind14 --as--o v12 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end