{"id":617,"date":"2019-05-16T10:06:34","date_gmt":"2019-05-16T09:06:34","guid":{"rendered":"http:\/\/blog.magnusmanske.de\/?p=617"},"modified":"2019-05-17T16:20:57","modified_gmt":"2019-05-17T15:20:57","slug":"papers-on-rust","status":"publish","type":"post","link":"http:\/\/magnusmanske.de\/wordpress\/archives\/617","title":{"rendered":"Papers on Rust"},"content":{"rendered":"<p>I have written about my attempt with <a href=\"http:\/\/magnusmanske.de\/wordpress\/?p=608\">Rust and MediaWiki<\/a> before. This post is an update on my progress.<\/p>\n<p>I started out writing a <a href=\"https:\/\/crates.io\/crates\/mediawiki\">MediaWiki API crate<\/a> to be able to talk to MediaWiki installations from Rust. I was then pointed to a <a href=\"https:\/\/crates.io\/crates\/wikibase\">wikibase crate<\/a> by Tobias Sch\u00f6nberg and others, to which I subsequently contributed some code, including improvements to the existing codebase, but also an &#8220;entity cache&#8221; struct (to retrieve and manage larger amounts of entities from Wikibase\/Wikidata), as well as an &#8220;entity diff&#8221; struct.<\/p>\n<p>The latter is something I had started in PHP before, but never really finished. The idea is that, when creating or updating an entity, instead of painstakingly testing if each statement\/label\/etc. exists, one simply creates a new, blank item, fills it with all the data that should be in there, and then generates a &#8220;diff&#8221; to a blank (for creating) or existing (for updating) entity. That diff can then be passed to the <a href=\"https:\/\/www.wikidata.org\/w\/api.php?action=help&amp;modules=wbeditentity\">wbeditentity<\/a> API action. The diff generation can be fine-tuned, e.g. only add English labels, or add\/update (but not remove) P31 statements.<\/p>\n<p>Armed with these two crates, I went to re-create a functionality that I had written in PHP before: creation and updating of items for scientific publications, mainly used in my <a href=\"https:\/\/tools.wmflabs.org\/sourcemd\/\">SouceMD tool<\/a>. The code underlying that tool has grown over the years, meaning it&#8217;s a mess, and has also developed some idiosyncrasies that lead to unfortunate edits.<\/p>\n<p>For a rewrite in Rust, I also wanted to make the code more modular, especially regarding the data sources. I did find a <a href=\"https:\/\/crates.io\/crates\/crossref\">crate to query CrossRef<\/a>, but not much else. So I wrote new crates to query <a href=\"https:\/\/crates.io\/crates\/pubmed\">pubmed<\/a>, <a href=\"https:\/\/crates.io\/crates\/orcid\">ORCID<\/a>, and <a href=\"https:\/\/crates.io\/crates\/semanticscholar\">Semantic Scholar<\/a>. All these crates are completely independent of MediaWiki\/Wikibase; they can be re-used in any kind of Rust code related to scientific publications. I consider them a sound investment into the Rust crate ecosystem.<\/p>\n<p>With these crates in a basic but usable state, I went to write <a href=\"https:\/\/github.com\/magnusmanske\/papers\">papers<\/a>, Rust code (not a crate just yet) to gather data from the above sources, and inject them into Wikidata. I wrote a Rust trait to represent a generic source, and then wrote adapter structs for each of the sources. Finally, I added some wrapper code to take a list of adapters, query them about a paper, and update Wikidata accordingly. It can already<\/p>\n<ul>\n<li>iteratively gather IDs (supply a PubMed ID, PubMed might get a DOI, which then can get you data from ORCID)<\/li>\n<li>find item(s) for these IDs on Wikidata<\/li>\n<li>gather information about the authors of the paper<\/li>\n<li>find items for these authors on Wikidata<\/li>\n<li>create new author items, or update existing ones, on Wikidata<\/li>\n<li>create new paper items, or update existing ones, on Wikidata (no author statement updates yet)<\/li>\n<\/ul>\n<p>The adapter trait is designed to both unify data across sources (e.g. use standardized author information), but also allow to update paper items with source-specific data (e.g. publication dates, Mesh terms). This system is open to add more adapters for different sources. It is also flexible enough to extend to other, similar &#8220;publication types&#8221;, such as book, or maybe even artwork. My <a href=\"https:\/\/github.com\/magnusmanske\/papers\/blob\/master\/src\/bin\/main.rs\">test example<\/a> shows how easy it is to use in other code; indeed, I am already using it in Rust code I developed for my work (publication in progress).<\/p>\n<p>I see all of this as a seeding of the Rust crate system with easily reusable, MediaWiki-related code. I will add more such code in the future, and hope this will help in the adoption of Rust in the MediaWiki programmer community. Watch this space.<\/p>\n<p><em>Update:<\/em> Now available <a href=\"https:\/\/crates.io\/crates\/papers\">as a crate<\/a>!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have written about my attempt with Rust and MediaWiki before. This post is an update on my progress. I started out writing a MediaWiki API crate to be able to talk to MediaWiki installations from Rust. I was then pointed to a wikibase crate by Tobias Sch\u00f6nberg and others, to which I subsequently contributed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,9],"tags":[],"class_list":["post-617","post","type-post","status-publish","format-standard","hentry","category-rust","category-wikidata"],"_links":{"self":[{"href":"http:\/\/magnusmanske.de\/wordpress\/wp-json\/wp\/v2\/posts\/617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/magnusmanske.de\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/magnusmanske.de\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/magnusmanske.de\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/magnusmanske.de\/wordpress\/wp-json\/wp\/v2\/comments?post=617"}],"version-history":[{"count":2,"href":"http:\/\/magnusmanske.de\/wordpress\/wp-json\/wp\/v2\/posts\/617\/revisions"}],"predecessor-version":[{"id":621,"href":"http:\/\/magnusmanske.de\/wordpress\/wp-json\/wp\/v2\/posts\/617\/revisions\/621"}],"wp:attachment":[{"href":"http:\/\/magnusmanske.de\/wordpress\/wp-json\/wp\/v2\/media?parent=617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/magnusmanske.de\/wordpress\/wp-json\/wp\/v2\/categories?post=617"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/magnusmanske.de\/wordpress\/wp-json\/wp\/v2\/tags?post=617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}