Source code for core.query

# -*- coding: utf-8 -*-
"""
Provide the base-level search class (layer 0) to fetch values from the database \
and store them into a class

:example:
    a = search('S_ut > 500 MPa AND S_y < 400 MPa AND normalized OR temper | MED:S_y') 
    print(a.unique_result['S_ut'])
:return:  a list of relevant results. Each result is a dictionary containing \
the properties. If an optimization keyword was given, the object self.unique_result \
return the best matching result of the list.

Usage :

*    the syntax is similar to Google search
*    text parameters are fetched in all text properties (name, category, etc.)
*    to retrieve numeric values for properties, use a SQL syntax such as PROPERTY =<> value
*    give every value with its unit
*    if you want only one result, give an optimization keyword with the property to optimize\
like :  | KEYWORD : parameter. 
"""

import os
import re
import sqlite3
import sys

from lib import aliases

CURRENT_PATH = os.path.dirname(os.path.abspath(__file__))
PARENT_PATH = os.path.dirname(CURRENT_PATH)
sys.path.append(PARENT_PATH)



        # TODO! add units

if __name__ == '__main__':
    # Debug stuff
    q_string = 'S_ut > 500 MPa AND S_y < 400 MPa AND normalized OR temper | MED:S_y'
    a = search(q_string)
    
    for item in a.results:
        print(item['category'], item['name'],item['S_ut'], item['S_y'], item['treatment'])
        
    print(a.condition)
    print(a.unique_result)