GithubHelp home page GithubHelp logo

el3um4s / denowiki Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 28 KB

A simple API for DenoJS to query Wikipedia and parse the results.

Home Page: https://deno.land/x/denowiki

License: MIT License

TypeScript 100.00%
deno wikipedia-api wikisearch-query wikiparser wikiparse-query

denowiki's Introduction

DenoWiki

GitHub license GitHub tag HitCount deno doc deno.land

A simple API for DenoJS to query Wikipedia and parse the results.

Usage

import * as wiki from "https://deno.land/x/denowiki/mod.ts";

const wikiSearchResult: wiki.WikiSearch_Query = await wiki.wikiSearch(
  { language: "en", srsearch: "doctor who", srlimit: 15 },
);
const pageID: number = wiki.getPageId(wikiSearchResult);
const wikiPage: wiki.WikiParse_Query = await wiki.wikiParse(
    { pageid: pageID, language: "en", prop: "wikitext|text" },
  );
const text: string = wiki.getWikiText(wikiPage);

console.log(text);

This module use the Wikipedia API:Search and API:Parsing wikitext.

Require deno (obviously) and --allow-net permission.

There are 2 demos available. The first demo queries Wikipedia and print the first result

deno run --allow-net .\demo_cmd.ts milan en false
deno run --allow-net .\demo_cmd.ts "doctor who" en true

The second demo searches a list of people and return how many exist in Wikipedia

deno run --allow-net .\demo_array.ts

You can run the demos directly from the repository with the commands:

deno run --allow-net https://deno.land/x/denowiki/demo_cmd.ts milan en false
deno run --allow-net https://deno.land/x/denowiki/demo_cmd.ts "doctor who" en true
deno run --allow-net https://raw.githubusercontent.com/el3um4s/DenoWiki/master/demo_array.ts

API: wikiSearch

  • function wikiSearch(options): Promise<WikiSearch_Query> : Search for a term on Wikipedia and return the corresponding pages (max 500)
  • function getPageId(wikiJSON: WikiSearch_Query, position): number : Returns the pageID number of Wikipedia referring to the searched term
  • function getSearchTitle(wikiJSON: WikiSearch_Query, position): string : Returns the Title of Wikipedia referring to the searched term
  • function getNumberResults(wikiJSON: WikiSearch_Query): number : Returns the total number of matches found for the search term. May be bigger than the results returned by wikiSearch(options)
  • function getNumberResultsListed(wikiJSON: WikiSearch_Query): number : Returns the number of results found by wikiSearch(options)
  • function getSuggestion(wikiJSON: WikiSearch_Query): string : Returns the suggested term related to the searched term
  • function hasResult(wikiJSON: WikiSearch_Query): boolean : TRUE if there are results for the searched term
  • function hasSuggestion(wikiJSON: WikiSearch_Query): boolean : TRUE if there are suggested searches related to the searched term
  • function wikiSearchQuery(options): string : Returns the url address to be used as the source to obtain the information

API: wikiParse

  • function wikiParse(options): Promise<WikiParse_Query> : Returns the contents of a Wikipedia page
  • function getWikiText(wikiPage: WikiParse_Query): string : Returns the original wikitext.
  • function getHTMLText(wikiPage: WikiParse_Query): string : Returns the parsed text of the wikitext.
  • function getPageTitle(wikiPage: WikiParse_Query): string : Returns the Title of Wikipedia referring to the page searched
  • function wikiParseQuery(options): string: Returns the url address to be used as the source to obtain the information

denowiki's People

Contributors

el3um4s avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.