extractor.py 1.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
# -*- coding: utf-8 -*
"""
Created on Thu Jan 28 09:38:20 2021
"""
import jkesExtractor
import sys, os, json

#Función que dado un path, un listado de datos y el modo de apertura del archivo,
#escribe los datos en el archivo correspondiente
def write(pathOutput,dataList,mode):

	#Output in the second route 
        if os.path.exists(pathOutput):          
            with open(pathOutput, mode) as outputfile:
                for i in range(0,len(dataList)):
                    strOutput = ""
                    for j in range(0,len(dataList[i])):
                        strOutput += str(dataList[i][j])+"\t"
                    outputfile.write(strOutput.strip()+"\n")

            print("Completed")
            
        else:
            print("Output file doesn't exist")


#Funcion principal: recibe el path del archivo de anotaciones y del archivo de salida
def main():
    #First arg is the route of .json BIO

    inputRoute = sys.argv[1]
    outputRoute = sys.argv[2]
    if os.path.exists(inputRoute):
        
        #Extraction of CUIS
        print("Checking JKES CUIS")
        listConceptsJkes, listConceptsUmls = jkesExtractor.jkes_concept_extractor(inputRoute)
        write(outputRoute,listConceptsJkes,"w")
        write(outputRoute,listConceptsUmls,"a")
        
    else:
        print("Input file doesn't exist")
       

if __name__ == "__main__":
    main()