Project:QuickStatements: Difference between revisions

From MaRDI portal
Line 7: Line 7:
## Find the qIDs with a statement using P12 = WikidataQId
## Find the qIDs with a statement using P12 = WikidataQId
## The thing you want to export, here a part of the external url P205
## The thing you want to export, here a part of the external url P205
## [https://query.portal.mardi4nfdi.de/#%23 This query produces statements for%0A%23 https%3A%2F%2Fquickstatements.portal.mardi4nfdi.de%2F%23%2Fbatch%2Fnew%0A%23 Help%3A https%3A%2F%2Fwww.wikidata.org%2Fwiki%2FHelp%3AQuickStatements .%0A%0APREFIX wdt%3A <https%3A%2F%2Fportal.mardi4nfdi.de%2Fprop%2Fdirect%2F>%0APREFIX wd%3A <https%3A%2F%2Fportal.mardi4nfdi.de%2Fentity%2F>%0A%0APREFIX wikidata_wd%3A <http%3A%2F%2Fwww.wikidata.org%2Fentity%2F>%0APREFIX wikidata_wdt%3A <http%3A%2F%2Fwww.wikidata.org%2Fprop%2Fdirect%2F>%0A%0ASELECT DISTINCT%0A%0A%23%23%23%23%23%23%23%0A%23 To get the QuickStatements commands%2C comment out the lines until the next hash line%0A%23 %3Fmardi_item%0A%23 %3Fmardi_item_label%0A%23 %3Fwikidata%0A%23 %3Fwikidata_label%0A%23 %3FDOI%0A%23%23%23%23%23%23%23%0A%0A(REPLACE(STR(%3Fmardi_item)%2C ".*Q"%2C "Q") AS %3Fmardi_qid) %0A("P12" AS %3Fproperty)%0A(CONCAT("\""%2C REPLACE(STR(%3Fwikidata)%2C ".*Q"%2C "Q")%2C "\"") AS %3Fwikidata_qid) %0A%0AWHERE {%0A%20 SERVICE bd%3Asample { %3Fmardi_item wdt%3AP205 %3Ffulltext . bd%3AserviceParam bd%3Asample.limit 20000 }%0A%20 %3Fmardi_item wdt%3AP27 %3Fdoi .%0A%20 BIND(UCASE(%3Fdoi) AS %3FDOI)%0A%20 FILTER NOT EXISTS { %3Fmardi_item wdt%3AP12 %3FWikidataQID } %0A%20 service <https%3A%2F%2Fquery.wikidata.org%2Fsparql> {%0A%20%20%20 %3Fwikidata wikidata_wdt%3AP356 %3FDOI .%0A%20%20%20 %3Fwikidata rdfs%3Alabel %3Fwikidata_label .%0A%20%20%20 FILTER (LANG(%3Fwikidata_label) %3D "en")%0A%20 }%0A%20 %3Fmardi_item rdfs%3Alabel %3Fmardi_item_label .%0A%20 FILTER (LANG(%3Fmardi_item_label) %3D "en")%0A}%0ALIMIT 1000 Check] whether there are MaRDI items with P205 (external URL) statements and without P12 (Wikidata QID) statements. If so, use MaRDI's QuickStatements tool to add that query's results to MaRDI.
# Write the query, example <syntaxhighlight lang=sparql>
# Write the query, example <syntaxhighlight lang=sparql>
SELECT ?MaRDI_qID ?MaRDI_item ?EuDMLid WHERE {
SELECT ?MaRDI_qID ?MaRDI_item ?EuDMLid WHERE {

Revision as of 12:14, 7 October 2024

Data transfer to Wikidata

This section describes how to export data from the MaRDI portal to Wikidata to make the data better findable for the general public.

Example EuDML prposed by Vladimir Alexiev in 2022, which has currently 17 results.

  1. Prepare query for the MaRDI SPARQL endpoint
    1. Find the qIDs with a statement using P12 = WikidataQId
    2. The thing you want to export, here a part of the external url P205
    3. This query produces statements for%0A%23 https%3A%2F%2Fquickstatements.portal.mardi4nfdi.de%2F%23%2Fbatch%2Fnew%0A%23 Help%3A https%3A%2F%2Fwww.wikidata.org%2Fwiki%2FHelp%3AQuickStatements .%0A%0APREFIX wdt%3A <https%3A%2F%2Fportal.mardi4nfdi.de%2Fprop%2Fdirect%2F>%0APREFIX wd%3A <https%3A%2F%2Fportal.mardi4nfdi.de%2Fentity%2F>%0A%0APREFIX wikidata_wd%3A <http%3A%2F%2Fwww.wikidata.org%2Fentity%2F>%0APREFIX wikidata_wdt%3A <http%3A%2F%2Fwww.wikidata.org%2Fprop%2Fdirect%2F>%0A%0ASELECT DISTINCT%0A%0A%23%23%23%23%23%23%23%0A%23 To get the QuickStatements commands%2C comment out the lines until the next hash line%0A%23 %3Fmardi_item%0A%23 %3Fmardi_item_label%0A%23 %3Fwikidata%0A%23 %3Fwikidata_label%0A%23 %3FDOI%0A%23%23%23%23%23%23%23%0A%0A(REPLACE(STR(%3Fmardi_item)%2C ".*Q"%2C "Q") AS %3Fmardi_qid) %0A("P12" AS %3Fproperty)%0A(CONCAT("\""%2C REPLACE(STR(%3Fwikidata)%2C ".*Q"%2C "Q")%2C "\"") AS %3Fwikidata_qid) %0A%0AWHERE {%0A%20 SERVICE bd%3Asample { %3Fmardi_item wdt%3AP205 %3Ffulltext . bd%3AserviceParam bd%3Asample.limit 20000 }%0A%20 %3Fmardi_item wdt%3AP27 %3Fdoi .%0A%20 BIND(UCASE(%3Fdoi) AS %3FDOI)%0A%20 FILTER NOT EXISTS { %3Fmardi_item wdt%3AP12 %3FWikidataQID } %0A%20 service <https%3A%2F%2Fquery.wikidata.org%2Fsparql> {%0A%20%20%20 %3Fwikidata wikidata_wdt%3AP356 %3FDOI .%0A%20%20%20 %3Fwikidata rdfs%3Alabel %3Fwikidata_label .%0A%20%20%20 FILTER (LANG(%3Fwikidata_label) %3D "en")%0A%20 }%0A%20 %3Fmardi_item rdfs%3Alabel %3Fmardi_item_label .%0A%20 FILTER (LANG(%3Fmardi_item_label) %3D "en")%0A}%0ALIMIT 1000 Check whether there are MaRDI items with P205 (external URL) statements and without P12 (Wikidata QID) statements. If so, use MaRDI's QuickStatements tool to add that query's results to MaRDI.
  2. Write the query, example
    SELECT ?MaRDI_qID ?MaRDI_item ?EuDMLid WHERE {
      ?MaRDI_item wdt:P205 ?URL;
                  wdt:P12 ?Wikidata_qID.
      FILTER(STRSTARTS(STR(?URL), "https://eudml"))
      BIND(SUBSTR(STR(?URL), 23 ) AS ?EuDMLid)
    }
    LIMIT 10
    
    and investigate the result.
    • Check for total number of MaRDI items with EuDML links (9296 as of 7 October 2024)
  3. Find the properties in Wikidata, here only P11166 for eudml.
  4. Check whether Wikidata already has a corresponding statement.
    1. If yes, check consistency with MaRDI.
    2. If no, prepare upload to Wikidata.
  5. Rewrite the query to match the Quickstatements CSV format
    SELECT ?qid ?P11166 WHERE {
      ?qal854 wdt:P205 ?url ;
            wdt:P12 ?qid
      FILTER (STRSTARTS(str(?url) ,"https://eudml")) .
      BIND (Concat( 
        "\"", ## Required for external identifiers by quickstatements
        SUBSTR(STR(?url),23), ## 23 = Length of the prefix
        "\"") as ?P11166)
      }
    LIMIT 3
    
  6. Download the CSV file and test with a few items on Wikidata
  7. Optional add source linking back to the source of the information (MaRDI)
    SELECT ?qid ?P11166 ?S854 WHERE {
      ?item wdt:P205 ?url ;
            wdt:P12 ?qid
      FILTER (STRSTARTS(str(?url) ,"https://eudml")) .
      BIND (Concat( 
        "\"", ## Required for external identifiers by quickstatements
        SUBSTR(STR(?url),23), ## 23 = Length of the prefix
        "\"") as ?P11166).
        BIND (Concat( 
        "\"", ## Required for external identifiers by quickstatements
        STR(?item), 
        "\"") as ?S854)
      }
    LIMIT 3
    
  8. Remove the limit and do the full import