Commit 72fbc6dc authored by matjaz's avatar matjaz

Latino package improved and debugged (now it works from start to show vocabulary table widget)

parent 387a3274
This diff is collapsed.
import logging
import os
import sys
from settings import package_root
from settings import PACKAGE_ROOT
#------------------------------------------------------------------------------
# prepare environment for loading latino (Python.net interpreter should be used)
# see: http://pythonnet.sourceforge.net/
#------------------------------------------------------------------------------
sys.path.append(os.path.join(package_root, 'bin'))
sys.path.append(os.path.join(PACKAGE_ROOT, 'bin'))
try:
import System
import Latino
from LatinoCloudFlows import *
from LatinoClowdFlows import *
except Exception:
logging.warning("DotNet assemblies could not be loaded! Probable reasons: missing dlls or wrong interpreter (see http://pythonnet.sourceforge.net). "
"Other functionality of ClowdFlows (besides .Net assemblies) should be OK!")
......
......@@ -5,6 +5,26 @@
from serialization_utils import *
from import_dotnet import *
def sentiment_analysis_con_cat(inputDict):
_str1 = ToString(inputDict['str1'])
_str2 = ToString(inputDict['str2'])
execResult = SentimentAnalysisCF.ConCat(_str1, _str2)
execResultPy = ToPyObj(execResult)
outputDict = {}
outputDict['out'] = execResultPy
return outputDict
def sentiment_analysis_ena_cudna_funk(inputDict):
_str1 = ToString(inputDict['str1'])
_str2 = ToString(inputDict['str2'])
_str3 = ToString(inputDict['str3'])
_str4 = ToString(inputDict['str4'])
execResult = SentimentAnalysisCF.EnaCudnaFunk(_str1, _str2, _str3, _str4)
execResultPy = ToPyObj(execResult)
outputDict = {}
outputDict['out'] = execResultPy
return outputDict
def latino_flatten_object_to_string_array(inputDict):
_data = ToNetObj(inputDict['data'])
execResult = LatinoCF.FlattenObjectToStringArray(_data)
......@@ -270,7 +290,7 @@ def latino_construct_snowball_stemmer(inputDict):
return outputDict
def latino_construct_stop_words_tagger(inputDict):
_stopWords = ToString(inputDict['stopWords'])
_stopWords = ToNetObj(inputDict['stopWords'])
_ignoreCase = ToBool(inputDict['ignoreCase'])
execResult = LatinoCF.ConstructStopWordsTagger(_stopWords, _ignoreCase)
execResultPy = ToPyObj(execResult)
......@@ -341,7 +361,7 @@ def latino_tag_string_stopwords(inputDict):
outputDict['string'] = execResultPy
return outputDict
def latino_construct_bow_space(inputDict):
def latino_construct_bow_space_1(inputDict):
_documents = ToNetObj(inputDict['documents'])
_tokenizer = ToNetObj(inputDict['tokenizer'])
_stemmer = ToNetObj(inputDict['stemmer'])
......@@ -358,7 +378,7 @@ def latino_construct_bow_space(inputDict):
outputDict['ds'] = execResultPy['ds']
return outputDict
def latino_construct_bow_space(inputDict):
def latino_construct_bow_space_2(inputDict):
_adc = ToNetObj(inputDict['adc'])
_tokenId = ToString(inputDict['tokenId'])
_stemId = ToString(inputDict['stemId'])
......@@ -473,7 +493,7 @@ def latino_sparse_matrix_to_table(inputDict):
def latino_construct_kmeans_clusterer(inputDict):
_k = ToInt(inputDict['k'])
_centroidType = ToEnum(Latino.Model.CentroidType, inputDict['centroidType'], Latino.Model.CentroidType.NrmL2)
_similarityModel = ToEnum(LatinoCloudFlows.SimilarityModel, inputDict['similarityModel'], LatinoCloudFlows.SimilarityModel.Cosine)
_similarityModel = ToEnum(LatinoClowdFlows.SimilarityModel, inputDict['similarityModel'], LatinoClowdFlows.SimilarityModel.Cosine)
_randomSeed = ToInt(inputDict['randomSeed'])
_eps = ToFloat(inputDict['eps'])
_trials = ToInt(inputDict['trials'])
......@@ -521,7 +541,7 @@ def latino_clustering_results_info(inputDict):
return outputDict
def latino_construct_centroid_classifier(inputDict):
_similarityModel = ToEnum(LatinoCloudFlows.SimilarityModel, inputDict['similarityModel'], LatinoCloudFlows.SimilarityModel.Cosine)
_similarityModel = ToEnum(LatinoClowdFlows.SimilarityModel, inputDict['similarityModel'], LatinoClowdFlows.SimilarityModel.Cosine)
_normalizeCentorids = ToBool(inputDict['normalizeCentorids'])
execResult = LatinoCF.ConstructCentroidClassifier(_similarityModel, _normalizeCentorids)
execResultPy = ToPyObj(execResult)
......@@ -596,7 +616,7 @@ def latino_construct_maximum_entropy_classifier_fast(inputDict):
return outputDict
def latino_construct_knn_classifier(inputDict):
_similarityModel = ToEnum(LatinoCloudFlows.SimilarityModel, inputDict['similarityModel'], LatinoCloudFlows.SimilarityModel.Cosine)
_similarityModel = ToEnum(LatinoClowdFlows.SimilarityModel, inputDict['similarityModel'], LatinoClowdFlows.SimilarityModel.Cosine)
_k = ToInt(inputDict['k'])
_softVoting = ToBool(inputDict['softVoting'])
execResult = LatinoCF.ConstructKnnClassifier(_similarityModel, _k, _softVoting)
......
......@@ -276,7 +276,10 @@ def ToPyObj(data):
l.append(ToPyObj(val))
return tuple(l)
if hasattr(data, "GetType"):
for interface in data.GetType().GetInterfaces():
type = data.GetType()
if type.IsArray:
return [ToPyObj(x) for x in data]
for interface in type.GetInterfaces():
if interface.Name == u'ISerializable':
return LSO(data)
return data
......@@ -34,5 +34,5 @@ def advanced_object_viewer(request,input_dict,output_dict,widget):
def show_table(request,input_dict,output_dict,widget):
tbl= input_dict['tbl']
output_dict = {'attrs':list(tbl.items()[0][0]), 'metas':[], 'data':tbl.values()[0], 'title':'Vocabulary Table'}
output_dict = {'attrs':list(tbl.items()[0][0]), 'metas':[], 'data':(((None, v) for v in inst) for inst in tbl.values()[0]), 'title':'Vocabulary Table'}
return render(request, 'visualizations/table_viewer.html',{'widget':widget,'input_dict':input_dict,'output_dict':output_dict})
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment