@@ -50,7 +50,7 @@ def __init__(self, config):
5050 self .language = config .target_language
5151 self .stopwords_class = config .stopwords_class
5252
53- def getLanguage (self , article ):
53+ def get_language (self , article ):
5454 """\
5555 Returns the language is by the article or
5656 the configuration language
@@ -62,7 +62,7 @@ def getLanguage(self, article):
6262 self .language = article .meta_lang [:2 ]
6363 self .language = self .config .target_language
6464
65- def getTitle (self , article ):
65+ def get_title (self , article ):
6666 """\
6767 Fetch the article title and analyze it
6868 """
@@ -81,28 +81,28 @@ def getTitle(self, article):
8181
8282 # split title with |
8383 if '|' in titleText :
84- titleText = self .doTitleSplits (titleText , PIPE_SPLITTER )
84+ titleText = self .split_title (titleText , PIPE_SPLITTER )
8585 usedDelimeter = True
8686
8787 # split title with -
8888 if not usedDelimeter and '-' in titleText :
89- titleText = self .doTitleSplits (titleText , DASH_SPLITTER )
89+ titleText = self .split_title (titleText , DASH_SPLITTER )
9090 usedDelimeter = True
9191
9292 # split title with »
9393 if not usedDelimeter and u'»' in titleText :
94- titleText = self .doTitleSplits (titleText , ARROWS_SPLITTER )
94+ titleText = self .split_title (titleText , ARROWS_SPLITTER )
9595 usedDelimeter = True
9696
9797 # split title with :
9898 if not usedDelimeter and ':' in titleText :
99- titleText = self .doTitleSplits (titleText , COLON_SPLITTER )
99+ titleText = self .split_title (titleText , COLON_SPLITTER )
100100 usedDelimeter = True
101101
102102 title = MOTLEY_REPLACEMENT .replaceAll (titleText )
103103 return title
104104
105- def doTitleSplits (self , title , splitter ):
105+ def split_title (self , title , splitter ):
106106 """\
107107 Split the title to best part possible
108108 """
@@ -121,7 +121,7 @@ def doTitleSplits(self, title, splitter):
121121 title = titlePieces [largeTextIndex ]
122122 return TITLE_REPLACEMENTS .replaceAll (title ).strip ()
123123
124- def getMetaFavicon (self , article ):
124+ def get_favicon (self , article ):
125125 """\
126126 Extract the favicon from a website
127127 http://en.wikipedia.org/wiki/Favicon
@@ -135,7 +135,7 @@ def getMetaFavicon(self, article):
135135 return favicon
136136 return ''
137137
138- def getMetaLang (self , article ):
138+ def get_meta_lang (self , article ):
139139 """\
140140 Extract content language from meta
141141 """
@@ -161,7 +161,7 @@ def getMetaLang(self, article):
161161
162162 return None
163163
164- def getMetaContent (self , doc , metaName ):
164+ def get_meta_content (self , doc , metaName ):
165165 """\
166166 Extract a given meta content form document
167167 """
@@ -176,19 +176,19 @@ def getMetaContent(self, doc, metaName):
176176
177177 return ''
178178
179- def getMetaDescription (self , article ):
179+ def get_meta_description (self , article ):
180180 """\
181181 if the article has meta description set in the source, use that
182182 """
183- return self .getMetaContent (article .doc , "meta[name=description]" )
183+ return self .get_meta_content (article .doc , "meta[name=description]" )
184184
185- def getMetaKeywords (self , article ):
185+ def get_meta_keywords (self , article ):
186186 """\
187187 if the article has meta keywords set in the source, use that
188188 """
189- return self .getMetaContent (article .doc , "meta[name=keywords]" )
189+ return self .get_meta_content (article .doc , "meta[name=keywords]" )
190190
191- def getCanonicalLink (self , article ):
191+ def get_canonical_link (self , article ):
192192 """\
193193 if the article has meta canonical link set in the url
194194 """
@@ -206,11 +206,11 @@ def getCanonicalLink(self, article):
206206 return href
207207 return article .final_url
208208
209- def getDomain (self , url ):
209+ def get_domain (self , url ):
210210 o = urlparse (url )
211211 return o .hostname
212212
213- def extractTags (self , article ):
213+ def extract_tags (self , article ):
214214 node = article .doc
215215
216216 # node doesn't have chidren
@@ -229,10 +229,10 @@ def extractTags(self, article):
229229
230230 return set (tags )
231231
232- def calculateBestNodeBasedOnClustering (self , article ):
232+ def calculate_best_node (self , article ):
233233 doc = article .doc
234234 topNode = None
235- nodesToCheck = self .getNodesToCheck (doc )
235+ nodesToCheck = self .nodes_to_check (doc )
236236
237237 startingBoost = float (1.0 )
238238 cnt = 0
@@ -243,7 +243,7 @@ def calculateBestNodeBasedOnClustering(self, article):
243243 for node in nodesToCheck :
244244 nodeText = Parser .getText (node )
245245 wordStats = self .stopwords_class (language = self .language ).getStopWordCount (nodeText )
246- highLinkDensity = self .isHighLinkDensity (node )
246+ highLinkDensity = self .is_highlink_density (node )
247247 if wordStats .getStopWordCount () > 2 and not highLinkDensity :
248248 nodesWithText .append (node )
249249
@@ -254,7 +254,7 @@ def calculateBestNodeBasedOnClustering(self, article):
254254 for node in nodesWithText :
255255 boostScore = float (0 )
256256 # boost
257- if (self .isOkToBoost (node )):
257+ if (self .is_boostable (node )):
258258 if cnt >= 0 :
259259 boostScore = float ((1.0 / startingBoost ) * 50 )
260260 startingBoost += 1
@@ -273,25 +273,25 @@ def calculateBestNodeBasedOnClustering(self, article):
273273
274274 # parent node
275275 parentNode = Parser .getParent (node )
276- self .updateScore (parentNode , upscore )
277- self .updateNodeCount (node .getparent (), 1 )
276+ self .update_score (parentNode , upscore )
277+ self .update_node_count (node .getparent (), 1 )
278278
279279 if node .getparent () not in parentNodes :
280280 parentNodes .append (node .getparent ())
281281
282282 # parentparent node
283283 parentParentNode = Parser .getParent (parentNode )
284284 if parentParentNode is not None :
285- self .updateNodeCount (parentParentNode , 1 )
286- self .updateScore (parentParentNode , upscore / 2 )
285+ self .update_node_count (parentParentNode , 1 )
286+ self .update_score (parentParentNode , upscore / 2 )
287287 if parentParentNode not in parentNodes :
288288 parentNodes .append (parentParentNode )
289289 cnt += 1
290290 i += 1
291291
292292 topNodeScore = 0
293293 for e in parentNodes :
294- score = self .getScore (e )
294+ score = self .get_score (e )
295295
296296 if score > topNodeScore :
297297 topNode = e
@@ -302,7 +302,7 @@ def calculateBestNodeBasedOnClustering(self, article):
302302
303303 return topNode
304304
305- def isOkToBoost (self , node ):
305+ def is_boostable (self , node ):
306306 """\
307307 alot of times the first paragraph might be the caption under an image
308308 so we'll want to make sure if we're going to boost a parent node that
@@ -316,7 +316,7 @@ def isOkToBoost(self, node):
316316 minimumStopWordCount = 5
317317 maxStepsAwayFromNode = 3
318318
319- nodes = self .walkSiblings (node )
319+ nodes = self .walk_siblings (node )
320320 for currentNode in nodes :
321321 # p
322322 if currentNode .tag == para :
@@ -329,7 +329,7 @@ def isOkToBoost(self, node):
329329 stepsAway += 1
330330 return False
331331
332- def walkSiblings (self , node ):
332+ def walk_siblings (self , node ):
333333 currentSibling = Parser .previousSibling (node )
334334 b = []
335335 while currentSibling is not None :
@@ -338,16 +338,16 @@ def walkSiblings(self, node):
338338 currentSibling = None if previousSibling is None else previousSibling
339339 return b
340340
341- def addSiblings (self , topNode ):
342- baselineScoreForSiblingParagraphs = self .getBaselineScoreForSiblings (topNode )
343- results = self .walkSiblings (topNode )
341+ def add_siblings (self , topNode ):
342+ baselineScoreForSiblingParagraphs = self .get_siblings_score (topNode )
343+ results = self .walk_siblings (topNode )
344344 for currentNode in results :
345- ps = self .getSiblingContent (currentNode , baselineScoreForSiblingParagraphs )
345+ ps = self .get_siblings_content (currentNode , baselineScoreForSiblingParagraphs )
346346 for p in ps :
347347 topNode .insert (0 , p )
348348 return topNode
349349
350- def getSiblingContent (self , currentSibling , baselineScoreForSiblingParagraphs ):
350+ def get_siblings_content (self , currentSibling , baselineScoreForSiblingParagraphs ):
351351 """\
352352 adds any siblings that may have a decent score to this node
353353 """
@@ -369,14 +369,14 @@ def getSiblingContent(self, currentSibling, baselineScoreForSiblingParagraphs):
369369 wordStats = self .stopwords_class (language = self .language ).getStopWordCount (text )
370370 paragraphScore = wordStats .getStopWordCount ()
371371 siblingBaseLineScore = float (.30 )
372- highLinkDensity = self .isHighLinkDensity (firstParagraph )
372+ highLinkDensity = self .is_highlink_density (firstParagraph )
373373 score = float (baselineScoreForSiblingParagraphs * siblingBaseLineScore )
374374 if score < paragraphScore and not highLinkDensity :
375375 p = Parser .createElement (tag = 'p' , text = text , tail = None )
376376 ps .append (p )
377377 return ps
378378
379- def getBaselineScoreForSiblings (self , topNode ):
379+ def get_siblings_score (self , topNode ):
380380 """\
381381 we could have long articles that have tons of paragraphs
382382 so if we tried to calculate the base score against
@@ -394,7 +394,7 @@ def getBaselineScoreForSiblings(self, topNode):
394394 for node in nodesToCheck :
395395 nodeText = Parser .getText (node )
396396 wordStats = self .stopwords_class (language = self .language ).getStopWordCount (nodeText )
397- highLinkDensity = self .isHighLinkDensity (node )
397+ highLinkDensity = self .is_highlink_density (node )
398398 if wordStats .getStopWordCount () > 2 and not highLinkDensity :
399399 numberOfParagraphs += 1
400400 scoreOfParagraphs += wordStats .getStopWordCount ()
@@ -404,7 +404,7 @@ def getBaselineScoreForSiblings(self, topNode):
404404
405405 return base
406406
407- def updateScore (self , node , addToScore ):
407+ def update_score (self , node , addToScore ):
408408 """\
409409 adds a score to the gravityScore Attribute we put on divs
410410 we'll get the current score then add the score
@@ -418,7 +418,7 @@ def updateScore(self, node, addToScore):
418418 newScore = currentScore + addToScore
419419 node .set ("gravityScore" , str (newScore ))
420420
421- def updateNodeCount (self , node , addToCount ):
421+ def update_node_count (self , node , addToCount ):
422422 """\
423423 stores how many decent nodes are under a parent node
424424 """
@@ -430,7 +430,7 @@ def updateNodeCount(self, node, addToCount):
430430 newScore = currentScore + addToCount
431431 node .set ("gravityNodes" , str (newScore ))
432432
433- def isHighLinkDensity (self , e ):
433+ def is_highlink_density (self , e ):
434434 """\
435435 checks the density of links within a node,
436436 is there not much text and most of it contains linky shit?
@@ -458,19 +458,19 @@ def isHighLinkDensity(self, e):
458458 return False
459459 # return True if score > 1.0 else False
460460
461- def getScore (self , node ):
461+ def get_score (self , node ):
462462 """\
463463 returns the gravityScore as an integer from this node
464464 """
465- return self .getGravityScoreFromNode (node ) or 0
465+ return self .get_node_gravity_score (node ) or 0
466466
467- def getGravityScoreFromNode (self , node ):
467+ def get_node_gravity_score (self , node ):
468468 grvScoreString = node .attrib .get ('gravityScore' )
469469 if not grvScoreString :
470470 return None
471471 return int (grvScoreString )
472472
473- def getNodesToCheck (self , doc ):
473+ def nodes_to_check (self , doc ):
474474 """\
475475 returns a list of nodes we want to search
476476 on like paragraphs and tables
@@ -481,7 +481,7 @@ def getNodesToCheck(self, doc):
481481 nodesToCheck += items
482482 return nodesToCheck
483483
484- def isTableTagAndNoParagraphsExist (self , e ):
484+ def is_table_and_no_para_exist (self , e ):
485485 subParagraphs = Parser .getElementsByTag (e , tag = 'p' )
486486 for p in subParagraphs :
487487 txt = Parser .getText (p )
@@ -493,26 +493,26 @@ def isTableTagAndNoParagraphsExist(self, e):
493493 return True
494494 return False
495495
496- def isNodeScoreThreshholdMet (self , node , e ):
497- topNodeScore = self .getScore (node )
498- currentNodeScore = self .getScore (e )
496+ def is_nodescore_threshold_met (self , node , e ):
497+ topNodeScore = self .get_score (node )
498+ currentNodeScore = self .get_score (e )
499499 thresholdScore = float (topNodeScore * .08 )
500500
501501 if (currentNodeScore < thresholdScore ) and e .tag != 'td' :
502502 return False
503503 return True
504504
505- def postExtractionCleanup (self , targetNode ):
505+ def post_cleanup (self , targetNode ):
506506 """\
507507 remove any divs that looks like non-content,
508508 clusters of links, or paras with no gusto
509509 """
510- node = self .addSiblings (targetNode )
510+ node = self .add_siblings (targetNode )
511511 for e in node .getchildren ():
512512 if e .tag != 'p' :
513- if self .isHighLinkDensity (e ) \
514- or self .isTableTagAndNoParagraphsExist (e ) \
515- or not self .isNodeScoreThreshholdMet (node , e ):
513+ if self .is_highlink_density (e ) \
514+ or self .is_table_and_no_para_exist (e ) \
515+ or not self .is_nodescore_threshold_met (node , e ):
516516 Parser .remove (e )
517517 return node
518518
0 commit comments