단어 추출기
단어 추출
by HYEONGJINKIM
HTML
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<textarea id="extract_text" rows="4" cols="50">
랜꾸술션프심포지러문이현기차관즈
</textarea>
<input id="extract_num" type="number" name="points" step="1" value="5">
<button id="test">
추출하기
</button>
JavaScript
!function(b,a){'object'==typeof exports&&'undefined'!=typeof module?module.exports=b():'function'==typeof define&&define.amd?define([],b):('undefined'!=typeof window?a=window:'undefined'!=typeof global?a=global:'undefined'!=typeof self&&(a=self),a.nGram=b())}(function(){return function a(b,c,e){function f(d,k){if(!c[d]){if(!b[d]){var i=typeof require=='function'&&require;if(!k&&i)return i(d,!0);if(g)return g(d,!0);var j=new Error("Cannot find module '"+d+"'");throw j.code='MODULE_NOT_FOUND',j}var h=c[d]={exports:{}};b[d][0].call(h.exports,function(c){var a=b[d][1][c];return f(a?a:c)},h,h.exports,a,b,c,e)}return c[d].exports}var g=typeof require=='function'&&require;for(var d=0;d<e.length;d++)f(e[d]);return f}({1:[function(c,b,d){'use strict';function a(a){if(typeof a!=='number'||a<1||a!==a||a===Infinity)throw new Error('Type error: `'+a+'` is not a valid argument for n-gram');return function(b){var c,d;if(c=[],b===null||b===undefined)return c;if(b=String(b),d=b.length-a+1,d<1)return c;while(d--)c[d]=b.substr(d,a);return c}}b.exports=a,a.bigram=a(2),a.trigram=a(3)},{}]},{},[1])(1)})
function k_combinations(set, k) {
var i, j, combs, head, tailcombs;
if (k > set.length || k <= 0) {
return [];
}
if (k == set.length) {
return [set];
}
if (k == 1) {
combs = [];
for (i = 0; i < set.length; i++) {
combs.push([set[i]]);
}
return combs;
}
// Assert {1 < k < set.length}
combs = [];
for (i = 0; i < set.length - k + 1; i++) {
head = set.slice(i, i+1);
tailcombs = k_combinations(set.slice(i + 1), k - 1);
for (j = 0; j < tailcombs.length; j++) {
combs.push(head.concat(tailcombs[j]));
}
}
return combs;
}
//nGram(2)('n-gram');
//k_combinations([1, 2, 3], 3)
$('#test').on('click', function(){
var sText = $.trim($('#extract_text').val());
var nNum = parseInt($('#extract_num').val(), 10);
console.log(sText.split(""));
//console.log(k_combinations(sText.split(""),nNum));
var aComb = k_combinations(sText.split(""),nNum);
var...