DEV Community

Oleg Aleksandrov
Oleg Aleksandrov

Posted on

The new open-source library to access to Arxiv.org API

Yo!
Recently, I faced with the task of sending various search requests to arxiv.org API on Java/Kotlin and as result of that, I and my mates had decided to realize it as an open-source library ArxivApiAccess.

A simple track to use it

For example, if you would like to find the last 20 articles about Java or Kotlin, this can be done as follows code:

val request: SearchRequest = SearchRequest.SearchRequestBuilder
            .create("Java", SearchField.ALL)
            .or("Kotlin", SearchField.ALL)
            .sortBy(SortBy.LAST_UPTATED_DATE)
            .sortOrder(SortOrder.DESCENDING)
            .maxResults(20)
            .build()

val response: Feed = SearchRequestExecutor().executeAndMap(request)

println(response)
Enter fullscreen mode Exit fullscreen mode

Also, you can load all articles by your request and save it to file or implement callback function as you want:

val subjectCategory = "astro-ph"
val fileToSave = "../arxiv_data_sets/${subjectCategory}.csv"

val request = SearchRequest.SearchRequestBuilder
        .create(subjectCategory, SearchField.SUBJECT_CATEGORY)
        .build()

loadAllByRequest(request, { feed ->
    // Donwload to file 
    val writer = FileWriter(fileToSave, true)
    writer.use {
        feed.entry?.forEach {
            val authorString = it.author.joinToString(", ") { author -> author.name }
            val resultString = "${it.updated}|${subjectCategory}|${it.title}|${authorString}".replace("\n", "")
            writer.write("${resultString}\n")
        }
        writer.close()
    }

    println("parsed ${feed.startIndex+feed.itemsPerPage}/${feed.totalResults}")
})
// return false to stop a process of the parsing
true
Enter fullscreen mode Exit fullscreen mode

Or you can find all articles about Java or Kotlin for last 30 days:

val request: SearchRequest = SearchRequest.SearchRequestBuilder
        .create("Java", SearchField.ALL)
        .or("Kotlin", SearchField.ALL)
        .build()

var list = searchAllAfterDate(request, Date(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(30, TimeUnit.DAYS)))

println(list)
Enter fullscreen mode Exit fullscreen mode

Getting started with Maven

<repository>
    <id>myMavenRepoRead</id>
    <url>https://mymavenrepo.com/repo/m3NxrnIEacYdXdF77zDL/</url>
</repository>

...

<dependency>
  <groupId>olegthelilfix</groupId>
  <artifactId>ArxivApiAccess</artifactId>
  <version>${ArxivApiAccess.version}</version>
</dependency>
Enter fullscreen mode Exit fullscreen mode

The current version is 0.2-RELEASE. More information about the project you can find in the project repository.

GitHub logo ResearchPreprintsTools / ArxivApiAccess

it's the Kotlin library to make search requests to API of Arvix.org

The future of the project

The current version of the project is not final and I’m planning to continue the project. The first is to stabilize the current functionality. The second is to enhance the library's ability to interact with arxiv.org API and so on.
Fell free to write me about everything.

Top comments (0)