Speech2TextPrototype/Repositories/LookupTableRepository.cs
/// <summary>
/// MAIN FUNCTION
/// Query the database based on the natural language tokens received from the Python NLTK api
/// </summary>
/// <param name="res">Python Tokenizer Response</param>
/// <returns>Tuple containing: the table response, the list of measurables, the list of dates and the query as a string</returns>
MAIN FUNCTION
Query the database based on the natural language tokens received from the Python NLTK api
MAIN FUNCTION Query the database based on the natural language tokens received from the Python NLTK api
public SqlAnswer token2Sql(PyRes res)
        {
            string[] tokens = res.tokens;
            string[] bigrams = res.bigrams;
            BigramLookup(bigrams);
            tokens = DeleteKnownTokens(tokens);
            TokenLookup(tokens);
            string query = ConstructQuery();
            double scalar = -1;
            if (!String.IsNullOrEmpty(aggregateFunction))
                {
                var result = _context.tdata.FromSqlRaw(query).ToList();
                Type type = typeof(TData);
                switch (aggregateFunction)
                {
                    case "max":
                        scalar = Convert.ToDouble(result.ToList().Max(r => type.GetProperty(listMeasures[0]).GetValue(r)));
                        break;
                    case "min":
                        scalar = Convert.ToDouble(result.ToList().Min(r => type.GetProperty(listMeasures[0]).GetValue(r)));
                        break;
                    case "sum":
                        scalar = result.ToList().Sum(r => Convert.ToDouble(type.GetProperty(listMeasures[0]).GetValue(r)));
                        break;
                    case "avg":
                        scalar = result.ToList().Average(r => Convert.ToDouble(type.GetProperty(listMeasures[0]).GetValue(r)));
                        break;
                }
                return new SqlAnswer { measures = listMeasures, sqlQuery = query, scalar = scalar };
            }
            return new SqlAnswer { measures = listMeasures, sqlQuery = query, scalar = scalar };
        }
public SqlAnswer token2Sql ( PyRes res ) { string [ ] tokens = res . tokens ; string [ ] bigrams = res . bigrams ; BigramLookup ( bigrams ) ; tokens = DeleteKnownTokens ( tokens ) ; TokenLookup ( tokens ) ; string query = ConstructQuery ( ) ; double scalar = - 1 ; if ( ! String . IsNullOrEmpty ( aggregateFunction ) ) { var result = _context . tdata . FromSqlRaw ( query ) . ToList ( ) ; Type type = typeof ( TData ) ; switch ( aggregateFunction ) { case " " : scalar = Convert . ToDouble ( result . ToList ( ) . Max ( r => type . GetProperty ( listMeasures [ 0 ] ) . GetValue ( r ) ) ) ; break ; case " " : scalar = Convert . ToDouble ( result . ToList ( ) . Min ( r => type . GetProperty ( listMeasures [ 0 ] ) . GetValue ( r ) ) ) ; break ; case " " : scalar = result . ToList ( ) . Sum ( r => Convert . ToDouble ( type . GetProperty ( listMeasures [ 0 ] ) . GetValue ( r ) ) ) ; break ; case " " : scalar = result . ToList ( ) . Average ( r => Convert . ToDouble ( type . GetProperty ( listMeasures [ 0 ] ) . GetValue ( r ) ) ) ; break ; } return new SqlAnswer { measures = listMeasures , sqlQuery = query , scalar = scalar } ; } return new SqlAnswer { measures = listMeasures , sqlQuery = query , scalar = scalar } ; }
MAIN FUNCTION
Query the database based on the natural language tokens received from the Python NLTK api
MAIN FUNCTION Query the database based on the natural language tokens received from the Python NLTK api
// Check for scalar values (Max, Sum, etc.) // Uses reflection for the measurable to avoid numerous if statements (x3 code)
Tuple containing: the table response, the list of measurables, the list of dates and the query as a string
Tuple containing : the table response the list of measurables the list of dates and the query as a string
res
PyRes
Python Tokenizer Response
Python Tokenizer Response