@@ -66,12 +66,21 @@ def __init__(self, config, article):
6666 # article
6767 self .article = article
6868
69- # language
70- self .language = config .target_language
71-
7269 # stopwords class
7370 self .stopwords_class = config .stopwords_class
7471
72+ def get_language (self ):
73+ """\
74+ Returns the language is by the article or
75+ the configuration language
76+ """
77+ # we don't want to force the target language
78+ # so we use the article.meta_lang
79+ if self .config .use_meta_language :
80+ if self .article .meta_lang :
81+ return self .article .meta_lang [:2 ]
82+ return self .config .target_language
83+
7584 def clean_title (self , title ):
7685 """Clean title with the use of og:site_name
7786 in this case try to get ride of site name
@@ -371,7 +380,7 @@ def calculate_best_node(self):
371380
372381 for node in nodes_to_check :
373382 text_node = self .parser .getText (node )
374- word_stats = self .stopwords_class (language = self .language ).get_stopword_count (text_node )
383+ word_stats = self .stopwords_class (language = self .get_language () ).get_stopword_count (text_node )
375384 high_link_density = self .is_highlink_density (node )
376385 if word_stats .get_stopword_count () > 2 and not high_link_density :
377386 nodes_with_text .append (node )
@@ -397,7 +406,7 @@ def calculate_best_node(self):
397406 boost_score = float (5 )
398407
399408 text_node = self .parser .getText (node )
400- word_stats = self .stopwords_class (language = self .language ).get_stopword_count (text_node )
409+ word_stats = self .stopwords_class (language = self .get_language () ).get_stopword_count (text_node )
401410 upscore = int (word_stats .get_stopword_count () + boost_score )
402411
403412 # parent node
@@ -453,7 +462,7 @@ def is_boostable(self, node):
453462 if steps_away >= max_stepsaway_from_node :
454463 return False
455464 paraText = self .parser .getText (current_node )
456- word_stats = self .stopwords_class (language = self .language ).get_stopword_count (paraText )
465+ word_stats = self .stopwords_class (language = self .get_language () ).get_stopword_count (paraText )
457466 if word_stats .get_stopword_count () > minimum_stopword_count :
458467 return True
459468 steps_away += 1
@@ -500,7 +509,7 @@ def get_siblings_content(self, current_sibling, baselinescore_siblings_para):
500509 for first_paragraph in potential_paragraphs :
501510 text = self .parser .getText (first_paragraph )
502511 if len (text ) > 0 :
503- word_stats = self .stopwords_class (language = self .language ).get_stopword_count (text )
512+ word_stats = self .stopwords_class (language = self .get_language () ).get_stopword_count (text )
504513 paragraph_score = word_stats .get_stopword_count ()
505514 sibling_baseline_score = float (.30 )
506515 high_link_density = self .is_highlink_density (first_paragraph )
@@ -527,7 +536,7 @@ def get_siblings_score(self, top_node):
527536
528537 for node in nodes_to_check :
529538 text_node = self .parser .getText (node )
530- word_stats = self .stopwords_class (language = self .language ).get_stopword_count (text_node )
539+ word_stats = self .stopwords_class (language = self .get_language () ).get_stopword_count (text_node )
531540 high_link_density = self .is_highlink_density (node )
532541 if word_stats .get_stopword_count () > 2 and not high_link_density :
533542 paragraphs_number += 1
0 commit comments