'Fetch the article title and analyze it
Assumptions:
- title tag is the most reliable (inherited from Goose)
- h1, if properly detected, is the best (visible to users)
- og:title and h1 can help improve the title extraction
- python == is too strict, often we need to compare filtered
versions, i.e. lowercase and ignoring special chars
Explicit rules:
1. title == h1, no need to split
2. h1 similar to og:title, use h1
3. title contains h1, title contains og:title, len(h1) > len(og:title), use h1
4. title starts with og:title, use og:title
5. use title, after splitting'

def get_title(self, doc):

    title = ''
    title_element = self.parser.getElementsByTag(doc, tag='title')
    if ((title_element is None) or (len(title_element) == 0)):
        return title
    title_text = self.parser.getText(title_element[0])
    used_delimeter = False
    title_text_h1 = ''
    title_element_h1_list = (self.parser.getElementsByTag(doc, tag='h1') or [])
    title_text_h1_list = [self.parser.getText(tag) for tag in title_element_h1_list]
    if title_text_h1_list:
        title_text_h1_list.sort(key=len, reverse=True)
        title_text_h1 = title_text_h1_list[0]
        if (len(title_text_h1.split('    ')) <= 2):
            title_text_h1 = ''
        title_text_h1 = '    '.join([x for x in title_text_h1.split() if x])
    title_text_fb = (self.get_meta_content(doc, 'meta[property="og:title"]') or self.get_meta_content(doc, 'meta[name="og:title"]') or '')
    filter_regex = re.compile('[^a-zA-Z0-9\\    ]')
    filter_title_text = filter_regex.sub('', title_text).lower()
    filter_title_text_h1 = filter_regex.sub('', title_text_h1).lower()
    filter_title_text_fb = filter_regex.sub('', title_text_fb).lower()
    if (title_text_h1 == title_text):
        used_delimeter = True
    elif (filter_title_text_h1 and (filter_title_text_h1 == filter_title_text_fb)):
        title_text = title_text_h1
        used_delimeter = True
    elif (filter_title_text_h1 and (filter_title_text_h1 in filter_title_text) and filter_title_text_fb and (filter_title_text_fb in filter_title_text) and (len(title_text_h1) > len(title_text_fb))):
        title_text = title_text_h1
        used_delimeter = True
    elif (filter_title_text_fb and (filter_title_text_fb != filter_title_text) and filter_title_text.startswith(filter_title_text_fb)):
        title_text = title_text_fb
        used_delimeter = True
    if ((not used_delimeter) and ('|' in title_text)):
        title_text = self.split_title(title_text, PIPE_SPLITTER, title_text_h1)
        used_delimeter = True
    if ((not used_delimeter) and ('-' in title_text)):
        title_text = self.split_title(title_text, DASH_SPLITTER, title_text_h1)
        used_delimeter = True
    if ((not used_delimeter) and ('_' in title_text)):
        title_text = self.split_title(title_text, UNDERSCORE_SPLITTER, title_text_h1)
        used_delimeter = True
    if ((not used_delimeter) and ('/' in title_text)):
        title_text = self.split_title(title_text, SLASH_SPLITTER, title_text_h1)
        used_delimeter = True
    if ((not used_delimeter) and ('    \xc2\xbb    ' in title_text)):
        title_text = self.split_title(title_text, ARROWS_SPLITTER, title_text_h1)
        used_delimeter = True
    title = MOTLEY_REPLACEMENT.replaceAll(title_text)
    filter_title = filter_regex.sub('', title).lower()
    if (filter_title_text_h1 == filter_title):
        title = title_text_h1
    return title
