新的开放源代码库可访问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

例如,如果您想查找有关Java或Kotlin的最后20篇文章,可以按以下代码进行操作:

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)

另外,您可以根据请求加载所有文章,然后将其保存到文件中,或者根据需要实现回调函数:

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

或者,您可以找到最近30天有关Java或Kotlin的所有文章:

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)

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>

当前版本是0.2-RELEASE。 您可以在项目存储库中找到有关该项目的更多信息。

GitHub logo olegthelilfix / ArxivApiAccess

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.

from: https://dev.to//olegthelilfix/the-new-open-source-library-to-access-to-arxiv-org-api-53cj

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值