Wikidata:WikiProject PCC Wikidata Pilot/UC Davis/Example Queries

From Wikidata
Jump to navigation Jump to search

These queries are meant to show some queries specific for the UC Library and Special Collection Contributors.

For more basic queries help to understand SPARQL and the Wikibase RDF format, see the Wikidata Example Page

Reference Queries

[edit]

List of Carnegie Melon Classifications

[edit]

The |University recommendations suggest the Carnegie Classification of Institutions of Higher Education (P2643) predicate for organizing university organizations. Valid entries are sub-classes of Carnegie Classification of Institutions of Higher Education (Q4223026)

The following query uses these:

  • Properties: subclass of (P279)  View with Reasonator View with SQID
    SELECT ?s ?sLabel ?p ?pLabel ?gp ?gpLabel
    WHERE {
    #  https://www.wikidata.org/wiki/Q23337118
      ?s wdt:P279+ wd:Q4223026.
      ?s wdt:P279 ?p.
      OPTIONAL {
        ?p wdt:P279 ?gp .
        }  
       SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    } order by ?sLabel
    

Academic Queries

[edit]

What we are trying to do is find some information about professors in WikiData. We can do a simple search in Wikidata to find the class Professor. This is a subclass of a University Teacher.

Common Predicates for Professors

[edit]

The following query uses these:

  • Items: professor (Q121594)  View with Reasonator View with SQID
    SELECT ?p (count(?s) as ?c)
    WHERE {
    	?s ?p wd:Q121594 .
    }
    GROUP BY (?p)
    ORDER BY DESC(?c)
    LIMIT 10
    

From the example, most entries use Occupation, but some use professorship, and some use academic degree, but that's not a profession, so we can ge most with the first two. We expect from above to get about 14K entries in this case.

Common Predicates for professors

[edit]

The following query uses these:

  • Properties: occupation (P106)  View with Reasonator View with SQID, professorship (P803)  View with Reasonator View with SQID
    SELECT ?p (count(?s) as ?c)
    WHERE {
       BIND(wd:Q121594 as ?prof).
       VALUES (?p) {
          (ps:P106)
           (ps:P803)
        }
    	?s ?p ?prof .
    }
    group by (?p)
    

Okay, let's get some examples. Let's choose some professors that were educated at UC Davis or UCLA

UC Davis Professors

[edit]

The following query uses these:

  • Properties: educated at (P69)  View with Reasonator View with SQID, employer (P108)  View with Reasonator View with SQID, occupation (P106)  View with Reasonator View with SQID, professorship (P803)  View with Reasonator View with SQID
    SELECT ?s ?sLabel ?is ?from ?ucLabel
    WHERE {
      BIND(wd:Q121594 as ?prof).
      VALUES(?from) {
       (wdt:P69) (wdt:P108)
        }
      VALUES(?is) {
        (wdt:P106)
        (wdt:P803)
      }
      VALUES(?uc ?uc_name) {
    #     (wd:Q174710 "ucla")
         (wd:Q129421 "ucd")
        }
       ?s ?is ?prof .
       ?s ?from ?uc .
       SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    }
    

Queries on UC Davis

[edit]

Employees

[edit]

There are many persons that are Employed by UCD.

The following query uses these:

  • Properties: occupation (P106)  View with Reasonator View with SQID, professorship (P803)  View with Reasonator View with SQID, employer (P108)  View with Reasonator View with SQID
    SELECT ?s ?sLabel ?is ?what ?whatLabel
    WHERE {
      BIND(wd:Q121594 as ?prof).
      VALUES(?is) {
        (wdt:P106)
        (wdt:P803)
      }
       ?s ?is ?what .
       ?s wdt:P108 wd:Q129421  .
       SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    }
    

Organizations

[edit]

One goal of this project is that all organizations within UC Davis can be captured with a single query, where we look at organizations that are part of Davis.

The following query uses these:

  • Properties: part of (P361)  View with Reasonator View with SQID
    SELECT ?org ?orgLabel
     WHERE {
      bind(wd:Q129421 as ?ucd)
       ?org wdt:P361 ?ucd.
       SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    }
    

Predicates that Point to UC Davis

[edit]

The following query uses these:

Items that have UC Davis in the label

[edit]

The query below uses the CirrusSearch extension. This extension uses another indexer (elasticsearch) to allow much better text searches. These are the SERVICE extensions below:

The following query uses these:

SELECT DISTINCT ?item ?label
WHERE {
{
  SERVICE wikibase:mwapi
  {
    bd:serviceParam wikibase:endpoint "www.wikidata.org";
                    wikibase:api "Generator";
                    mwapi:generator "search";
                    mwapi:gsrsearch "inlabel:university_of_California_davis"@en;
                    mwapi:gsrlimit "max".
    ?item wikibase:apiOutputItem mwapi:title.
  }
  ?item rdfs:label ?label. FILTER( LANG(?label)="en" )

} UNION {
    SERVICE wikibase:mwapi
  {
    bd:serviceParam wikibase:endpoint "www.wikidata.org";
                    wikibase:api "Generator";
                    mwapi:generator "search";
                    mwapi:gsrsearch "inlabel:UC Davis"@en;
                    mwapi:gsrlimit "max".
    ?item wikibase:apiOutputItem mwapi:title.
  }
  ?item rdfs:label ?label. FILTER( LANG(?label)="en" )
}
}

The types of items that have these labels

[edit]

The following query uses these:

  • Properties: instance of (P31)  View with Reasonator View with SQID
    SELECT ?class ?classLabel ?cnt 
    WHERE {
    {
    SELECT ?class (count(*) as ?cnt)
    WHERE {  
    SELECT DISTINCT ?item ?class
    WHERE {
    {
      SERVICE wikibase:mwapi {
        bd:serviceParam wikibase:endpoint "www.wikidata.org";
                        wikibase:api "Generator";
                        mwapi:generator "search";
                        mwapi:gsrsearch "inlabel:university of California, davis"@en;
                        mwapi:gsrlimit "max".
        ?item wikibase:apiOutputItem mwapi:title. }
      ?item wdt:P31 ?class.
    } UNION {
        SERVICE wikibase:mwapi {
        bd:serviceParam wikibase:endpoint "www.wikidata.org";
                        wikibase:api "Generator";
                        mwapi:generator "search";
                        mwapi:gsrsearch "inlabel:UC Davis"@en;
                        mwapi:gsrlimit "max".
        ?item wikibase:apiOutputItem mwapi:title. }
        ?item wdt:P31 ?class.
    } } #order by ?item ?class limit 300
    } group by ?class order by ?class
    }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    } order by?classLabel
    

Reference Queries

[edit]

Specific Types of Objects

[edit]

Using the above query, we can limit the objects that we need to review by looking at the items that match the UC Davis label, and are instances of types that look like some sort of organization. From this, we can

The following query uses these:

  • Properties: instance of (P31)  View with Reasonator View with SQID
    SELECT ?item ?itemLabel (group_concat(?orglikeLabel;SEPARATOR=";") as ?orgs)
    {
    SELECT ?item ?itemLabel ?orglikeLabel
    WHERE {
      VALUES (?orglike) { (wd:Q2467461) (wd:Q4671277) (wd:Q856234) (wd:Q166118)
    (wd:Q167346) (wd:Q1143635) (wd:Q498162) (wd:Q13226383) (wd:Q180958)
    (wd:Q6498663) (wd:Q2659904) (wd:Q181916) (wd:Q16917) (wd:Q1664720) (wd:Q615150)
    (wd:Q1321960) (wd:Q28324850) (wd:Q4287745) (wd:Q494230) (wd:Q43229)
    (wd:Q23002039) (wd:Q31855) (wd:Q3918) (wd:Q1384955) }
    {
    SELECT DISTINCT ?item ?orglike
    WHERE {
    {
      SERVICE wikibase:mwapi {
        bd:serviceParam wikibase:endpoint "www.wikidata.org";
                        wikibase:api "Generator";
                        mwapi:generator "search";
                        mwapi:gsrsearch "inlabel:university of California, davis"@en;
                        mwapi:gsrlimit "max".
        ?item wikibase:apiOutputItem mwapi:title. }
      ?item wdt:P31 ?orglike.
    } UNION {
        SERVICE wikibase:mwapi {
        bd:serviceParam wikibase:endpoint "www.wikidata.org";
                        wikibase:api "Generator";
                        mwapi:generator "search";
                        mwapi:gsrsearch "inlabel:UC Davis"@en;
                        mwapi:gsrlimit "max".
        ?item wikibase:apiOutputItem mwapi:title. }
        ?item wdt:P31 ?orglike.
    } } }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    } } group by ?item ?itemLabel order by ?itemLabel
    

Potential Missing Oraganizations

[edit]

We may also be interested in Organizations that might by part of UC Davis, but are not properly Standardized. For example, this query shows potential Organizations that don't show to be partOf UC Davis

The following query uses these:

  • Properties: part of (P361)  View with Reasonator View with SQID, instance of (P31)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID
    SELECT ?item ?itemLabel WHERE {# (group_concat(?instanceLabel;SEPARATOR=";") as ?org_types) WHERE {
      filter(NOT EXISTS {?item  wdt:P361 wd:Q129421.} )
      filter(EXISTS{?item  wdt:P31/wdt:P279* wd:Q43229})
    {
      SELECT ?item WHERE {
      {
        SERVICE wikibase:mwapi {
          bd:serviceParam wikibase:endpoint "www.wikidata.org";
                        wikibase:api "Generator";
                        mwapi:generator "search";
                        mwapi:gsrsearch "inlabel:university of California, davis"@en;
                        mwapi:gsrlimit "max".
          ?item wikibase:apiOutputItem mwapi:title.
        }
      } UNION {
        SERVICE wikibase:mwapi {
        bd:serviceParam wikibase:endpoint "www.wikidata.org";
                        wikibase:api "Generator";
                        mwapi:generator "search";
                        mwapi:gsrsearch "inlabel:UC Davis"@en;
                        mwapi:gsrlimit "max".
        ?item wikibase:apiOutputItem mwapi:title.
        }
      }
    }
    }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    } limit 20 #group by ?item ?itemLabel