/ArxivApiAccess

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

Primary LanguageKotlinApache License 2.0Apache-2.0

Buy Me A Coffee

Build Status GuardRails badge GitHub License

ArvixApiAccess

ArvixApiAccess is Kotlin written open-source library to make search requests to API of Arvix.org

Getting started with Maven

In order to start using you should add that dependency to your project.

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

...

<dependency>
  <groupId>olegthelilfix</groupId>
  <artifactId>ArxivApiAccess</artifactId>
  <version>${ArxivApiAccess.version}</version>
</dependency>

Getting started with gradle

In order to start using you should add that dependency to your project.

repositories {
    ...
    maven {
        url "https://mymavenrepo.com/repo/m3NxrnIEacYdXdF77zDL/"
    }
    ...
}
...
dependencies {
    ...
    compile group: 'olegthelilfix', name: 'ArxivApiAccess', version: '0.2-RELEASE'
    ...
}

A simple example of usage

// Request to find the last 20 articles about Java or Kotlin 
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)

val responseAsString: String = SearchRequestExecutor().execute(request)
    
println(response)
println(responseAsString)

load all by request to file

val subjectCategory = "JAVA"
val fileToSave = "../arxiv_data_sets/${subjectCategory}.csv"

// All article about java
val request = SearchRequest.SearchRequestBuilder
        .create(subjectCategory, SearchField.ALL)
        .build()

loadAllByRequest(request, {feed ->
    // save 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
})

load all from date to date

// the request to 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 = searchAllByPeriod(request, Date(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(30, TimeUnit.DAYS)))

println(list)

mapping of subjects

feed.entry?.forEach {
    it.category.forEach { category ->
        try {
            val categoryFullName = convertTermCode(category.term)
            println("Mapped ${category.term} to ${categoryFullName}")
        }
        catch (e: TermNotFoundException) {
            println(e.message)
        }
    }
}

#linked projects @articleflowbot or ArticleFlow github is the telegram bot to make search request to arxiv.org

contacts

Feel free to email me at olegthelilfix@pm.me