<commit_before>class Contexor:
    
    'EXAMPLE USE: o = Contexor(\'nytimes.com\') and then o.similar([\'cnn.com\',\'wsj.com\',\'bbc.com\'])'

    def __init__(self, control_url):
        
        self.control_url = control_url
        self.req = urllib2.build_opener(urllib2.HTTPCookieProcessor())
        self.nlp = spacy.load('en')
        self.control_doc = self._control_group()

    def _control_group(self):
        
        html = self.req.open('http://' + self.control_url)
        soup = BeautifulSoup(html, "lxml")
        self.control_doc = nlp(unicode(soup.find_all('p')))
        
        return self.control_doc
    
    def similar(self,comparison_url):
        
        if len(comparison_url) == 1:
            
            comparison_url = [comparison_url]
        
        for url in comparison_url:    
        
            html = self.req.open('http://' + url)
            soup = BeautifulSoup(html, "lxml")
            self.comparison_doc = nlp(unicode(soup.find_all('p')))
        
            print url,self.control_doc.similarity(self.comparison_doc)<commit_msg>much improved html to text parsing<commit_after>import urllib2
import spacy
from bs4 import BeautifulSoup

class Contexor:
    
    'EXAMPLE USE: o = Contexor(\'nytimes.com\') and then o.similar([\'cnn.com\',\'wsj.com\',\'bbc.com\'])'

    def __init__(self, control_url):
        
        self.control_url = control_url
        self.req = urllib2.build_opener(urllib2.HTTPCookieProcessor())
        self.nlp = spacy.load('en')
        self.control_doc = self._control_group()

    def _control_group(self):
        
        html = self.req.open('http://' + self.control_url)
        soup = BeautifulSoup(html, "lxml")
        self.control_doc = self.nlp(unicode(soup.find_all('p')))
        
        return self.control_doc
    
    def similar(self,comparison_url):
        
        if len(comparison_url) == 1:
            
            comparison_url = [comparison_url]
        
        for url in comparison_url:    
        
            html = self.req.open('http://' + url)
            soup = BeautifulSoup(html, "lxml")
            
            text = ''

            for item in soup.find_all('p'):

                item = item.get_text()
                item = unicode(item)
                item = item.replace('  ','')
                text += ' ' + item
                
            self.comparison_doc = self.nlp(unicode(text))
        
            print url,self.control_doc.similarity(self.comparison_doc)
{'fraction_non_alphanumeric': 0.12490023942537909, 'fraction_numerical': 0.0031923383878691143, 'mean_word_length': 1.8849252013808975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '166371', 'n_tokens_mistral': 819, 'n_tokens_neox': 786, 'n_words': 131}