Esempio n. 1
0
    def write_keywords(self, number: int = 10, limit: int = 1.3) -> 'KeywordRanking':
        """Print top number keywords"""
        node_weight = OrderedDict(sorted(self.node_weight.items(), key=lambda t: t[1], reverse=True))

        if self.date and self.index is not None:
            with Storage('statistics.json') as storage:
                data = deepcopy(storage.data)

                for i, (key, value) in enumerate(node_weight.items()):
                    if value >= limit:
                        if i > number:
                            break
                        if key not in data:
                            data[key] = {
                                'ru': translator.translate(key, src='en', dest='ru').text,
                                'date_index': [[self.date, str(self.index)]]
                            }
                        elif [self.date, str(self.index)] not in data[key]['date_index']:
                            data[key]['date_index'].append([self.date, str(self.index)])
                if data != storage.data:
                    storage.write(data=data)
        else:
            keywords = []
            for i, (key, value) in enumerate(node_weight.items()):
                if i > number:
                    break
                elif value >= limit:
                    keywords.append([key, translator.translate(key, src='en', dest='ru').text, value])
            print(f'{keywords[0]} = {keywords[1]} - {keywords[2]}')
        return self
Esempio n. 2
0
def translate(vm_file_name: str) -> None:
    instructions = parser.get_instructions(vm_file_name)
    binary_instructions = [
        translator.translate(instruction, vm_file_name)
        for instruction in instructions
    ]
    write_in_file(binary_instructions, vm_file_name)
Esempio n. 3
0
def assemble(asm_file: str) -> None:
    symbol_table = SymbolTable()
    instructions = get_instructions(asm_file, symbol_table)
    binary_instructions = [
        translate(instruction, symbol_table) for instruction in instructions
    ]
    write_in_file(binary_instructions, asm_file)
Esempio n. 4
0
def translate_text():
    text = request.form["text"]
    source_language = request.form["source_language"]
    dest_language = request.form["dest_language"]
    result = translator.translate(text,
                                  src=source_language,
                                  dest=dest_language)
    return jsonify({"text": result.text})
Esempio n. 5
0
    def __init__(self, path: str = None,
                 date: str = None,
                 index: int = None,
                 text: str = None,
                 candidate_pos: list = None,
                 window_size: int = 4,
                 damp_coef: float = 0.85,
                 min_diff: float = 1e-5,
                 steps: int = 10,
                 stopwords: set = None,
                 to_lower: bool = True):

        if text and path:
            raise BaseException('text OR path should be passed, not both.')
        elif not text and not path:
            raise BaseException('path or text should be passed.')
        elif (not date or len(date.split('-')) != 3) and path:
            raise BaseException('If path exists, date should be passed in format dd-MM-yyyy.')
        elif index is None and path:
            raise BaseException('If path exists, index should be passed.')

        if text:
            text = translator.translate(text, src='ru', dest='en').text
        elif path:
            with Storage(path=path) as storage:
                text = translator.translate(storage.data[date][str(index)], src='ru', dest='en').text

        self.doc = nlp(text)
        self.date = date
        self.index = index

        self.candidate_pos = candidate_pos if candidate_pos else ['NOUN', 'PRON']
        self.window_size = window_size
        self.damp_coef = damp_coef
        self.min_diff = min_diff
        self.steps = steps
        self.stopwords = stopwords
        self.to_lower = to_lower
        self.node_weight = None
Esempio n. 6
0
 def test_hello_world_translation(self):
     translation = translator.translate("Bonjour",
                                        dest_lang='en',
                                        src_lang='fr')
     self.assertEqual('Hello', translation)
Esempio n. 7
0
def translate_text():
    return jsonify({'text': translator.translate(request.form['text'],
                                                 request.form['source_language'],
                                                 request.form['dest_language'])})
Esempio n. 8
0
def translate_file(vm_file_name: str) -> List[str]:
    instructions = parser.get_instructions(vm_file_name)
    asm_instructions = [
        translator.translate(instruction, vm_file_name) for instruction in instructions
    ]
    return asm_instructions