Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6536e9f

Browse files
committed
scoring and suggeting tags
1 parentdd76d5c commit6536e9f

File tree

3 files changed

+818
-1
lines changed

3 files changed

+818
-1
lines changed

‎lib/scoring-words.js

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
if(typeofScoring=='undefined'){
2+
varScoring={};
3+
}
4+
5+
(function(ns){
6+
varUtil={
7+
inherit:function(child,parent){
8+
varobj=child||{};
9+
for(varpropinparent){
10+
if(typeofobj[prop]=='undefined'){
11+
obj[prop]=parent[prop];
12+
}
13+
}
14+
returnobj;
15+
},
16+
countMatch:function(text,regex){
17+
returntext.split(regex).length-1;
18+
// var n=0;
19+
// for (var i=0;;) {
20+
// i = text.search(regex);
21+
// if (i < 0) break;
22+
// n++;
23+
// text = text.substr(i+1);
24+
// }
25+
// return n;
26+
},
27+
dump:function(obj){
28+
if(typeofobj=='undefined')return'undefined';
29+
if(typeofobj=='string')return'"'+obj+'"';
30+
if(typeofobj!='object')return''+obj;
31+
if(obj===null)return'null';
32+
if(objinstanceofArray){
33+
return'['
34+
+obj.map(function(v){return'obj'/*Util.dump(v)*/;}).join(',')
35+
+']';
36+
}else{
37+
vararr=[];
38+
for(varpropinobj){
39+
arr.push(prop+':'+'obj'/*Util.dump(obj[prop])*/);
40+
}
41+
return'{'+arr.join(',')+'}';
42+
}
43+
}
44+
};
45+
46+
varA={
47+
indexOf:Array.indexOf||function(self,elt/*, from*/){
48+
varargi=2;
49+
varlen=self.length;
50+
varfrom=Number(arguments[argi++])||0;
51+
from=(from<0) ?Math.ceil(from) :Math.floor(from);
52+
if(from<0)from+=len;
53+
for(;from<len;from++){
54+
if(frominself&&self[from]===elt)returnfrom;
55+
}
56+
return-1;
57+
},
58+
filter:Array.filter||function(self,fun/*, thisp*/){
59+
varargi=2;
60+
varlen=self.length;
61+
if(typeoffun!="function"){
62+
thrownewTypeError('A.filter: not a function');
63+
}
64+
varrv=newArray();
65+
varthisp=arguments[argi++];
66+
for(vari=0;i<len;i++){
67+
if(iinself){
68+
varval=self[i];// in case fun mutates this
69+
if(fun.call(thisp,val,i,self))rv.push(val);
70+
}
71+
}
72+
returnrv;
73+
},
74+
forEach:Array.forEach||function(self,fun/*, thisp*/){
75+
varargi=2;
76+
varlen=self.length;
77+
if(typeoffun!='function'){
78+
thrownewTypeError('A.forEach: not a function');
79+
}
80+
varthisp=arguments[argi++];
81+
for(vari=0;i<len;i++){
82+
if(iinself)fun.call(thisp,self[i],i,self);
83+
}
84+
},
85+
every:Array.every||function(self,fun/*, thisp*/){
86+
varargi=2;
87+
varlen=self.length;
88+
if(typeoffun!='function'){
89+
thrownewTypeError('A.every: not a function');
90+
}
91+
varthisp=arguments[argi++];
92+
for(vari=0;i<len;i++){
93+
if(iinself&&
94+
!fun.call(thisp,self[i],i,self)){
95+
returnfalse;
96+
}
97+
}
98+
returntrue;
99+
},
100+
map:Array.map||function(self,fun/*, thisp*/){
101+
varargi=2;
102+
varlen=self.length;
103+
if(typeoffun!='function'){
104+
thrownewTypeError('A.map: not a function');
105+
}
106+
varrv=newArray(len);
107+
varthisp=arguments[argi++];
108+
for(vari=0;i<len;i++){
109+
if(iinself){
110+
rv[i]=fun.call(thisp,self[i],i,self);
111+
}
112+
}
113+
returnrv;
114+
},
115+
some:Array.some||function(self,fun/*, thisp*/){
116+
varargi=2;
117+
varlen=self.length;
118+
if(typeoffun!="function"){
119+
thrownewTypeError('A.some: not a function');
120+
}
121+
varthisp=arguments[argi++];
122+
for(vari=0;i<len;i++){
123+
if(iinself&&
124+
fun.call(thisp,self[i],i,self)){
125+
returntrue;
126+
}
127+
}
128+
returnfalse;
129+
},
130+
reduce:Array.reduce||function(self,fun/*, initial*/){
131+
varargi=2;
132+
varlen=self.length;
133+
if(typeoffun!='function'){
134+
throwTypeError('A.reduce: not a function ');
135+
}
136+
vari=0;
137+
varprev;
138+
if(arguments.length>argi){
139+
varrv=arguments[argi++];
140+
}else{
141+
do{
142+
if(iinself){
143+
rv=self[i++];
144+
break;
145+
}
146+
if(++i>=len){
147+
thrownewTypeError('A.reduce: empty array');
148+
}
149+
}while(true);
150+
}
151+
for(;i<len;i++){
152+
if(iinself)rv=fun.call(null,rv,self[i],i,self);
153+
}
154+
returnrv;
155+
},
156+
zip:function(self){
157+
if(self[0]instanceofArray){
158+
varl=self[0].length;
159+
varlen=self.length;
160+
varz=newArray(l);
161+
for(vari=0;i<l;i++){
162+
z[i]=[];
163+
for(varj=0;j<len;j++){
164+
z[i].push(self[j][i]);
165+
}
166+
}
167+
returnz;
168+
}
169+
return[];
170+
},
171+
first:function(self){
172+
returnself ?self[0] :null;
173+
},
174+
last:function(self){
175+
returnself ?self[self.length-1] :null;
176+
},
177+
push:function(self,other){
178+
returnArray.prototype.push.apply(self,other);
179+
}
180+
};
181+
182+
ns.RelativeWords=function(/* engines */){
183+
varself={engine:arguments[0]||[]};
184+
185+
self.factory={
186+
getEngine:function(name){
187+
if(typeofns.RelativeWords.Engine!='undefined'){
188+
returnnewns.RelativeWords.Engine[name];
189+
}
190+
}
191+
};
192+
193+
self.addEngine=function(engine){
194+
if(typeofengine!='undefined'){
195+
self.engine.push(engine);
196+
}
197+
returnself;
198+
};
199+
200+
self.top=function(doc,words){
201+
varscores={};
202+
for(vartinwords)scores[t]={score:0,df:words[t]};
203+
self.engine.forEach(function(e){e.vote(doc,scores);});
204+
205+
varresult=[];
206+
for(vartinscores){
207+
result.push({word:t,score:scores[t].score});
208+
}
209+
result.sort(function(a,b){returnb.score-a.score;});
210+
211+
returnresult;
212+
};
213+
214+
returnself;
215+
};
216+
217+
ns.RelativeWords.Engine={};
218+
219+
ns.RelativeWords.Engine.TfIdf=function(){
220+
varopt=arguments[0]||{};
221+
varself={weight:opt.weight||0.3};
222+
223+
self.vote=function(doc,words){
224+
vartotal=0;
225+
varmax=0;
226+
varscores={};
227+
for(vartinwords)total+=words[t].df;
228+
for(vartinwords){
229+
vardf=words[t].df;
230+
if(!df)continue;
231+
232+
varidf=Math.log(total/df);
233+
234+
vartf=0;
235+
varw=t.toLowerCase();
236+
tf+=Util.countMatch(doc.content.asText().toLowerCase(),w);
237+
if(doc.title){
238+
tf+=Util.countMatch(doc.title.toLowerCase(),w);
239+
}
240+
241+
scores[t]=tf/idf;
242+
if(scores[t]>max)max=scores[t];
243+
}
244+
if(!max)return;
245+
for(vartinwords){
246+
varscore=scores[t]/max;// normalize
247+
words[t].score+=score*self.weight;
248+
}
249+
};
250+
251+
returnself;
252+
};
253+
})(Scoring);

‎sketch/extract-content.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
returnself;
9999
};
100100

101-
vari=0;
102101
newLibs(url,null).loadEach(list,callback);
103102
})('http://labs.orezdnu.org/js/',[
104103
['extract-content.js','WWW.LayeredExtractor']

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp