Giter Site home page Giter Site logo

fever365 / go-wiki Goto Github PK

View Code? Open in Web Editor NEW

This project forked from trietmn/go-wiki

0.0 0.0 0.0 37 KB

This is a Golang open-source module that makes it easy to access and parse data from Wikipedia (Wikipedia API wrapper)

License: MIT License

Go 100.00%

go-wiki's Introduction

Go-wiki

go report card MIT license GoDoc

This is a Golang Wikipedia API wrapper - The Golang module that makes it easy to access and parse data from Wikipedia. You can use this module to crawl data for your data warehouse or use it for your "Know-it-all" AI Chatbot.

Contents

Instalation

To install Go-Wiki package, you need to install Go and set your Go workspace first.

  1. You first need Go installed, then you can use the below Go command to install Go-wiki.
go get -u github.com/trietmn/go-wiki
  1. Import it in your code.
import "github.com/trietmn/go-wiki"

Documentation

You can read the documentation at: https://pkg.go.dev/github.com/trietmn/go-wiki

I will update a full tutorial article on some popular blog as soon as possiple.

Quick start

# assume the following codes in example.go file
$ cat example.go
package main

import (
    "fmt"
    "github.com/trietmn/go-wiki"
)

func main() {
    // Search for the Wikipedia page title
    search_result, _, err := gowiki.Search("Why is the sky blue", 3, false)
    if err != nil {
        fmt.Println(err)
    }
    fmt.Printf("This is your search result: %v\n", search_result)

    // Get the page
    page, err := gowiki.GetPage("Rafael Nadal", -1, false, true)
    if err != nil {
        fmt.Println(err)
    }

    // Get the content of the page
    content, err := page.GetContent()
    if err != nil {
        fmt.Println(err)
    }
    fmt.Printf("This is the page content: %v\n", content)
}
# run example.go
$ go run example.go

Functions Examples

Note: The functions below are functions that you would usually use. Read the document to see all the functions.

1. Search

search_result, suggestion, err := gowiki.Search("Why is the sky blue", 3, true)
if err != nil {
    fmt.Println(err)
}
fmt.Printf("Search result: %v\n", search_result)
fmt.Printf("Suggestion: %v\n", suggestion)

2. GetPage (There are multiple page methods in the Wikipedia Page Methods)

page, err := gowiki.GetPage("Rafael Nadal", -1, false, true)
if err != nil {
    fmt.Println(err)
}
// Then now you can use the page methods

3. Suggest

suggestion, err := gowiki.Suggest("nadal")
if err != nil {
    fmt.Println(err)
}
fmt.Printf("Suggestion: %v\n", suggestion)

4. Geosearch

res, err := gowiki.GeoSearch(40.67693, 117.23193, -1, "", -1)
if err != nil {
    fmt.Println(err)
}
fmt.Printf("Geosearch result: %v\n", res)

5. GetRandom

res, err := gowiki.GetRandom(5)
if err != nil {
    fmt.Println(err)
}
fmt.Printf("Random titles: %v\n", res)

6. Summary

res, err := gowiki.Summary("Rafael Nadal", 5, -1, false, true)
if err != nil {
    fmt.Println(err)
}
fmt.Printf("Summary: %v\n", res)

Wikipedia Page Methods

Methods Description Example
Equal Check if 2 pages are equal to each other page1.Equal(page2)
GetContent Get the page content page.GetContent()
GetHTML Get the page HTML page.GetHTML()
GetRevisionID Get revid field of a page page.GetRevisionID()
GetParentID Get parentid field of a page page.GetParentID()
GetSummary Get the summary of the page page.GetSummary()
GetImagesURL Get all of the image URL appear in the page page.GetImageURL()
GetCoordinate Get the page coordinate if exist page.GetCoordinate()
GetReference Get all of the extenal links in the page page.GetReference()
GetLink Get all the titles of Wikipedia page links on a page page.GetLink()
GetCategory Get all of the categories of a page page.GetCategory()
GetSectionList Get all of the sections of the page page.GetSectionList()
GetSection Get the content of a specific section in the page page.GetSection("History")

License

MIT licensed. See the LICENSE file for full details.

About me

Connect with me on Linkedin: https://www.linkedin.com/in/triet-m-nguyen-a94b4b20b/

Credit

go-wiki's People

Contributors

trietmn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.