def create_preposition(html_full_preposition): data = scrap_preposition(html_full_preposition) query = "CREATE (:Preposicao {nid:\"%s\", mais_informacoes:\"%s\", divisao_silabica:\"%s\"});" query = query % (data['lemma'], data['mais_informacoes'], data['divisao_silabica']) db_utils.execute_query(query=query) return query
def create_adverb(html_full_adverb): data = scrap_adverb(html_full_adverb) query = "CREATE (:Adverbio {nid:\"%s\", mais_informacoes:\"%s\", divisao_silabica:\"%s\"});" query = query % (data['lemma'], data['mais_informacoes'], data['divisao_silabica']) db_utils.execute_query(query=query) return query
def create_verb(html_full_verb): main_verb_token = regex.findall(r"<h1>.+?</h1>", html_full_verb) main_verb_token = regex.sub(r"<.+?>", "", main_verb_token[0]) main_term = str(main_verb_token).split(" -")[0].strip(" ") verb_data = scrap_verb(html_full_verb) data_len = len(verb_data[0]) divisao_silabica = verb_data[2].replace("·", "-") query = "CREATE (:Verbo {nid:\"" + main_term + "\", divisao_silabica:\"" + divisao_silabica + "\", " for vvv in range(0, data_len): if str(vvv) in verb_structure.keys(): data = verb_data[0][vvv] if vvv == 31: data = scrapper.ascii_2_portuguese(verb_data[1].replace( ":::", ",")) query += verb_structure[str(vvv)] + ":[\"" + data.replace( "Pessoal:::", "").replace(":::", "\",\"").replace( " ", "") + "\"]" else: query += verb_structure[str(vvv)] + ":[\"" + data.replace( "Pessoal:::", "").replace(":::", "\",\"").replace( " ", "") + "\"], " query += "});" db_utils.execute_query(query=query) return query
def create_number(html_full_number): data = scrap_number(html_full_number) query = "CREATE (:Numero {nid:\"%s\", divisao_silabica:\"%s\", masculino_plural:\"%s\", feminino_plural:\"%s\", " query += "masculino_singular:\"%s\", feminino_singular:\"%s\"});" query = query % (data['lemma'], data['divisao_silabica'], data['plur_masc'], data['plur_femi'], data['sing_masc'], data['sing_femi']) db_utils.execute_query(query=query) return query
def create_noun(html_full_noun): data = scrap_noun(html_full_noun) main_term = scrapper.ascii_2_portuguese(data[0][0].split(" - ")[0]) gender = scrapper.ascii_2_portuguese( data[0][0].split(" - ")[1]).split(" ")[-1] divisao_silabica = scrapper.ascii_2_portuguese(data[1].replace("·", "-")) plural = data[0][-1].split(" ")[-1] query = "CREATE (:Substantivo {nid:\"%s\", divisao_silabica:\"%s\", genero:\"%s\", plural:\"%s\"" % ( main_term, divisao_silabica, gender, plural) query += "});" db_utils.execute_query(query=query) return query
def create_adjective(html_full_adjective): data = scrap_adjective(html_full_adjective) query = "CREATE (:Adjetivo {nid:\"%s\", divisao_silabica:\"%s\", masculino_plural:\"%s\", feminino_plural:\"%s\", " if "more_info" in data.keys(): query += "masculino_singular:\"%s\", feminino_singular:\"%s\", mais_informacoes:\"%s\"});" query = query % (data['lemma'], data['divisao_silabica'], data['plur_masc'], data['plur_femi'], data['sing_masc'], data['sing_femi'], data['more_info']) else: query += "masculino_singular:\"%s\", feminino_singular:\"%s\"});" query = query % (data['lemma'], data['divisao_silabica'], data['plur_masc'], data['plur_femi'], data['sing_masc'], data['sing_femi']) db_utils.execute_query(query=query) return query
import os import sys project_path = os.path.abspath(__file__).split('/') del project_path[-1] del project_path[-1] del project_path[-1] sys.path.append(os.path.join('/'.join(project_path), 'generators')) from generators.utils import db_utils import generators.utils.defs as d categories = [d.VERBO] for category in categories: print category all_words = set() result = db_utils.execute_query("MATCH (n:%s) RETURN n.nid" % category).data() for node in result: w = node['n.nid'] all_words.add(w) count = 0 file_ = open('all_' + category.lower() + '.txt', 'w') for it in all_words: if '"' in it: continue el = 'u"' + it + '": None, ' count += 1 file_.write(el)
from generators.utils import db_utils from glob import glob if __name__ == '__main__': # file_ = 'simple_dict_outputs/word_queries/file_query1.txt' for file_ in glob('simple_dict_outputs/word_queries/*'): print 'file:', file_ queries = open(file_, 'r') for line in queries.readlines(): word = line.replace('\n', '').split('"')[1] gram = line.replace('\n', '').split(':')[1].split(' ')[0] query = """MATCH (n:%s {nid: "%s"}) WITH n SKIP 1 DELETE n;""" % ( gram, word) # query = """MATCH (n:%s {nid: "%s"}) RETURN n;""" % (gram, word) result = db_utils.execute_query(query).evaluate() if result: print result