phonghng-url-kw-extractordeprecated

Extract keyword from any url in many languages

Usage no npm install needed!

<script type="module">
  import phonghngUrlKwExtractor from 'https://cdn.skypack.dev/phonghng-url-kw-extractor';
</script>

README

Intro

Support over 60 languages and if you want to add more language, just add their stopwords in stopwords.json

Usage

Install via npm:

npm install phonghng-url-kw-extractor 

Let's code:

var uke = require("phonghng-url-kw-extractor");

/* Extract keyword from url */
var url = "https://example.com",
    onload_event = false; // see the note below this code
uke.get_keyword(url, onload_event, keywords => {
    console.log(keywords); //return an object with keywords and scores
});

/* Extract keyword from html */
var html = "your html here - includes doctype, html, head, body tags",
    onload_event = false; // see the note below this code
uke.get_keyword_from_html(html, onload_event, keywords => {
    console.log(keywords); // return an object with keywords and scores
});

/* Extract keyword from string */
var html = "Việt Nam, tên gọi chính thức là Cộng hòa Xã hội chủ nghĩa Việt Nam, là quốc gia nằm ở cực Đông của bán đảo Đông Dương thuộc khu vực Đông Nam Á, giáp với Lào, Campuchia, Trung Quốc, Biển Đông và vịnh Thái Lan. Quốc gia này có chung đường biên giới trên biển với Thái Lan qua vịnh Thái Lan và với Trung Quốc, Philippines, Indonesia, Brunei, Malaysia qua Biển Đông. Việt Nam có diện tích 331.212 km², đường biên giới trên đất liền dài 4.639 km, đường bờ biển trải dài 3.260 km, dân số ước tính vào khoảng 98 triệu người với 54 dân tộc trong đó người Kinh chiếm đa số. Thủ đô của Việt Nam là thành phố Hà Nội, thành phố đông dân cũng như có quy mô GRDP lớn nhất là Thành phố Hồ Chí Minh (ngày nay vẫn thường được gọi phổ biến với tên cũ là Sài Gòn).";
uke.get_keyword_from_string(string, keywords => {
    console.log(keywords); // return an array with keywords
});

onload_event: Set to true if you want to set keyword (from url/html) "only when" the page is loaded. See this Stack Overflow answer for "load event"

Web API POST

Note: We using Heroku to host this API, and Heroku is limit 4500 requests per hour (or about 1.25 request per seconds). So, don't send request if it's not necessary! By the way, Heroku limit request timeout is "only 30s" so the "onload_event" (as above) is always be false. Tip: If your website take longer than 30s to load, try to get its HTML and use the "Extract keyword from HTML" API

/* ------------
| Using jQuery | 
------------- */

/* Extract keyword from url */
$.post("https://uke-api.herokuapp.com/kwurl", { url: "https://example.com" }, keywords => {
    console.log(keywords);
});

/* Extract keyword from html */
$.post("https://uke-api.herokuapp.com/kwhtml", { html: "your html here - includes doctype, html, head, body tags" }, keywords => {
    console.log(keywords);
});

/* (Not recommend) Extract keyword from string */
$.post("https://uke-api.herokuapp.com/kwstring", { string: "Việt Nam, tên gọi chính thức là Cộng hòa Xã hội chủ nghĩa Việt Nam, là quốc gia nằm ở cực Đông của bán đảo Đông Dương thuộc khu vực Đông Nam Á, giáp với Lào, Campuchia, Trung Quốc, Biển Đông và vịnh Thái Lan. Quốc gia này có chung đường biên giới trên biển với Thái Lan qua vịnh Thái Lan và với Trung Quốc, Philippines, Indonesia, Brunei, Malaysia qua Biển Đông. Việt Nam có diện tích 331.212 km², đường biên giới trên đất liền dài 4.639 km, đường bờ biển trải dài 3.260 km, dân số ước tính vào khoảng 98 triệu người với 54 dân tộc trong đó người Kinh chiếm đa số. Thủ đô của Việt Nam là thành phố Hà Nội, thành phố đông dân cũng như có quy mô GRDP lớn nhất là Thành phố Hồ Chí Minh (ngày nay vẫn thường được gọi phổ biến với tên cũ là Sài Gòn). Việt Nam tuyên bố chủ quyền đối với hai thực thể địa lý tranh chấp trên Biển Đông là các quần đảo Hoàng Sa (nhưng không kiểm soát trên thực tế) và Trường Sa (kiểm soát một phần)" }, response => {
    console.log(response.keywords);
});