Index: utils/build_lda.py
===================================================================
--- utils/build_lda.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
+++ utils/build_lda.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+"""
+Sistema de Modelado de TÃ³picos
+
+Copyleft (@) 2014 CENDITEL nodo MÃ©rida - https://planificacion.cenditel.gob.ve/trac/
+"""
+## @package django_topic_explorer.utils
+#
+# MÃ©todos para generar los archivos del LDA resultantes de verificar el pre-procesamiento
+# @author Jorge Redondo (jredondo at cenditel.gob.ve)
+# @author <a href='http://www.cenditel.gob.ve'>Centro Nacional de Desarrollo e InvestigaciÃ³n en TecnologÃ­as Libres
+# (CENDITEL) nodo MÃ©rida - Venezuela</a>
+# @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versiÃ³n 2 (GPLv2)</a>
+# @version 1.3
+
+import glob
+import sys
+
+def build_lda(path_corpus,path_output):
+  """!
+  FunciÃ³n para construir los archivos del lda
+  
+  @author Jorge Redondo (jredondo at cenditel.gob.ve)
+  @copyright GNU/GPLv2
+  @param path_corpus Recibe la ruta donde esta ubicado el corpus
+  @param path_output Recibe la ruta de destino donde es secribirÃ¡n los archivos
+  """
+  
+  files = glob.glob(path_corpus+'/*')
+
+  vocab = []
+  f_dict = {}
+  # To build vocabulary, first
+  for f in files:
+    # It's supposed that each files has only one line, thus index 0
+    f_words = open(f).readlines()[0].split(' ')
+    f_words = [w.decode('utf8').strip(u'\ufeff') for w in f_words if len(w) > 0]
+    f_dict[f.split('/')[-1]] = f_words
+    vocab += f_words
+
+  vocab = sorted(set(vocab))
+
+  with open(path_output+'corpus.dat','w') as outfile:
+    for item in f_dict.items():
+      outfile.write(str(len(item[1]))+' ')
+
+      for w in set(item[1]):
+        outfile.write(str(vocab.index(w)) + ':' + str(item[1].count(w)) + ' ')
+
+      outfile.write('\n')
+
+  with open(path_output+'vocab.txt','w') as outfile:
+    for item in vocab:
+      outfile.write(item.encode('utf8')+'\n')
+    
+
+if __name__ == '__main__':
+  if(len(sys.argv)==3):
+    path_corpus = sys.argv[1]
+    path_output = sys.argv[2]
+    build_lda(path_corpus,path_output)
+    print "Se ejecutÃ³ el comando con Ã©xito"
+  else:
+    print "Debe ingresar (2) argumentos a la funciÃ³n: path_corpus y path_output"
+
+
Index: utils/colorlib.py
===================================================================
--- utils/colorlib.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
+++ utils/colorlib.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
@@ -0,0 +1,21 @@
+import brewer2mpl as brewer
+
+def brew(N, n_cls, reverse=True):
+    b = [
+        brewer.get_map('Blues', 'Sequential', N+1, reverse=reverse).hex_colors[:N],
+        brewer.get_map('Oranges', 'Sequential', N+1, reverse=reverse).hex_colors[:N],
+        brewer.get_map('Greens', 'Sequential', N+1, reverse=reverse).hex_colors[:N],
+        brewer.get_map('Purples', 'Sequential', N+1, reverse=reverse).hex_colors[:N],
+        brewer.get_map('Greys', 'Sequential', N+1, reverse=reverse).hex_colors[:N],
+        brewer.get_map('Reds', 'Sequential', N+1, reverse=reverse).hex_colors[:N]
+    ]
+    return b[:n_cls]
+
+# d3.category20c()
+category20c = [
+    ['#3182bd','#6baed6','#9ecae1','#c6dbef'],
+    ['#e6550d','#fd8d3c','#fdae6b','#fdd0a2'],
+    ['#31a354','#74c476','#a1d99b','#c7e9c0'],
+    ['#756bb1','#9e9ac8','#bcbddc','#dadaeb'],
+    ['#636363','#969696','#bdbdbd','#d9d9d9']
+]
Index: utils/corpusScript.py
===================================================================
--- utils/corpusScript.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
+++ utils/corpusScript.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+"""
+Sistema de Modelado de TÃ³picos
+
+Copyleft (@) 2014 CENDITEL nodo MÃ©rida - https://planificacion.cenditel.gob.ve/trac/
+"""
+## @package django_topic_explorer.utils
+#
+# MÃ©todo para crea los archivos copus.dat y vocab.txt
+# @author Jorge Redondo (jredondo at cenditel.gob.ve)
+# @author <a href='http://www.cenditel.gob.ve'>Centro Nacional de Desarrollo e InvestigaciÃ³n en TecnologÃ­as Libres
+# (CENDITEL) nodo MÃ©rida - Venezuela</a>
+# @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versiÃ³n 2 (GPLv2)</a>
+# @version 1.3
+from vsm.extensions.corpusbuilders import dir_corpus
+from vsm.extensions.interop.ldac import export_corpus
+import sys
+
+def corpus_script(path_corpus,path_output):
+	"""!
+	FunciÃ³n para construir los archivos del lda
+	
+	@author Jorge Redondo (jredondo at cenditel.gob.ve)
+	@copyright GNU/GPLv2
+	@param path_corpus Recibe la ruta donde esta ubicado el corpus
+	@param path_output Recibe la ruta de destino donde es secribirÃ¡n los archivos
+	"""
+	corpus_object = dir_corpus(path_corpus)
+	export_corpus(corpus=corpus_object, outfolder=path_output, context_type=corpus_object.context_types[0])
+
+if __name__ == '__main__':
+	if(len(sys.argv)>2):
+		path_corpus = sys.argv[1]
+		path_output = sys.argv[2]
+		corpus_script(path_corpus,path_output)
+	else:
+		print "Debe ingresar (2) argumentos a la funcion: path_corpus y path_output"
Index: utils/freeling.py
===================================================================
--- utils/freeling.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
+++ utils/freeling.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
@@ -0,0 +1,285 @@
+# -*- coding: utf-8 -*-
+"""
+Sistema de Modelado de TÃ³picos
+
+Copyleft (@) 2014 CENDITEL nodo MÃ©rida - https://planificacion.cenditel.gob.ve/trac/
+"""
+## @package django_topic_explorer.utils
+#
+# MÃ©todos utilizados para realizar el pre-procesamiento
+# @author Jorge Redondo (jredondo at cenditel.gob.ve)
+# @author <a href='http://www.cenditel.gob.ve'>Centro Nacional de Desarrollo e InvestigaciÃ³n en TecnologÃ­as Libres
+# (CENDITEL) nodo MÃ©rida - Venezuela</a>
+# @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versiÃ³n 2 (GPLv2)</a>
+# @version 1.3
+from subprocess import Popen, PIPE
+import shlex, os
+from codecs import open
+from nltk.corpus import stopwords
+import math, operator
+
+def files_to_lower(path_orig,path_dest):
+    """!
+    FunciÃ³n para convertir los archivos a sÃ³lo letras minusculas
+    
+    @author Jorge Redondo (jredondo at cenditel.gob.ve)
+    @copyright GNU/GPLv2
+    @param path_orig Ruta de Origen
+    @param path_dest Ruta de Destino
+    """
+    files = os.listdir(path_orig)
+    for file in files:
+        file_string = open(path_orig+file,'r','utf8').read()
+        f = open(path_dest+file,'w','utf8')
+        f.write(file_string.lower())
+        f.close()
+
+#os.environ['FREELINGSHARE'] = '/home/jredondo/Proyectos/Analisis_del_Discurso/src/freeling/share/freeling'
+
+#Ruta de la librerÃ­a del freeling
+os.environ['FREELINGSHARE'] = '/usr/local/share/freeling'
+def call_freeling(freeling_cmd,file_string):
+    """!
+    FunciÃ³n para llamar al proceso del freeling
+    
+    @author Jorge Redondo (jredondo at cenditel.gob.ve)
+    @copyright GNU/GPLv2
+    @param freeling_cmd Recibe el subproceso a ejecutar
+    @param file_string Recibe el contenido del archivo
+    @return output Retorna la salida del subproceso
+    """
+    p = Popen(freeling_cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+    output, err = p.communicate(file_string.encode('utf8'))
+    print output
+
+    if err < 0:
+        return "ERROR: FALLÃ EJECUCIÃN DE FREELING" 
+
+    return output
+
+def clean_words(w):
+    """!
+    FunciÃ³n para limpiar la palabra de caracteres molestos
+    
+    @author Jorge Redondo (jredondo at cenditel.gob.ve)
+    @copyright GNU/GPLv2
+    @param w Recibe la palabra
+    @return w Retorna la palabra limpia
+    """
+    w = w.encode('unicode-escape')
+    return w.replace(u'\xe0'.encode('unicode-escape'),u'a').replace(u'\xe8'.encode('unicode-escape'),u'e').replace(u'\xec'.encode('unicode-escape'),u'i').replace(u'\xf2'.encode('unicode-escape'),u'o').replace(u'\xfa'.encode('unicode-escape'),u'u').replace(u'\xe1'.encode('unicode-escape'),u'a').replace(u'\xe9'.encode('unicode-escape'),u'e').replace(u'\xed'.encode('unicode-escape'),u'i').replace(u'\xf3'.encode('unicode-escape'),u'o').replace(u'\xfa'.encode('unicode-escape'),u'u').replace(u'Ã¡',u'a').replace(u'Ã©',u'e').replace(u'Ã­',u'i').replace(u'Ã³',u'o').replace(u'Ãº',u'u').replace(u'Ã ',u'a').replace(u'Ãš',u'e').replace(u'Ã¬',u'i').replace(u'Ã²',u'o').replace(u'Ã¹',u'u').decode('unicode-escape')
+
+def is_pos(word,pos_list):
+    """!
+    FunciÃ³n para comparar si una palabra esta en una lista
+    
+    @author Jorge Redondo (jredondo at cenditel.gob.ve)
+    @copyright GNU/GPLv2
+    @param word Recibe la palabra
+    @param pos_list Recibe la lista con las palabras
+    @return Si la palabra esta en la lista retorna Verdadero, en caso contrario retorna Falso
+    """
+    for item in pos_list:
+        if word.startswith(item): return True
+    return False
+
+def complete_word(words_list,word):
+    indexes = [i for i,j in enumerate(words_list) if j == word]
+    if len(indexes) == 1: return word
+    if len(indexes) == 0: return word
+
+    index = 1
+    complete_word = word
+    i1 = indexes[0]
+    while True:
+        for i2 in indexes[1:]:
+            try:
+                if words_list[i1+index] != words_list[i2+index]:
+                    return complete_word
+            except IndexError:
+                return complete_word 
+        complete_word += '-' + words_list[i1+index]        
+        index += 1
+        if indexes[1] == i1+index or i1+index == len(words_list): 
+            return complete_word
+
+def all_complete_words(words_list):
+    """!
+    FunciÃ³n para remover STOPWORDS y caracteres no deseados
+    
+    @author Jorge Redondo (jredondo at cenditel.gob.ve)
+    @copyright GNU/GPLv2
+    @param words_list Recibe la lista de las palabras
+    @return Las palabras pre-procesadas
+    """
+    words_list = [w for w in words_list]
+    ret_val = []
+    c = ''.encode('utf8')
+    for w in words_list:
+        c_aux = complete_word(words_list,w)
+        if c_aux in c:
+            continue
+
+        c = c_aux
+        ret_val += [c]
+    return list(set(ret_val))
+
+
+
+def select_pos(path,words_fl,pos_list=['V','A','N','R','D','P','C','I','S']):
+    """!
+    FunciÃ³n que crea los corpus sin acentos y demÃ¡s excluye verbos, adjetivos, sutantivos, etc
+    
+    @author Jorge Redondo (jredondo at cenditel.gob.ve)
+    @copyright GNU/GPLv2
+    @param path Recibe la palabra
+    @param words_fl Recibe las palabras resultantes del freeling
+    @param pos_list Recibe los elementos a tomar en cuenta
+    @return output_list Retorna una lista con las palabras limpias (sin acentos)
+    """
+    output_list = []
+    all_words_list = []
+    for item in words_fl.split('\n'):
+        try:
+            w = item.split(' ')[0] 
+            cleaned_word = clean_words(w.decode('utf8'))
+            all_words_list += [cleaned_word]
+            if w.decode('utf8') not in stopwords.words('spanish') and is_pos(item.split(' ')[2],pos_list) and w not in '*+.,?Â¿!Â¡":;-=/$@#ââ()[]{}' and not w.isdigit() and len(w) > 3:
+                # Selecciona el lema
+                #output_list += [item.split(' ')[1]]
+                # Selecciona la palabra original
+                #output_list += [item.split(' ')[0]]
+                output_list += [cleaned_word]
+        except IndexError:
+            pass
+    na_file = open(path,'w','utf8')
+    na_file.write(' '.join(all_words_list))
+    na_file.close()
+    return output_list 
+
+def preprocess(corpus_path,do_fl=True,pos_list = ['V','A','N','R','D','P','C','I','S']):
+    """!
+    FunciÃ³n para realizar el pre-procesamiento
+    
+    @author Jorge Redondo (jredondo at cenditel.gob.ve)
+    @copyright GNU/GPLv2
+    @param corpus_path Recibe la ruta del corpus
+    @param do_fl Recibe la opcion del preprocesamiento (True si se quiere ejecutar, False en caso contrario)
+    @return ret_val Retorna un diccionario de los archivos preprocesados
+    @return set(corpus_words) Retorna un diccionario con las palabras del corpus preprocesados
+    """
+    freeling_corpus_path = corpus_path + '../freeling/'
+    no_accent_path = corpus_path + '../noaccent/'
+    ret_val = dict()
+    corpus_words = []
+    i = 0
+    for file in os.listdir(corpus_path):
+        file_string = open(corpus_path+file,'r','utf8').read()
+        if do_fl:
+            ## Comando por consola que ejecutarÃ¡ el freeling
+            freeling_cmd = shlex.split('/usr/local/bin/analyzer -f /usr/local/share/freeling/config/es.cfg',' ')
+            # LematizaciÃ³n con FREELING
+            words_fl = call_freeling(freeling_cmd,file_string)
+            fl_file = open(freeling_corpus_path+file,'w','utf8')
+            fl_file.write(words_fl.decode('utf-8'))
+            fl_file.close()
+        else:
+            words_fl = open(freeling_corpus_path+file,'r').read()
+        ####################################
+        ####################################
+        #'V', verbos
+        #'A', adjetivos
+        #'N', sustantivos
+        #'R', adverbios
+        #'D', determinantes
+        #'P', pronombres     
+        #'C', conjunciones
+        #'I', interjecciones
+        #'S', preposiciones
+        ####################################
+        ####################################
+
+        words_fl = select_pos(no_accent_path+file,words_fl=words_fl,pos_list=pos_list)
+
+        # Quitar STOPWORDS y caracteres no deseados
+        words_pp = all_complete_words(words_fl)
+        ret_val[file] = words_pp
+        corpus_words += words_pp
+        i += 1
+
+    return ret_val,set(corpus_words)
+
+def idf(file_words_pp,corpus_words):
+    idf = {}
+    num_docs = len(file_words_pp)
+    for w in corpus_words:
+        count = 0
+        for file,words in file_words_pp.items():
+            if w in words: count += 1
+        idf[w] = math.log(float(num_docs)/float(1+count))
+    return idf
+
+def generate_exluded_file(corpus_path,pp_corpus_path,file_words_pp,exclude_words):
+    """!
+    FunciÃ³n que generra el archivo de palabras excluidas
+    
+    @author Jorge Redondo (jredondo at cenditel.gob.ve)
+    @copyright GNU/GPLv2
+    @param corpus_path Recibe la ruta del corpus
+    @param pp_corpus_path Recibe la ruta de los archivos pre-procesados
+    @param file_words_pp Recibe los archivos pre-procesados
+    @param exclude_words Recibe la lista con las palabras excluidas
+    """
+    excluded = open(corpus_path+'excluded.txt','w','utf8')
+    added_files = []
+    repeated_count = 0
+    flag = False
+    for file,words_pp in file_words_pp.items():
+        # Excluir documentos repetidos
+        for aux_words_pp in added_files:
+            if words_pp == aux_words_pp:
+                repeated_count += 1
+                print "Repetido: " + file
+                flag = True
+                break
+        if flag:
+            flag = False
+            continue
+             
+        if len(words_pp) <= 50: continue
+        # Guardar archivo 
+        file_pp = open(pp_corpus_path+file,'w','utf8')
+        added_files.append(words_pp)
+        for w in words_pp:
+            if w not in exclude_words and not '_' in w:
+                file_pp.write(w + ' ')
+            else:
+                try:
+                    excluded.write(w.encode('utf8') + ' (' + file + ')\n')
+                except UnicodeDecodeError:
+                    excluded.write(w + ' (' + file + ')\n')
+        file_pp.close()
+    excluded.close()
+
+ 
+if __name__ == '__main__':
+    
+    ## Ruta donde se encuentra el corpus
+    corpus_path = '/home/rodrigo/Proyectos/Interpretacion/demo-data/corta/'
+    orig_corpus_path = corpus_path + 'orig/'
+    lower_corpus_path = corpus_path + 'lower/'
+    pp_corpus_path = corpus_path + 'pp/'
+    
+    ## Crea los archivos de puro minusculas
+    files_to_lower(orig_corpus_path,lower_corpus_path)
+    
+    ## Se realiza el pre-procesamiento
+    file_words_pp,corpus_words = preprocess(lower_corpus_path,do_fl=True,pos_list=['A','R','V','N'])
+    ## Palabras a excluir
+    exclude_words = ['descripcion','justificacion','construccion','desarrollo','comunidad','comunal','proyecto','prueblo','desarrollar','mismo','nacional','pueblo','sistema','aÃ±o','aÃ±os']
+    ## Se decodifican las Ã±
+    other_words = [x.decode('utf8') for x in exclude_words]
+    ## Se genera el archivo de vocabulario excluido
+    generate_exluded_file(corpus_path,pp_corpus_path,file_words_pp,other_words)
+   
+
Index: utils/json_data.py
===================================================================
--- utils/json_data.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
+++ utils/json_data.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
@@ -0,0 +1,89 @@
+# -*- coding: utf-8 -*-
+"""
+Sistema de Modelado de TÃ³picos
+
+Copyleft (@) 2014 CENDITEL nodo MÃ©rida - https://planificacion.cenditel.gob.ve/trac/
+"""
+## @package django_topic_explorer.utils
+#
+# MÃ©todos para el trato de json
+# @author Jorge Redondo (jredondo at cenditel.gob.ve)
+# @author <a href='http://www.cenditel.gob.ve'>Centro Nacional de Desarrollo e InvestigaciÃ³n en TecnologÃ­as Libres
+# (CENDITEL) nodo MÃ©rida - Venezuela</a>
+# @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versiÃ³n 2 (GPLv2)</a>
+# @version 1.3
+from utils import colorlib
+import itertools
+
+label = lambda x: x
+
+def populateJson(lda_v):
+    """!
+    FunciÃ³n para cargar un json
+
+    @author Jorge Redondo (jredondo at cenditel.gob.ve)
+    @copyright GNU/GPLv2
+    @param lda_v <b>{object}</b> Recibe el objeto del lda
+    @return Retorna un json
+    """
+    # populate entropy values
+    data = lda_v.topic_oscillations()
+
+    colors = [itertools.cycle(cs) for cs in zip(*colorlib.brew(3,n_cls=4))]
+    factor = len(data) / len(colors)
+
+    js = {}
+    for rank,topic_H in enumerate(data):
+        topic, H = topic_H
+        js[str(topic)] = {
+            "H" : H,
+            "color" : colors[min(rank / factor, len(colors)-1)].next()
+        }
+
+    # populate word values
+    data = lda_v.topics()
+    for i,topic in enumerate(data):
+        js[str(i)].update({'words' : dict([(w, p) for w,p in topic[:20]])})
+    return js
+
+
+def doc_json(lda_v,doc_id,N=40):
+    """!
+    FunciÃ³n para cargar los documentos y sus tÃ³picos en un json
+
+    @author Jorge Redondo (jredondo at cenditel.gob.ve)
+    @copyright GNU/GPLv2
+    @param lda_v <b>{object}</b> Recibe el objeto del lda
+    @param doc_id <b>{string}</b> Recibe el id del documento
+    @param N <b>{object}</b> Recibe la cantidad
+    @return Retorna un json
+    """
+    if doc_id!='null':
+        try:
+            if N > 0:
+                data = lda_v.dist_doc_doc(doc_id)[:N]
+            else:
+                data = lda_v.dist_doc_doc(doc_id)[N:]
+                data = reversed(data)
+            #data = docs_data(lda_v,doc_id,N)
+            docs = [doc for doc,prob in data]
+            doc_topics_mat = lda_v.doc_topics(docs)
+    
+            js = []
+            for doc_prob, topics in zip(data, doc_topics_mat):
+                doc, prob = doc_prob
+                js.append({'doc' : doc, 'label': label(doc), 'prob' : 1-prob,
+                    'topics' : dict([(str(t), p) for t,p in topics])})
+            return js
+        except:
+            import sys,traceback
+            exc_type, exc_value, exc_traceback = sys.exc_info()
+            print "*** print_tb:"
+            traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
+            print "*** print_exception:"
+            traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stdout)
+            return "error"
+    
+
+
+
Index: utils/lda/settings.txt
===================================================================
--- utils/lda/settings.txt	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
+++ utils/lda/settings.txt	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
@@ -0,0 +1,5 @@
+var max iter 20
+var convergence 1e-6
+em max iter 100
+em convergence 1e-4
+alpha estimate
Index: utils/ldac2vsm.py
===================================================================
--- utils/ldac2vsm.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
+++ utils/ldac2vsm.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
@@ -0,0 +1,143 @@
+from vsm.extensions.interop.ldac import import_corpus
+from vsm.extensions.corpusbuilders import dir_corpus
+from vsm.corpus import Corpus
+from vsm.model.ldacgsmulti import LdaCgsMulti
+from vsm.viewer.ldagibbsviewer import LDAGibbsViewer as LDAViewer
+
+from vsm.model.ldafunctions import *
+import math
+import numpy as np
+
+#path = '/home/rodrigo/Proyectos/Interpretacion/demo-data/data_ldac/test50'
+#path = '/home/jredondo/Proyectos/Analisis_del_Discurso/src/lda-blei/lda-c-dist/test15/'
+#corpus_file = '/home/jredondo/Proyectos/Analisis_del_Discurso/src/vsm2ldac/corpus.dat'
+#vocab_file = '/home/jredondo/Proyectos/Analisis_del_Discurso/src/vsm2ldac/vocab.txt'
+#corpus_dir = '/home/jredondo/Proyectos/Analisis_del_Discurso/src/topic-explorer/demo-data/corpus_propuestas/pp'
+#path = '/home/jredondo/Proyectos/Analisis_del_Discurso/src/lda-blei/lda-c-dist/output/'
+#corpus_file = '/home/jredondo/Proyectos/Analisis_del_Discurso/src/lda-blei/ap/ap.dat'
+#vocab_file = '/home/jredondo/Proyectos/Analisis_del_Discurso/src/lda-blei/ap/vocab.txt'
+path = '/home/rodrigo/Proyectos/Interpretacion/recursos/lda-blei/lda-c-dist/pruebas10/'
+corpus_file = '/home/rodrigo/Proyectos/Interpretacion/demo-data/prueba/lda/corpus.dat'
+vocab_file = '/home/rodrigo/Proyectos/Interpretacion/demo-data/prueba/lda/vocab.txt'
+corpus_dir = '/home/rodrigo/Proyectos/Interpretacion/demo-data/prueba/pp'
+
+def likelihood(path):
+  with open(path + 'likelihood.dat') as f:
+    lh = f.readlines()
+  return np.array([item.strip('\n').split('\t')[0] for item in lh],dtype=np.float)
+
+def beta(path):
+  b = []
+  with open(path + 'final.beta') as f:
+    for line in f:
+      b.append([math.exp(float(item)) for item in line.strip('\n').split()])
+      #b.append([10**float(item) for item in line.strip('\n').split()])
+  return b
+
+
+def alpha(path):
+  with open(path + 'final.other') as f:
+    a = f.readlines()
+  return float(a[2].split()[1])
+
+def word_assigments(path):
+  indices_tmp = []
+  z_tmp = []
+  with open(path + 'word-assignments.dat') as f:
+    for line in f:
+      indices_tmp += [int(line.strip('\n').split()[0])]
+      line_split = line.strip('\n').split()
+      z_tmp.append(line_split[1:len(line_split)])
+  indices = []
+  for i in xrange(len(indices_tmp)):
+    indices += [sum(indices_tmp[0:i+1])]
+
+  z = list(range(len(z_tmp)))
+  for i,doc in enumerate(z_tmp):
+    z[i] = [int(item.split(':')[1]) for item in doc]
+  
+  return z,indices
+
+def corpus(file):
+  with open(file) as f:
+    c = f.readlines()
+  indices_tmp = [int(item.strip('\n').split()[0]) for item in c]
+  indices = []
+  for i in xrange(len(indices_tmp)):
+    indices += [sum(indices_tmp[0:i+1])]
+
+  c_tmp = [item.strip('\n').split()[1:len(item.strip('\n').split())] for item in c]
+  c = list(range(len(c_tmp)))
+  for i,doc in enumerate(c_tmp):
+    c[i] = [int(item.split(':')[0]) for item in doc]
+
+  return c,indices
+
+def vocab(file):
+  with open(file) as f:
+    v = f.readlines()
+  return len(v)
+
+def alpha_list(z,path):
+  a = alpha(path)
+  a_list = []
+  for i in range(len(z)):
+    a_list += [a]
+  return a_list 
+
+
+def top_doc(path):
+  z,indices = word_assigments(path)
+  b = beta(path)
+  a_list = alpha_list(z,path)
+  return compute_top_doc(z, len(b), np.array(a_list))
+   
+def word_top(path):
+  c,indices = corpus()
+  z,indices = word_assigments(path)
+  b = beta(path)
+  v = vocab()
+  return compute_word_top(c, z, len(b), v, np.transpose(b))
+ 
+def log_prob(path): 
+  wt =  word_top(path)
+  td = top_doc(path)
+  c,indices = corpus()
+  z,indices = word_assigments(path)
+  return compute_log_prob(c, z, wt, td)
+ 
+def corpus_model(k_param,path,corpus_file,vocab_file,corpus_dir):
+  z,indices = word_assigments(path)
+  zeta = []
+  for item in z:
+    zeta.extend(item)
+  b = beta(path)
+  v = vocab(vocab_file)
+  a = alpha_list(z,path)
+  c = import_corpus(corpusfilename=corpus_file, vocabfilename=vocab_file, path=corpus_dir, context_type='propesta')
+  alpha = []
+
+  for i in range(len(b)):
+    alpha.append(a)
+  alpha = (np.array(alpha, dtype=np.float).reshape(len(alpha),len(alpha[0])))
+
+  b = (np.array(b, dtype=np.float).reshape(len(b[0]),len(b)))
+  m = LdaCgsMulti(corpus=c,
+                  context_type='propesta',
+                  #K=50,
+                  K=int(k_param),
+                  V=v,
+                  #alpha=alpha,
+                  #beta=b,
+                  Z=np.array(zeta))
+
+
+  return c,m 
+
+if __name__=='__main__':
+  print "******************** MAIN **********************"
+  #save_path = '/home/jredondo/Proyectos/Analisis_del_Discurso/src/topic-explorer/demo-data/corpus_propuestas/lda2vsm_models/'
+  save_path = '/home/rodrigo/Proyectos/Interpretacion/demo-data/prueba/models/'
+  c,m = corpus_model(50,path,corpus_file,vocab_file,corpus_dir)
+  c.save(save_path+'corpus.npz')
+  save_lda(m,save_path+'model.npz')
Index: utils/run_lda.py
===================================================================
--- utils/run_lda.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
+++ utils/run_lda.py	(revision 0ff122b697211e39002ab2e9b7ae219151b90c13)
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+"""
+Sistema de Modelado de TÃ³picos
+
+Copyleft (@) 2014 CENDITEL nodo MÃ©rida - https://planificacion.cenditel.gob.ve/trac/
+"""
+## @package django_topic_explorer.utils
+#
+# MÃ©todos para correr el lda
+# @author Rodrigo Boet (rboet at cenditel.gob.ve)
+# @author <a href='http://www.cenditel.gob.ve'>Centro Nacional de Desarrollo e InvestigaciÃ³n en TecnologÃ­as Libres
+# (CENDITEL) nodo MÃ©rida - Venezuela</a>
+# @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versiÃ³n 2 (GPLv2)</a>
+# @version 1.3
+from subprocess import Popen
+
+def call_lda(command):
+    """!
+    FunciÃ³n para llamar al proceso del LDA
+    
+    @author Rodrigo Boet (rboet at cenditel.gob.ve)
+    @copyright GNU/GPLv2
+    @date 09-02-2017
+    @param command Recibe el comando a ejecutar
+    @return output Retorna la salida del subproceso
+    """
+    print command
+    p = Popen(command)
+    
+    output, errs = p.communicate()
+
+    if errs < 0:
+        return "ERROR: FALLÃ EJECUCIÃN DE LDA" 
+    return output
+
+
+def generate_comand(base_dir,corpus_path,filename,topics_number):
+    """!
+    FunciÃ³n para generar los procesos del LDA
+    
+    @author Rodrigo Boet (rboet at cenditel.gob.ve)
+    @copyright GNU/GPLv2
+    @date 09-02-2017
+    @param base_dir Recibe la ruta base
+    @param corpus_path Recibe la ruta del corpus.dat
+    @param filename Recibe el nombre con el que se generarÃ¡ el directorio
+    @param topics_number Recibe el nÃºmero de tÃ³picos
+    """
+    settings_path = base_dir+'/utils/lda/settings.txt'
+    lda_exe = base_dir+'/utils/lda/lda'
+    name = filename.split("/")[-1]
+    filename = filename+"/lda/"+name
+    for i in range(1,topics_number+1):
+        command = "{0} est 0.1 {1} {2} {3} random {4}{1}".format(lda_exe,i*10,settings_path,corpus_path,filename)
+        call_lda(command.split(" "))
