Пример #1
0
def get_fev1fvc(sentence):
    fev1fvc_list = []
    # Running a loop on the range in which fev1/fvc value could be found.
    # Includes ratios both exprecessed as percent and decimal, > 100% is for predicted values
    for x,y in [(0,2),(10,180)]:
        fev1_fvc = ve.run("fev1/fvc", sentence, x, y)

        if json.loads(fev1_fvc)['querySuccess']:
            for i in range(json.loads(fev1_fvc)['measurementCount']):
                fev1fvc_dict = {}
                fev1fvc_dict['type'] = "fev1_fvc_ratio"
                fev1fvc_dict['text'] = json.loads(fev1_fvc)['measurementList'][i]['text']
                fev1fvc_dict['condition'] = json.loads(fev1_fvc)['measurementList'][i]['condition']
                fev1fvc_dict['x'] = json.loads(fev1_fvc)['measurementList'][i]['x']
                fev1fvc_dict['y'] = json.loads(fev1_fvc)['measurementList'][i]['y']

                clean_text = json.loads(fev1_fvc)['measurementList'][i]['text'].replace(')','').replace('(','')
                sentence = sentence.replace(')','').replace('(','')

                fev1_fvc_units = re.findall(clean_text+r'\s?(%)?',sentence)[0]
                if fev1_fvc_units == '%':
                    fev1_fvc_units = re.findall(clean_text+r'\s?(% ?pred|% ?of ?pred| ?%)',sentence)[0]
                if fev1_fvc_units == '':
                    fev1_fvc_units = ve.EMPTY_FIELD
                fev1fvc_dict['units'] = fev1_fvc_units
                fev1fvc_list.append(fev1fvc_dict)
        else:
            None
    return fev1fvc_list
Пример #2
0
def get_fev1(sentence):
    fev1_list = []
    # Includes values in ml, l and % predicted
    for x,y in [(0,6),(20,190),(300,6000)]:
        fev1 = ve.run("fev1", sentence, x, y)

        if json.loads(fev1)['querySuccess']:
            for i in range(json.loads(fev1)['measurementCount']):
                fev1_dict = {}
                fev1_dict['type'] = "fev1"
                fev1_dict['text'] = json.loads(fev1)['measurementList'][i]['text']
                fev1_dict['condition'] = json.loads(fev1)['measurementList'][i]['condition']
                fev1_dict['x'] = json.loads(fev1)['measurementList'][i]['x']
                fev1_dict['y'] = json.loads(fev1)['measurementList'][i]['y']

                clean_text = json.loads(fev1)['measurementList'][i]['text'].replace(')','').replace('(','')
                sentence = sentence.replace(')','').replace('(','')

                fev1_units = re.findall( clean_text +r'\s?(ml|cc|l|L|ML|CC|%)?',sentence)[0]
                if fev1_units == '%':
                    fev1_units = re.findall( clean_text +r'\s?(% ?predicted|% ?of ?predicted|% ?pred|% ?of ?pred| ?%)',sentence)[0]
                if fev1_units == '':
                    fev1_units = ve.EMPTY_FIELD
                fev1_dict['units'] = fev1_units
                fev1_list.append(fev1_dict)
        else:
            None
    return fev1_list
Пример #3
0
def _compare_results(term_string,
                     test_data,
                     minval,
                     maxval,
                     enumlist=None,
                     is_case_sensitive=False,
                     denom_only=False,
                     values_before_terms=False):
    """
    Run the value extractor on the test data using the supplied term string
    and check the results.
    """

    for sentence, expected_list in test_data.items():

        # run value extractor on the next test sentence
        json_result = ve.run(term_string,
                             sentence,
                             minval,
                             maxval,
                             str_enumlist=enumlist,
                             is_case_sensitive=is_case_sensitive,
                             is_denom_only=denom_only,
                             values_before_terms=values_before_terms)

        num_expected = len(expected_list)

        is_mismatched = False
        if 0 == num_expected and ve.EMPTY_RESULT == json_result:
            # expected not to find anything and actually did not
            continue
        elif num_expected > 0 and ve.EMPTY_RESULT == json_result:
            is_mismatched = True

        value_result = None
        if not is_mismatched:
            # load the json result and decode as a ValueResult namedtuple
            result_data = json.loads(json_result)
            value_result = ve.ValueResult(**result_data)

        # check that len(computed) == len(expected)
        if is_mismatched or (value_result.measurementCount != num_expected):
            print('\tMismatch in computed vs. expected results: ')
            print('\tSentence: {0}'.format(sentence))
            print('\tComputed: ')
            if value_result is None:
                print('\t\tNone')
            else:
                for m in value_result.measurementList:
                    print('\t\t{0}'.format(m))
            print('\tExpected: ')
            for e in expected_list:
                print('\t\t{0}'.format(e))

            return False

        # check fields
        failures = []
        for i, value in enumerate(value_result.measurementList):

            computed = value['matchingTerm']
            expected = expected_list[i].term
            failures = _compare_fields('matching term', computed, expected,
                                       failures)

            computed = value['x']
            expected = expected_list[i].x
            failures = _compare_fields('x', computed, expected, failures)

            computed = value['y']
            expected = expected_list[i].y
            failures = _compare_fields('y', computed, expected, failures)

            computed = value['condition']
            expected = expected_list[i].condition
            failures = _compare_fields('condition', computed, expected,
                                       failures)

        if len(failures) > 0:
            print(sentence)
            for f in failures:
                print(f)
            return False

    return True