Merge branch 'master' of http://pakal.ccg.unam.mx/cmendezc/automatic-extraction-growth-conditions
Showing
2 changed files
with
78 additions
and
0 deletions
CoreNLP/bin/filtering_v2.py
0 → 100644
1 | +# Importacion de librerias | ||
2 | +import pandas as pd | ||
3 | +import re | ||
4 | +import argparse | ||
5 | +import os | ||
6 | + | ||
7 | +__author__ = 'kevinml' | ||
8 | + | ||
9 | +# Objective: | ||
10 | +# Take two column files and make 1 file that contains just numbers and letters: | ||
11 | +# 1.- Alphanum.txt - Archivo unipalabra. | ||
12 | +# | ||
13 | +# Input parameters | ||
14 | +# --inputPath=PATH Path of inputfiles. | ||
15 | +# --outputPath=PATH Path of outputfiles. | ||
16 | +# --iFile Archivo a partir del cual se obtendran los 3 archivos. | ||
17 | +# | ||
18 | +# Examples | ||
19 | +# python filtering_v2.py --inputPath /home/kevinml/automatic-extraction-growth-conditions/CoreNLP/input --outputPath /home/kevinml/automatic-extraction-growth-conditions/CoreNLP/input --iFile NER_words.txt | ||
20 | + | ||
21 | +#################################################################################### | ||
22 | +# FUNCTIONS # | ||
23 | +#################################################################################### | ||
24 | + | ||
25 | +def alphanum(word): | ||
26 | + ''' Esta funcion regresa True si en la palabra que recibe como parametro NO SE ENCUENTRAN CARACTERES ALFANUMERICOS | ||
27 | + y regresa False si en la palabra se encuentra algun caracter NO ALFANUMERICO | ||
28 | + ''' | ||
29 | + if re.search("[^a-zA-Z0-9]", word): | ||
30 | + return False | ||
31 | + else: | ||
32 | + return True | ||
33 | + | ||
34 | +#################################################################################### | ||
35 | +# MAIN PROGRAM # | ||
36 | +#################################################################################### | ||
37 | + | ||
38 | +if __name__ == '__main__': | ||
39 | + | ||
40 | + # Definicion de Parametros | ||
41 | + parser = argparse.ArgumentParser() | ||
42 | + parser.add_argument('--inputPath', help="Ruta donde se encuentra el archivo a procesar. Ej: --inputPath /home/kevinml/transporter-substrate-interactions/", required=True) | ||
43 | + parser.add_argument('--outputPath', help="Ruta donde se depositaran los archivos resultantes. Ej: --outputPath /home/kevinml/transporter-substrate-interactions/", required=True) | ||
44 | + parser.add_argument('--iFile', help="Archivo a procesar. Ej: --iFile NER_words.txt", required=True) | ||
45 | + args = parser.parse_args() | ||
46 | + | ||
47 | + # Se imprimen los parametros ingresados | ||
48 | + print('\n-------------------------------- PARAMETERS --------------------------------\n') | ||
49 | + print('Input Path: ' + str(args.inputPath)) | ||
50 | + print('File: ' + str(args.iFile)) | ||
51 | + print('Output Path: ' + str(args.outputPath)) | ||
52 | + print('\n-------------------------------- PROCESSING --------------------------------\n') | ||
53 | + | ||
54 | + # Se abre el archivo a procesar | ||
55 | + file = pd.read_csv(os.path.join(args.inputPath, args.iFile), sep = "\t") | ||
56 | + | ||
57 | + print("######################\n# PRIMER ARCHIVO #\n######################") | ||
58 | + conditions = [] | ||
59 | + lines = [] | ||
60 | + # Se abre el archivo. | ||
61 | + with open (os.path.join(args.outputPath,"Alphanum.txt"), "w+") as oFile: | ||
62 | + for index, row in file.iterrows(): | ||
63 | + # La bandera en 1 indica que ninguna palabra de la primer columna tiene caracteres NO alfanumericos | ||
64 | + # La bandera en 0 indica que al menos una palabra tienes caracteres NO alfanumericos. | ||
65 | + bandera = 1 | ||
66 | + # Con el for se va a verificando la presencia de caracteres alfanumericos en cada palabra de la primera columna | ||
67 | + for i in range(0, len(row[0].split(" "))): | ||
68 | + if alphanum(str(row[0].split(" ")[i])) == False: | ||
69 | + bandera = 0 | ||
70 | + if bandera == 1: | ||
71 | + conditions.append(row[0]) | ||
72 | + lines.append(row[1]) | ||
73 | + # Se escriben en el primer archivo aquellos valores que cumplen las condiciones. | ||
74 | + for i in range(len(lines)): | ||
75 | + oFile.write(conditions[i] + "\t" + lines[i] + '\n') | ||
76 | + | ||
77 | + print("\nArchivo cuyo contenido unicamente son numeros y letras ha sido generado.\nNombre del archivo: Alphanum.txt\n") | ||
78 | + |
CoreNLP/input/Alphanum.txt
0 → 100644
This diff could not be displayed because it is too large.
-
Please register or login to post a comment