示例#1
0
 def _parse_solutions(self, solution_nodes):
     self.solutions = list()
     current_solution = None
     for node in solution_nodes:
         # print '================================node: ', \
             # node.encode('utf8'), \
             # 'task:', self.task_name
         # print type(node)
         if type(node) is parser.nodes.heading.Heading:
             lang = \
                 self._parse_language_from_header(node.title.encode('utf8'))
             if lang is None:
                 current_solution['content'].append({'type': 'description',
                     'value': node.title.encode('utf8')})
                 continue
             if current_solution is not None:
                 self.solutions.append(current_solution)
             current_solution = dict()
             current_solution['language'] = get_standardized_lang(lang, rd)
             current_solution['content'] = list()
         if type(node) is parser.nodes.tag.Tag and node.tag == 'lang':
             current_solution['content'].append({'type': 'code',
                 'content': node.contents.encode('utf8')})
         if type(node) is parser.nodes.text.Text:
             text = str(node.value.encode('utf8'))
             (commentary, code, entirematch) = self.parse_text(text)
             while code is not None:
                 current_solution['content'].append({'type': 'code',
                     'content': code})
                 commentary = self.trim(commentary)
                 if len(commentary) > 0:
                     current_solution['content'].append({'type':
                         'commentary', 'content': commentary})
                 text = text[len(entirematch):]
                 (commentary, code, entirematch) = self.parse_text(text)
示例#2
0
 def _parse_solutions(self, solution_nodes):
     self.solutions = list()
     current_solution = None
     for node in solution_nodes:
         # print '================================node: ', \
         # node.encode('utf8'), \
         # 'task:', self.task_name
         # print type(node)
         if type(node) is parser.nodes.heading.Heading:
             lang = \
                 self._parse_language_from_header(node.title.encode('utf8'))
             if lang is None:
                 current_solution['content'].append({
                     'type':
                     'description',
                     'value':
                     node.title.encode('utf8')
                 })
                 continue
             if current_solution is not None:
                 self.solutions.append(current_solution)
             current_solution = dict()
             current_solution['language'] = get_standardized_lang(lang, rd)
             current_solution['content'] = list()
         if type(node) is parser.nodes.tag.Tag and node.tag == 'lang':
             current_solution['content'].append({
                 'type':
                 'code',
                 'content':
                 node.contents.encode('utf8')
             })
         if type(node) is parser.nodes.text.Text:
             text = str(node.value.encode('utf8'))
             (commentary, code, entirematch) = self.parse_text(text)
             while code is not None:
                 current_solution['content'].append({
                     'type': 'code',
                     'content': code
                 })
                 commentary = self.trim(commentary)
                 if len(commentary) > 0:
                     current_solution['content'].append({
                         'type':
                         'commentary',
                         'content':
                         commentary
                     })
                 text = text[len(entirematch):]
                 (commentary, code, entirematch) = self.parse_text(text)
def index_rosetta_page(page, algo_ids):
    pagetask = Task(page)  # extract data from page using Task from pr

    for impl in pagetask.solutions:
        body = {
            'language': impl['language'],
            'algorithm': algo_ids,
            'source': 'rosetta',
            'implementation': impl['content'],
        }

        if len(algo_ids) > 1:
            body['description'] = '\n'.join(pagetask.task_summary)

        es.index(index=INDEX_NAME, doc_type='implementation',
            id='rosetta:' + normalize(pagetask.task_name) + ':' +
            get_standardized_lang(impl['language'].decode('utf8'), rd),
            body=body)
示例#4
0
def index_rosetta_page(page, algo_ids):
    pagetask = Task(page)  # extract data from page using Task from pr

    for impl in pagetask.solutions:
        body = {
            'language': impl['language'],
            'algorithm': algo_ids,
            'source': 'rosetta',
            'implementation': impl['content'],
        }

        if len(algo_ids) > 1:
            body['description'] = '\n'.join(pagetask.task_summary)

        es.index(index=INDEX_NAME,
                 doc_type='implementation',
                 id='rosetta:' + normalize(pagetask.task_name) + ':' +
                 get_standardized_lang(impl['language'].decode('utf8'), rd),
                 body=body)