-
Notifications
You must be signed in to change notification settings - Fork 4
/
jgtextrank.metrics.html
200 lines (184 loc) · 13.9 KB
/
jgtextrank.metrics.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module jgtextrank.metrics</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="jgtextrank.html"><font color="#ffffff">jgtextrank</font></a>.metrics</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:c%3A%5Coak-project%5Cpython%5Cgithub%5Cjgtextrank%5Cjgtextrank%5Cmetrics.py">c:\oak-project\python\github\jgtextrank\jgtextrank\metrics.py</a></font></td></tr></table>
<p><tt># -*- coding: utf-8 -*-<br>
# ==============================================================================<br>
#<br>
# Authors: Jie Gao <[email protected]><br>
#<br>
# Copyright (c) 2017 JIE GAO . All Rights Reserved.<br>
#<br>
# Permission is hereby granted, free of charge, to any person<br>
# obtaining a copy of this software and associated documentation<br>
# files (the "Software"), to deal in the Software without<br>
# restriction, including without limitation the rights to use,<br>
# copy, modify, merge, publish, distribute, sublicense, and/or sell<br>
# copies of the Software, and to permit persons to whom the<br>
# Software is furnished to do so, subject to the following<br>
# conditions:<br>
#<br>
# The above copyright notice and this permission notice shall be<br>
# included in all copies or substantial portions of the Software.<br>
#<br>
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,<br>
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES<br>
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND<br>
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT<br>
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,<br>
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br>
# OTHER DEALINGS IN THE SOFTWARE.<br>
#<br>
# ==============================================================================</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="logging.html">logging</a><br>
</td><td width="25%" valign=top><a href="math.html">math</a><br>
</td><td width="25%" valign=top><a href="numpy.html">numpy</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="jgtextrank.metrics.html#TermGraphValue">TermGraphValue</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="jgtextrank.metrics.html#GCValue">GCValue</a>
</font></dt></dl>
</dd>
</dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="GCValue">class <strong>GCValue</strong></a>(<a href="jgtextrank.metrics.html#TermGraphValue">TermGraphValue</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Experimental metrics to weight MWTs<br> </tt></td></tr>
<tr><td> </td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="jgtextrank.metrics.html#GCValue">GCValue</a></dd>
<dd><a href="jgtextrank.metrics.html#TermGraphValue">TermGraphValue</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="GCValue-__init__"><strong>__init__</strong></a>(self, weight_comb='len_log_norm_avg', mu=5, parallel_workers=1)</dt><dd><tt>Initialize self. See help(type(self)) for accurate signature.</tt></dd></dl>
<dl><dt><a name="GCValue-weighing"><strong>weighing</strong></a>(self, all_candidates, all_vertices, top_t_vertices) -> Dict[str, float]</dt></dl>
<hr>
Static methods defined here:<br>
<dl><dt><a name="GCValue-calculate"><strong>calculate</strong></a>(candidate_term, all_candidates, all_vertices, optional_params=None) -> Tuple[str, float]</dt></dl>
<hr>
Static methods inherited from <a href="jgtextrank.metrics.html#TermGraphValue">TermGraphValue</a>:<br>
<dl><dt><a name="GCValue-g_value"><strong>g_value</strong></a>(collapsed_term, all_vertices, weight_comb='norm_sum', mu=5, **kwargs)</dt></dl>
<hr>
Data descriptors inherited from <a href="jgtextrank.metrics.html#TermGraphValue">TermGraphValue</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="TermGraphValue">class <strong>TermGraphValue</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Metrics to weigh Multi-Word Terms(MWTs)<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="TermGraphValue-__init__"><strong>__init__</strong></a>(self, weight_comb='norm_max', mu=5, parallel_workers=1)</dt><dd><tt>Initialize self. See help(type(self)) for accurate signature.</tt></dd></dl>
<dl><dt><a name="TermGraphValue-weighing"><strong>weighing</strong></a>(self, all_candidates, all_vertices, top_t_vertices) -> Dict[str, float]</dt></dl>
<hr>
Static methods defined here:<br>
<dl><dt><a name="TermGraphValue-calculate"><strong>calculate</strong></a>(candidate_term, all_candidates, all_vertices, optional_params=None) -> Tuple[str, float]</dt></dl>
<dl><dt><a name="TermGraphValue-g_value"><strong>g_value</strong></a>(collapsed_term, all_vertices, weight_comb='norm_sum', mu=5, **kwargs)</dt></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-_gaussian_normalise"><strong>_gaussian_normalise</strong></a>(base_score, mu, sigma, unit_size)</dt><dd><tt>gaussian normalisation of 'base' weight<br>
:param base_score: float, base weight of candidate terms<br>
:param mu: int, mean value to set a center point (default to 5) in order to rank the candidates higher that are near the central point<br>
This param is only required for normalisation based MWT weighting method<br>
:param sigma: float64, standard deviation of term length in MWTs<br>
:param unit_size: int, size of MWTs<br>
:return:float</tt></dd></dl>
<dl><dt><a name="-_get_average_score"><strong>_get_average_score</strong></a>(all_syntactic_units, all_vertices, unit_size)</dt><dd><tt>get average score from single candidate term<br>
<br>
:param all_syntactic_units: tokens of single candidate term<br>
:param all_vertices: all the vertices used for computing combined weight<br>
:param unit_size: size of multi-word candidate term<br>
:return:</tt></dd></dl>
<dl><dt><a name="-_get_max_score"><strong>_get_max_score</strong></a>(all_syntactic_units, all_vertices)</dt><dd><tt>get max term unit score (normalised by term unit frequency in MWTs)<br>
:param all_syntactic_units:<br>
:param all_vertices:<br>
:return:</tt></dd></dl>
<dl><dt><a name="-_get_plus_score"><strong>_get_plus_score</strong></a>(all_syntactic_units, boosted_term_size_range, boosted_word_length_range, combined_weight, unit_size)</dt><dd><tt>Experimental weighting method to provide extra small fraction weight to the final score<br>
<br>
More weight can be given to longer term<br>
<br>
:type all_syntactic_units: list (of str)<br>
:param all_syntactic_units: all the tokens of a candidate term(SWT or MWT)<br>
:type boosted_term_size_range: (int, int) | None<br>
:param boosted_term_size_range: range of token size of a candidate term that will be boosted with a small weight fraction<br>
:type boosted_word_length_range: (int, int) | None<br>
:param boosted_word_length_range: range of word length (number of character) that will be boosted with a small weight fraction<br>
:type combined_weight: float<br>
:param combined_weight: combined the weight (i.e., 'avg' or 'max') of current candidate term<br>
This weight is important and used as base value for final boosted weight<br>
:type unit_size: int<br>
:param unit_size: token size of current candidate term<br>
:return: a small weight fraction that can be added to the final weight</tt></dd></dl>
<dl><dt><a name="-_get_sum_score"><strong>_get_sum_score</strong></a>(all_syntactic_units, all_vertices)</dt></dl>
<dl><dt><a name="-_log_normalise"><strong>_log_normalise</strong></a>(base_score, mu, unit_size)</dt></dl>
<dl><dt><a name="-_probability_density"><strong>_probability_density</strong></a>(x_value, mu, sigma)</dt><dd><tt> probability density of the normal distribution<br>
<br>
see also https://en.wikipedia.org/wiki/Normal_distribution<br>
:param x_value:<br>
:param mu:<br>
:param sigma:<br>
:return:</tt></dd></dl>
<dl><dt><a name="-_term_size_normalize"><strong>_term_size_normalize</strong></a>(base_score, unit_size)</dt></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>__all__</strong> = ['_get_max_score', '_get_average_score', '_get_sum_score', '_term_size_normalize', '_log_normalise', '_probability_density', '_gaussian_normalise', '_get_plus_score', 'TermGraphValue', 'GCValue']</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
<tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td>
<td width="100%">Jie Gao <[email protected]></td></tr></table>
</body></html>