R语言 wikifacts包

R语言 wikifacts包

在这篇文章中,我们将使用R编程语言的wikifacts包。我们将看一下wikifacts包的几个功能,以刮取事件、事实和新闻等数据。

安装

要安装这个包,请在终端输入以下命令。

install.packages("wikifacts")

wikifacts是一个R包,可用于从维基百科和维基数据中刮取数据。

获取词的定义

wiki_define(“word”)函数: 从维基百科和维基数据中返回单词的定义。

语法

wiki_define("word") 
# installing packages
install.packages("wikifacts")
  
# importing packages
library(wikifacts)
  
# gets definition of the word
cat(wiki_define("python"))

输出

Python may refer to:

Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia

Python (genus), a genus of nonvenomous Pythonidae found in Africa and Asia

== Computing ==

Python (programming language)

Python, a native code compiler for CMU Common Lisp

Python, the internal project name for the PERQ 3 computer workstation

…..

获取新闻

wiki_inthenews() 函数: 返回随机的inthenews。

语法

wiki_inthenews()

例子

# installing packages
install.packages("wikifacts")
  
# importing packages
library(wikifacts)
  
# returns the random news
cat(wiki_inthenews())

输出

Here’s some news from 07 October 2017. In Saudi Arabia, a decree by King Salman effectively removes a longstanding ban on women driving in the country. (Courtesy of Wikipedia)

获取随机事实

wiki_didyouknow()函数: 返回随机事实。

语法

wiki_didyouknow()

wiki_onthisday()函数: 返回当前日期的过去的随机事实。

语法

wiki_onthisday()
# installing packages
install.packages("wikifacts")
  
# importing packages
library(wikifacts)
  
# Gets random fact
cat(wiki_didyouknow())
  
# Get random fact from the past of 
# current date
cat(wiki_onthisday())

输出

Did you know that the population of Kunság (banner pictured) was “almost entirely wiped out” during the Ottoman occupation, before recovering through re-colonization? (Courtesy of Wikipedia)

Did you know that on March 9 in 1932 – Éamon de Valera (pictured), one of the dominant political figures in twentieth-century Ireland, became President of the Executive Council of the Irish Free State. (Courtesy of Wikipedia)

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程