User:Dirac/Altmetric
Goal:
- First: make a link between all the Wikidata elements with a DOI and their corresponding altmetric ID.
- Secondary: use Wikidata element with altmetric, but no DOI, to retrieve the DOI and enter in WD
Element in Wikidata with
- DOI: 26,694,908
- altmetric ID: 12759 (52 with no DOI)
Next steps
editSend email to altmetric to inform them of the request- Dump of ~26M element ID from Linked Data Fragment, with their corresponding DOI (is it possible?)
- Filter for those that fits the right format for DOI
- Find what the result is when there is no entry for the corresponding DOI in altmetrics
- How to find DOI when we already have altmetric using their API
Altmetric ID
editAnswer received by Altmetric:
[...] there is a bit of a problem in that the Altmetric IDs are not designed to be persistent IDs. With that in mind, it would be fairly inefficient for you and for our API if you kept those IDs up to date all the time.
I would suggest instead building the URL in the following way:
www.altmetric.com/details/doi/ [doi] - just replace [doi] with the relevant article DOI. It will lead to a details page as long as we have a record for that item. If we do not have a record for the item, it will simply lead to a page stating that we have not received any attention for the item yet. This will be a much easier and more reliable way to link to the Altmetric details page.
Considerations posted on Altmetric ID property discussion page.
Pseudo code
edit- For every DOI:
- Check if the corresponding WD element already have an altmetric ID
- If not, fetch the JSON
- If the altmetric exits, add it in a column
- Output: CSV with [Q, DOI, altmetric]
Requests / Lists
editAll DOI
edit- LDF request for elements with a DOI (>26 millions)
Element with Altmetric ID
edit# Element with altmetric defined
SELECT ?item ?itemLabel ?altMetric ?DOI WHERE {
?item wdt:P5530 ?altMetric .
# Display DOI if any
OPTIONAL { ?item wdt:P356 ?DOI. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Scientific papers with Altmetric ID but no DOI
edit# Scientific paper with altmetric
SELECT ?item ?itemLabel ?altMetric WHERE {
# Scientific paper
?item wdt:P31 wd:Q13442814.
?item wdt:P5530 ?altMetric .
# That doesn't have a a DOI
FILTER NOT EXISTS { ?item wdt:P356 ?DOI }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Article CC-BY with a DOI but no Altmetrics
edit# Scientific paper with DOI and CC-BY license
SELECT ?item ?itemLabel ?DOI ?altMetric WHERE {
# Scientific paper
?item wdt:P31 wd:Q13442814.
# CC-BY
?item wdt:P275 wd:Q20007257 .
# with DOI
?item wdt:P356 ?DOI .
# That doesn't have an altmetric
FILTER NOT EXISTS { ?item wdt:P5530 ?altMetric }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Code
editBookmarklet
edit
javascript:((function(){var%20a;a=function(){var%20a,b,c,d,e;b=document,e=b.createElement("script"),a=b.body,d=b.location;try{if(!a)throw%200;c="d1bxh8uas1mnw7.cloudfront.net";if(typeof%20runInject!="function")return%20e.setAttribute("src",""+d.protocol+"//"+c+"/assets/content.js?cb="+Date.now()),e.setAttribute("type","text/javascript"),e.setAttribute("onload","runInject()"),a.appendChild(e)}catch(f){return%20console.log(f),alert("Please%20wait%20until%20the%20page%20has%20loaded.")}},a(),void%200})).call(this);
This bookmarklet is a call to this Javascript:
https://d1bxh8uas1mnw7.cloudfront.net/assets/content.js
Altmetric API
editIt is possible to get the altmetric ID with the help of a DOI by using their API. This will result in a JSON file.
To get the corresponding altmetric ID for the DOI 10.1098/rstb.2003.1449:
curl -s https://api.altmetric.com/v1/doi/10.1098/rstb.2003.1449 | \ jq .altmetric_id
Download the data
editGenerate URLs:
for i in `seq 1 1000`;do echo "https://query.wikidata.org/bigdata/ldf?accept=application/rdf+xml&subject=&predicate=http%3A%2F%2Fwww.wikidata.org%2Fprop%2Fstatement%2FP356&object=&page=$i" >> list.txt;done
Download the data and concatenate the result in a text file:
wget -i list.txt -O 1-1000.html -o log/1-1000.txt
Identify URLs with errors:
grep ERROR fichier.log -B 3 | sed 's/.*https/https/g' | grep https
Extract the element id:
grep "wds\:" 1-1000.html | grep -v prefix | sed 's/wds\://g' | sed 's/\-.*//g' > Q1-1000.txt
Extract DOI:
grep "\:P356" 1-1000.html | sed 's/^[^"]*"//g' | sed 's/".*//g' > DOI_1-1000.txt
Check if they have the same number of lines:
wc -l Q1-1000.txt DOI_1-1000.txt
Combine Q element and DOI in one file:
paste Q1-1000.txt DOI_1-1000.txt | column -c 2 > Q_DOI_1-1000.txt
Find the line index of DOI that does not have the proper syntax:
egrep -v -n "10\.[[:digit:]]{4,9}/.+" Q_DOI_1-1000.txt | cut -d : -f 1 > improper-DOI-indices_1-1000.txt
Remove the index of the improper indices:
cp Q_DOI_1-1000.txt Q_DOI-valid_1-1000.txt;for ligne in `tac improper-DOI-indices_1-1000.txt`;do sed -i ${ligne}d Q_DOI-valid_1-1000.txt;done
Get the AltMetric for each valid DOI, if any:
for DOI in `head -n 100 Q_DOI-valid_1-1000.txt | awk '{print $2}'`; do if curl --head --silent --fail https://api.altmetric.com/v1/doi/${DOI} 2> /dev/null; then ALT=`curl -s https://api.altmetric.com/v1/doi/10.1098/rstb.2003.1449 | \ jq .altmetric_id` echo "Altmetric found" echo $DOI, $ALT else echo $DOI "not found!" fi done
Python to get the info
editSee also
editWikidata
editProperties:
Example:
- Reference ranges for estradiol, progesterone, luteinizing hormone and follicle-stimulating hormone during the menstrual cycle (Q44275619)
- In Altmetric