Created
August 7, 2024 08:21
-
-
Save egonw/379c72a49517716712b70bdee0d845ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='io.github.egonw.bacting', module='managers-ui', version='1.0.0') | |
@Grab(group='io.github.egonw.bacting', module='net.bioclipse.managers.wikidata', version='1.0.0') | |
import java.util.*; | |
import java.text.SimpleDateFormat; | |
workspaceRoot = "." | |
ui = new net.bioclipse.managers.UIManager(workspaceRoot); | |
wikidata = new net.bioclipse.managers.WikidataManager(workspaceRoot); | |
citoIntents = new HashMap<String,String>() | |
citoIntents.put("cites","Q96471816") | |
citoIntents.put("citesasevidence","Q111736347") | |
citoIntents.put("citesasrecommendedreading","Q111736358") | |
citoIntents.put("citesforinformation","Q96479970") | |
citoIntents.put("credits","Q117121919") | |
citoIntents.put("critiques","Q105624924") | |
citoIntents.put("describes","Q117358004") | |
citoIntents.put("discusses","Q96471822") | |
citoIntents.put("disputes","Q117121923") | |
citoIntents.put("extends","Q96472100") | |
citoIntents.put("includesexcerptfrom","Q117121925") | |
citoIntents.put("obtainsbackgroundfrom","Q96480394") | |
citoIntents.put("obtainssupportfrom","Q115470993") | |
citoIntents.put("qualifies","Q117121930") | |
citoIntents.put("refutes","Q107710355") | |
citoIntents.put("ridicules","Q117121932") | |
citoIntents.put("updates","Q96473628") | |
citoIntents.put("usesconclusionsfrom","Q117121934") | |
citoIntents.put("usesdatafrom","Q101149476") | |
citoIntents.put("usesmethodin","Q96472102") | |
Map<String,List<String>> data = new HashMap(); | |
new File("cits_clean.csv").eachLine { line -> | |
fields = line.trim().split(",") | |
data.put(fields[0], fields[1]) | |
} | |
entityIDs = wikidata.getEntityIDsForDOIs(data.keySet().asList()) | |
def outputCitation(String doi, String wikidata, String intention) { | |
intention = intention.trim().toLowerCase() | |
if (intention.isEmpty()) { // do nothing | |
} else if (citoIntents.containsKey(intention)) { | |
today = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); | |
println "${wikidata},Q28264479,${citoIntents.get(intention)},Q128383261,+${today}T00:00:00Z/11" | |
} else { | |
println "# unrecognized intention: ${intention} Wakefield" | |
} | |
} | |
println "qid,P2860,qal3712,S248,s813" | |
entityIDs.each { doi, wikidataIRI -> | |
wikidata = wikidataIRI.substring(31) | |
intentions = data.get(doi).replaceAll(" ", "") | |
println "# data: ${doi} = ${wikidata} ${intentions}" | |
if (intentions.contains(";")) { | |
intentions.split(";").each { intention -> | |
outputCitation(doi, wikidata, intention) | |
} | |
} else { | |
outputCitation(doi, wikidata, intention) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment