#NEWLINE# def __loadDataFromES( self , dataType , domain ) : #NEWLINE# #INDENT# table = None #NEWLINE# if ( dataType != 'train' ) : #NEWLINE# #INDENT# table = orange . ExampleTable ( domain ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# attributes = map ( self . __getOrangeVariableForFeature , self . features ) #NEWLINE# classAttribute = orange . EnumVariable ( 'is_good' , values = [ '0' , '1' ] ) #NEWLINE# domain = orange . Domain ( attributes , attr ) #NEWLINE# domain . addmeta ( orange . newmetaid ( ) , orange . StringVariable ( 'phrase' ) ) #NEWLINE# table = orange . ExampleTable ( domain ) #NEWLINE# #UNINDENT# phrases = [ ] #NEWLINE# if ( dataType == 'train' ) : #NEWLINE# #INDENT# phrasesCount = self . esClient . count ( index = self . processorIndex , doc_type = self . processorPhraseType , body = { #NEWLINE# #INDENT# 'query' : { #NEWLINE# #INDENT# 'terms' : { #NEWLINE# #INDENT# 'is_training' : [ '1' , '0' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# size = phrasesCount [ 'count' ] #NEWLINE# phrases = self . esClient . search ( index = self . processorIndex , doc_type = self . processorPhraseType , body = { #NEWLINE# #INDENT# 'query' : { #NEWLINE# #INDENT# 'terms' : { #NEWLINE# #INDENT# 'is_training' : [ '1' , '0' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , size = size ) #NEWLINE# phrases = phrases [ 'hits' ] [ 'hits' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dataType == 'holdout' ) : #NEWLINE# #INDENT# phraseCount = self . esClient . count ( index = self . processorIndex , doc_type = self . processorPhraseType , body = { #NEWLINE# #INDENT# 'query' : { #NEWLINE# #INDENT# 'terms' : { #NEWLINE# #INDENT# 'is_holdout' : [ '1' , '0' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# size = phrasesCount [ 'count' ] #NEWLINE# phrases = self . esClient . search ( index = self . processorIndex , doc_type = self . processorPhraseType , body = { #NEWLINE# #INDENT# 'query' : { #NEWLINE# #INDENT# 'terms' : { #NEWLINE# #INDENT# 'is_holdout' : [ '1' , '0' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , size = size ) #NEWLINE# phrases = phrases [ 'hits' ] [ 'hits' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . phraseData = self . esClient . get ( index = self . processorIndex , doc_type = self . processorPhraseType , id = self . phraseId ) #NEWLINE# phrases = [ self . phraseData ] #NEWLINE# #UNINDENT# #UNINDENT# for row in phrases : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# row = row [ '_source' ] #NEWLINE# featureValues = [ ] #NEWLINE# classType = '?' #NEWLINE# for feature in self . features : #NEWLINE# #INDENT# featureValues . append ( row [ 'features' ] [ feature [ 'name' ] ] . encode ( 'ascii' ) ) #NEWLINE# #UNINDENT# if ( dataType == 'train' ) : #NEWLINE# #INDENT# classType = row [ 'is_training' ] . encode ( 'ascii' , 'ignore' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dataType == 'holdout' ) : #NEWLINE# #INDENT# classType = row [ 'is_holdout' ] . encode ( 'ascii' ) #NEWLINE# #UNINDENT# #UNINDENT# example = None #NEWLINE# for ( i , featureValue ) in enumerate ( featureValues ) : #NEWLINE# #INDENT# attr = domain . attributes [ i ] #NEWLINE# if ( type ( attr ) is orange . EnumVariable ) : #NEWLINE# #INDENT# attr . addValue ( featureValue ) #NEWLINE# #UNINDENT# #UNINDENT# example = orange . Example ( domain , ( featureValues + [ classType ] ) ) #NEWLINE# example [ domain . getmetas ( ) . items ( ) [ 0 ] [ 0 ] ] = row [ 'phrase' ] . encode ( 'ascii' ) #NEWLINE# table . append ( example ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# self . logger . error ( ( ( "Error classifying phrase '" + row [ 'phrase' ] ) + "'" ) ) #NEWLINE# #UNINDENT# #UNINDENT# return table