示例#1
0
def handle_operation(context, phenotype: PhenotypeModel, define_name, final):
    print('operation')

    # SepsisState = PhenotypeOperations('SepsisState', 'OR', ['onVentilator', 'hasSepsis'], final=True)

    # : notOperator=(NOT | BANG) expression
    # | expression logicalOperator expression
    # | predicate IS NOT? BOOL
    expression_context = context.getChild(1)
    first = expression_context.getChild(0)

    res = None
    if type(first) == nlpql_parserParser.NotOperatorContext:
        res = get_not_expression(expression_context, define_name, final)
    elif type(first) == nlpql_parserParser.ExpressionContext:
        res = get_logical_expression(expression_context, define_name, final)
    elif type(first) == nlpql_parserParser.PredicateBooleanContext:
        res = get_predicate_boolean(expression_context, define_name, final)
    elif type(first) == nlpql_parserParser.PredicateContext:
        res = get_predicate_expression(expression_context.getChild(0),
                                       define_name, final)

    if not phenotype.operations:
        phenotype.operations = list()

    if res:
        phenotype.operations.append(res)
示例#2
0
def handle_operation(context, phenotype: PhenotypeModel, define_name, final):
    print('operation')

    # SepsisState = PhenotypeOperations('SepsisState', 'OR', ['onVentilator', 'hasSepsis'], final=True)

    # : notOperator=(NOT | BANG) expression
    # | expression logicalOperator expression
    # | predicate IS NOT? BOOL
    expression_context = context.getChild(1)
    first = expression_context.getChild(0)

    res = None
    if type(first) == nlpql_parserParser.NotOperatorContext:
        res = get_not_expression(expression_context, define_name, final)
    elif type(first) == nlpql_parserParser.ExpressionContext:
        res = get_logical_expression(expression_context, define_name, final)
    elif type(first) == nlpql_parserParser.PredicateBooleanContext:
        res = get_predicate_boolean(expression_context, define_name, final)
    elif type(first) == nlpql_parserParser.PredicateContext:
        res = get_predicate_expression(expression_context.getChild(0), define_name, final)

    if not phenotype.operations:
        phenotype.operations = list()

    if res:
        phenotype.operations.append(res)
示例#3
0
def handle_tuple(context, phenotype: PhenotypeModel, define_name, final):
    log('tuple')

    obj = get_obj_context(context.getChild(0).getChild(1), to_string=True)
    num_children = len(context.children)
    op_raw_text = ''
    tuple_name = '{}_Step1'.format(define_name)
    if num_children == 2:
        operation = parse_operation(context.getChild(1), tuple_name, final)
        if operation:
            if not phenotype.operations:
                phenotype.operations = list()
            phenotype.operations.append(operation)
            op_raw_text = operation.get('raw_text')

    else:
        operation = None

    raw_text = '''
        Tuple {}
        {}
    '''

    if not operation:
        where = ''
    else:
        where = 'where {}'.format(op_raw_text)
    tuple_str = json.dumps(obj, indent=4)
    pe = PhenotypeEntity(tuple_name, 'define', final=final, tuple_=True, tuple_object=obj, tuple_predicate=operation,
                         raw_text=raw_text.format(tuple_str, where), tuple_raw_text='Tuple {}'.format(tuple_str))

    if not phenotype.tuples:
        phenotype.tuples = list()

    phenotype.tuples.append(pe)
示例#4
0
def handle_operation(context, phenotype: PhenotypeModel, define_name, final):
    log('operation')

    # SepsisState = PhenotypeOperations('SepsisState', 'OR', ['onVentilator', 'hasSepsis'], final=True)

    # : notOperator=(NOT | BANG) expression
    # | expression logicalOperator expression
    # | predicate IS NOT? BOOL

    res = parse_operation(context, define_name, final)
    if not phenotype.operations:
        phenotype.operations = list()

    if res:
        phenotype.operations.append(res)