User:Daniel Mietchen/Sandbox4URLshortening

From Wikidata
Revision as of 01:47, 14 September 2020 by Research Bot (talk | contribs) (viral transmission ontology skeleton)
Jump to navigation Jump to search

This page is used in conjunction with m:Special:UrlShortener as a workaround to https://phabricator.wikimedia.org/T220703 . URL shortening can also be triggered via the MediaWiki API.

The following query uses these:

  • Properties: KIT Linked Open Numbers ID (P5176)  View with Reasonator View with SQID, numeric value (P1181)  View with Reasonator View with SQID, title (P1476)  View with Reasonator View with SQID
    # Most common ngrams in titles of works that contain the string "bologna" 
    # where the work has not been tagged as being about anything that contains that string
    
    SELECT DISTINCT ?Ngram ?Count ?Length ?CountTimesLength ?N ?ExamplePub ?ExamplePubTitle
    
    WITH
    { # Generating a list of regexes to look for the NumericValue-th word in a string                                                              
      SELECT ?Regex1 ?Regex2 ?Regex3 ?Regex4 ?NumericValue 
        { 
          ?NumberItem wdt:P5176 []; wdt:P1181 ?NumericValue . 
          FILTER( ?NumericValue > 0 ) 
          FILTER( ?NumericValue < 51)
          BIND( CONCAT( "^([^ ]+ ){", STR( ?NumericValue - 1 ),"}([^ ]+) .*") AS ?Regex1)
          BIND( CONCAT( "^([^ ]+ ){", STR( ?NumericValue + 1 ),"}([^ ]+) .*") AS ?Regex2) 
          BIND( CONCAT( "^([^ ]+ ){", STR( ?NumericValue + 3 ),"}([^ ]+) .*") AS ?Regex3) 
          BIND( CONCAT( "^([^ ]+ ){", STR( ?NumericValue + 5 ),"}([^ ]+) .*") AS ?Regex4) 
        }
    } AS %regexes 
    WITH
    { # Generating a list of titles to be analyzed
      SELECT ?Title ?Publication ?Seeds ?ClearTitleLength
       { # Choosing the entities whose titles are to be analyzed
          {
              SELECT ?Title ?Publication  WHERE {  
               hint:Query hint:optimizer "None".
    
                {  SERVICE wikibase:mwapi {
                  bd:serviceParam wikibase:api "Search";
                                  wikibase:endpoint "www.wikidata.org";
                                  mwapi:srsearch "virus and haswbstatement:P31=Q13442814".
                  ?page_title wikibase:apiOutput mwapi:title.
                }
                }
                UNION
                {  SERVICE wikibase:mwapi {
                  bd:serviceParam wikibase:api "Search";
                                  wikibase:endpoint "www.wikidata.org";
                                  mwapi:srsearch "virus -and haswbstatement:P31=Q13442814".
                  ?page_title wikibase:apiOutput mwapi:title.
                }
                }
                                      
            BIND(IRI(CONCAT(STR(wd:), ?page_title)) AS ?Publication)
            ?Publication wdt:P1476 ?Title.
    
            FILTER (REGEX(LCASE(?Title), "(transmi